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

Proposed by Rob Snelders
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 Approve
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.
Revision history for this message
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
=== modified file 'src/alarm.c'
--- src/alarm.c 2012-03-18 16:06:43 +0000
+++ src/alarm.c 2013-02-14 22:22:23 +0000
@@ -965,7 +965,7 @@
965 // Do we want to repeat this alarm?965 // Do we want to repeat this alarm?
966 if (alarm_should_repeat (alarm)) {966 if (alarm_should_repeat (alarm)) {
967 g_debug ("Alarm(%p) #%d: alarm() Repeating...", alarm, alarm->id);967 g_debug ("Alarm(%p) #%d: alarm() Repeating...", alarm, alarm->id);
968 alarm_update_timestamp_full (alarm, FALSE);968 alarm_update_timestamp (alarm);
969 } else {969 } else {
970 alarm_disable (alarm);970 alarm_disable (alarm);
971 }971 }
@@ -1785,15 +1785,15 @@
1785 * Set time according to hour, min, sec and alarm->repeat1785 * Set time according to hour, min, sec and alarm->repeat
1786 */1786 */
1787static void1787static void
1788alarm_set_timestamp (Alarm *alarm, guint hour, guint minute, guint second, gboolean include_today)1788alarm_set_timestamp (Alarm *alarm, guint hour, guint minute, guint second)
1789{1789{
1790 time_t now, new;1790 time_t now, new;
1791 gint i, d, wday;1791 gint i, d, wday;
1792 AlarmRepeat rep;1792 AlarmRepeat rep;
1793 struct tm *tm;1793 struct tm *tm;
1794 1794
1795 g_debug ("Alarm(%p) #%d: set_timestamp (%d, %d, %d, %d)", alarm, alarm->id,1795 g_debug ("Alarm(%p) #%d: set_timestamp (%d, %d, %d)", alarm, alarm->id,
1796 hour, minute, second, include_today);1796 hour, minute, second);
1797 1797
1798 time (&now);1798 time (&now);
1799 tm = localtime (&now);1799 tm = localtime (&now);
@@ -1801,38 +1801,24 @@
1801 // Automatically detect Daylight Savings Time (DST)1801 // Automatically detect Daylight Savings Time (DST)
1802 tm->tm_isdst = -1;1802 tm->tm_isdst = -1;
1803 1803
1804 //i = (today == 6) ? 0 : today + 1;
1805 //today--;
1806
1807 if (alarm->repeat == ALARM_REPEAT_NONE) {1804 if (alarm->repeat == ALARM_REPEAT_NONE) {
1808 // Check if the alarm is for tomorrow1805 // Check if the alarm is for tomorrow
1809 if (!alarm_time_is_future (tm, hour, minute, second)) {1806 if (!alarm_time_is_future (tm, hour, minute, second)) {
1810 1807
1811 //if (wday < 0) {1808 g_debug("\tAlarm is for tomorrow.");
1812 g_debug("\tAlarm is for tomorrow.");1809 tm->tm_mday++;
1813 tm->tm_mday++;
1814 /*} else {
1815 // wday == tm->tm_wday
1816 g_debug("alarm_set_time_full: Alarm is in 1 week.");
1817 tm->tm_mday += 7;
1818 }*/
1819 }1810 }
1820 } else {1811 } else {
1821 // REPEAT SET: Find the closest repeat day1812 // REPEAT SET: Find the closest repeat day
1822 wday = -1;1813 wday = -1;
1823 1814
1824 i = tm->tm_wday;1815 i = tm->tm_wday;
1825 if (!include_today)
1826 i++;
1827 1816
1828 // Try finding a day in this week1817 // Try finding a day in this week
1829 for (; i < 7; i++) {1818 for (; i < 7; i++) {
1830 rep = 1 << i;1819 rep = 1 << i;
1831 if (alarm->repeat & rep) {1820 if (alarm->repeat & rep) {
1832 if (i == tm->tm_wday && !alarm_time_is_future (tm, hour, minute, second)) continue;1821 if (i == tm->tm_wday && !alarm_time_is_future (tm, hour, minute, second)) continue;
1833
1834 // FOUND!
1835 //g_debug ("\tMATCH");
1836 wday = i;1822 wday = i;
1837 break;1823 break;
1838 }1824 }
@@ -1842,9 +1828,7 @@
1842 if (wday == -1) {1828 if (wday == -1) {
1843 for (i = 0; i <= tm->tm_wday; i++) {1829 for (i = 0; i <= tm->tm_wday; i++) {
1844 rep = 1 << i;1830 rep = 1 << i;
1845 if (alarm->repeat & rep/* && alarm_time_is_future (tm, hour, minute, second)*/) {1831 if (alarm->repeat & rep) {
1846 // FOUND!
1847 //g_debug ("\tMATCH");
1848 wday = i;1832 wday = i;
1849 break;1833 break;
1850 }1834 }
@@ -1853,16 +1837,14 @@
1853 1837
1854 g_debug ("Closest WDAY = %d", wday);1838 g_debug ("Closest WDAY = %d", wday);
1855 1839
1856 if (wday == tm->tm_wday && (!include_today || !alarm_time_is_future (tm, hour, minute, second)))1840 if (wday == tm->tm_wday && (!alarm_time_is_future (tm, hour, minute, second)))
1857 wday = 7;1841 wday = 7;
1858 1842
1859
1860 // Calculate distance from now to wday1843 // Calculate distance from now to wday
1861 if (wday == 7) {1844 if (wday == 7) {
1862 g_debug("\tAlarm is in (forced) 1 week.");1845 g_debug("\tAlarm is in (forced) 1 week.");
1863 d = 7;1846 d = 7;
1864 } else {1847 } else {
1865// g_debug ("\td = tm->tm_wday(%d) - wday(%d)", tm->tm_wday, wday);
1866 d = alarm_wday_distance (tm->tm_wday, wday);1848 d = alarm_wday_distance (tm->tm_wday, wday);
1867 }1849 }
1868 1850
@@ -1875,11 +1857,6 @@
1875 tm->tm_min = minute;1857 tm->tm_min = minute;
1876 tm->tm_sec = second;1858 tm->tm_sec = second;
1877 1859
1878 // DEBUG:
1879 char tmp[512];
1880 strftime (tmp, sizeof (tmp), "%c", tm);
1881 g_debug ("\tAlarm will trigger at %s", tmp);
1882
1883 new = mktime (tm);1860 new = mktime (tm);
1884 g_debug ("\tSetting to %d", (gint) new);1861 g_debug ("\tSetting to %d", (gint) new);
1885 g_object_set (alarm, "timestamp", new, NULL);1862 g_object_set (alarm, "timestamp", new, NULL);
@@ -1890,13 +1867,13 @@
1890 * hour/min/sec according to the time value.1867 * hour/min/sec according to the time value.
1891 */1868 */
1892void1869void
1893alarm_update_timestamp_full (Alarm *alarm, gboolean include_today)1870alarm_update_timestamp (Alarm *alarm)
1894{1871{
1895 if (alarm->type == ALARM_TYPE_CLOCK) {1872 if (alarm->type == ALARM_TYPE_CLOCK) {
1896 struct tm *tm = alarm_get_time (alarm);1873 struct tm *tm = alarm_get_time (alarm);
1897 g_debug ("Alarm(%p) #%d: update_timestamp_full: %d:%d:%d", alarm, alarm->id,1874 g_debug ("Alarm(%p) #%d: update_timestamp_full: %d:%d:%d", alarm, alarm->id,
1898 tm->tm_hour, tm->tm_min, tm->tm_sec);1875 tm->tm_hour, tm->tm_min, tm->tm_sec);
1899 alarm_set_timestamp (alarm, tm->tm_hour, tm->tm_min, tm->tm_sec, include_today);1876 alarm_set_timestamp (alarm, tm->tm_hour, tm->tm_min, tm->tm_sec);
1900 } else {1877 } else {
1901 /* ALARM_TYPE_TIMER */1878 /* ALARM_TYPE_TIMER */
1902 g_object_set (alarm, "timestamp", time(NULL) + alarm->time, NULL);1879 g_object_set (alarm, "timestamp", time(NULL) + alarm->time, NULL);
@@ -1904,18 +1881,6 @@
1904}1881}
19051882
1906/*1883/*
1907 * Update the alarm timestamp to point to the nearest future
1908 * hour/min/sec according to the time value.
1909 *
1910 * Equivalent to alarm_update_timestamp_full (alarm, TRUE)
1911 */
1912void
1913alarm_update_timestamp (Alarm *alarm)
1914{
1915 alarm_update_timestamp_full (alarm, TRUE);
1916}
1917
1918/*
1919 * Get the alarm time.1884 * Get the alarm time.
1920 */1885 */
1921struct tm *1886struct tm *

Subscribers

People subscribed via source and target branches