CedarGroveStudios / CircuitPython_DST_Adjuster

A CircuitPython helper to adjust to North American Daylight Saving Time (DST).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction

Discord

Build Status

Code Style: Black

A CircitPython helper to detect and adjust North American Daylight Saving Time (DST).

Adjust DST converts Standard Time (xST) to North American DST. Input to this function is a structured time object in xST. The function returns a structured time object adjusted to a DST value if appropriate and a flag indicating the DST adjustment was made. The helper cannot detect DST for a structured time object that is encoded as DST.

image

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 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 cedargrove_dst_adjuster

Or the following command to update an existing version:

circup update

Usage Example

import time
from cedargrove_dst_adjuster import adjust_dst

# Today's date: 11/01/2020 00:00 Standard Time (xST)
datetime = time.struct_time((2020, 11, 1, 0, 0, 0, 6, 0, -1))

# Check datetime and adjust if DST
adj_datetime, is_dst = adjust_dst(datetime)

if is_dst:
    flag_text = "DST"
else:
    flag_text = "xST"

# Print the submitted time
print(
    "     {}/{}/{} {:02}:{:02}:{:02}  week_day={}".format(
        datetime.tm_mon,
        datetime.tm_mday,
        datetime.tm_year,
        datetime.tm_hour,
        datetime.tm_min,
        datetime.tm_sec,
        datetime.tm_wday,
    )
)

# Print the adjusted time
print(
    "{}: {}/{}/{} {:02}:{:02}:{:02}  week_day={}".format(
        flag_text,
        adj_datetime.tm_mon,
        adj_datetime.tm_mday,
        adj_datetime.tm_year,
        adj_datetime.tm_hour,
        adj_datetime.tm_min,
        adj_datetime.tm_sec,
        adj_datetime.tm_wday,
    )
)

Documentation

API documentation for this library can be found here.

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.

About

A CircuitPython helper to adjust to North American Daylight Saving Time (DST).

License:MIT License


Languages

Language:Python 100.0%