1 # $NetBSD: varmod-localtime.mk,v 1.5 2020/10/31 20:30:06 rillig Exp $
3 # Tests for the :localtime variable modifier, which formats a timestamp
4 # using strftime(3) in local time.
6 .if ${TZ} != "Europe/Berlin" # see unit-tests/Makefile
11 all: mod-localtime-indirect
14 # Test for the default time format, %c. Since the time always varies, it's
15 # only possible to check for the general format here. The names of the
16 # month and weekday are always in English, independent from the locale.
17 # Example: Thu Oct 29 18:56:41 2020
18 .if ${:U:localtime:tW:M??? ??? ?? ??\:??\:?? ????} == ""
25 # modifier name too short
26 @echo ${%Y:L:localtim=1593536400}
28 # 2020-07-01T00:00:00Z
29 @echo ${%Y:L:localtime=1593536400}
31 # modifier name too long
32 @echo ${%Y:L:localtimer=1593536400}
34 # If the modifier name is not matched exactly, fall back to the
36 @echo ${localtime:L:local%=gm%} == gmtime
38 mod-localtime-indirect:
41 # As of 2020-08-16, it is not possible to pass the seconds via a
42 # variable expression. This is because parsing of the :localtime
43 # modifier stops at the '$' and returns to ApplyModifiers.
45 # There, a colon would be skipped but not a dollar.
46 # Parsing therefore continues at the '$' of the ${:U159...}, looking
47 # for an ordinary variable modifier.
49 # At this point, the ${:U} is expanded and interpreted as a variable
50 # modifier, which results in the error message "Unknown modifier '1'".
52 # If ApplyModifier_Localtime were to pass its argument through
53 # ParseModifierPart, this would work.
54 @echo ${%Y:L:localtime=${:U1593536400}}
59 # As of 2020-10-31, it is possible to pass negative time stamps
60 # to the :localtime modifier, resulting in dates before 1970.
61 # Going back 50 years in the past is not a practical use case for
63 : -1 becomes ${:L:localtime=-1}.
65 # Spaces are allowed, not because it would make sense but just as
66 # a side-effect from using strtoul.
67 : space 1 becomes ${:L:localtime= 1}.
69 # 0 means now; to get consistent test results, the actual value has
71 : 0 becomes ${:L:localtime=0:C,^... ... .. ..:..:.. 20..$,ok,W}.
73 : 1 becomes ${:L:localtime=1}.
75 : INT32_MAX becomes ${:L:localtime=2147483647}.
77 # This may be different if time_t is still a 32-bit signed integer.
78 : INT32_MAX + 1 becomes ${:L:localtime=2147483648}.
81 # Because this modifier is implemented using strtoul, the parsed
82 # time is ULONG_MAX, which gets converted to -1. This results
83 # in a time stamp of the second before 1970 (in UTC) or 3599 seconds
84 # after New Year's Day in Europe/Berlin.
85 : overflow becomes ${:L:localtime=10000000000000000000000000000000}.
87 # As of 2020-10-31, there is no error handling while parsing the
88 # :localtime modifier, thus no error message is printed. Parsing
89 # stops after the '=', and the remaining string is parsed for
90 # more variable modifiers. Because of the unknown modifier 'e',
91 # the whole variable value is discarded and thus not printed.
92 : letter becomes ${:L:localtime=error}.