Simple test¶
Ensure your device works with this simple test.
1#!/usr/bin/env python3
2# SPDX-FileCopyrightText: Copyright (c) 2022 Evin Dunn
3# SPDX-License-Identifier: MIT
4
5from time import time
6
7from adafruit_datetime import datetime
8
9try:
10 from tzdb import timezone
11except ImportError:
12 from sys import path as sys_path
13 from pathlib import Path
14
15 sys_path.insert(0, str(Path(__file__).parent.parent))
16 from tzdb import timezone
17
18
19def main():
20 TARGETS = [
21 "America/Chicago",
22 "America/Argentina/Buenos_Aires",
23 "Pacific/Guam",
24 "Asia/Tokyo",
25 ]
26
27 # First use adafruit_ntp to fetch the current utc time & update the board's
28 # RTC
29
30 utc_now = time()
31 utc_now_dt = datetime.fromtimestamp(utc_now)
32
33 print("UTC: {}".format(utc_now_dt.ctime()))
34
35 for target in TARGETS:
36 localtime = utc_now_dt + timezone(target).utcoffset(utc_now_dt)
37 print("{}: {}".format(target, localtime.ctime()))
38
39
40if __name__ == "__main__":
41 main()