From db5b700c7c116c73283019b3fbf823a23639a405 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 14 Mar 2015 21:20:30 -0500 Subject: Add DateTime::start_of_day() to use instead of the add_hours(-hours()) trick, which doesn't work on days when DST changes. Implementing this requires DateTime objects to keep their own GTimeZone pointer, since the one inside GDateTime is private and can't be used for DateTime::start_of_day()'s call to g_date_time_new(). As a result the public API of DateTime changes, since we'll need a GTimeZone when constructing or assigning from a GDateTime pointer. --- include/datetime/date-time.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'include/datetime') diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index 4be35f7..6e73ff3 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -38,13 +38,15 @@ public: static DateTime NowLocal(); static DateTime Local(int years, int months, int days, int hours, int minutes, int seconds); + DateTime(); explicit DateTime(time_t t); - explicit DateTime(GDateTime* in=nullptr); - DateTime& operator=(GDateTime* in); + DateTime(GTimeZone* tz, GDateTime* dt); DateTime& operator=(const DateTime& in); DateTime to_timezone(const std::string& zone) const; + DateTime start_of_day() const; + DateTime start_of_minute() const; + DateTime add_days(int days) const; DateTime add_full(int years, int months, int days, int hours, int minutes, double seconds) const; - void reset(GDateTime* in=nullptr); GDateTime* get() const; GDateTime* operator()() const {return get();} @@ -69,6 +71,8 @@ public: bool is_set() const { return m_dt != nullptr; } private: + void reset(GTimeZone*, GDateTime*); + std::shared_ptr m_tz; std::shared_ptr m_dt; }; -- cgit v1.2.3