-
-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve timezone support #2770
Merged
Merged
Improve timezone support #2770
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mikee47
force-pushed
the
feature/timezone-changes
branch
from
April 23, 2024 20:10
487a0a9
to
1c2cf76
Compare
mikee47
force-pushed
the
feature/timezone-changes
branch
2 times, most recently
from
April 28, 2024 08:58
d5aa6c4
to
1c2cf76
Compare
mikee47
changed the title
[WIP] Add timezone check callback to SystemClock
[WIP] Improve timezone support
Jun 17, 2024
mikee47
force-pushed
the
feature/timezone-changes
branch
2 times, most recently
from
June 17, 2024 07:35
7d0c23f
to
2e6696e
Compare
Can vary much more than plus/minus 12 hours
Causes all sorts of hidden issues performing arithmetic otherwise
This uses `DateTime::ZoneInfo` and `ZonedTime` to provide a basic mechanism for dealing with zoned time information. Handling rules, etc. must be handled with separate library.
…kday correctly Requires full conversion to/from time_t. So add static versions of these methods which can also be used where broken-down time isn't required. Any failure in parsing means the DateTime value is left unchanged, rather than in an indeterminate state.
mikee47
force-pushed
the
feature/timezone-changes
branch
from
June 19, 2024 15:36
2e6696e
to
0569303
Compare
Add to Windows CI builds
mikee47
force-pushed
the
feature/timezone-changes
branch
from
June 19, 2024 15:37
0569303
to
6123664
Compare
slaff
approved these changes
Jun 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fills some gaps in Sming's support of time zones.
Time zones are a complex issue and best left to a separate library.
However, some minimal changes are required to the framework itself.
Fixes
Remove
DT_DATE_SEPARATOR
- no longer usedAdd MINS_PER_HOUR definition
Don't restrict SystemClock timezone offset range. Can vary much more than plus/minus 12 hours.
Make core DateTime defines signed. Causes all sorts of hidden issues performing arithmetic otherwise.
Ensure DateTime:: fromHttpDate(), fromISO8601() and setTime() set weekday correctly.
Requires full conversion to/from time_t, so add static versions of these methods which can also be used where broken-down time isn't required.
Any failure in parsing means the DateTime value is left unchanged, rather than in an indeterminate state.
Add Zoned Time support
This uses
DateTime::ZoneInfo
andZonedTime
to provide a basic mechanism for dealing with zoned time information.Handling rules, etc. must be handled with separate library.
ZoneInfo
provides information associated with a point-in-timeZonedTime
contains a UTC timestamp (time_t) plus ZoneInfoThis naming is common amongst other libraries, e.g. java.
DateTime
formatting now supports "z", ":z" and "%Z" format specifiers with provided (optional)ZoneInfo
parameter.Handle transitions to/from daylight savings
Adds a callback to the SystemClock so that the timezone offset can be maintained efficiently.
Update
SystemClock_NTP
sample and add to Windows CI builds.Obtaining the local time involves converting the current system clock time from UTC using an offset based on the currently active timezone rules. The
Timezone
library is one way to deal with this, but not the only way of course.There is currently no mechanism for keeping the system clock time offset correct, other than periodically setting it. For example, this is how the
SystemClock_NTP
sample currently does it. However, that's not ideal since we might only need to update via NTP infrequently; the two tasks aren't actually related.This is the code added to the
SystemClock_NTP
sample, in theNtpClientDemo.cpp
file:It's important to note that the system clock must be correctly set before this is called for the first time.
Therefore the call to
SystemClock.onCheckTimeZoneOffset(checkTimeZoneOffset)
is made only after setting the clock in our NTP callback. From then on,checkTimeZoneOffset
is called whenever the local time is requested fromSystemClock
.It's efficient because we note when the next change to/from DST is and so only need to check it, but will guarantee that the correct local time is returned without having to perform a full TimeChangeRule calculation every time.
NOTE: This isn't a perfect solution since there are ways to easily bypass the update check. Something the user might want to add into their applications is a periodic manual check, perhap?
Timezone library changes
Add POSIX timezone string support
Adds support for parsing POSIX timezone definition strings.
C library support for timezone generally involves code like this:
This approach is complex and inflexible so the code has been ported from newlib so that rules can be easily defined using these strings.
Provide standard timezone rule definitions
A set of timezone data can be built directly from the IANA database information.
This is limited to the standard POSIX string definitions.
The data itself is deliberately NOT included in the library as it changes frequently, sometimes several times a year.
Note: Whilst currently this data is generated statically for linking with applications,
future improvements to the library will consider mechanisms for keeping this information updated in a running system,
without having to re-flash the firmware.
Testing
Add extensive testing to validate generated rules and compare against OS-provided transition tables.
TODO: