Refactor duration/end time parsing
Replace all remaining invocations of parse_time() by parse_datetime() which now indicates whether a date was supplied or not. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
adf29c8ee9
commit
48bd82a003
64
src/ui-day.c
64
src/ui-day.c
@ -89,8 +89,7 @@ static int day_edit_duration(int start, int dur, unsigned *new_duration)
|
|||||||
const char *enter_str = _("Press [Enter] to continue");
|
const char *enter_str = _("Press [Enter] to continue");
|
||||||
const char *fmt_msg =
|
const char *fmt_msg =
|
||||||
_("You entered an invalid time, should be [hh:mm] or [hhmm]");
|
_("You entered an invalid time, should be [hh:mm] or [hhmm]");
|
||||||
long newtime = start + dur;
|
long end;
|
||||||
unsigned hr, mn;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int ret;
|
int ret;
|
||||||
@ -102,25 +101,29 @@ static int day_edit_duration(int start, int dur, unsigned *new_duration)
|
|||||||
} else if (ret == GETSTRING_RET) {
|
} else if (ret == GETSTRING_RET) {
|
||||||
*new_duration = 0;
|
*new_duration = 0;
|
||||||
break;
|
break;
|
||||||
} else if (*timestr == '+'
|
}
|
||||||
&& parse_duration(timestr + 1, new_duration) == 1) {
|
if (*timestr == '+') {
|
||||||
|
if (parse_duration(timestr + 1, new_duration)) {
|
||||||
*new_duration *= MININSEC;
|
*new_duration *= MININSEC;
|
||||||
break;
|
break;
|
||||||
} else if (parse_time(timestr, &hr, &mn) == 1) {
|
}
|
||||||
newtime = update_time_in_date(start + dur, hr, mn);
|
}
|
||||||
*new_duration =
|
end = start + dur;
|
||||||
(newtime >
|
ret = parse_datetime(timestr, &end);
|
||||||
start) ? newtime - start : DAYINSEC +
|
/*
|
||||||
newtime - start;
|
* If the user enters a end time which is smaller than
|
||||||
|
* the start time, assume that the time belongs to the
|
||||||
|
* next day.
|
||||||
|
*/
|
||||||
|
if (ret == 2 && end < start)
|
||||||
|
end = date_sec_change(end, 0, 1);
|
||||||
|
if (ret) {
|
||||||
|
*new_duration = end - start;
|
||||||
break;
|
break;
|
||||||
} else if (parse_datetime(timestr, &newtime)) {
|
}
|
||||||
*new_duration = newtime - start;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
status_mesg(fmt_msg, enter_str);
|
status_mesg(fmt_msg, enter_str);
|
||||||
wgetch(win[KEY].p);
|
wgetch(win[KEY].p);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mem_free(timestr);
|
mem_free(timestr);
|
||||||
return 1;
|
return 1;
|
||||||
@ -518,8 +521,7 @@ void ui_day_item_add(void)
|
|||||||
char item_time[LDUR] = "";
|
char item_time[LDUR] = "";
|
||||||
char item_mesg[BUFSIZ] = "";
|
char item_mesg[BUFSIZ] = "";
|
||||||
time_t start = date2sec(*ui_calendar_get_slctd_day(), 0, 0), end;
|
time_t start = date2sec(*ui_calendar_get_slctd_day(), 0, 0), end;
|
||||||
unsigned apoint_duration;
|
unsigned dur;
|
||||||
unsigned end_h, end_m;
|
|
||||||
int is_appointment = 1;
|
int is_appointment = 1;
|
||||||
int ret;
|
int ret;
|
||||||
union aptev_ptr item;
|
union aptev_ptr item;
|
||||||
@ -556,23 +558,26 @@ void ui_day_item_add(void)
|
|||||||
GETSTRING_ESC)
|
GETSTRING_ESC)
|
||||||
return;
|
return;
|
||||||
if (strlen(item_time) == 0) {
|
if (strlen(item_time) == 0) {
|
||||||
apoint_duration = 0;
|
dur = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (*item_time == '+' && parse_duration(item_time + 1,
|
if (*item_time == '+') {
|
||||||
&apoint_duration) == 1) {
|
if (parse_duration(item_time + 1, &dur)) {
|
||||||
apoint_duration *= MININSEC;
|
dur *= MININSEC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (parse_time(item_time, &end_h, &end_m) == 1) {
|
|
||||||
end = update_time_in_date(start, end_h, end_m);
|
|
||||||
apoint_duration = (end > start) ? end - start :
|
|
||||||
DAYINSEC + end - start;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
end = start;
|
end = start;
|
||||||
if (parse_datetime(item_time, &end)) {
|
ret = parse_datetime(item_time, &end);
|
||||||
apoint_duration = end - start;
|
/*
|
||||||
|
* If the user enters a end time which is smaller than
|
||||||
|
* the start time, assume that the time belongs to the
|
||||||
|
* next day.
|
||||||
|
*/
|
||||||
|
if (ret == 2 && end < start)
|
||||||
|
end = date_sec_change(end, 0, 1);
|
||||||
|
if (ret) {
|
||||||
|
dur = end - start;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
status_mesg(format_message_2, enter_str);
|
status_mesg(format_message_2, enter_str);
|
||||||
@ -584,8 +589,7 @@ void ui_day_item_add(void)
|
|||||||
if (getstring(win[STA].p, item_mesg, BUFSIZ, 0, 1) ==
|
if (getstring(win[STA].p, item_mesg, BUFSIZ, 0, 1) ==
|
||||||
GETSTRING_VALID) {
|
GETSTRING_VALID) {
|
||||||
if (is_appointment) {
|
if (is_appointment) {
|
||||||
item.apt = apoint_new(item_mesg, 0L, start,
|
item.apt = apoint_new(item_mesg, 0L, start, dur, 0L);
|
||||||
apoint_duration, 0L);
|
|
||||||
if (notify_bar())
|
if (notify_bar())
|
||||||
notify_check_added(item_mesg, start, 0L);
|
notify_check_added(item_mesg, start, 0L);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user