Skip to content

Commit 391e65a

Browse files
committed
Move default timezone (back) into config.h
1 parent 5f248fc commit 391e65a

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/GetLocation.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RTC_DATA_ATTR time_t lastGetLocationTS = 0; // can use this to throttle
1919
RTC_DATA_ATTR location currentLocation = {
2020
DEFAULT_LOCATION_LATITUDE, // lat
2121
DEFAULT_LOCATION_LONGDITUDE, // lon
22-
"AEST-10AEDT,M10.1.0,M4.1.0/3", // timezone
22+
DEFAULT_TIMEZONE, // timezone
2323
"Melbourne" // default location is in Melbourne
2424
};
2525

@@ -757,7 +757,7 @@ uint32_t fnvHash(const char *str) {
757757
// hashed values. It assumes that the "olson" string is a valid timezone name
758758
// from the same version of the tzdb as it was compiled for. If passed an
759759
// invalid string the behaviour is undefined.
760-
const char *getPosixTZforOlson(const char *olson, char *buf, size_t buflen) {
760+
const char *getPosixTZforOlson(const char *olson) {
761761
static_assert(NumZones > 0, "zones should not be empty");
762762
auto olsonHash = fnvHash(olson) & mask;
763763
auto i = &zones[0];
@@ -771,9 +771,9 @@ const char *getPosixTZforOlson(const char *olson, char *buf, size_t buflen) {
771771
}
772772
}
773773
if (i->hash == olsonHash) {
774-
return strncpy(buf, posix[i->posix], buflen);
774+
return posix[i->posix];
775775
}
776-
return nullptr;
776+
return "UTC0"; // couldn't find it, use default
777777
}
778778

779779
const location *getLocation() {
@@ -810,8 +810,9 @@ const location *getLocation() {
810810
loc.lon = double(responseObject["lon"]);
811811
strncpy(loc.city, responseObject["city"], sizeof(loc.city));
812812

813-
auto olsonTZ = (const char *)responseObject["timezone"];
814-
if (getPosixTZforOlson(olsonTZ, loc.timezone, sizeof(loc.timezone))) {
813+
const char* olsonTZ = static_cast<const char *>(responseObject["timezone"]);
814+
loc.timezone = getPosixTZforOlson(olsonTZ);
815+
if ( loc.timezone ) {
815816
currentLocation = loc;
816817
lastGetLocationTS = now();
817818
Watchy::err = Watchy::OK;

src/GetLocation.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Watchy_GetLocation {
66
typedef struct {
77
float lat;
88
float lon;
9-
char timezone[128]; // POSIX tz spec https://developer.ibm.com/articles/au-aix-posix/
9+
const char *timezone; // POSIX tz spec https://developer.ibm.com/articles/au-aix-posix/
1010
char city[30]; // even if we get a longer name from the API, we'll truncate it to fit the sceen width
1111
} location;
1212

src/SyncTime.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ namespace Watchy_SyncTime {
88
// but can be set to a more specific ntp server if known
99
extern const char* ntpServer;
1010

11-
constexpr const char *DEFAULT_TIMEZONE = "UTC0"; // posix format
12-
1311
extern time_t lastSyncTimeTS; // timestamp of last successful syncTime
1412
// sets RTC, now() and time() to UTC
1513
// sets current timezone so that localtime works
16-
extern void syncTime(const char* timezone = DEFAULT_TIMEZONE);
14+
extern void syncTime(const char* timezone);
1715
}; // namespace Watchy_SyncTime

src/config.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ constexpr const char * WIFI_AP_SSID = "Watchy AP";
2929
//set time
3030
const int YEAR_OFFSET = 1970;
3131
constexpr const char *NTP_SERVER = "pool.ntp.org";
32+
constexpr const char *DEFAULT_TIMEZONE = "AEST-10AEDT,M10.1.0,M4.1.0/3"; // posix format
3233

3334
//BLE OTA
3435
constexpr const char * BLE_DEVICE_NAME = "Watchy BLE OTA";

0 commit comments

Comments
 (0)