IANA timezones for adafruit_datetime
Project description
Introduction
IANA timezones for adafruit_datetime
Build
To regenerate the timezone database files in tzdb/_zones
Create a python>=3.9 environment: python3.9 -m venv .venv
Activate the environment: source .venv/bin/activate
Install dependencies: pip install -r requirements.txt
And run the utils/generate_tz_db.py script: ./utils/generate_tz_db.py
This creates a python file in _zones for each timezone. These files each contain a dictionary that maps names to utc offsets throughout the year using python3.9’s ZoneInfo
This file is included in this repository/package and is current as of 2022-05-22
See tzdb/_timezone.py for details on how it’s used
Dependencies
This driver depends on:
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle or individual libraries can be installed using circup.
Installing from PyPI
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:
pip3 install circuitpython-tzdb
To install system-wide (this may be required in some cases):
sudo pip3 install circuitpython-tzdb
To install in a virtual environment in your current project:
mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install circuitpython-tzdb
Installing to a Connected CircuitPython Device with Circup
Make sure that you have circup installed in your Python environment. Install it with the following command if necessary:
pip3 install circup
With circup installed and your CircuitPython device connected use the following command to install:
circup install tzdb
Or the following command to update an existing version:
circup update
Usage Example
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Copyright (c) 2022 Evin Dunn
# SPDX-License-Identifier: MIT
from time import time
from adafruit_datetime import datetime
try:
from tzdb import timezone
except ImportError:
from sys import path as sys_path
from pathlib import Path
sys_path.insert(0, str(Path(__file__).parent.parent))
from tzdb import timezone
def main():
TARGETS = [
"America/Chicago",
"America/Argentina/Buenos_Aires",
"Pacific/Guam",
"Asia/Tokyo",
]
# First use adafruit_ntp to fetch the current utc time & update the board's
# RTC
utc_now = time()
utc_now_dt = datetime.fromtimestamp(utc_now)
print("UTC: {}".format(utc_now_dt.ctime()))
for target in TARGETS:
localtime = utc_now_dt + timezone(target).utcoffset(utc_now_dt)
print("{}: {}".format(target, localtime.ctime()))
if __name__ == "__main__":
main()
Documentation
API documentation for this library can be found on Read the Docs.
For information on building library documentation, please check out this guide.
Contributing
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.