Skip to content

Commit bef7240

Browse files
Add optional timezone offset for NTP.set_time()
1 parent d125eac commit bef7240

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

adafruit_ntp.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
class NTP:
5050
"""Network Time Protocol (NTP) helper module for CircuitPython.
51-
This module does not handle daylight savings or local time.
51+
This module does not handle daylight savings time.
5252
5353
:param adafruit_esp32spi esp: ESP32SPI object.
5454
"""
@@ -61,13 +61,16 @@ 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
66-
in seconds since since Jan 1, 1970.
66+
in seconds since since Jan 1, 1970. Optionally offsets
67+
the current time to that of the requested timezone.
68+
69+
:param int tz_offset: Timezone offset from GMT in hours
6770
"""
6871
try:
6972
now = self._esp.get_time()
70-
now = time.localtime(now[0])
73+
now = time.localtime(now[0]+ (tz_offset * 3600)) # 3600 seconds in an hour
7174
rtc.RTC().datetime = now
7275
self.valid_time = True
7376
except ValueError:

0 commit comments

Comments
 (0)