1# $NetBSD: varmod-localtime.mk,v 1.12 2023/05/10 15:53:32 rillig Exp $ 2# 3# Tests for the :localtime variable modifier, which formats a timestamp 4# using strftime(3) in local time. 5# 6# See also: 7# varmod-gmtime.mk 8 9.if ${TZ:Uno:NEurope/Berlin:NUTC-1} != "" # see unit-tests/Makefile 10. error 11.endif 12 13# Test for the default time format, %c. Since the time always varies, it's 14# only possible to check for the general format here. The names of the 15# month and weekday are always in English, independent from the locale. 16# Example: Thu Oct 29 18:56:41 2020 17.if ${:U:localtime:tW:M??? ??? ?? ??\:??\:?? ????} == "" 18. error 19.endif 20 21 22# modifier name too short, falling back to the SysV modifier. 23.if ${%Y:L:localtim=1593536400} != "%Y" 24. error 25.endif 26 27 28# 2020-07-01T00:00:00Z 29.if ${%Y:L:localtime=1593536400} != "2020" 30. error 31.endif 32 33 34# modifier name too long, falling back to the SysV modifier. 35.if ${%Y:L:localtimer=1593536400} != "%Y" 36. error 37.endif 38 39 40# If the modifier name is not matched exactly, fall back to the 41# :from=to modifier. 42.if ${localtime:L:local%=gm%} != "gmtime" 43. error 44.endif 45 46 47# Before var.c 1.1050 from 2023-05-09, it was not possible to pass the 48# seconds via a variable expression. 49.if ${%Y:L:localtime=${:U1593536400}} != "2020" 50. error 51.endif 52 53 54# Before var.c 1.631 from 2020-10-31 21:40:20, it was possible to pass 55# negative time stamps to the :localtime modifier, resulting in dates before 56# 1970. Going back 50 years in the past is not a practical use case for 57# make. Therefore, since var.c 1.631, negative time stamps produce a 58# parse error. 59.if ${:L:localtime=-1} != "" 60. error 61.else 62. error 63.endif 64 65 66# Spaces were allowed before var.c 1.631 from 2020-10-31 21:40:20, not 67# because it would make sense but just as a side-effect from using strtoul. 68.if ${:L:localtime= 1} != "" 69. error 70.else 71. error 72.endif 73 74 75# 0 means now; this differs from GNode.mtime, where a 0 means nonexistent. 76# Since "now" constantly changes, the strongest possible test is to match the 77# resulting pattern. 78.if !${:L:localtime=0:tW:M??? ??? ?? ??\:??\:?? 20??} 79. error 80.endif 81 82 83.if ${:L:localtime=1} != "Thu Jan 1 01:00:01 1970" 84. error 85.endif 86 87 88# INT32_MAX 89.if ${:L:localtime=2147483647} != "Tue Jan 19 04:14:07 2038" 90. error 91.endif 92 93 94.if ${:L:localtime=2147483648} == "Tue Jan 19 04:14:08 2038" 95# All systems that have unsigned time_t or 64-bit time_t. 96.elif ${:L:localtime=2147483648} == "Fri Dec 13 21:45:52 1901" 97# FreeBSD-12.0-i386 still has 32-bit signed time_t, see 98# sys/x86/include/_types.h, __LP64__. 99# 100# Linux on 32-bit systems may still have 32-bit signed time_t, see 101# sysdeps/unix/sysv/linux/generic/bits/typesizes.h, __TIMESIZE. 102.else 103. error 104.endif 105 106 107# Integer overflow, at least before var.c 1.631 from 2020-10-31. 108# Because this modifier is implemented using strtoul, the parsed time was 109# ULONG_MAX, which got converted to -1. This resulted in a time stamp of 110# the second before 1970. 111# 112# Since var.c 1.631 from 2020-10-31, the overflow is detected and produces a 113# parse error. 114.if ${:L:localtime=10000000000000000000000000000000} != "" 115. error 116.else 117. error 118.endif 119 120# Before var.c 1.631 from 2020-10-31, there was no error handling while 121# parsing the :localtime modifier, thus no error message was printed. Parsing 122# stopped after the '=', and the remaining string was parsed for more variable 123# modifiers. Because of the unknown modifier 'e' from the 'error', the whole 124# variable value was discarded and thus not printed. 125.if ${:L:localtime=error} != "" 126. error 127.else 128. error 129.endif 130 131# Before var.c 1.1050 from 2023-05-09, the timestamp could be directly 132# followed by the next modifier, without a ':' separator. This was the same 133# bug as for the ':L' and ':P' modifiers. 134.if ${%Y:L:localtime=100000S,1970,bad,} != "bad" 135. error 136.endif 137 138all: 139