Skip to content

Commit

Permalink
Merge pull request #877 from pacohope/tz-adjust
Browse files Browse the repository at this point in the history
add adjustment for time zone offset
  • Loading branch information
Gadgetoid authored Jan 16, 2024
2 parents 4e3e2c8 + 078d813 commit 911cbb7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions micropython/examples/inky_frame/inky_frame_rtc_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"

# Set tz_offset to be the number of hours off of UTC for your local zone.
# Examples: tz_offset = -7 # Pacific time (PST)
# tz_offset = 1 # CEST (Paris)
tz_offset = 0
tz_seconds = tz_offset * 3600

# Sync the Inky (always on) RTC to the Pico W so that "time.localtime()" works.
inky_frame.pcf_to_pico_rtc()

Expand Down Expand Up @@ -36,7 +42,7 @@
def status_handler(mode, status, ip):
print(mode, status, ip)

year, month, day, hour, minute, second, dow, _ = time.localtime()
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time() + tz_seconds)

# Connect to the network and get the time if it's not set
if year < 2023:
Expand All @@ -60,7 +66,7 @@ def status_handler(mode, status, ip):
graphics.text("Failed to connect!", 0, 40)

# Display the date and time
year, month, day, hour, minute, second, dow, _ = time.localtime()
year, month, day, hour, minute, second, dow, _ = time.localtime(time.time() + tz_seconds)

date_time = f"{year:04}/{month:02}/{day:02} {hour:02}:{minute:02}:{second:02}"

Expand Down

0 comments on commit 911cbb7

Please sign in to comment.