diff --git a/date.c b/date.c index 3ba4cb9c13cf3d62dd17aa17fb68d14e97c70b16..1f070399cac148d246b4da4fcd469d5a62cacdd0 100644 --- a/date.c +++ b/date.c @@ -1127,45 +1127,47 @@ static void pending_number(struct tm *tm, int *num) static void date_now(struct tm *tm, struct tm *now, int *num) { *num = 0; + tm->tm_mday = -1; update_tm(tm, now, 0); } static void date_yesterday(struct tm *tm, struct tm *now, int *num) { *num = 0; + tm->tm_mday = -1; update_tm(tm, now, 24*60*60); } -static void date_time(struct tm *tm, struct tm *now, int hour) +static void date_time(struct tm *tm, int hour) { /* * By default, "tea" and "noon" refer to last such time in the * past, be it today or yesterday. With a specified mday, - * that logic is overridden. + * or e.g. "noon today", that logic is overridden. */ if (tm->tm_mday < 0 && tm->tm_hour < hour) - update_tm(tm, now, 24*60*60); + tm->tm_mday = -2; /* eventually handled by update_tm() */ tm->tm_hour = hour; tm->tm_min = 0; tm->tm_sec = 0; } -static void date_midnight(struct tm *tm, struct tm *now, int *num) +static void date_midnight(struct tm *tm, struct tm *now UNUSED, int *num) { pending_number(tm, num); - date_time(tm, now, 0); + date_time(tm, 0); } -static void date_noon(struct tm *tm, struct tm *now, int *num) +static void date_noon(struct tm *tm, struct tm *now UNUSED, int *num) { pending_number(tm, num); - date_time(tm, now, 12); + date_time(tm, 12); } -static void date_tea(struct tm *tm, struct tm *now, int *num) +static void date_tea(struct tm *tm, struct tm *now UNUSED, int *num) { pending_number(tm, num); - date_time(tm, now, 17); + date_time(tm, 17); } static void date_pm(struct tm *tm, struct tm *now UNUSED, int *num) @@ -1215,6 +1217,7 @@ static const struct special { { "AM", date_am }, { "never", date_never }, { "now", date_now }, + { "today", date_now }, { NULL } }; diff --git a/t/t0006-date.sh b/t/t0006-date.sh index c69a2fa745b3cbb014a35ed5c0885addfabf96ad..e58c0c595b15180b17d9af24f87f37a15a50a73c 100755 --- a/t/t0006-date.sh +++ b/t/t0006-date.sh @@ -186,7 +186,11 @@ check_approxidate '6pm yesterday' '2009-08-29 18:00:00' check_approxidate '3:00' '2009-08-30 03:00:00' check_approxidate '15:00' '2009-08-30 15:00:00' check_approxidate 'noon today' '2009-08-30 12:00:00' +check_approxidate 'noon today' '2009-08-30 12:00:00' success '-12' +check_approxidate 'noon today' '2009-09-01 12:00:00' success '+36' check_approxidate 'noon yesterday' '2009-08-29 12:00:00' +check_approxidate 'noon yesterday' '2009-08-29 12:00:00' success '-12' +check_approxidate 'tea last saturday' '2009-08-29 17:00:00' success '-12' check_approxidate 'January 5th noon pm' '2009-01-05 12:00:00' check_approxidate 'January 5th noon pm' '2009-01-05 12:00:00' success '-12' check_approxidate '10am noon' '2009-08-29 12:00:00'