From fff19d70649589b81a896e4deb032a7bd4bdca1e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 31 Mar 2015 18:54:04 -0500 Subject: add an Alarm class to represent ical valarm components; change the Appointment class to hold an arbitrary number of Alarms. --- include/datetime/appointment.h | 26 ++++++++++++++++++++++---- include/datetime/snap.h | 3 ++- 2 files changed, 24 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index ab89c2f..337d9b8 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -21,14 +21,31 @@ #define INDICATOR_DATETIME_APPOINTMENT_H #include + +#include #include +#include +#include namespace unity { namespace indicator { namespace datetime { /** - * \brief Plain Old Data Structure that represents a calendar appointment. + * \brief Basic information required to raise a notification about some Appointment. + */ +struct Alarm +{ + std::string text; + std::string audio_url; + DateTime time; + std::chrono::seconds duration; + + bool operator== (const Alarm& that) const; +}; + +/** + * \brief An instance of an appointment; e.g. a calendar event or clock-app alarm * * @see Planner */ @@ -39,14 +56,15 @@ public: Type type = EVENT; bool is_ubuntu_alarm() const { return type == UBUNTU_ALARM; } + std::string uid; std::string color; std::string summary; - std::string url; - std::string uid; - std::string audio_url; + std::string activation_url; DateTime begin; DateTime end; + std::vector alarms; + bool operator== (const Appointment& that) const; }; diff --git a/include/datetime/snap.h b/include/datetime/snap.h index 572158d..cc091d3 100644 --- a/include/datetime/snap.h +++ b/include/datetime/snap.h @@ -42,8 +42,9 @@ public: const std::shared_ptr& settings); virtual ~Snap(); - typedef std::function appointment_func; + typedef std::function appointment_func; void operator()(const Appointment& appointment, + const Alarm& alarm, appointment_func snooze, appointment_func ok); -- cgit v1.2.3 From eab70c8626906fcf98f5d5653a8ea1bebd2cfc89 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 3 Apr 2015 12:31:36 -0500 Subject: add override keyword to WakeupTimer --- include/datetime/wakeup-timer-mainloop.h | 4 ++-- include/datetime/wakeup-timer-powerd.h | 4 ++-- include/datetime/wakeup-timer.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/datetime/wakeup-timer-mainloop.h b/include/datetime/wakeup-timer-mainloop.h index 86da8cf..5acb150 100644 --- a/include/datetime/wakeup-timer-mainloop.h +++ b/include/datetime/wakeup-timer-mainloop.h @@ -41,8 +41,8 @@ class MainloopWakeupTimer: public WakeupTimer public: explicit MainloopWakeupTimer(const std::shared_ptr&); ~MainloopWakeupTimer(); - void set_wakeup_time (const DateTime&); - core::Signal<>& timeout(); + void set_wakeup_time (const DateTime&) override; + core::Signal<>& timeout() override; private: MainloopWakeupTimer(const MainloopWakeupTimer&) =delete; diff --git a/include/datetime/wakeup-timer-powerd.h b/include/datetime/wakeup-timer-powerd.h index f11febe..5237fb9 100644 --- a/include/datetime/wakeup-timer-powerd.h +++ b/include/datetime/wakeup-timer-powerd.h @@ -41,8 +41,8 @@ class PowerdWakeupTimer: public WakeupTimer public: explicit PowerdWakeupTimer(const std::shared_ptr&); ~PowerdWakeupTimer(); - void set_wakeup_time(const DateTime&); - core::Signal<>& timeout(); + void set_wakeup_time(const DateTime&) override; + core::Signal<>& timeout() override; private: PowerdWakeupTimer(const PowerdWakeupTimer&) =delete; diff --git a/include/datetime/wakeup-timer.h b/include/datetime/wakeup-timer.h index 0a9923c..3e5344c 100644 --- a/include/datetime/wakeup-timer.h +++ b/include/datetime/wakeup-timer.h @@ -41,7 +41,7 @@ public: WakeupTimer() =default; virtual ~WakeupTimer() =default; virtual void set_wakeup_time (const DateTime&) =0; - virtual core::Signal<>& timeout() = 0; + virtual core::Signal<>& timeout() =0; }; /*** -- cgit v1.2.3 From 6e4367c088eb9026f29295c650f8639e09423212 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 3 Apr 2015 12:36:46 -0500 Subject: add override keyword to Clock class --- include/datetime/clock-mock.h | 2 +- include/datetime/clock.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/datetime/clock-mock.h b/include/datetime/clock-mock.h index 84fd860..011d079 100644 --- a/include/datetime/clock-mock.h +++ b/include/datetime/clock-mock.h @@ -39,7 +39,7 @@ public: explicit MockClock(const DateTime& dt): m_localtime(dt) {} ~MockClock() =default; - DateTime localtime() const { return m_localtime; } + DateTime localtime() const override { return m_localtime; } void set_localtime(const DateTime& dt) { diff --git a/include/datetime/clock.h b/include/datetime/clock.h index 8745d24..4a0642f 100644 --- a/include/datetime/clock.h +++ b/include/datetime/clock.h @@ -76,7 +76,7 @@ class LiveClock: public Clock public: LiveClock (const std::shared_ptr& zones); virtual ~LiveClock(); - virtual DateTime localtime() const; + virtual DateTime localtime() const override; private: class Impl; -- cgit v1.2.3 From 8c7daeeb87abd0be1b96169da18baf018c4859c9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 3 Apr 2015 13:11:39 -0500 Subject: add the new Alarm class as an argument to the alarm queue class --- include/datetime/alarm-queue-simple.h | 18 +-- include/datetime/alarm-queue.h | 2 +- include/datetime/date-time.h | 3 + include/datetime/planner-snooze.h | 3 +- src/alarm-queue-simple.cpp | 226 ++++++++++++++++++++-------------- src/date-time.cpp | 10 ++ src/main.cpp | 8 +- src/planner-snooze.cpp | 16 ++- tests/test-alarm-queue.cpp | 17 +-- 9 files changed, 178 insertions(+), 125 deletions(-) (limited to 'include') diff --git a/include/datetime/alarm-queue-simple.h b/include/datetime/alarm-queue-simple.h index d191aec..838d28a 100644 --- a/include/datetime/alarm-queue-simple.h +++ b/include/datetime/alarm-queue-simple.h @@ -20,6 +20,8 @@ #ifndef INDICATOR_DATETIME_ALARM_QUEUE_SIMPLE_H #define INDICATOR_DATETIME_ALARM_QUEUE_SIMPLE_H +#include // std::shared_ptr + #include #include #include @@ -39,20 +41,12 @@ public: const std::shared_ptr& upcoming_planner, const std::shared_ptr& timer); ~SimpleAlarmQueue(); - core::Signal& alarm_reached(); + core::Signal& alarm_reached() override; private: - void requeue(); - bool find_next_alarm(Appointment& setme) const; - std::vector find_current_alarms() const; - void check_alarms(); - - std::set> m_triggered; - const std::shared_ptr m_clock; - const std::shared_ptr m_planner; - const std::shared_ptr m_timer; - core::Signal m_alarm_reached; - DateTime m_datetime; + class Impl; + friend class Impl; + std::unique_ptr impl; }; diff --git a/include/datetime/alarm-queue.h b/include/datetime/alarm-queue.h index ea51957..98abd7a 100644 --- a/include/datetime/alarm-queue.h +++ b/include/datetime/alarm-queue.h @@ -45,7 +45,7 @@ class AlarmQueue public: AlarmQueue() =default; virtual ~AlarmQueue() =default; - virtual core::Signal& alarm_reached() = 0; + virtual core::Signal& alarm_reached() =0; }; /*** diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index 7dfc207..7e19a9d 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -22,6 +22,7 @@ #include // GDateTime +#include #include // time_t #include // std::shared_ptr @@ -43,6 +44,8 @@ public: DateTime(GTimeZone* tz, GDateTime* dt); DateTime(GTimeZone* tz, int year, int month, int day, int hour, int minute, double seconds); DateTime& operator=(const DateTime& in); + DateTime& operator+=(const std::chrono::minutes&); + DateTime& operator+=(const std::chrono::seconds&); DateTime to_timezone(const std::string& zone) const; DateTime start_of_month() const; DateTime start_of_day() const; diff --git a/include/datetime/planner-snooze.h b/include/datetime/planner-snooze.h index e2619fa..fc08d27 100644 --- a/include/datetime/planner-snooze.h +++ b/include/datetime/planner-snooze.h @@ -39,9 +39,8 @@ public: SnoozePlanner(const std::shared_ptr&, const std::shared_ptr&); ~SnoozePlanner(); - void add(const Appointment&); - core::Property>& appointments() override; + void add(const Appointment&, const Alarm&); protected: class Impl; diff --git a/src/alarm-queue-simple.cpp b/src/alarm-queue-simple.cpp index f45e61a..db0fd21 100644 --- a/src/alarm-queue-simple.cpp +++ b/src/alarm-queue-simple.cpp @@ -20,134 +20,174 @@ #include #include +#include namespace unity { namespace indicator { namespace datetime { /*** -**** Public API +**** ***/ -SimpleAlarmQueue::SimpleAlarmQueue(const std::shared_ptr& clock, - const std::shared_ptr& planner, - const std::shared_ptr& timer): - m_clock(clock), - m_planner(planner), - m_timer(timer), - m_datetime(clock->localtime()) +class SimpleAlarmQueue::Impl { - m_planner->appointments().changed().connect([this](const std::vector&){ - g_debug("AlarmQueue %p calling requeue() due to appointments changed", this); - requeue(); - }); - - m_clock->minute_changed.connect([=]{ - const auto now = m_clock->localtime(); - constexpr auto skew_threshold_usec = int64_t{90} * G_USEC_PER_SEC; - const bool clock_jumped = std::abs(now - m_datetime) > skew_threshold_usec; - m_datetime = now; - if (clock_jumped) { - g_debug("AlarmQueue %p calling requeue() due to clock skew", this); +public: + + Impl(const std::shared_ptr& clock, + const std::shared_ptr& planner, + const std::shared_ptr& timer): + m_clock{clock}, + m_planner{planner}, + m_timer{timer}, + m_datetime{clock->localtime()} + { + m_planner->appointments().changed().connect([this](const std::vector&){ + g_debug("AlarmQueue %p calling requeue() due to appointments changed", this); requeue(); - } - }); + }); + + m_clock->minute_changed.connect([=]{ + const auto now = m_clock->localtime(); + constexpr auto skew_threshold_usec = int64_t{90} * G_USEC_PER_SEC; + const bool clock_jumped = std::abs(now - m_datetime) > skew_threshold_usec; + m_datetime = now; + if (clock_jumped) { + g_debug("AlarmQueue %p calling requeue() due to clock skew", this); + requeue(); + } + }); + + m_timer->timeout().connect([this](){ + g_debug("AlarmQueue %p calling requeue() due to timeout", this); + requeue(); + }); - m_timer->timeout().connect([this](){ - g_debug("AlarmQueue %p calling requeue() due to timeout", this); requeue(); - }); - - requeue(); -} + } -SimpleAlarmQueue::~SimpleAlarmQueue() -{ -} + ~Impl() + { + } -core::Signal& SimpleAlarmQueue::alarm_reached() -{ - return m_alarm_reached; -} + core::Signal& alarm_reached() + { + return m_alarm_reached; + } -/*** -**** -***/ +private: -void SimpleAlarmQueue::requeue() -{ - // kick any current alarms - for (auto current : find_current_alarms()) + void requeue() { - const std::pair trig {current.uid, current.begin}; - m_triggered.insert(trig); - m_alarm_reached(current); + // kick any current alarms + for (const auto& appointment : m_planner->appointments().get()) + { + Alarm alarm; + if (appointment_get_current_alarm(appointment, alarm)) + { + m_triggered.insert(std::make_pair(appointment.uid, alarm.time)); + m_alarm_reached(appointment, alarm); + } + } + + // idle until the next alarm + Alarm next; + if (find_next_alarm(next)) + { + g_debug ("setting timer to wake up for next appointment '%s' at %s", + next.text.c_str(), + next.time.format("%F %T").c_str()); + + m_timer->set_wakeup_time(next.time); + } } - // idle until the next alarm - Appointment next; - if (find_next_alarm(next)) + // find the next alarm that will kick now or in the future + bool find_next_alarm(Alarm& setme) const { - g_debug ("setting timer to wake up for next appointment '%s' at %s", - next.summary.c_str(), - next.begin.format("%F %T").c_str()); + bool found = false; + Alarm best; + const auto now = m_clock->localtime(); + const auto beginning_of_minute = now.start_of_minute(); - m_timer->set_wakeup_time(next.begin); - } -} + const auto appointments = m_planner->appointments().get(); + g_debug ("planner has %zu appointments in it", (size_t)appointments.size()); -// find the next alarm that will kick now or in the future -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.start_of_minute(); + for(const auto& appointment : appointments) + { + for(const auto& alarm : appointment.alarms) + { + const std::pair trig{appointment.uid, alarm.time}; + if (m_triggered.count(trig)) + continue; - const auto appointments = m_planner->appointments().get(); - g_debug ("planner has %zu appointments in it", (size_t)appointments.size()); + if (alarm.time < beginning_of_minute) // has this one already passed? + continue; - for(const auto& walk : appointments) - { - const std::pair trig {walk.uid, walk.begin}; - if (m_triggered.count(trig)) - continue; + if (found && (best.time < alarm.time)) // do we already have a better match? + continue; - if (walk.begin < beginning_of_minute) // has this one already passed? - continue; + best = alarm; + found = true; + } + } - if (found && (tmp.begin < walk.begin)) // do we already have a better match? - continue; + if (found) + setme = best; - tmp = walk; - found = true; + return found; } - if (found) - setme = tmp; - return found; -} + bool appointment_get_current_alarm(const Appointment& appointment, Alarm& setme) const + { + const auto now = m_clock->localtime(); -// find the alarm(s) that should kick right now -std::vector SimpleAlarmQueue::find_current_alarms() const -{ - std::vector appointments; + for (const auto& alarm : appointment.alarms) + { + const auto trig = std::make_pair(appointment.uid, alarm.time); + if (m_triggered.count(trig)) // did we already use this one? + continue; + + if (DateTime::is_same_minute(now, alarm.time)) + { + setme = alarm; + return true; + } + } - const auto now = m_clock->localtime(); + return false; + } - for(const auto& walk : m_planner->appointments().get()) - { - const std::pair trig {walk.uid, walk.begin}; - if (m_triggered.count(trig)) // did we already use this one? - continue; - if (!DateTime::is_same_minute(now, walk.begin)) - continue; - appointments.push_back(walk); - } + std::set> m_triggered; + const std::shared_ptr m_clock; + const std::shared_ptr m_planner; + const std::shared_ptr m_timer; + core::Signal m_alarm_reached; + DateTime m_datetime; +}; + +/*** +**** Public API +***/ + - return appointments; +SimpleAlarmQueue::SimpleAlarmQueue(const std::shared_ptr& clock, + const std::shared_ptr& planner, + const std::shared_ptr& timer): + impl{new Impl{clock, planner, timer}} +{ +} + +SimpleAlarmQueue::~SimpleAlarmQueue() +{ +} + +core::Signal& +SimpleAlarmQueue::alarm_reached() +{ + return impl->alarm_reached(); } /*** diff --git a/src/date-time.cpp b/src/date-time.cpp index 689688c..ecfc971 100644 --- a/src/date-time.cpp +++ b/src/date-time.cpp @@ -55,6 +55,16 @@ DateTime& DateTime::operator=(const DateTime& that) return *this; } +DateTime& DateTime::operator+=(const std::chrono::minutes& minutes) +{ + return (*this = add_full(0, 0, 0, 0, minutes.count(), 0)); +} + +DateTime& DateTime::operator+=(const std::chrono::seconds& seconds) +{ + return (*this = add_full(0, 0, 0, 0, 0, seconds.count())); +} + DateTime::DateTime(time_t t) { auto gtz = g_time_zone_new_local(); diff --git a/src/main.cpp b/src/main.cpp index 38e5caa..907d49f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -138,11 +138,11 @@ main(int /*argc*/, char** /*argv*/) auto notification_engine = std::make_shared("indicator-datetime-service"); std::unique_ptr snap (new Snap(notification_engine, state->settings)); auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone_); - auto on_snooze = [snooze_planner](const Appointment& appointment, const Alarm&) {snooze_planner->add(appointment);}; + auto on_snooze = [snooze_planner](const Appointment& appointment, const Alarm& alarm) { + snooze_planner->add(appointment, alarm); + }; auto on_ok = [](const Appointment&, const Alarm&){}; - auto on_alarm_reached = [&engine, &snap, &on_snooze, &on_ok](const Appointment& appointment) { -#warning placeholder; next step is to have AlarmQueue pass an appointment and alarm - Alarm alarm; + auto on_alarm_reached = [&engine, &snap, &on_snooze, &on_ok](const Appointment& appointment, const Alarm& alarm) { (*snap)(appointment, alarm, on_snooze, on_ok); engine->disable_ubuntu_alarm(appointment); }; diff --git a/src/planner-snooze.cpp b/src/planner-snooze.cpp index 29d5f06..e4062d2 100644 --- a/src/planner-snooze.cpp +++ b/src/planner-snooze.cpp @@ -51,14 +51,18 @@ public: return m_appointments; } - void add(const Appointment& appt_in) + void add(const Appointment& appt_in, const Alarm& alarm) { + // make a copy of the appointment with only this alarm Appointment appt = appt_in; + appt.alarms.clear(); + appt.alarms.push_back(alarm); // reschedule the alarm to go off N minutes from now - const auto alarm_duration_secs = appt.end - appt.begin; - appt.begin = m_clock->localtime().add_full(0,0,0,0,m_settings->snooze_duration.get(),0); - appt.end = appt.begin.add_full(0,0,0,0,0,alarm_duration_secs); + const auto offset = std::chrono::minutes(m_settings->snooze_duration.get()); + appt.begin += offset; + appt.end += offset; + appt.alarms[0].time += offset; // give it a new ID gchar* uid = e_uid_new(); @@ -95,9 +99,9 @@ SnoozePlanner::~SnoozePlanner() } void -SnoozePlanner::add(const Appointment& appointment) +SnoozePlanner::add(const Appointment& appointment, const Alarm& alarm) { - impl->add(appointment); + impl->add(appointment, alarm); } core::Property>& diff --git a/tests/test-alarm-queue.cpp b/tests/test-alarm-queue.cpp index 3fdf787..fdab425 100644 --- a/tests/test-alarm-queue.cpp +++ b/tests/test-alarm-queue.cpp @@ -48,7 +48,7 @@ protected: m_range_planner.reset(new MockRangePlanner); m_upcoming.reset(new UpcomingPlanner(m_range_planner, m_state->clock->localtime())); m_watcher.reset(new SimpleAlarmQueue(m_state->clock, m_upcoming, m_wakeup_timer)); - m_watcher->alarm_reached().connect([this](const Appointment& appt){ + m_watcher->alarm_reached().connect([this](const Appointment& appt, const Alarm& /*alarm*/){ m_triggered.push_back(appt.uid); }); @@ -71,7 +71,7 @@ protected: const auto tomorrow_begin = now.add_days(1).start_of_day(); const auto tomorrow_end = tomorrow_begin.end_of_day(); - Appointment a1; // an alarm clock appointment + Appointment a1; // an ubuntu alarm a1.color = "red"; a1.summary = "Alarm"; a1.summary = "http://www.example.com/"; @@ -79,18 +79,20 @@ protected: a1.type = Appointment::UBUNTU_ALARM; a1.begin = tomorrow_begin; a1.end = tomorrow_end; + a1.alarms.push_back(Alarm{"Alarm Text", "", a1.begin, std::chrono::seconds::zero()}); const auto ubermorgen_begin = now.add_days(2).start_of_day(); const auto ubermorgen_end = ubermorgen_begin.end_of_day(); - Appointment a2; // a non-alarm appointment + Appointment a2; // something else a2.color = "green"; a2.summary = "Other Text"; a2.summary = "http://www.monkey.com/"; a2.uid = "monkey"; - a1.type = Appointment::EVENT; + a2.type = Appointment::EVENT; a2.begin = ubermorgen_begin; a2.end = ubermorgen_end; + a2.alarms.push_back(Alarm{"Alarm Text", "", a2.begin, std::chrono::seconds::zero()}); return std::vector({a1, a2}); } @@ -105,7 +107,7 @@ TEST_F(AlarmQueueFixture, AppointmentsChanged) // Add some appointments to the planner. // One of these matches our state's localtime, so that should get triggered. std::vector a = build_some_appointments(); - a[0].begin = m_state->clock->localtime(); + a[0].begin = a[0].alarms.front().time = m_state->clock->localtime(); m_range_planner->appointments().set(a); // Confirm that it got fired @@ -135,7 +137,8 @@ TEST_F(AlarmQueueFixture, MoreThanOne) { const auto now = m_state->clock->localtime(); std::vector a = build_some_appointments(); - a[0].begin = a[1].begin = now; + a[0].alarms.front().time = now; + a[1].alarms.front().time = now; m_range_planner->appointments().set(a); ASSERT_EQ(2, m_triggered.size()); @@ -151,7 +154,7 @@ TEST_F(AlarmQueueFixture, NoDuplicates) const std::vector appointments = build_some_appointments(); std::vector a; a.push_back(appointments[0]); - a[0].begin = now; + a[0].alarms.front().time = now; m_range_planner->appointments().set(a); ASSERT_EQ(1, m_triggered.size()); EXPECT_EQ(a[0].uid, m_triggered[0]); -- cgit v1.2.3 From 62d68e6453c0ad69ff4d71099441a8151e9a9bea Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 5 Apr 2015 17:27:52 -0500 Subject: fix misuse of ECalComponentAlarmInstance's fields. --- include/datetime/appointment.h | 1 - src/appointment.cpp | 3 +-- src/engine-eds.cpp | 4 +--- tests/manual-test-snap.cpp | 2 +- tests/test-alarm-queue.cpp | 4 ++-- tests/test-snap.cpp | 2 +- 6 files changed, 6 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index 337d9b8..e9c1bc2 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -39,7 +39,6 @@ struct Alarm std::string text; std::string audio_url; DateTime time; - std::chrono::seconds duration; bool operator== (const Alarm& that) const; }; diff --git a/src/appointment.cpp b/src/appointment.cpp index 236c5f4..1edd93c 100644 --- a/src/appointment.cpp +++ b/src/appointment.cpp @@ -31,8 +31,7 @@ bool Alarm::operator==(const Alarm& that) const { return (text==that.text) && (audio_url==that.audio_url) - && (this->time==that.time) - && (duration==that.duration); + && (this->time==that.time); } bool Appointment::operator==(const Appointment& that) const diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index ecbee59..856f190 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -559,7 +559,7 @@ private: if (a != nullptr) { - const DateTime alarm_begin{ai->occur_start}; + const DateTime alarm_begin{ai->trigger}; auto& alarm = alarms[alarm_begin]; if (alarm.text.empty()) @@ -568,8 +568,6 @@ private: alarm.audio_url = get_alarm_sound_url(a); if (!alarm.time.is_set()) alarm.time = alarm_begin; - if (alarm.duration == std::chrono::seconds::zero()) - alarm.duration = std::chrono::seconds(ai->occur_end - ai->occur_start); e_cal_component_alarm_free(a); } diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index cbe79cd..d04cf14 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -71,7 +71,7 @@ int main(int argc, const char* argv[]) a.type = Appointment::UBUNTU_ALARM; a.begin = DateTime::Local(2014, 12, 25, 0, 0, 0); a.end = a.begin.end_of_day(); - a.alarms.push_back(Alarm{"Alarm Text", "", a.begin, std::chrono::seconds::zero()}); + a.alarms.push_back(Alarm{"Alarm Text", "", a.begin}); auto loop = g_main_loop_new(nullptr, false); auto on_snooze = [loop](const Appointment& appt, const Alarm&){ diff --git a/tests/test-alarm-queue.cpp b/tests/test-alarm-queue.cpp index fdab425..aa35668 100644 --- a/tests/test-alarm-queue.cpp +++ b/tests/test-alarm-queue.cpp @@ -79,7 +79,7 @@ protected: a1.type = Appointment::UBUNTU_ALARM; a1.begin = tomorrow_begin; a1.end = tomorrow_end; - a1.alarms.push_back(Alarm{"Alarm Text", "", a1.begin, std::chrono::seconds::zero()}); + a1.alarms.push_back(Alarm{"Alarm Text", "", a1.begin}); const auto ubermorgen_begin = now.add_days(2).start_of_day(); const auto ubermorgen_end = ubermorgen_begin.end_of_day(); @@ -92,7 +92,7 @@ protected: a2.type = Appointment::EVENT; a2.begin = ubermorgen_begin; a2.end = ubermorgen_end; - a2.alarms.push_back(Alarm{"Alarm Text", "", a2.begin, std::chrono::seconds::zero()}); + a2.alarms.push_back(Alarm{"Alarm Text", "", a2.begin}); return std::vector({a1, a2}); } diff --git a/tests/test-snap.cpp b/tests/test-snap.cpp index 2e29132..46fbd10 100644 --- a/tests/test-snap.cpp +++ b/tests/test-snap.cpp @@ -111,7 +111,7 @@ protected: const auto christmas = DateTime::Local(2015,12,25,0,0,0); appt.begin = christmas.start_of_day(); appt.end = christmas.end_of_day(); - appt.alarms.push_back(Alarm{"Alarm Text", "", appt.begin, std::chrono::seconds::zero()}); + appt.alarms.push_back(Alarm{"Alarm Text", "", appt.begin}); service = dbus_test_service_new(nullptr); -- cgit v1.2.3 From 38a39c03d5b44c825afe0d10f67cc0802dcf2573 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 5 Apr 2015 21:12:01 -0500 Subject: remove some new bits that turned out to be unneeded after all --- include/datetime/appointment.h | 2 -- tests/test-eds-valarms.cpp | 24 ++---------------------- 2 files changed, 2 insertions(+), 24 deletions(-) (limited to 'include') diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index e9c1bc2..e323c9c 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -22,9 +22,7 @@ #include -#include #include -#include #include namespace unity { diff --git a/tests/test-eds-valarms.cpp b/tests/test-eds-valarms.cpp index f30539a..e9e07d8 100644 --- a/tests/test-eds-valarms.cpp +++ b/tests/test-eds-valarms.cpp @@ -19,8 +19,6 @@ #include -#include - #include #include #include @@ -32,27 +30,8 @@ #include "timezone-mock.h" #include "wakeup-timer-mock.h" - using namespace unity::indicator::datetime; - -class VAlarmFixture: public GlibFixture -{ -private: - - typedef GlibFixture super; - -protected: - - void SetUp() - { - super::SetUp(); - } - - void TearDown() - { - super::TearDown(); - } -}; +using VAlarmFixture = GlibFixture; /*** **** @@ -83,6 +62,7 @@ TEST_F(VAlarmFixture, MultipleAppointments) wait_msec(max_wait_sec * G_TIME_SPAN_MILLISECOND); } + // the planner should match what we've got in the calendar.ics file const auto appts = planner->appointments().get(); ASSERT_EQ(1, appts.size()); const auto& appt = appts.front(); -- cgit v1.2.3 From 4438c3a50d4c10d7516d736cb31ded01c57c791e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 6 Apr 2015 13:16:24 -0500 Subject: in DateTime class, make it harder to accidentally mix local and nonlocal timezones by replacing DateTime::DateTime(time_t) with two methods, DateTime::Local(time_t) and DateTime(GTimeZone*, time_t) --- include/datetime/date-time.h | 3 ++- src/date-time.cpp | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index 7e19a9d..ea9ea36 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -37,10 +37,11 @@ class DateTime { public: static DateTime NowLocal(); + static DateTime Local(time_t); static DateTime Local(int year, int month, int day, int hour, int minute, double seconds); DateTime(); - explicit DateTime(time_t t); + DateTime(GTimeZone* tz, time_t t); DateTime(GTimeZone* tz, GDateTime* dt); DateTime(GTimeZone* tz, int year, int month, int day, int hour, int minute, double seconds); DateTime& operator=(const DateTime& in); diff --git a/src/date-time.cpp b/src/date-time.cpp index 54601d0..4930bf6 100644 --- a/src/date-time.cpp +++ b/src/date-time.cpp @@ -65,13 +65,13 @@ DateTime& DateTime::operator+=(const std::chrono::seconds& seconds) return (*this = add_full(0, 0, 0, 0, 0, seconds.count())); } -DateTime::DateTime(time_t t) +DateTime::DateTime(GTimeZone* gtz, time_t t) { - auto gtz = g_time_zone_new_local(); - auto gdt = g_date_time_new_from_unix_local(t); + auto utc = g_date_time_new_from_unix_utc(t); + auto gdt = g_date_time_to_timezone (utc, gtz); reset(gtz, gdt); - g_time_zone_unref(gtz); g_date_time_unref(gdt); + g_date_time_unref(utc); } DateTime DateTime::NowLocal() @@ -84,6 +84,16 @@ DateTime DateTime::NowLocal() return dt; } +DateTime DateTime::Local(time_t t) +{ + auto gtz = g_time_zone_new_local(); + auto gdt = g_date_time_new_from_unix_local(t); + 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, double seconds) { auto gtz = g_time_zone_new_local(); -- cgit v1.2.3