summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/03_stdlib/53_timelocal
blob: e4d0db41b3e76b817fcafd0f0155a0e844f5704c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
The `timelocal()` function performs the inverse operation of `localtime()`
by taking a broken-down date and time dictionary and transforming it into
an epoch value according to the local system timezone.

-- Testcase --
{%
	// check expected epoch
	let d1 = {
		"sec": 42,
		"min": 51,
		"hour": 13,
		"mday": 22,
		"mon": 3,
		"year": 2022,
		"wday": 2,
		"yday": 81,
		"isdst": 0
	};

	// check that out of range values are normalized
	let d2 = {
		"sec": 33,
		"min": 22,
		"hour": 11,
		"mday": 40,
		"mon": 10,
		"year": 2022,
		"wday": 2,
		"yday": 81,
		"isdst": 0
	};

	// check that everything except mday, mon, year is optional
	let d3 = {
		"mday": 1,
		"mon": 1,
		"year": 2000
	};

	printf("%.J\n", [
		timelocal(d1),
		timelocal(d2),
		timelocal(d3)
	]);
%}
-- End --

-- Vars --
TZ=CET-1CEST,M3.5.0/2,M10.5.0/3
-- End --

-- Expect stdout --
[
	1647953502,
	1667989353,
	946681200
]
-- End --