summaryrefslogtreecommitdiff
path: root/src/ui-day.c
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2016-10-09 18:11:33 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2016-10-09 18:12:45 +0200
commit343d68596d0bf16d6e041d3a7871ceacbf54300b (patch)
tree425a3c6a56a56407904a7871fa95841dafd41829 /src/ui-day.c
parent1f39b5c6681536ef833a2e2e1312f2747be728f3 (diff)
downloadcalcurse-343d68596d0bf16d6e041d3a7871ceacbf54300b.zip
Factor out parse_datetime()
Create a new function that takes a time stamp and updates the date or time components of that time stamp according to a given date/time string. Use that function for updating the start time of an item. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/ui-day.c')
-rw-r--r--src/ui-day.c30
1 files changed, 5 insertions, 25 deletions
diff --git a/src/ui-day.c b/src/ui-day.c
index b651ca5..0c31b3c 100644
--- a/src/ui-day.c
+++ b/src/ui-day.c
@@ -67,36 +67,16 @@ static int day_edit_time(int time)
const char *enter_str = _("Press [Enter] to continue");
const char *fmt_msg =
_("You entered an invalid time, should be [hh:mm] or [hhmm]");
- unsigned int hour, minute;
- int year, month, day;
- struct date new_date;
+ long ts = time;
for (;;) {
status_mesg(msg_time, "");
if (updatestring(win[STA].p, &input, 0, 1) != GETSTRING_VALID)
return 0;
- char *inputcpy = mem_strdup(input);
- char *p = strtok(inputcpy, " ");
- while (p) {
- if (parse_date(p, conf.input_datefmt, &year, &month,
- &day, ui_calendar_get_slctd_day())) {
- new_date.dd = day;
- new_date.mm = month;
- new_date.yyyy = year;
- time = date2sec(new_date, 0, 0) +
- get_item_time(time);
- } else if (parse_time(p, &hour, &minute) == 1) {
- time = update_time_in_date(time, hour, minute);
- } else {
- status_mesg(fmt_msg, enter_str);
- wgetch(win[KEY].p);
- break;
- }
- p = strtok(NULL, " ");
- }
- mem_free(inputcpy);
- if (!p)
- return time;
+ if (parse_datetime(input, &ts))
+ return ts;
+ status_mesg(fmt_msg, enter_str);
+ wgetch(win[KEY].p);
}
}