aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2013-05-02 15:38:57 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2013-05-02 15:38:57 +0200
commit370c4031be9c921ae54ccb7cafff71d0a2c9b790 (patch)
tree12bb3072277a8f9cabf6d968de702ea6241294b0 /src
parentec837150a0910026c60bf51ccf58db2a0e2fb5e0 (diff)
downloadcalcurse-370c4031be9c921ae54ccb7cafff71d0a2c9b790.tar.gz
calcurse-370c4031be9c921ae54ccb7cafff71d0a2c9b790.zip
recur.c: Refactor/Reformat recur_item_find_occurrence()
Fix a couple of whitespace and line breaks. Bail out early instead of using nested if statements. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src')
-rw-r--r--src/recur.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/recur.c b/src/recur.c
index c5b5f5e..801346d 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -597,8 +597,7 @@ recur_item_find_occurrence(long item_start, long item_dur,
lt_item_day = lt_item;
lt_item_day.tm_sec = lt_item_day.tm_min = lt_item_day.tm_hour = 0;
- span =
- (item_start - mktime(&lt_item_day) + item_dur - 1) / DAYINSEC;
+ span = (item_start - mktime(&lt_item_day) + item_dur - 1) / DAYINSEC;
switch (rpt_type) {
case RECUR_DAILY:
@@ -608,9 +607,8 @@ recur_item_find_occurrence(long item_start, long item_dur,
lt_item_day.tm_year = lt_day.tm_year;
break;
case RECUR_WEEKLY:
- diff =
- diff_days(lt_item_day,
- lt_day) % (rpt_freq * WEEKINDAYS);
+ diff = diff_days(lt_item_day, lt_day) %
+ (rpt_freq * WEEKINDAYS);
lt_item_day.tm_mday = lt_day.tm_mday - diff;
lt_item_day.tm_mon = lt_day.tm_mon;
lt_item_day.tm_year = lt_day.tm_year;
@@ -646,21 +644,19 @@ recur_item_find_occurrence(long item_start, long item_dur,
localtime_r(&t, &lt_item_day);
diff = diff_days(lt_item_day, lt_day);
- if (diff <= span) {
- if (occurrence) {
- start_date.dd = lt_item_day.tm_mday;
- start_date.mm = lt_item_day.tm_mon + 1;
- start_date.yyyy = lt_item_day.tm_year + 1900;
+ if (diff > span)
+ return 0;
- *occurrence =
- date2sec(start_date, lt_item.tm_hour,
- lt_item.tm_min);
- }
+ if (occurrence) {
+ start_date.dd = lt_item_day.tm_mday;
+ start_date.mm = lt_item_day.tm_mon + 1;
+ start_date.yyyy = lt_item_day.tm_year + 1900;
- return 1;
- } else {
- return 0;
+ *occurrence = date2sec(start_date, lt_item.tm_hour,
+ lt_item.tm_min);
}
+
+ return 1;
}
unsigned