Merge lp:~ertainl/alarm-clock/bug1122500 into lp:~joh/alarm-clock/trunk

Proposed by Rob Snelders on 2013-02-14
Status: Merged
Merge reported by: Johannes H. Jensen
Merged at revision: not available
Proposed branch: lp:~ertainl/alarm-clock/bug1122500
Merge into: lp:~joh/alarm-clock/trunk
Diff against target: 148 lines (+10/-45)
1 file modified
src/alarm.c (+10/-45)
To merge this branch: bzr merge lp:~ertainl/alarm-clock/bug1122500
Reviewer Review Type Date Requested Status
Johannes H. Jensen 2013-02-14 Approve on 2013-02-16
Review via email: mp+148567@code.launchpad.net

Description of the change

This problem solves lp#1122500.

It removes the option in the code to ask specificly for setting the alarm-time on the next day, as you always want the next one and never the one after that first.
There is a check to never take one that already has been.

To post a comment you must log in.
Johannes H. Jensen (joh) wrote :

Looks good! The include_today flag was added to guard against a corner case, but the call to alarm_time_is_future() seems to make it obsolete.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/alarm.c'
2--- src/alarm.c 2012-03-18 16:06:43 +0000
3+++ src/alarm.c 2013-02-14 22:22:23 +0000
4@@ -965,7 +965,7 @@
5 // Do we want to repeat this alarm?
6 if (alarm_should_repeat (alarm)) {
7 g_debug ("Alarm(%p) #%d: alarm() Repeating...", alarm, alarm->id);
8- alarm_update_timestamp_full (alarm, FALSE);
9+ alarm_update_timestamp (alarm);
10 } else {
11 alarm_disable (alarm);
12 }
13@@ -1785,15 +1785,15 @@
14 * Set time according to hour, min, sec and alarm->repeat
15 */
16 static void
17-alarm_set_timestamp (Alarm *alarm, guint hour, guint minute, guint second, gboolean include_today)
18+alarm_set_timestamp (Alarm *alarm, guint hour, guint minute, guint second)
19 {
20 time_t now, new;
21 gint i, d, wday;
22 AlarmRepeat rep;
23 struct tm *tm;
24
25- g_debug ("Alarm(%p) #%d: set_timestamp (%d, %d, %d, %d)", alarm, alarm->id,
26- hour, minute, second, include_today);
27+ g_debug ("Alarm(%p) #%d: set_timestamp (%d, %d, %d)", alarm, alarm->id,
28+ hour, minute, second);
29
30 time (&now);
31 tm = localtime (&now);
32@@ -1801,38 +1801,24 @@
33 // Automatically detect Daylight Savings Time (DST)
34 tm->tm_isdst = -1;
35
36- //i = (today == 6) ? 0 : today + 1;
37- //today--;
38-
39 if (alarm->repeat == ALARM_REPEAT_NONE) {
40 // Check if the alarm is for tomorrow
41 if (!alarm_time_is_future (tm, hour, minute, second)) {
42
43- //if (wday < 0) {
44- g_debug("\tAlarm is for tomorrow.");
45- tm->tm_mday++;
46- /*} else {
47- // wday == tm->tm_wday
48- g_debug("alarm_set_time_full: Alarm is in 1 week.");
49- tm->tm_mday += 7;
50- }*/
51+ g_debug("\tAlarm is for tomorrow.");
52+ tm->tm_mday++;
53 }
54 } else {
55 // REPEAT SET: Find the closest repeat day
56 wday = -1;
57
58 i = tm->tm_wday;
59- if (!include_today)
60- i++;
61
62 // Try finding a day in this week
63 for (; i < 7; i++) {
64 rep = 1 << i;
65 if (alarm->repeat & rep) {
66 if (i == tm->tm_wday && !alarm_time_is_future (tm, hour, minute, second)) continue;
67-
68- // FOUND!
69- //g_debug ("\tMATCH");
70 wday = i;
71 break;
72 }
73@@ -1842,9 +1828,7 @@
74 if (wday == -1) {
75 for (i = 0; i <= tm->tm_wday; i++) {
76 rep = 1 << i;
77- if (alarm->repeat & rep/* && alarm_time_is_future (tm, hour, minute, second)*/) {
78- // FOUND!
79- //g_debug ("\tMATCH");
80+ if (alarm->repeat & rep) {
81 wday = i;
82 break;
83 }
84@@ -1853,16 +1837,14 @@
85
86 g_debug ("Closest WDAY = %d", wday);
87
88- if (wday == tm->tm_wday && (!include_today || !alarm_time_is_future (tm, hour, minute, second)))
89+ if (wday == tm->tm_wday && (!alarm_time_is_future (tm, hour, minute, second)))
90 wday = 7;
91
92-
93 // Calculate distance from now to wday
94 if (wday == 7) {
95 g_debug("\tAlarm is in (forced) 1 week.");
96 d = 7;
97 } else {
98-// g_debug ("\td = tm->tm_wday(%d) - wday(%d)", tm->tm_wday, wday);
99 d = alarm_wday_distance (tm->tm_wday, wday);
100 }
101
102@@ -1875,11 +1857,6 @@
103 tm->tm_min = minute;
104 tm->tm_sec = second;
105
106- // DEBUG:
107- char tmp[512];
108- strftime (tmp, sizeof (tmp), "%c", tm);
109- g_debug ("\tAlarm will trigger at %s", tmp);
110-
111 new = mktime (tm);
112 g_debug ("\tSetting to %d", (gint) new);
113 g_object_set (alarm, "timestamp", new, NULL);
114@@ -1890,13 +1867,13 @@
115 * hour/min/sec according to the time value.
116 */
117 void
118-alarm_update_timestamp_full (Alarm *alarm, gboolean include_today)
119+alarm_update_timestamp (Alarm *alarm)
120 {
121 if (alarm->type == ALARM_TYPE_CLOCK) {
122 struct tm *tm = alarm_get_time (alarm);
123 g_debug ("Alarm(%p) #%d: update_timestamp_full: %d:%d:%d", alarm, alarm->id,
124 tm->tm_hour, tm->tm_min, tm->tm_sec);
125- alarm_set_timestamp (alarm, tm->tm_hour, tm->tm_min, tm->tm_sec, include_today);
126+ alarm_set_timestamp (alarm, tm->tm_hour, tm->tm_min, tm->tm_sec);
127 } else {
128 /* ALARM_TYPE_TIMER */
129 g_object_set (alarm, "timestamp", time(NULL) + alarm->time, NULL);
130@@ -1904,18 +1881,6 @@
131 }
132
133 /*
134- * Update the alarm timestamp to point to the nearest future
135- * hour/min/sec according to the time value.
136- *
137- * Equivalent to alarm_update_timestamp_full (alarm, TRUE)
138- */
139-void
140-alarm_update_timestamp (Alarm *alarm)
141-{
142- alarm_update_timestamp_full (alarm, TRUE);
143-}
144-
145-/*
146 * Get the alarm time.
147 */
148 struct tm *

Subscribers

People subscribed via source and target branches