From 39dd3c251db7a70b9ec013781ca74fe6fc241792 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Wed, 5 Oct 2011 09:28:17 +0200 Subject: Use parse_{time,duration}() where appropriate Make use of these new helpers at various places. Note that this patch implies a few behavioural changes: * Short forms such as "23:" and ":45" are allowed when entering times. * Durations always need to be prefixed with a plus sign ("+"), with the nice side effect that you can now use "+3:30" to declare an appointment that lasts three hours and thirty minutes (that's much more convenient than "+210"). Signed-off-by: Lukas Fleischer --- src/day.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src/day.c') diff --git a/src/day.c b/src/day.c index 496eeda..894d730 100644 --- a/src/day.c +++ b/src/day.c @@ -567,26 +567,28 @@ day_chk_busy_slices (struct date day, int slicesno, int *slices) } /* Request the user to enter a new time. */ -static char * -day_edit_time (long time) +static int +day_edit_time (int time, unsigned *new_hour, unsigned *new_minute) { - char *timestr; - char *msg_time = _("Enter the new time ([hh:mm] or [h:mm]) : "); + char *timestr = date_sec2date_str (time, "%H:%M"); + char *msg_time = _("Enter the new time ([hh:mm]) : "); char *enter_str = _("Press [Enter] to continue"); - char *fmt_msg = _("You entered an invalid time, should be [h:mm] or [hh:mm]"); + char *fmt_msg = _("You entered an invalid time, should be [hh:mm]"); - while (1) + for (;;) { status_mesg (msg_time, ""); - timestr = date_sec2date_str (time, "%H:%M"); updatestring (win[STA].p, ×tr, 0, 1); - if (check_time (timestr) != 1 || strlen (timestr) == 0) + if (parse_time (timestr, new_hour, new_minute) == 1) + { + mem_free (timestr); + return 1; + } + else { status_mesg (fmt_msg, enter_str); (void)wgetch (win[STA].p); } - else - return (timestr); } } @@ -596,15 +598,12 @@ update_start_time (long *start, long *dur) long newtime; unsigned hr, mn; int valid_date; - char *timestr; char *msg_wrong_time = _("Invalid time: start time must be before end time!"); char *msg_enter = _("Press [Enter] to continue"); do { - timestr = day_edit_time (*start); - (void)sscanf (timestr, "%u:%u", &hr, &mn); - mem_free (timestr); + day_edit_time (*start, &hr, &mn); newtime = update_time_in_date (*start, hr, mn); if (newtime < *start + *dur) { @@ -627,11 +626,8 @@ update_duration (long *start, long *dur) { long newtime; unsigned hr, mn; - char *timestr; - timestr = day_edit_time (*start + *dur); - (void)sscanf (timestr, "%u:%u", &hr, &mn); - mem_free (timestr); + day_edit_time (*start + *dur, &hr, &mn); newtime = update_time_in_date (*start, hr, mn); *dur = (newtime > *start) ? newtime - *start : DAYINSEC + newtime - *start; } -- cgit v1.2.3-54-g00ecf