From 370c4031be9c921ae54ccb7cafff71d0a2c9b790 Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <calcurse@cryptocrack.de>
Date: Thu, 2 May 2013 15:38:57 +0200
Subject: 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>
---
 src/recur.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

(limited to 'src')

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
-- 
cgit v1.2.3-70-g09d2