Skip to content
Snippets Groups Projects
Verified Commit d070263e authored by Tuomas Ahola's avatar Tuomas Ahola
Browse files

approxidate: overwrite mday for now, today and yesterday


In c27cc94f (approxidate: handle pending number for
"specials", 2018-11-02) "Jan 5 yesterday" was given as
an example of an approxidate string where "the number
shouldn't be respected at all".  Likewise, "tea today"
shouldn't respect the usual tea-time logic of going
backwards in time; instead "today" should be able to
override the mday change possibly caused by "tea".

Add a new format "today" as an alias of "now", and make
it and "yesterday" overwrite mday.  Make date_time() use
the new method for deferred mday adjustment, and add tests
to cover the changes.

Signed-off-by: default avatarTuomas Ahola <taahol@utu.fi>
parent a923137e
No related branches found
No related tags found
No related merge requests found
......@@ -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 }
};
......
......@@ -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'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment