Mercurial > minori
diff src/time.cpp @ 6:1d82f6e04d7d
Update: add first parts to the settings dialog
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 16 Aug 2023 00:49:17 -0400 |
parents | 23d0d9319a00 |
children |
line wrap: on
line diff
--- a/src/time.cpp Sat Aug 12 13:10:34 2023 -0400 +++ b/src/time.cpp Wed Aug 16 00:49:17 2023 -0400 @@ -1,64 +1,64 @@ -#include "time_utils.h" -#include <string> -#include <cstdint> -#include <cmath> -#include <ctime> -#include <cassert> - -namespace Time { - -Duration::Duration(int64_t l) { - length = l; -} - -std::string Duration::AsRelativeString() { - std::string result; - - auto get = [](int64_t val, const std::string& s, const std::string& p) { - return std::to_string(val) + " " + (val == 1 ? s : p); - }; - - if (InSeconds() < 60) - result = get(InSeconds(), "second", "seconds"); - else if (InMinutes() < 60) - result = get(InMinutes(), "minute", "minutes"); - else if (InHours() < 24) - result = get(InHours(), "hour", "hours"); - else if (InDays() < 28) - result = get(InDays(), "day", "days"); - else if (InDays() < 365) - result = get(InDays()/30, "month", "months"); - else - result = get(InDays()/365, "year", "years"); - - if (length < 0) - result = "In " + result; - else - result += " ago"; - - return result; -} - -int64_t Duration::InSeconds() { - return length; -} - -int64_t Duration::InMinutes() { - return std::llround((double)length / 60.0); -} - -int64_t Duration::InHours() { - return std::llround((double)length / 3600.0); -} - -int64_t Duration::InDays() { - return std::llround((double)length / 86400.0); -} - -int64_t GetSystemTime() { - assert(sizeof(int64_t) >= sizeof(time_t)); - time_t t = std::time(nullptr); - return *reinterpret_cast<int64_t*>(&t); -} - +#include "time_utils.h" +#include <string> +#include <cstdint> +#include <cmath> +#include <ctime> +#include <cassert> + +namespace Time { + +Duration::Duration(int64_t l) { + length = l; +} + +std::string Duration::AsRelativeString() { + std::string result; + + auto get = [](int64_t val, const std::string& s, const std::string& p) { + return std::to_string(val) + " " + (val == 1 ? s : p); + }; + + if (InSeconds() < 60) + result = get(InSeconds(), "second", "seconds"); + else if (InMinutes() < 60) + result = get(InMinutes(), "minute", "minutes"); + else if (InHours() < 24) + result = get(InHours(), "hour", "hours"); + else if (InDays() < 28) + result = get(InDays(), "day", "days"); + else if (InDays() < 365) + result = get(InDays()/30, "month", "months"); + else + result = get(InDays()/365, "year", "years"); + + if (length < 0) + result = "In " + result; + else + result += " ago"; + + return result; +} + +int64_t Duration::InSeconds() { + return length; +} + +int64_t Duration::InMinutes() { + return std::llround((double)length / 60.0); +} + +int64_t Duration::InHours() { + return std::llround((double)length / 3600.0); +} + +int64_t Duration::InDays() { + return std::llround((double)length / 86400.0); +} + +int64_t GetSystemTime() { + assert(sizeof(int64_t) >= sizeof(time_t)); + time_t t = std::time(nullptr); + return *reinterpret_cast<int64_t*>(&t); +} + } \ No newline at end of file