-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Enhancements for civil time conversions #17003
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
Conversation
Provide POSIX-compatible definitions for a subset of the time types that must be provided by this file, in anticipation of supporting civil time in Zephyr. Signed-off-by: Peter A. Bigot <[email protected]>
|
All checks are passing now. Review history of this comment for details about previous failed status. |
In anticipation of the need to support civil time (year/month/day) and to align system time with civil time add functions that convert between time_t and struct tm representations. Signed-off-by: Peter A. Bigot <[email protected]>
|
The proposed solution seems to be much more simple than the standard POSIX combination:
Instead, what if we implemented:
https://pubs.opengroup.org/onlinepubs/009695399/functions/gmtime.html |
|
I've verified that
If a way to use A motivation to stick with custom ones would be the fact that |
|
Actually @pabigot my proposal was that you simply rename those but keep the implementation for minimal libc. I wasn't really suggesting you withdraw the PR, just to use more standard names. |
|
@carlescufi I can certainly provide I'm less happy about the reverse function. Zephyr doesn't seem to have a place for completely generic utility code that requires an implementation file (not just a header) and isn't associated with any subsystem. Until there's a solution to that, I think the best path forward is adding That'd be two drivers with the |
pfalcon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conflicts with existing PR on elaborating POSIX compatibility with both minlibc and newlib.
| typedef int64_t time_t; | ||
| typedef int32_t suseconds_t; | ||
|
|
||
| struct timespec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conflicts with #16626 , which takes care about minlibc vs newlib compatibility.
| * @return the signed number of days between 1970-01-01 and the | ||
| * specified day. Negative days are before 1970-01-01. | ||
| */ | ||
| s64_t time_days_from_civil(s64_t y, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use more descriptive names than "y", etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable names match the reference implementation from which this was translated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reference implementation from which this was translated.
Then it should have licensing and copyright of it, in addition to yours? But even then, as long as you modify it at all, you can use more descriptive names.
| z += 719468; | ||
|
|
||
| s64_t era = ((z >= 0) ? z : (z - 146096)) / 146097; | ||
| unsigned int doe = (z - era * (s64_t)146097); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even for local vars, more descriptive names are prefererrable.
|
I'm with @carlescufi here: at all times we should prefer standard, well-known APIs instead of |
|
This will be reworked based on adding |
Fairly speaking, that's not the outcome expected. The idea is to pool together people interested in adding standard APIs to Zephyr (and POSIX offers quite a good functionality coverage for systems APIs), and motivate them to work together towards good solutions, instead of on-spot workarounds (like "putting functions in drivers"). But good to hear a new version will be submitted, thanks! |
|
@pfalcon Yes to coordinating changes, but the approach and details in this specific PR are clearly no longer the right path forward. We'll argue about whether the hinnant function should be put in a shareable location, and whether its variables should be renamed from the reference implementation, when there's a PR that introduces a second copy. |
Commits in this PR are a first step towards providing support in Zephyr to register system time (e.g. milliseconds since startup) against civil time (UTC, TAI, etc.), which is necessary for things like Bluetooth mesh scheduled operations.
The first commit provides the minimal libc implementation in Zephyr with the same time-related types that are present in POSIX and newlib in all other toolchains.
The second commit uses conversion algorithms to translate between
struct tmandtime_trepresentations.Once this functionality is in place it should be possible to use external time sources such as NTP or Bluetooth Mesh Time Service to get current time onto a Zephyr device, then translate between system time and real time, including (in the future) dealing with leap seconds, local time offsets, and daylight saving time.
I anticipate adding new types to provide TAI-UTC offset, local time offset, and DST change information in a future PR.
A proactive comment about two style issues that may raise questions:
int64_t) instead of the Zephyr alias (s64_t). Here I am following existing practice inlibc/minimal.Also I'm not entirely happy about the creating of a new
libsubdirectory, but I tried to usemiscand failed to convince CMake to pay attention to me. I don't see any other location to put cross-platform utility code; if this belongs somewhere else please let me know.Finally, I would very much like to explicitly identify the algorithm implementation as being a translation of the public-domain material by Howard Hinnant, but I don't know how to express that without breaking the format of the license block. I've at least been able to put the link to the original in comments near the functions.