diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2015-03-14 21:31:42 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2015-03-14 21:31:42 -0500 |
commit | c940b70c65b1550fe65dbad5841adfe906cf0cdf (patch) | |
tree | 141b128f526f719b09069e5b06e2ee0c9678bea7 | |
parent | db5b700c7c116c73283019b3fbf823a23639a405 (diff) | |
download | ayatana-indicator-datetime-c940b70c65b1550fe65dbad5841adfe906cf0cdf.tar.gz ayatana-indicator-datetime-c940b70c65b1550fe65dbad5841adfe906cf0cdf.tar.bz2 ayatana-indicator-datetime-c940b70c65b1550fe65dbad5841adfe906cf0cdf.zip |
use the new DateTime::start_of_day() and DateTime::start_of_minute() functions.
-rw-r--r-- | src/actions-live.cpp | 3 | ||||
-rw-r--r-- | src/actions.cpp | 4 | ||||
-rw-r--r-- | src/alarm-queue-simple.cpp | 2 | ||||
-rw-r--r-- | src/menu.cpp | 4 | ||||
-rw-r--r-- | src/planner-month.cpp | 7 | ||||
-rw-r--r-- | src/planner-upcoming.cpp | 2 | ||||
-rw-r--r-- | tests/test-actions.cpp | 21 | ||||
-rw-r--r-- | tests/test-alarm-queue.cpp | 19 | ||||
-rw-r--r-- | tests/test-live-actions.cpp | 27 | ||||
-rw-r--r-- | tests/test-menus.cpp | 8 |
10 files changed, 26 insertions, 71 deletions
diff --git a/src/actions-live.cpp b/src/actions-live.cpp index 7efc2b2..121744a 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -119,8 +119,7 @@ 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"); + const auto gmt = dt.start_of_day().to_timezone("UTC"); auto cmd = gmt.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..41c7f11 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); } 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/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..fd8a568 100644 --- a/src/planner-month.cpp +++ b/src/planner-month.cpp @@ -32,12 +32,7 @@ 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_begin = m.start_of_day().add_full(0, 0, -(m.day_of_month()-1), 0, 0, 0); auto month_end = month_begin.add_full(0, 1, 0, 0, 0, -0.1); 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)); diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp index fc89426..74fc380 100644 --- a/tests/test-actions.cpp +++ b/tests/test-actions.cpp @@ -30,9 +30,7 @@ class ActionsFixture: public StateFixture std::vector<Appointment> build_some_appointments() { const auto now = m_state->clock->localtime(); - auto gdt_tomorrow = g_date_time_add_days(now.get(), 1); - const auto tomorrow = DateTime(gdt_tomorrow); - g_date_time_unref(gdt_tomorrow); + const auto tomorrow = now.add_days(1); Appointment a1; // an alarm clock appointment a1.color = "red"; @@ -255,9 +253,7 @@ TEST_F(ActionsFixture, SetCalendarDate) EXPECT_TRUE(g_action_group_has_action(action_group, action_name)); // pick an arbitrary DateTime... - auto tmp = g_date_time_new_local(2010, 1, 2, 3, 4, 5); - const auto now = DateTime(tmp); - g_date_time_unref(tmp); + const auto now = DateTime::Local(2010, 1, 2, 3, 4, 5); // confirm that Planner.time gets changed to that date when we // activate the 'calendar' action with that date's time_t as the arg @@ -280,16 +276,14 @@ TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate) // move calendar-date a week into the future... const auto now = m_state->clock->localtime(); - auto next_week = g_date_time_add_weeks(now.get(), 1); - const auto next_week_unix = g_date_time_to_unix(next_week); + const auto next_week = now.add_days(7); + const auto next_week_unix = next_week.to_unix(); g_action_group_activate_action (action_group, "calendar", g_variant_new_int64(next_week_unix)); // confirm the planner and calendar action state moved a week into the future // but that m_state->clock is unchanged - auto expected = g_date_time_add_full (next_week, 0, 0, 0, -g_date_time_get_hour(next_week), - -g_date_time_get_minute(next_week), - -g_date_time_get_seconds(next_week)); - const auto expected_unix = g_date_time_to_unix(expected); + auto expected = next_week.start_of_day(); + const auto expected_unix = expected.to_unix(); EXPECT_EQ(expected_unix, m_state->calendar_month->month().get().to_unix()); EXPECT_EQ(now, m_state->clock->localtime()); auto calendar_state = g_action_group_get_action_state(action_group, "calendar"); @@ -301,9 +295,6 @@ TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate) g_clear_pointer(&v, g_variant_unref); g_clear_pointer(&calendar_state, g_variant_unref); - g_date_time_unref(expected); - g_date_time_unref(next_week); - /// /// Now the actual test. /// We set the state of 'calendar-active' to true, which should reset the calendar date. diff --git a/tests/test-alarm-queue.cpp b/tests/test-alarm-queue.cpp index 12ffe92..0492539 100644 --- a/tests/test-alarm-queue.cpp +++ b/tests/test-alarm-queue.cpp @@ -68,12 +68,8 @@ protected: std::vector<Appointment> build_some_appointments() { const auto now = m_state->clock->localtime(); - auto tomorrow = g_date_time_add_days (now.get(), 1); - auto tomorrow_begin = g_date_time_add_full (tomorrow, 0, 0, 0, - -g_date_time_get_hour(tomorrow), - -g_date_time_get_minute(tomorrow), - -g_date_time_get_seconds(tomorrow)); - auto tomorrow_end = g_date_time_add_full (tomorrow_begin, 0, 0, 1, 0, 0, -1); + const auto tomorrow_begin = now.add_days(1).start_of_day(); + const auto tomorrow_end = tomorrow_begin.add_full(0, 0, 1, 0, 0, -1); Appointment a1; // an alarm clock appointment a1.color = "red"; @@ -84,8 +80,8 @@ protected: a1.begin = tomorrow_begin; a1.end = tomorrow_end; - auto ubermorgen_begin = g_date_time_add_days (tomorrow, 1); - auto ubermorgen_end = g_date_time_add_full (tomorrow_begin, 0, 0, 1, 0, 0, -1); + const auto ubermorgen_begin = now.add_days(2).start_of_day(); + const auto ubermorgen_end = ubermorgen_begin.add_full(0, 0, 1, 0, 0, -1); Appointment a2; // a non-alarm appointment a2.color = "green"; @@ -96,13 +92,6 @@ protected: a2.begin = ubermorgen_begin; a2.end = ubermorgen_end; - // cleanup - g_date_time_unref(ubermorgen_end); - g_date_time_unref(ubermorgen_begin); - g_date_time_unref(tomorrow_end); - g_date_time_unref(tomorrow_begin); - g_date_time_unref(tomorrow); - return std::vector<Appointment>({a1, a2}); } }; diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index 1197e3e..98e9c58 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -346,9 +346,7 @@ TEST_F(LiveActionsFixture, PhoneOpenSettingsApp) TEST_F(LiveActionsFixture, CalendarState) { // init the clock - auto tmp = g_date_time_new_local (2014, 1, 1, 0, 0, 0); - const DateTime now (tmp); - g_date_time_unref (tmp); + auto now = DateTime::Local(2014, 1, 1, 0, 0, 0); m_mock_state->mock_clock->set_localtime (now); m_state->calendar_month->month().set(now); //m_state->planner->time.set(now); @@ -388,12 +386,8 @@ TEST_F(LiveActionsFixture, CalendarState) /// Now add appointments to the planner and confirm that the state keeps in sync /// - auto tomorrow = g_date_time_add_days (now.get(), 1); - auto tomorrow_begin = g_date_time_add_full (tomorrow, 0, 0, 0, - -g_date_time_get_hour(tomorrow), - -g_date_time_get_minute(tomorrow), - -g_date_time_get_seconds(tomorrow)); - auto tomorrow_end = g_date_time_add_full (tomorrow_begin, 0, 0, 1, 0, 0, -1); + auto tomorrow_begin = now.add_days(1).start_of_day(); + auto tomorrow_end = tomorrow_begin.add_full(0,0,1,0,0,-1); Appointment a1; a1.color = "green"; a1.summary = "write unit tests"; @@ -402,8 +396,8 @@ TEST_F(LiveActionsFixture, CalendarState) a1.begin = tomorrow_begin; a1.end = tomorrow_end; - auto next_begin = g_date_time_add_days (tomorrow_begin, 1); - auto next_end = g_date_time_add_full (next_begin, 0, 0, 1, 0, 0, -1); + auto next_begin = now.add_days(2).start_of_day(); + auto next_end = next_begin.add_days(1); Appointment a2; a2.color = "orange"; a2.summary = "code review"; @@ -424,19 +418,12 @@ TEST_F(LiveActionsFixture, CalendarState) EXPECT_TRUE (v != nullptr); int i; g_variant_get_child (v, 0, "i", &i); - EXPECT_EQ (g_date_time_get_day_of_month(a1.begin.get()), i); + EXPECT_EQ (a1.begin.day_of_month(), i); g_variant_get_child (v, 1, "i", &i); - EXPECT_EQ (g_date_time_get_day_of_month(a2.begin.get()), i); + EXPECT_EQ (a2.begin.day_of_month(), i); g_clear_pointer(&v, g_variant_unref); g_clear_pointer(&calendar_state, g_variant_unref); - // cleanup this step - g_date_time_unref (next_end); - g_date_time_unref (next_begin); - g_date_time_unref (tomorrow_end); - g_date_time_unref (tomorrow_begin); - g_date_time_unref (tomorrow); - /// /// Confirm that the action state's dictionary /// keeps in sync with settings.show_week_numbers diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp index e0e63ac..fb9c50a 100644 --- a/tests/test-menus.cpp +++ b/tests/test-menus.cpp @@ -151,9 +151,7 @@ protected: // now change the clock and see if the date label changes appropriately - auto gdt_tomorrow = g_date_time_add_days(now.get(), 1); - auto tomorrow = DateTime(gdt_tomorrow); - g_date_time_unref(gdt_tomorrow); + auto tomorrow = now.add_days(1).start_of_day(); m_mock_state->mock_clock->set_localtime(tomorrow); wait_msec(); @@ -182,9 +180,7 @@ private: std::vector<Appointment> build_some_appointments() { const auto now = m_state->clock->localtime(); - auto gdt_tomorrow = g_date_time_add_days(now.get(), 1); - const auto tomorrow = DateTime(gdt_tomorrow); - g_date_time_unref(gdt_tomorrow); + const auto tomorrow = now.add_days(1); Appointment a1; // an alarm clock appointment a1.color = "red"; |