From 65dc58466260320303c7af8c5c8a8bfe3b0802c8 Mon Sep 17 00:00:00 2001 From: William Pettersson Date: Sun, 7 Oct 2012 20:30:12 +1000 Subject: Add support for entering times in 24 hour format Signed-off-by: Lukas Fleischer --- src/interaction.c | 16 ++++++++-------- src/utils.c | 6 ++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/interaction.c b/src/interaction.c index 0a3b743..2d6830e 100644 --- a/src/interaction.c +++ b/src/interaction.c @@ -42,9 +42,9 @@ struct day_item day_cut[38] = { { 0, 0, { NULL } } }; static int day_edit_time(int time, unsigned *new_hour, unsigned *new_minute) { char *timestr = date_sec2date_str(time, "%H:%M"); - const char *msg_time = _("Enter the new time ([hh:mm]) : "); + const char *msg_time = _("Enter the new time ([hh:mm] or [hhmm]) : "); const char *enter_str = _("Press [Enter] to continue"); - const char *fmt_msg = _("You entered an invalid time, should be [hh:mm]"); + const char *fmt_msg = _("You entered an invalid time, should be [hh:mm] or [hhmm]"); for (;;) { status_mesg(msg_time, ""); @@ -67,9 +67,9 @@ static int day_edit_duration(int start, int dur, unsigned *new_duration) char *timestr = date_sec2date_str(start + dur, "%H:%M"); const char *msg_time = _ - ("Enter new end time ([hh:mm]) or duration ([+hh:mm], [+xxxdxxhxxm] or [+mm]) : "); + ("Enter new end time ([hh:mm], [hhmm]) or duration ([+hh:mm], [+xxxdxxhxxm] or [+mm]) : "); const char *enter_str = _("Press [Enter] to continue"); - const char *fmt_msg = _("You entered an invalid time, should be [hh:mm]"); + const char *fmt_msg = _("You entered an invalid time, should be [hh:mm] or [hhmm]"); long newtime; unsigned hr, mn; @@ -414,16 +414,16 @@ void interact_day_item_add(void) #define LTIME 6 #define LDUR 12 const char *mesg_1 = - _("Enter start time ([hh:mm]), leave blank for an all-day event : "); + _("Enter start time ([hh:mm] or [hhmm]), leave blank for an all-day event : "); const char *mesg_2 = _ - ("Enter end time ([hh:mm]) or duration ([+hh:mm], [+xxxdxxhxxm] or [+mm]) : "); + ("Enter end time ([hh:mm] or [hhmm]) or duration ([+hh:mm], [+xxxdxxhxxm] or [+mm]) : "); const char *mesg_3 = _("Enter description :"); const char *format_message_1 = - _("You entered an invalid start time, should be [hh:mm]"); + _("You entered an invalid start time, should be [hh:mm] or [hhmm]"); const char *format_message_2 = _ - ("Invalid end time/duration, should be [hh:mm], [+hh:mm], [+xxxdxxhxxm] or [+mm]"); + ("Invalid end time/duration, should be [hh:mm], [hhmm], [+hh:mm], [+xxxdxxhxxm] or [+mm]"); const char *enter_str = _("Press [Enter] to continue"); int Id = 1; char item_time[LDUR] = ""; diff --git a/src/utils.c b/src/utils.c index 3e86f17..2ca35de 100644 --- a/src/utils.c +++ b/src/utils.c @@ -740,9 +740,11 @@ int parse_time(const char *string, unsigned *hour, unsigned *minute) if (*p == ':') { if ((++n) > 1) return 0; - } else if ((*p >= '0') && (*p <= '9')) + } else if ((*p >= '0') && (*p <= '9')) { + if ((n == 0) && (p == (string + 2)) && *(p + 1)) + n++; in[n] = in[n] * 10 + (int)(*p - '0'); - else + } else return 0; } -- cgit v1.2.3