Replace parse_datetime() constants by named flags

Remove the magic constants used in the return value of parse_datetime()
and use named flags instead.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lukas Fleischer 2016-10-10 08:56:54 +02:00
parent 48bd82a003
commit 007a73f7a2
3 changed files with 9 additions and 5 deletions

View File

@ -628,6 +628,10 @@ enum getstr {
GETSTRING_RET /* return was pressed without entering any text. */ GETSTRING_RET /* return was pressed without entering any text. */
}; };
/* Return codes for parse_datetime(). */
#define PARSE_DATETIME_HAS_DATE (1 << 0)
#define PARSE_DATETIME_HAS_TIME (1 << 1)
/* Week days. */ /* Week days. */
enum wday { enum wday {
SUNDAY, SUNDAY,

View File

@ -115,7 +115,7 @@ static int day_edit_duration(int start, int dur, unsigned *new_duration)
* the start time, assume that the time belongs to the * the start time, assume that the time belongs to the
* next day. * next day.
*/ */
if (ret == 2 && end < start) if (!(ret & PARSE_DATETIME_HAS_DATE) && end < start)
end = date_sec_change(end, 0, 1); end = date_sec_change(end, 0, 1);
if (ret) { if (ret) {
*new_duration = end - start; *new_duration = end - start;
@ -537,7 +537,7 @@ void ui_day_item_add(void)
break; break;
} }
ret = parse_datetime(item_time, &start); ret = parse_datetime(item_time, &start);
if (!(ret & 2)) if (!(ret & PARSE_DATETIME_HAS_TIME))
is_appointment = 0; is_appointment = 0;
if (ret) if (ret)
break; break;
@ -574,7 +574,7 @@ void ui_day_item_add(void)
* the start time, assume that the time belongs to the * the start time, assume that the time belongs to the
* next day. * next day.
*/ */
if (ret == 2 && end < start) if (!(ret & PARSE_DATETIME_HAS_DATE) && end < start)
end = date_sec_change(end, 0, 1); end = date_sec_change(end, 0, 1);
if (ret) { if (ret) {
dur = end - start; dur = end - start;

View File

@ -1132,10 +1132,10 @@ int parse_datetime(const char *string, long *ts)
new_date.mm = month; new_date.mm = month;
new_date.yyyy = year; new_date.yyyy = year;
*ts = date2sec(new_date, 0, 0) + get_item_time(*ts); *ts = date2sec(new_date, 0, 0) + get_item_time(*ts);
ret |= 1; ret |= PARSE_DATETIME_HAS_DATE;
} else if (parse_time(p, &hour, &minute) == 1) { } else if (parse_time(p, &hour, &minute) == 1) {
*ts = update_time_in_date(*ts, hour, minute); *ts = update_time_in_date(*ts, hour, minute);
ret |= 2; ret |= PARSE_DATETIME_HAS_TIME;
} else { } else {
return 0; return 0;
} }