Add support for entering times in 24 hour format

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
William Pettersson 2012-10-07 20:30:12 +10:00 committed by Lukas Fleischer
parent 7e7987575a
commit 65dc584662
2 changed files with 12 additions and 10 deletions

View File

@ -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) static int day_edit_time(int time, unsigned *new_hour, unsigned *new_minute)
{ {
char *timestr = date_sec2date_str(time, "%H:%M"); 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 *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 (;;) { for (;;) {
status_mesg(msg_time, ""); 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"); char *timestr = date_sec2date_str(start + dur, "%H:%M");
const char *msg_time = 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 *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; long newtime;
unsigned hr, mn; unsigned hr, mn;
@ -414,16 +414,16 @@ void interact_day_item_add(void)
#define LTIME 6 #define LTIME 6
#define LDUR 12 #define LDUR 12
const char *mesg_1 = 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 = 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 *mesg_3 = _("Enter description :");
const char *format_message_1 = 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 = 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"); const char *enter_str = _("Press [Enter] to continue");
int Id = 1; int Id = 1;
char item_time[LDUR] = ""; char item_time[LDUR] = "";

View File

@ -740,9 +740,11 @@ int parse_time(const char *string, unsigned *hour, unsigned *minute)
if (*p == ':') { if (*p == ':') {
if ((++n) > 1) if ((++n) > 1)
return 0; 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'); in[n] = in[n] * 10 + (int)(*p - '0');
else } else
return 0; return 0;
} }