varmod-gmtime.mk revision 1.4 1 1.4 rillig # $NetBSD: varmod-gmtime.mk,v 1.4 2020/10/31 19:48:23 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for the :gmtime variable modifier, which formats a timestamp
4 1.2 rillig # using strftime(3).
5 1.1 rillig
6 1.2 rillig all: mod-gmtime
7 1.2 rillig all: mod-gmtime-indirect
8 1.4 rillig all: parse-errors
9 1.2 rillig
10 1.3 rillig # Test for the default time format, %c. Since the time always varies, it's
11 1.3 rillig # only possible to check for the general format here. The names of the
12 1.3 rillig # month and weekday are always in English, independent from the locale.
13 1.3 rillig # Example: Thu Oct 29 18:56:41 2020
14 1.3 rillig .if ${:U:gmtime:tW:M??? ??? ?? ??\:??\:?? ????} == ""
15 1.3 rillig . error
16 1.3 rillig .endif
17 1.3 rillig
18 1.2 rillig mod-gmtime:
19 1.2 rillig @echo $@:
20 1.2 rillig @echo ${%Y:L:gmtim=1593536400} # modifier name too short
21 1.2 rillig @echo ${%Y:L:gmtime=1593536400} # 2020-07-01T00:00:00Z
22 1.2 rillig @echo ${%Y:L:gmtimer=1593536400} # modifier name too long
23 1.2 rillig @echo ${%Y:L:gm=gm:M*}
24 1.2 rillig
25 1.2 rillig mod-gmtime-indirect:
26 1.2 rillig @echo $@:
27 1.2 rillig
28 1.2 rillig # As of 2020-08-16, it is not possible to pass the seconds via a
29 1.2 rillig # variable expression. This is because parsing of the :gmtime
30 1.2 rillig # modifier stops at the '$' and returns to ApplyModifiers.
31 1.2 rillig #
32 1.2 rillig # There, a colon would be skipped but not a dollar.
33 1.2 rillig # Parsing therefore continues at the '$' of the ${:U159...}, looking
34 1.2 rillig # for an ordinary variable modifier.
35 1.2 rillig #
36 1.2 rillig # At this point, the ${:U} is expanded and interpreted as a variable
37 1.2 rillig # modifier, which results in the error message "Unknown modifier '1'".
38 1.2 rillig #
39 1.2 rillig # If ApplyModifier_Gmtime were to pass its argument through
40 1.2 rillig # ParseModifierPart, this would work.
41 1.2 rillig @echo ${%Y:L:gmtime=${:U1593536400}}
42 1.1 rillig
43 1.4 rillig parse-errors:
44 1.4 rillig @echo $@:
45 1.4 rillig
46 1.4 rillig # As of 2020-10-31, it is possible to pass negative time stamps
47 1.4 rillig # to the :gmtime modifier, resulting in dates before 1970.
48 1.4 rillig # Going back 50 years in the past is not a practical use case for
49 1.4 rillig # make.
50 1.4 rillig : -1 becomes ${:L:gmtime=-1}.
51 1.4 rillig
52 1.4 rillig # 0 means now; to get consistent test results, the actual value has
53 1.4 rillig # to be normalized.
54 1.4 rillig : 0 becomes ${:L:gmtime=0:C,^... ... .. ..:..:.. 20..$,ok,W}.
55 1.4 rillig
56 1.4 rillig : 1 becomes ${:L:gmtime=1}.
57 1.4 rillig
58 1.4 rillig : INT32_MAX becomes ${:L:gmtime=2147483647}.
59 1.4 rillig
60 1.4 rillig # This may be different if time_t is still a 32-bit signed integer.
61 1.4 rillig : INT32_MAX + 1 becomes ${:L:gmtime=2147483648}.
62 1.4 rillig
63 1.4 rillig # Integer overflow.
64 1.4 rillig # Because this modifier is implemented using strtoul, the parsed
65 1.4 rillig # time is ULONG_MAX, which gets converted to -1. This results
66 1.4 rillig # in a time stamp of the second before 1970.
67 1.4 rillig : overflow becomes ${:L:gmtime=10000000000000000000000000000000}.
68 1.4 rillig
69 1.4 rillig # As of 2020-10-31, there is no error handling while parsing the
70 1.4 rillig # :gmtime modifier, thus no error message is printed. Parsing
71 1.4 rillig # stops after the '=', and the remaining string is parsed for
72 1.4 rillig # more variable modifiers. Because of the unknown modifier 'e',
73 1.4 rillig # the whole variable value is discarded and thus not printed.
74 1.4 rillig : letter becomes ${:L:gmtime=error}.
75 1.4 rillig
76 1.1 rillig all:
77 1.1 rillig @:;
78