Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

"ArduinoIoTCloudTCP::handle_SyncTime could not get valid time" caused by timezone diffrence #506

Closed
kytpbs opened this issue Aug 23, 2024 · 1 comment · Fixed by #509
Closed
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@kytpbs
Copy link
Contributor

kytpbs commented Aug 23, 2024

If the user's timezone is higher than UTC (ex. UTC+4) than if the code is compiled at 22.00 UTC, EPOCH_AT_COMPILE_TIME will return a value higher than the current epoch because cvt_time(__DATE__) returns the date according to the user's local timezone.

This means that code compiled at 23.00 UTC will not function for timezones UTC+1 and higher.

according to wiki the biggest offset is UTC+14 so decreasing 50400 (14 * 60 * 60) would work:

ArduinoIoTCloud/src/utility/time/TimeService.cpp line 97

#define EPOCH_AT_COMPILE_TIME (cvt_time(__DATE__) - 50400)

or

ArduinoIoTCloud/src/utility/time/TimeService.cpp line 323

bool TimeServiceClass::isTimeValid(unsigned long const time)
{
  return (time > (EPOCH_AT_COMPILE_TIME - 50400));
}

This may not be the best solution but is one nevertheless.
I can open a simple PR for this if it is ok for you guys.

@pennam
Copy link
Collaborator

pennam commented Aug 23, 2024

@kytpbs thanks for the heads up! If you can provide a PR I will be happy to review and merge it! Your second proposal sounds goot to me i would only keep 50400 in the form of (14 * 60 * 60) so it is more clear from where the number comes from.

Also adding a comment would make the code more clear, something like

/* EPOCH_AT_COMPILE_TIME is in local time so we need to remove the maximum timezone offset */

Thanks

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Sep 7, 2024
@per1234 per1234 added the conclusion: resolved Issue was resolved label Sep 16, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
3 participants