Skip to content

Add optional timezone offset for NTP.set_time() #10

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

Merged
merged 2 commits into from
May 12, 2020
Merged
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: 6 additions & 3 deletions adafruit_ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ def __init__(self, esp):
raise TypeError("Provided object is not an ESP_SPIcontrol object.")
self.valid_time = False

def set_time(self):
def set_time(self, tz_offset=0):
"""Fetches and sets the microcontroller's current time
in seconds since since Jan 1, 1970.

:param int tz_offset: Timezone offset from GMT
"""
try:
now = self._esp.get_time()
now = time.localtime(now[0])
now = time.localtime(now[0] + (tz_offset * 3600)) # 3600 seconds in an hour
rtc.RTC().datetime = now
self.valid_time = True
except ValueError:
except ValueError as error:
print(str(error))
return