Skip to content

Commit c8ec219

Browse files
authored
Merge pull request #10 from theelectricmayhem/patch-1
Add optional timezone offset for NTP.set_time()
2 parents d125eac + 059aeeb commit c8ec219

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

adafruit_ntp.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ def __init__(self, esp):
6161
raise TypeError("Provided object is not an ESP_SPIcontrol object.")
6262
self.valid_time = False
6363

64-
def set_time(self):
64+
def set_time(self, tz_offset=0):
6565
"""Fetches and sets the microcontroller's current time
6666
in seconds since since Jan 1, 1970.
67+
68+
:param int tz_offset: Timezone offset from GMT
6769
"""
6870
try:
6971
now = self._esp.get_time()
70-
now = time.localtime(now[0])
72+
now = time.localtime(now[0] + (tz_offset * 3600)) # 3600 seconds in an hour
7173
rtc.RTC().datetime = now
7274
self.valid_time = True
73-
except ValueError:
75+
except ValueError as error:
76+
print(str(error))
7477
return

0 commit comments

Comments
 (0)