Skip to content

Commit

Permalink
avoid unnecessary ntp requests in refreshTimezoneOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
leoclee authored Aug 9, 2018
1 parent 93d5409 commit 5bc5bef
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Arduino/clock.ino
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void setup() {
if (lat != overrideLatitude || lng != overrideLongitude) {
overrideLatitude = lat;
overrideLongitude = lng;
refreshTime();
refreshTimezoneOffset();
saveConfig();
}
});
Expand Down Expand Up @@ -497,7 +497,7 @@ void loop() {
// see: https://www.timeanddate.com/time/dst/statistics.html#dstuse
// see: https://en.wikipedia.org/wiki/Daylight_saving_time#Procedure
if (minute() == 0 && hour() <= 4) {
refreshTime();
refreshTimezoneOffset();
}
printTime();
}
Expand All @@ -508,7 +508,7 @@ void loop() {
fadeToColor();
}

void refreshTime() {
void refreshTimezoneOffset() {
// handle the scenario where override location is loaded from json, but then removed during runtime--we will need to do an ip location lookup
if ((overrideLatitude == "" || overrideLongitude == "") && (ipLatitude == "" || ipLongitude == "")) {
// if no override location specified, attempt to look up using IP based geolocation
Expand All @@ -517,7 +517,7 @@ void refreshTime() {
int newTzOffset = getTimeZoneOffset(now() - tzOffset, (overrideLatitude != "") ? overrideLatitude : ipLatitude, (overrideLongitude != "") ? overrideLongitude : ipLongitude, googleApiKey);
if (newTzOffset != tzOffset) {
tzOffset = newTzOffset;
setTime(getNtpTime());
setTime(time(nullptr) + tzOffset);
}
}

Expand Down

0 comments on commit 5bc5bef

Please sign in to comment.