1try:
2    import utime as time
3except ImportError:
4    import time
5
6DAYS_PER_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
7
8tzseconds = -time.mktime((1970, 1, 1, 14, 0, 0, 0, 0, 0))
9
10
11def is_leap(year):
12    return (year % 4) == 0
13
14
15def test():
16    seconds = 0
17    wday = 3  # Jan 1, 1970 was a Thursday
18    for year in range(1970, 2038):
19        print("Testing %d" % year)
20        yday = 1
21        for month in range(1, 13):
22            if month == 2 and is_leap(year):
23                DAYS_PER_MONTH[2] = 29
24            else:
25                DAYS_PER_MONTH[2] = 28
26            for day in range(1, DAYS_PER_MONTH[month] + 1):
27                secs = time.mktime((year, month, day, 14, 0, 0, 0, 0, 0)) + tzseconds
28                if secs != seconds:
29                    print(
30                        "mktime failed for %d-%02d-%02d got %d expected %d"
31                        % (year, month, day, secs, seconds)
32                    )
33                    return
34                tuple = time.localtime(seconds)
35                secs = time.mktime(tuple)
36                if secs != seconds:
37                    print(
38                        "localtime failed for %d-%02d-%02d got %d expected %d"
39                        % (year, month, day, secs, seconds)
40                    )
41                    return
42                seconds += 86400
43                if yday != tuple[7]:
44                    print(
45                        "locatime for %d-%02d-%02d got yday %d, expecting %d"
46                        % (year, month, day, tuple[7], yday)
47                    )
48                    return
49                if wday != tuple[6]:
50                    print(
51                        "locatime for %d-%02d-%02d got wday %d, expecting %d"
52                        % (year, month, day, tuple[6], wday)
53                    )
54                    return
55                yday += 1
56                wday = (wday + 1) % 7
57
58
59test()
60