From 8c7daeeb87abd0be1b96169da18baf018c4859c9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 3 Apr 2015 13:11:39 -0500 Subject: add the new Alarm class as an argument to the alarm queue class --- src/date-time.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/date-time.cpp') diff --git a/src/date-time.cpp b/src/date-time.cpp index 689688c..ecfc971 100644 --- a/src/date-time.cpp +++ b/src/date-time.cpp @@ -55,6 +55,16 @@ DateTime& DateTime::operator=(const DateTime& that) return *this; } +DateTime& DateTime::operator+=(const std::chrono::minutes& minutes) +{ + return (*this = add_full(0, 0, 0, 0, minutes.count(), 0)); +} + +DateTime& DateTime::operator+=(const std::chrono::seconds& seconds) +{ + return (*this = add_full(0, 0, 0, 0, 0, seconds.count())); +} + DateTime::DateTime(time_t t) { auto gtz = g_time_zone_new_local(); -- cgit v1.2.3 From 32de6c5e866527c03e015f2c691837ea7800290e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 5 Apr 2015 18:26:37 -0500 Subject: make DateTime::is_same_day() faster --- src/date-time.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/date-time.cpp') diff --git a/src/date-time.cpp b/src/date-time.cpp index ecfc971..54601d0 100644 --- a/src/date-time.cpp +++ b/src/date-time.cpp @@ -254,10 +254,12 @@ bool DateTime::is_same_day(const DateTime& a, const DateTime& b) if (!a.m_dt || !b.m_dt) return false; - const auto adt = a.get(); - const auto bdt = b.get(); - return (g_date_time_get_year(adt) == g_date_time_get_year(bdt)) - && (g_date_time_get_day_of_year(adt) == g_date_time_get_day_of_year(bdt)); + int ay, am, ad; + int by, bm, bd; + g_date_time_get_ymd(a.get(), &ay, &am, &ad); + g_date_time_get_ymd(b.get(), &by, &bm, &bd); + + return (ay==by) && (am==bm) && (ad==bd); } bool DateTime::is_same_minute(const DateTime& a, const DateTime& b) -- cgit v1.2.3 From 4438c3a50d4c10d7516d736cb31ded01c57c791e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 6 Apr 2015 13:16:24 -0500 Subject: 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) --- src/date-time.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/date-time.cpp') 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(); -- cgit v1.2.3