Hey Folks, just want to bring this to attention see what the work around might be that I am missing.
I am using the time input widget with time zone capability. When I select a time zone of (GMT-6:00) America/Chicago in the mobile app, I get a time zone offset from GMT in seconds of -18,000s. When I do the math, 60s60min6hrs gives me 21,600s, which is an hour off of what the time zone offset should actually be. This error is present in only some of the (GMT-6:00) time zone selections. My best guess is that this is compensated for Daylight Savings Time (DST), but that means my program needs something to know when DST is active in order to compensate.
The unix time I get from the New York Server gives me the local time, not true unix time. So in my program, I adjust for this by finding the difference between the server time zone and the local time zone. Currently in American Central time, I subtract 5 hours in seconds (18,000s) from the local time zone offset of 6 hours, (21,600s). If there is a better way of working around the server time in unix time not adjusting for DST and the time input widget time zones automatically adjusting for DST, let me know. Personally, I think that the unix time stamp provided from the server should be what adjusts for DST, or the time zones should not adjust for DST and be constant.
Currently, all American time zone settings for GMT-6:00 are 18,000s. South American and other ‘forgien’ areas have the ‘correct’ time zone offset of 21,600s.
In this excerpt from my program, I use the Blynk provided handles to parse out the current time and time zone from the timer widget entry:
// Function called every time time entry changes virtual pin V7 (LightTimeVirtual)
BLYNK_WRITE(L_TIME_V)
{
TimeInputParam t(param); // gather time params
if(t.hasStartTime()) // if start time exists
{
startTime.hr = t.getStartHour(); // save away hour
startTime.min = t.getStartMinute(); // save start min
} // end if start time exists
else {} // if no start time, do nothing
if(t.hasStopTime()) // if stop time exists
{
endTime.hr = t.getStopHour(); // save away hour
endTime.min = t.getStopMinute(); // save away min
} // end if stop time exists
else {} // if no stop time, do nothing
startTime.tz = t.getTZ_Offset(); // collect time zone
endTime.tz = t.getTZ_Offset();
Serial.print("Start TZ:");
Serial.println(startTime.tz);
Serial.print("End TZ:");
Serial.println(endTime.tz);
} // end V7 change function
The prints here provide me with the following when the time widget writes to my virtual pin for the time when the time zone selected is American Central Time or any American local in central time, (GMT-6:00):
When the time zone is changed in the time input widget to a different time zone, still denoted by GMT-6:00, the prints provide the following. For this example, I used America/El Salvador as the time zone.
Then when the internalRTC pin in Blynk updates, the following code runs to update the software with the current time:
BLYNK_WRITE(InternalPinRTC)
{
// Process Time
uint32_t unix = param.asLong(); // collect time from RTC
Serial.print("Unix:");
Serial.println(unix);
Serial.print("Start Time:");
Serial.println(startTime.tz);
Serial.print("Offset:");
Serial.println(NY_SERVER_TZ);
unix += (startTime.tz - NY_SERVER_TZ); // refrence to local time, Unix time based on server time & server in New York
Serial.print("Unix Adjust:");
Serial.println(unix);
stamp.getDateTime(unix); // pass unix time to UnixTime.h methods
// Update Time
nowTime.hr = stamp.hour; // convert to hour
nowTime.min = stamp.minute; // convert to min
nowTime.sec = stamp.second; // convert to sec
...
The prints here in this portion of the program show me that the Unix time isn’t being adjusted because the time zone I get from the time input widget is the same as the server time zone, which cancels out the adjustment. This was done with the time zone set to (GMT-6:00) America/Chicago. Note the match between “Unix:” and “Unix Adjust:”
It seems my options are to either make the user tell the controller if DST is active or not and adjusting the local time zone, the server time zone (New York), or the input unix time from the server. Is there any way to dynamically pull the time zone from the server so that I can have the adjustment for DST done without having the user tell the controller when DST is active? Any other ideas for how to proceed?
Hardware/Software Specs:
• ESP32 Node MCU-32S on WIFI w/ Dynamic Provisioning
• Android
• New York Server, non-local server
• Blynk 1.0.1