From aad7e86a109aeec75b3772cda20478363f966745 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 14:28:20 -0600 Subject: Alarms is going to need to know when the clock's minute changes. We already have a timer for that in Formatter, so move it from there to Clock and add a corresponding public signal Clock.minuteChanged that both Formatter and Alarms can use. Sync unit tests. --- src/date-time.cpp | 65 +++++++++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 40 deletions(-) (limited to 'src/date-time.cpp') diff --git a/src/date-time.cpp b/src/date-time.cpp index 3842ac0..40c638f 100644 --- a/src/date-time.cpp +++ b/src/date-time.cpp @@ -76,11 +76,6 @@ int64_t DateTime::to_unix() const return g_date_time_to_unix(get()); } -int DateTime::day_of_year() const -{ - return m_dt ? g_date_time_get_day_of_year(get()) : -1; -} - void DateTime::reset(GDateTime* in) { if (in) @@ -95,39 +90,6 @@ void DateTime::reset(GDateTime* in) } } -#if 0 -DateTime& DateTime::operator=(GDateTime* in) -{ - reset(in); - return *this; -} - -DateTime& DateTime::operator=(const DateTime& in) -{ - m_dt = in.m_dt; - return *this; -} -#endif - -gint64 DateTime::difference(const DateTime& that) const -{ - const auto dt = get(); - const auto tdt = that.get(); - - gint64 ret; - - if (dt && tdt) - ret = g_date_time_difference(dt, tdt); - else if (dt) - ret = to_unix(); - else if (tdt) - ret = that.to_unix(); - else - ret = 0; - - return ret; -} - bool DateTime::operator<(const DateTime& that) const { return g_date_time_compare(get(), that.get()) < 0; @@ -141,13 +103,36 @@ bool DateTime::operator!=(const DateTime& that) const bool DateTime::operator==(const DateTime& that) const { - GDateTime * dt = get(); - GDateTime * tdt = that.get(); + auto dt = get(); + auto tdt = that.get(); if (!dt && !tdt) return true; if (!dt || !tdt) return false; return g_date_time_compare(get(), that.get()) == 0; } +bool DateTime::is_same_day(const DateTime& a, const DateTime& b) +{ + // it's meaningless to compare uninitialized dates + 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)); +} + +bool DateTime::is_same_minute(const DateTime& a, const DateTime& b) +{ + if (!is_same_day(a,b)) + return false; + + const auto adt = a.get(); + const auto bdt = b.get(); + return (g_date_time_get_hour(adt) == g_date_time_get_hour(bdt)) + && (g_date_time_get_minute(adt) == g_date_time_get_minute(bdt)); +} + /*** **** ***/ -- cgit v1.2.3