diff --git a/date.c b/date.c index 4c57c599be3235fd4f0377cd9596a4f21a49e733..02e7304f9a40a3bd87d9780f17aede0a188134ef 100644 --- a/date.c +++ b/date.c @@ -1126,12 +1126,14 @@ 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); } @@ -1140,10 +1142,10 @@ static void date_time(struct tm *tm, struct tm *now, 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; tm->tm_hour = hour; tm->tm_min = 0; tm->tm_sec = 0; @@ -1214,6 +1216,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..44ecd50e8eac68c38d8d25666375a34be353bbd6 100755 --- a/t/t0006-date.sh +++ b/t/t0006-date.sh @@ -186,7 +186,10 @@ 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 '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'