jecottrell:
No, that wouldn't have ever occurred to me. I will give that a shot.Is there a way to get the timezone names to populate a list? The ausNT, ausSA, etc. Or will I still need to make another array of strings and have the indexes of the two arrays (timezones and strings) matched?
Thanks for the help and ideas.
If you want to use the names for another purpose, you'd need to make a separate list.
For example:-
char zoneList[NUMBER_OF_TIME_ZONES][7] =
{
"ausQLD",
"ausNSW",
"ausNT",
"ausSA",
"ausWA"
};
And by the way, to access an element of the array of pointers to time zones, you'd do this:-
(This will set the time of one TimeZone in 'setup()')setTime(timeZones_arr[0]->toUTC(compileTime()));
N.B. The 'compileTime()' function is in the "WorldClock" example that came with the "TimeZone" library.
This compiles fine for me:-
#include <Timezone.h> //https://github.com/JChristensen/Timezone
//Australia Eastern Time Zone (Sydney, Melbourne)
TimeChangeRule aEDT = {"AEDT", First, Sun, Oct, 2, 660}; //UTC + 11 hours
TimeChangeRule aEST = {"AEST", First, Sun, Apr, 3, 600}; //UTC + 10 hours
Timezone ausQLD(aEST, aEST);
Timezone ausNSW(aEDT, aEST);
//Australia Central Time Zone (Darwin)
TimeChangeRule aCDT = {"ACDT", First, Sun, Oct, 2, 630}; //UTC + 10.5 hours
TimeChangeRule aCST = {"ACST", First, Sun, Apr, 3, 570}; //UTC + 9.5 hours
Timezone ausNT(aCST, aCST);
Timezone ausSA(aCDT, aCST);
//Australia Western Time Zone (Perth)
TimeChangeRule aWST = {"AWST", First, Sun, Apr, 3, 480}; //UTC + 8 hours
Timezone ausWA(aWST, aWST);
#define NUMBER_OF_TIME_ZONES 5
Timezone* timeZones_arr[NUMBER_OF_TIME_ZONES] =
{
&ausQLD,
&ausNSW,
&ausNT,
&ausSA,
&ausWA
};
char zoneList[NUMBER_OF_TIME_ZONES][7] =
{
"ausQLD",
"ausNSW",
"ausNT",
"ausSA",
"ausWA"
};
void setup()
{
Serial.begin(115200);
setTime(timeZones_arr[0]->toUTC(compileTime()));
Serial.println(zoneList[0]);
}
void loop()
{
}
//Function to return the compile date and time as a time_t value
time_t compileTime(void)
{
#define FUDGE 25 //fudge factor to allow for compile time (seconds, YMMV)
char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
char chMon[3], *m;
int d, y;
tmElements_t tm;
time_t t;
strncpy(chMon, compDate, 3);
chMon[3] = '\0';
m = strstr(months, chMon);
tm.Month = ((m - months) / 3 + 1);
tm.Day = atoi(compDate + 4);
tm.Year = atoi(compDate + 7) - 1970;
tm.Hour = atoi(compTime);
tm.Minute = atoi(compTime + 3);
tm.Second = atoi(compTime + 6);
t = makeTime(tm);
return t + FUDGE; //add fudge factor to allow for compile time
}
And if I upload and run it, it prints "ausQLD" to the serial monitor.