summaryrefslogtreecommitdiff
path: root/src/day.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2011-10-05 09:28:17 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2011-10-06 12:37:06 +0200
commit39dd3c251db7a70b9ec013781ca74fe6fc241792 (patch)
tree2d51ca2c43a18354441fb13233728f38a339a01e /src/day.c
parent0acbc06c4308576c50e7c4929f35fd09ff069ac7 (diff)
downloadcalcurse-39dd3c251db7a70b9ec013781ca74fe6fc241792.zip
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 <calcurse@cryptocrack.de>
Diffstat (limited to 'src/day.c')
-rw-r--r--src/day.c32
1 files changed, 14 insertions, 18 deletions
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, &timestr, 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;
}