varmod-gmtime.mk revision 1.16 1 1.16 rillig # $NetBSD: varmod-gmtime.mk,v 1.16 2023/08/19 08:19:25 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for the :gmtime variable modifier, which formats a timestamp
4 1.6 rillig # using strftime(3) in UTC.
5 1.11 rillig #
6 1.11 rillig # See also:
7 1.11 rillig # varmod-localtime.mk
8 1.1 rillig
9 1.8 rillig .if ${TZ:Uundefined} != "undefined" # see unit-tests/Makefile
10 1.8 rillig . error
11 1.8 rillig .endif
12 1.2 rillig
13 1.3 rillig # Test for the default time format, %c. Since the time always varies, it's
14 1.3 rillig # only possible to check for the general format here. The names of the
15 1.3 rillig # month and weekday are always in English, independent from the locale.
16 1.3 rillig # Example: Thu Oct 29 18:56:41 2020
17 1.3 rillig .if ${:U:gmtime:tW:M??? ??? ?? ??\:??\:?? ????} == ""
18 1.3 rillig . error
19 1.3 rillig .endif
20 1.3 rillig
21 1.6 rillig
22 1.7 rillig # modifier name too short, falling back to the SysV modifier.
23 1.7 rillig .if ${%Y:L:gmtim=1593536400} != "%Y"
24 1.7 rillig . error
25 1.7 rillig .endif
26 1.7 rillig
27 1.7 rillig
28 1.7 rillig # 2020-07-01T00:00:00Z
29 1.7 rillig .if ${%Y:L:gmtime=1593536400} != "2020"
30 1.7 rillig . error
31 1.7 rillig .endif
32 1.7 rillig
33 1.7 rillig
34 1.7 rillig # modifier name too long, falling back to the SysV modifier.
35 1.7 rillig .if ${%Y:L:gmtimer=1593536400} != "%Y"
36 1.7 rillig . error
37 1.7 rillig .endif
38 1.7 rillig
39 1.7 rillig
40 1.7 rillig # If the modifier name is not matched exactly, fall back to the
41 1.7 rillig # :from=to modifier.
42 1.7 rillig .if ${gmtime:L:gm%=local%} != "localtime"
43 1.7 rillig . error
44 1.7 rillig .endif
45 1.7 rillig
46 1.7 rillig
47 1.12 rillig # Before var.c 1.1050 from 2023-05-09, it was not possible to pass the
48 1.12 rillig # seconds via a variable expression.
49 1.12 rillig .if ${%Y:L:gmtime=${:U1593536400}} != "2020"
50 1.7 rillig . error
51 1.7 rillig .endif
52 1.7 rillig
53 1.7 rillig
54 1.7 rillig # Before var.c 1.631 from 2020-10-31 21:40:20, it was possible to pass
55 1.7 rillig # negative time stamps to the :gmtime modifier, resulting in dates before
56 1.7 rillig # 1970. Going back 50 years in the past is not a practical use case for
57 1.7 rillig # make. Therefore, since var.c 1.631, negative time stamps produce a
58 1.7 rillig # parse error.
59 1.15 rillig # expect+2: Invalid time value "-1"
60 1.15 rillig # expect+1: Malformed conditional (${:L:gmtime=-1} != "")
61 1.7 rillig .if ${:L:gmtime=-1} != ""
62 1.7 rillig . error
63 1.7 rillig .else
64 1.7 rillig . error
65 1.7 rillig .endif
66 1.7 rillig
67 1.7 rillig
68 1.10 rillig # Spaces were allowed before var.c 1.631 from 2020-10-31 21:40:20, not
69 1.10 rillig # because it would make sense but just as a side-effect from using strtoul.
70 1.15 rillig # expect+2: Invalid time value " 1"
71 1.15 rillig # expect+1: Malformed conditional (${:L:gmtime= 1} != "")
72 1.7 rillig .if ${:L:gmtime= 1} != ""
73 1.7 rillig . error
74 1.11 rillig .else
75 1.11 rillig . error
76 1.7 rillig .endif
77 1.7 rillig
78 1.7 rillig
79 1.7 rillig # 0 means now; this differs from GNode.mtime, where a 0 means nonexistent.
80 1.7 rillig # Since "now" constantly changes, the strongest possible test is to match the
81 1.7 rillig # resulting pattern.
82 1.7 rillig .if !${:L:gmtime=0:tW:M??? ??? ?? ??\:??\:?? 20??}
83 1.7 rillig . error
84 1.7 rillig .endif
85 1.7 rillig
86 1.7 rillig
87 1.7 rillig .if ${:L:gmtime=1} != "Thu Jan 1 00:00:01 1970"
88 1.7 rillig . error
89 1.7 rillig .endif
90 1.7 rillig
91 1.7 rillig
92 1.7 rillig # INT32_MAX
93 1.7 rillig .if ${:L:gmtime=2147483647} != "Tue Jan 19 03:14:07 2038"
94 1.7 rillig . error
95 1.7 rillig .endif
96 1.7 rillig
97 1.7 rillig
98 1.7 rillig .if ${:L:gmtime=2147483648} == "Tue Jan 19 03:14:08 2038"
99 1.7 rillig # All systems that have unsigned time_t or 64-bit time_t.
100 1.10 rillig .elif ${:L:gmtime=2147483648} == "Fri Dec 13 20:45:52 1901"
101 1.10 rillig # FreeBSD-12.0-i386 still has 32-bit signed time_t, see
102 1.10 rillig # sys/x86/include/_types.h, __LP64__.
103 1.10 rillig #
104 1.10 rillig # Linux on 32-bit systems may still have 32-bit signed time_t, see
105 1.10 rillig # sysdeps/unix/sysv/linux/generic/bits/typesizes.h, __TIMESIZE.
106 1.7 rillig .else
107 1.7 rillig . error
108 1.7 rillig .endif
109 1.7 rillig
110 1.7 rillig
111 1.7 rillig # Integer overflow, at least before var.c 1.631 from 2020-10-31.
112 1.7 rillig # Because this modifier is implemented using strtoul, the parsed time was
113 1.7 rillig # ULONG_MAX, which got converted to -1. This resulted in a time stamp of
114 1.7 rillig # the second before 1970.
115 1.7 rillig #
116 1.11 rillig # Since var.c 1.631 from 2020-10-31, the overflow is detected and produces a
117 1.11 rillig # parse error.
118 1.15 rillig # expect+2: Invalid time value "10000000000000000000000000000000"
119 1.15 rillig # expect+1: Malformed conditional (${:L:gmtime=10000000000000000000000000000000} != "")
120 1.7 rillig .if ${:L:gmtime=10000000000000000000000000000000} != ""
121 1.7 rillig . error
122 1.7 rillig .else
123 1.7 rillig . error
124 1.7 rillig .endif
125 1.7 rillig
126 1.9 rillig # Before var.c 1.631 from 2020-10-31, there was no error handling while
127 1.10 rillig # parsing the :gmtime modifier, thus no error message was printed. Parsing
128 1.7 rillig # stopped after the '=', and the remaining string was parsed for more variable
129 1.7 rillig # modifiers. Because of the unknown modifier 'e' from the 'error', the whole
130 1.7 rillig # variable value was discarded and thus not printed.
131 1.15 rillig # expect+2: Invalid time value "error"
132 1.15 rillig # expect+1: Malformed conditional (${:L:gmtime=error} != "")
133 1.7 rillig .if ${:L:gmtime=error} != ""
134 1.7 rillig . error
135 1.7 rillig .else
136 1.7 rillig . error
137 1.7 rillig .endif
138 1.6 rillig
139 1.12 rillig # Before var.c 1.1050 from 2023-05-09, the timestamp could be directly
140 1.14 rillig # followed by the next modifier, without a ':' separator. This was the same
141 1.11 rillig # bug as for the ':L' and ':P' modifiers.
142 1.15 rillig # expect+2: Invalid time value "100000S,1970,bad,"
143 1.15 rillig # expect+1: Malformed conditional (${%Y:L:gmtime=100000S,1970,bad,} != "bad")
144 1.11 rillig .if ${%Y:L:gmtime=100000S,1970,bad,} != "bad"
145 1.11 rillig . error
146 1.11 rillig .endif
147 1.6 rillig
148 1.16 rillig
149 1.16 rillig # As of 2023-08-19, ':gmtime' but not ':localtime' reports wrong values for
150 1.16 rillig # '%s', depending on the operating system and the timezone, as demonstrated by
151 1.16 rillig # the following test program:
152 1.16 rillig #
153 1.16 rillig # for mod in gmtime localtime; do
154 1.16 rillig # for tz in UTC Europe/Berlin America/Los_Angeles; do
155 1.16 rillig # TZ=$tz bmake -r -v "\${%F %T %z %s $mod $tz:L:$mod}"
156 1.16 rillig # done
157 1.16 rillig # done
158 1.16 rillig #
159 1.16 rillig # Cygwin:
160 1.16 rillig # 2023-08-19 07:34:06 +0000 1692430446 gmtime UTC
161 1.16 rillig # 2023-08-19 07:34:06 +0000 1692430446 gmtime Europe/Berlin
162 1.16 rillig # 2023-08-19 07:34:06 +0000 1692430446 gmtime America/Los_Angeles
163 1.16 rillig # 2023-08-19 07:34:06 +0000 1692430446 localtime UTC
164 1.16 rillig # 2023-08-19 09:34:07 +0200 1692430447 localtime Europe/Berlin
165 1.16 rillig # 2023-08-19 00:34:07 -0700 1692430447 localtime America/Los_Angeles
166 1.16 rillig #
167 1.16 rillig # Looks good:
168 1.16 rillig # * ':gmtime' consistently reports timezone offset '+0000'.
169 1.16 rillig # * '%s' is independent of the timezone.
170 1.16 rillig #
171 1.16 rillig # NetBSD 10.99:
172 1.16 rillig # 2023-08-19 07:34:37 +0000 1692430477 gmtime UTC
173 1.16 rillig # 2023-08-19 07:34:37 +0100 1692426877 gmtime Europe/Berlin
174 1.16 rillig # 2023-08-19 07:34:37 -0800 1692459277 gmtime America/Los_Angeles
175 1.16 rillig # 2023-08-19 07:34:37 +0000 1692430477 localtime UTC
176 1.16 rillig # 2023-08-19 09:34:37 +0200 1692430477 localtime Europe/Berlin
177 1.16 rillig # 2023-08-19 00:34:37 -0700 1692430477 localtime America/Los_Angeles
178 1.16 rillig #
179 1.16 rillig # Looks bad:
180 1.16 rillig # * ':gmtime' reports different timezone offsets.
181 1.16 rillig # * ':gmtime' reports different seconds since the Epoch.
182 1.16 rillig # * ':gmtime' reports the timezone offset '+0100' for Europe/Berlin,
183 1.16 rillig # even though at 2023-08-19, DST with offset '+0200' was in place.
184 1.16 rillig #
185 1.16 rillig # Debian:
186 1.16 rillig # 2023-08-19 07:29:10 +0000 1692430150 gmtime UTC
187 1.16 rillig # 2023-08-19 07:29:10 +0000 1692426550 gmtime Europe/Berlin
188 1.16 rillig # 2023-08-19 07:29:10 +0000 1692458950 gmtime America/Los_Angeles
189 1.16 rillig # 2023-08-19 07:29:10 +0000 1692430150 localtime UTC
190 1.16 rillig # 2023-08-19 09:29:10 +0200 1692430150 localtime Europe/Berlin
191 1.16 rillig # 2023-08-19 00:29:10 -0700 1692430150 localtime America/Los_Angeles
192 1.16 rillig #
193 1.16 rillig # Looks mixed:
194 1.16 rillig # * ':gmtime' reports the correct timezone offset '+0000'.
195 1.16 rillig # * ':gmtime' reports different seconds since the Epoch, and the '%s'
196 1.16 rillig # value cannot be derived from the '%F %T %z' values.
197 1.16 rillig
198 1.7 rillig all:
199