aboutsummaryrefslogtreecommitdiff
path: root/src/date-time.cpp
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-01-22 14:28:20 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-01-22 14:28:20 -0600
commitaad7e86a109aeec75b3772cda20478363f966745 (patch)
tree5049662b13435cc5b422e1194bd617a1089e6fb6 /src/date-time.cpp
parente2fd6e620ce7f18c2cbf7c7b353d7cb5f86dce11 (diff)
downloadayatana-indicator-datetime-aad7e86a109aeec75b3772cda20478363f966745.tar.gz
ayatana-indicator-datetime-aad7e86a109aeec75b3772cda20478363f966745.tar.bz2
ayatana-indicator-datetime-aad7e86a109aeec75b3772cda20478363f966745.zip
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.
Diffstat (limited to 'src/date-time.cpp')
-rw-r--r--src/date-time.cpp65
1 files changed, 25 insertions, 40 deletions
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));
+}
+
/***
****
***/