Refactor day_edit_time()
Make the function more flexible by returning the updated time instead of single hour and minute components. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
1af9ccccd7
commit
1003be18df
15
src/ui-day.c
15
src/ui-day.c
@ -59,8 +59,7 @@ void ui_day_set_selitem(struct day_item *day)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Request the user to enter a new time. */
|
/* Request the user to enter a new time. */
|
||||||
static int day_edit_time(int time, unsigned *new_hour,
|
static int day_edit_time(int time)
|
||||||
unsigned *new_minute)
|
|
||||||
{
|
{
|
||||||
char *timestr = date_sec2date_str(time, "%H:%M");
|
char *timestr = date_sec2date_str(time, "%H:%M");
|
||||||
const char *msg_time =
|
const char *msg_time =
|
||||||
@ -68,15 +67,16 @@ static int day_edit_time(int time, unsigned *new_hour,
|
|||||||
const char *enter_str = _("Press [Enter] to continue");
|
const char *enter_str = _("Press [Enter] to continue");
|
||||||
const char *fmt_msg =
|
const char *fmt_msg =
|
||||||
_("You entered an invalid time, should be [hh:mm] or [hhmm]");
|
_("You entered an invalid time, should be [hh:mm] or [hhmm]");
|
||||||
|
int hour, minute;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
status_mesg(msg_time, "");
|
status_mesg(msg_time, "");
|
||||||
if (updatestring(win[STA].p, ×tr, 0, 1) !=
|
if (updatestring(win[STA].p, ×tr, 0, 1) !=
|
||||||
GETSTRING_VALID)
|
GETSTRING_VALID)
|
||||||
return 0;
|
return 0;
|
||||||
if (parse_time(timestr, new_hour, new_minute) == 1) {
|
if (parse_time(timestr, &hour, &minute) == 1) {
|
||||||
mem_free(timestr);
|
mem_free(timestr);
|
||||||
return 1;
|
return update_time_in_date(time, hour, minute);
|
||||||
} else {
|
} else {
|
||||||
status_mesg(fmt_msg, enter_str);
|
status_mesg(fmt_msg, enter_str);
|
||||||
wgetch(win[KEY].p);
|
wgetch(win[KEY].p);
|
||||||
@ -131,20 +131,19 @@ static int day_edit_duration(int start, int dur, unsigned *new_duration)
|
|||||||
static void update_start_time(long *start, long *dur, int update_dur)
|
static void update_start_time(long *start, long *dur, int update_dur)
|
||||||
{
|
{
|
||||||
long newtime;
|
long newtime;
|
||||||
unsigned hr, mn;
|
|
||||||
int valid_date;
|
int valid_date;
|
||||||
const char *msg_wrong_time =
|
const char *msg_wrong_time =
|
||||||
_("Invalid time: start time must be before end time!");
|
_("Invalid time: start time must be before end time!");
|
||||||
const char *msg_enter = _("Press [Enter] to continue");
|
const char *msg_enter = _("Press [Enter] to continue");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (!day_edit_time(*start, &hr, &mn))
|
newtime = day_edit_time(*start);
|
||||||
|
if (!newtime)
|
||||||
break;
|
break;
|
||||||
if (!update_dur) {
|
if (!update_dur) {
|
||||||
*start = update_time_in_date(*start, hr, mn);
|
*start = newtime;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
newtime = update_time_in_date(*start, hr, mn);
|
|
||||||
if (newtime < *start + *dur) {
|
if (newtime < *start + *dur) {
|
||||||
*dur -= (newtime - *start);
|
*dur -= (newtime - *start);
|
||||||
*start = newtime;
|
*start = newtime;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user