Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use epoch seconds to allow applying timezone offset #32

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions examples/word_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# Length of time between updates in minutes.
UPDATE_INTERVAL = 15
OFFSET = 0

rtc = machine.RTC()
time_string = None
Expand Down Expand Up @@ -57,8 +58,12 @@ def update():
except OSError:
print("Unable to contact NTP server")

current_t = rtc.datetime()
time_string = approx_time(current_t[4] - 12 if current_t[4] > 12 else current_t[4], current_t[5])
epoch_secs = ntptime.time()
if OFFSET:
epoch_secs = epoch_secs + OFFSET*3600

(year, month, day, hours, minutes, seconds, weekday, yearday) = time.localtime(epoch_secs)
time_string = approx_time(hours - 12 if hours > 12 else hours, minutes)

# Splits the string into an array of words for displaying later
time_string = time_string.split()
Expand Down