aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2015-03-17 15:23:49 +0000
committerCI Train Bot <ci-train-bot@canonical.com>2015-03-17 15:23:49 +0000
commitddde67df581dea8c5a261e43d5b12a3821f06ed1 (patch)
treee3c2859c54b0bba9c72ad221ea41c95ed8f5a70f /src
parent15ec7f61fa84a9a8b40c1c9fcfa6c2a268d3232b (diff)
parent273c3b3829c9a3e853d0b6b0a32ae87cc3c6852b (diff)
downloadayatana-indicator-datetime-ddde67df581dea8c5a261e43d5b12a3821f06ed1.tar.gz
ayatana-indicator-datetime-ddde67df581dea8c5a261e43d5b12a3821f06ed1.tar.bz2
ayatana-indicator-datetime-ddde67df581dea8c5a261e43d5b12a3821f06ed1.zip
Fix bug that prevented clicking on calendar days where DST sprang forward. Fixes: #1429388
Approved by: Ted Gould, PS Jenkins bot
Diffstat (limited to 'src')
-rw-r--r--src/actions-live.cpp5
-rw-r--r--src/actions.cpp12
-rw-r--r--src/alarm-queue-simple.cpp2
-rw-r--r--src/clock-live.cpp2
-rw-r--r--src/date-time.cpp113
-rw-r--r--src/menu.cpp4
-rw-r--r--src/planner-month.cpp9
-rw-r--r--src/planner-upcoming.cpp2
8 files changed, 104 insertions, 45 deletions
diff --git a/src/actions-live.cpp b/src/actions-live.cpp
index 7efc2b2..4d1f770 100644
--- a/src/actions-live.cpp
+++ b/src/actions-live.cpp
@@ -119,9 +119,8 @@ void LiveActions::desktop_open_appointment(const Appointment& appt)
void LiveActions::desktop_open_calendar_app(const DateTime& dt)
{
- const auto day_begins = dt.add_full(0, 0, 0, -dt.hour(), -dt.minute(), -dt.seconds());
- const auto gmt = day_begins.to_timezone("UTC");
- auto cmd = gmt.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\"");
+ const auto utc = dt.start_of_day().to_timezone("UTC");
+ auto cmd = utc.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\"");
execute_command(cmd.c_str());
}
diff --git a/src/actions.cpp b/src/actions.cpp
index 1b665cc..839c9cd 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -143,9 +143,7 @@ void on_calendar_activated(GSimpleAction * /*action*/,
g_return_if_fail(t != 0);
- // the client gave us a date; remove the HMS component from the resulting DateTime
- auto dt = DateTime(t);
- dt = dt.add_full (0, 0, 0, -dt.hour(), -dt.minute(), -dt.seconds());
+ auto dt = DateTime(t).start_of_day();
static_cast<Actions*>(gself)->set_calendar_date(dt);
}
@@ -225,18 +223,26 @@ Actions::Actions(const std::shared_ptr<State>& state):
auto v = create_default_header_state();
auto a = g_simple_action_new_stateful("desktop-header", nullptr, v);
g_action_map_add_action(gam, G_ACTION(a));
+ g_object_unref(a);
+
a = g_simple_action_new_stateful("desktop_greeter-header", nullptr, v);
g_action_map_add_action(gam, G_ACTION(a));
+ g_object_unref(a);
+
a = g_simple_action_new_stateful("phone-header", nullptr, v);
g_action_map_add_action(gam, G_ACTION(a));
+ g_object_unref(a);
+
a = g_simple_action_new_stateful("phone_greeter-header", nullptr, v);
g_action_map_add_action(gam, G_ACTION(a));
+ g_object_unref(a);
// add the calendar action
v = create_calendar_state(state);
a = g_simple_action_new_stateful("calendar", G_VARIANT_TYPE_INT64, v);
g_action_map_add_action(gam, G_ACTION(a));
g_signal_connect(a, "activate", G_CALLBACK(on_calendar_activated), this);
+ g_object_unref(a);
///
/// Keep our GActionGroup's action's states in sync with m_state
diff --git a/src/alarm-queue-simple.cpp b/src/alarm-queue-simple.cpp
index fa6c0bc..f45e61a 100644
--- a/src/alarm-queue-simple.cpp
+++ b/src/alarm-queue-simple.cpp
@@ -102,7 +102,7 @@ bool SimpleAlarmQueue::find_next_alarm(Appointment& setme) const
bool found = false;
Appointment tmp;
const auto now = m_clock->localtime();
- const auto beginning_of_minute = now.add_full (0, 0, 0, 0, 0, -now.seconds());
+ const auto beginning_of_minute = now.start_of_minute();
const auto appointments = m_planner->appointments().get();
g_debug ("planner has %zu appointments in it", (size_t)appointments.size());
diff --git a/src/clock-live.cpp b/src/clock-live.cpp
index 7f8bd1b..89541ae 100644
--- a/src/clock-live.cpp
+++ b/src/clock-live.cpp
@@ -68,7 +68,7 @@ public:
g_assert(m_gtimezone != nullptr);
auto gdt = g_date_time_new_now(m_gtimezone);
- DateTime ret(gdt);
+ DateTime ret(m_gtimezone, gdt);
g_date_time_unref(gdt);
return ret;
}
diff --git a/src/date-time.cpp b/src/date-time.cpp
index a139ea9..689688c 100644
--- a/src/date-time.cpp
+++ b/src/date-time.cpp
@@ -27,43 +27,58 @@ namespace datetime {
****
***/
-DateTime::DateTime(GDateTime* gdt)
+DateTime::DateTime()
{
- reset(gdt);
}
-DateTime& DateTime::operator=(GDateTime* gdt)
+DateTime::DateTime(GTimeZone* gtz, GDateTime* gdt)
{
- reset(gdt);
- return *this;
+ g_return_if_fail(gtz!=nullptr);
+ g_return_if_fail(gdt!=nullptr);
+
+ reset(gtz, gdt);
+}
+
+DateTime::DateTime(GTimeZone* gtz, int year, int month, int day, int hour, int minute, double seconds)
+{
+ g_return_if_fail(gtz!=nullptr);
+
+ auto gdt = g_date_time_new(gtz, year, month, day, hour, minute, seconds);
+ reset(gtz, gdt);
+ g_date_time_unref(gdt);
}
DateTime& DateTime::operator=(const DateTime& that)
{
+ m_tz = that.m_tz;
m_dt = that.m_dt;
return *this;
}
DateTime::DateTime(time_t t)
{
+ auto gtz = g_time_zone_new_local();
auto gdt = g_date_time_new_from_unix_local(t);
- reset(gdt);
+ reset(gtz, gdt);
+ g_time_zone_unref(gtz);
g_date_time_unref(gdt);
}
DateTime DateTime::NowLocal()
{
- auto gdt = g_date_time_new_now_local();
- DateTime dt(gdt);
+ auto gtz = g_time_zone_new_local();
+ auto gdt = g_date_time_new_now(gtz);
+ 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, int seconds)
+DateTime DateTime::Local(int year, int month, int day, int hour, int minute, double seconds)
{
- auto gdt = g_date_time_new_local (year, month, day, hour, minute, seconds);
- DateTime dt(gdt);
- g_date_time_unref(gdt);
+ auto gtz = g_time_zone_new_local();
+ DateTime dt(gtz, year, month, day, hour, minute, seconds);
+ g_time_zone_unref(gtz);
return dt;
}
@@ -71,20 +86,66 @@ DateTime DateTime::to_timezone(const std::string& zone) const
{
auto gtz = g_time_zone_new(zone.c_str());
auto gdt = g_date_time_to_timezone(get(), gtz);
- DateTime dt(gdt);
+ DateTime dt(gtz, gdt);
g_time_zone_unref(gtz);
g_date_time_unref(gdt);
return dt;
}
-DateTime DateTime::add_full(int years, int months, int days, int hours, int minutes, double seconds) const
+DateTime DateTime::end_of_day() const
+{
+ g_assert(is_set());
+
+ return add_days(1).start_of_day().add_full(0,0,0,0,0,-1);
+}
+
+DateTime DateTime::end_of_month() const
+{
+ g_assert(is_set());
+
+ return add_full(0,1,0,0,0,0).start_of_month().add_full(0,0,0,0,0,-1);
+}
+
+DateTime DateTime::start_of_month() const
+{
+ g_assert(is_set());
+
+ int year=0, month=0, day=0;
+ ymd(year, month, day);
+ return DateTime(m_tz.get(), year, month, 1, 0, 0, 0);
+}
+
+DateTime DateTime::start_of_day() const
+{
+ g_assert(is_set());
+
+ int year=0, month=0, day=0;
+ ymd(year, month, day);
+ return DateTime(m_tz.get(), year, month, day, 0, 0, 0);
+}
+
+DateTime DateTime::start_of_minute() const
+{
+ g_assert(is_set());
+
+ int year=0, month=0, day=0;
+ ymd(year, month, day);
+ return DateTime(m_tz.get(), year, month, day, hour(), minute(), 0);
+}
+
+DateTime DateTime::add_full(int year, int month, int day, int hour, int minute, double seconds) const
{
- auto gdt = g_date_time_add_full(get(), years, months, days, hours, minutes, seconds);
- DateTime dt(gdt);
+ auto gdt = g_date_time_add_full(get(), year, month, day, hour, minute, seconds);
+ DateTime dt(m_tz.get(), gdt);
g_date_time_unref(gdt);
return dt;
}
+DateTime DateTime::add_days(int days) const
+{
+ return add_full(0, 0, days, 0, 0, 0);
+}
+
GDateTime* DateTime::get() const
{
g_assert(m_dt);
@@ -135,18 +196,16 @@ int64_t DateTime::to_unix() const
return g_date_time_to_unix(get());
}
-void DateTime::reset(GDateTime* in)
+void DateTime::reset(GTimeZone* gtz, GDateTime* gdt)
{
- if (in)
- {
- auto deleter = [](GDateTime* dt){g_date_time_unref(dt);};
- m_dt = std::shared_ptr<GDateTime>(g_date_time_ref(in), deleter);
- g_assert(m_dt);
- }
- else
- {
- m_dt.reset();
- }
+ g_return_if_fail (gdt!=nullptr);
+ g_return_if_fail (gtz!=nullptr);
+
+ auto tz_deleter = [](GTimeZone* tz){g_time_zone_unref(tz);};
+ m_tz = std::shared_ptr<GTimeZone>(g_time_zone_ref(gtz), tz_deleter);
+
+ auto dt_deleter = [](GDateTime* dt){g_date_time_unref(dt);};
+ m_dt = std::shared_ptr<GDateTime>(g_date_time_ref(gdt), dt_deleter);
}
bool DateTime::operator<(const DateTime& that) const
diff --git a/src/menu.cpp b/src/menu.cpp
index f11de77..ff894bc 100644
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -152,9 +152,9 @@ protected:
const auto now = m_state->clock->localtime();
const auto calendar_day = m_state->calendar_month->month().get();
if ((profile() == Desktop) && !DateTime::is_same_day(now, calendar_day))
- begin = calendar_day.add_full (0, 0, 0, -calendar_day.hour(), -calendar_day.minute(), -calendar_day.seconds());
+ begin = calendar_day.start_of_day();
else
- begin = now.add_full (0, 0, 0, 0, 0, -now.seconds());
+ begin = now.start_of_minute();
std::vector<Appointment> upcoming;
for(const auto& a : m_state->calendar_upcoming->appointments().get())
diff --git a/src/planner-month.cpp b/src/planner-month.cpp
index 5920daa..cdae26f 100644
--- a/src/planner-month.cpp
+++ b/src/planner-month.cpp
@@ -32,13 +32,8 @@ MonthPlanner::MonthPlanner(const std::shared_ptr<RangePlanner>& range_planner,
m_range_planner(range_planner)
{
month().changed().connect([this](const DateTime& m){
- auto month_begin = m.add_full(0, // no years
- 0, // no months
- -(m.day_of_month()-1),
- -m.hour(),
- -m.minute(),
- -m.seconds());
- auto month_end = month_begin.add_full(0, 1, 0, 0, 0, -0.1);
+ auto month_begin = m.start_of_month();
+ auto month_end = m.end_of_month();
g_debug("PlannerMonth %p setting calendar month range: [%s..%s]", this, month_begin.format("%F %T").c_str(), month_end.format("%F %T").c_str());
m_range_planner->range().set(std::pair<DateTime,DateTime>(month_begin,month_end));
});
diff --git a/src/planner-upcoming.cpp b/src/planner-upcoming.cpp
index ed45955..338329c 100644
--- a/src/planner-upcoming.cpp
+++ b/src/planner-upcoming.cpp
@@ -33,7 +33,7 @@ UpcomingPlanner::UpcomingPlanner(const std::shared_ptr<RangePlanner>& range_plan
{
date().changed().connect([this](const DateTime& dt){
// set the range to the upcoming month
- const auto b = dt.add_full(0, 0, -1, -dt.hour(), -dt.minute(), -dt.seconds());
+ const auto b = dt.add_days(-1).start_of_day();
const auto e = b.add_full(0, 1, 0, 0, 0, 0);
g_debug("%p setting date range to [%s..%s]", this, b.format("%F %T").c_str(), e.format("%F %T").c_str());
m_range_planner->range().set(std::pair<DateTime,DateTime>(b,e));