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 1 commit
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
11 changes: 7 additions & 4 deletions adafruit_ntp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

class NTP:
"""Network Time Protocol (NTP) helper module for CircuitPython.
This module does not handle daylight savings or local time.
This module does not handle daylight savings time.

:param adafruit_esp32spi esp: ESP32SPI object.
"""
Expand All @@ -61,13 +61,16 @@ 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.
in seconds since since Jan 1, 1970. Optionally offsets
the current time to that of the requested timezone.

:param int tz_offset: Timezone offset from GMT in hours
"""
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:
Expand Down