diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2015-04-06 13:16:24 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2015-04-06 13:16:24 -0500 |
commit | 4438c3a50d4c10d7516d736cb31ded01c57c791e (patch) | |
tree | 646150852f6f796f41db56e7dcf82f128b0c49b8 /src | |
parent | af81477b2f5d4ffc76c51c72bd3ac89a4c4cac64 (diff) | |
download | ayatana-indicator-datetime-4438c3a50d4c10d7516d736cb31ded01c57c791e.tar.gz ayatana-indicator-datetime-4438c3a50d4c10d7516d736cb31ded01c57c791e.tar.bz2 ayatana-indicator-datetime-4438c3a50d4c10d7516d736cb31ded01c57c791e.zip |
in DateTime class, make it harder to accidentally mix local and nonlocal timezones by replacing DateTime::DateTime(time_t) with two methods, DateTime::Local(time_t) and DateTime(GTimeZone*, time_t)
Diffstat (limited to 'src')
-rw-r--r-- | src/date-time.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/date-time.cpp b/src/date-time.cpp index 54601d0..4930bf6 100644 --- a/src/date-time.cpp +++ b/src/date-time.cpp @@ -65,13 +65,13 @@ DateTime& DateTime::operator+=(const std::chrono::seconds& seconds) return (*this = add_full(0, 0, 0, 0, 0, seconds.count())); } -DateTime::DateTime(time_t t) +DateTime::DateTime(GTimeZone* gtz, time_t t) { - auto gtz = g_time_zone_new_local(); - auto gdt = g_date_time_new_from_unix_local(t); + auto utc = g_date_time_new_from_unix_utc(t); + auto gdt = g_date_time_to_timezone (utc, gtz); reset(gtz, gdt); - g_time_zone_unref(gtz); g_date_time_unref(gdt); + g_date_time_unref(utc); } DateTime DateTime::NowLocal() @@ -84,6 +84,16 @@ DateTime DateTime::NowLocal() return dt; } +DateTime DateTime::Local(time_t t) +{ + auto gtz = g_time_zone_new_local(); + auto gdt = g_date_time_new_from_unix_local(t); + DateTime dt(gtz, gdt); + g_time_zone_unref(gtz); + g_date_time_unref(gdt); + return dt; +} + DateTime DateTime::Local(int year, int month, int day, int hour, int minute, double seconds) { auto gtz = g_time_zone_new_local(); |