-
Notifications
You must be signed in to change notification settings - Fork 2.1k
board/native: set TZ to UTC by default #20023
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
setting the enviroment is actually the suggested portable solution by gnu libc https://www.gnu.org/software/libc/manual/html_node/Broken_002ddown-Time.html#index-timegm |
I assume this will also affect the time returned by Then this will cause confusion because the time 'inside' native does no longer line up with the system time. |
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.
> rtc gettime
2023-10-26 14:53:09
$ date
Do 26. Okt 16:53:17 CEST 2023
I think this will lead to confusion.
boards/native/board_init.c
Outdated
@@ -79,5 +80,6 @@ VFS_AUTO_MOUNT(native, { .hostpath = FS_NATIVE_DIR }, VFS_DEFAULT_NVM(0), 0); | |||
*/ | |||
void board_init(void) | |||
{ | |||
setenv("TZ", "UTC", 0); |
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.
Let's guard this behind a pseudo-module or config option that gets selected by Makefile.tests_common
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.
how did you set the rtc ? (we should probably start it at 0 where most of our boards start) :)
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.
I did not set it at all, it's synced with the system time by default.
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.
I like sane defaults and the time functions are insane and even more so if timezone things are happening lets ditch then in a more sane direction by default.
if you like your localtime to much TZ=/etc/localtime <elf_file>
or TZ=/etc/localtime make term or test
is an option
using mktime on native is a gamble otherwise maybe we should run a Linter that warns and errors about that.
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.
IMHO native
showing the same time as the host system is a sane default.
Why not make it a config option so we can have predictive behavior for tests that need it without forcing everyone to accept UTC as the one true time?
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.
- cause in networking our timestamps are usually UNIX time - which is kind of UTC.
- since RIOT is an IoT OS we should probably be as compatible as we can.
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.
2423137
to
842a74e
Compare
Maybe we could have the Not being slightly off but a lot off may look more intentional to a user and is more consistent to the behavior of real hardware. Having the timezone of the host not leak into the |
What's the status on this one? Mind looking into it before the upcoming release? |
rebased to resolve merge confict |
I blocked that because back then I was doing a lot of tests with I'm not doing that now, so if you really think running |
because it effects the application that use mktime and co and is not isolated to tests |
boards/common/native/doc.md
Outdated
- execute `export TZ=":/etc/localtime"` prior `make term` in the very shell you intend to run make term in | ||
- add `export TZ=":/etc/localtime"` to your `~/.profile` | ||
- run `TZ=":/etc/localtime" make term` | ||
- set `TZ` in riot application picolibc and newlib are able to respect that setting if `+/-hh:mm:ss` |
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.
Can't we just add this to pyterm
so it's less user hostile?
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.
i will not: i think doing things wrong (make embedded things that assume no timezone behave wrong) should not be the default.
i think mktime behaving different on native and on embedded is much more user hostile
if one wants mktime behave like it is in a timezone there are easy ways in application or environment
and i put them in the documentation
ae55ecc
to
933a498
Compare
boards/common/native/doc.md
Outdated
- RTC: host-time but at 'UTC' to behave consistent with embedded systems if TZ is set that timezone will be used. | ||
- set `TZ` environment variable e.g.: | ||
- execute `export TZ=":/etc/localtime"` prior `make term` in the very shell you intend to run make term in | ||
- add `export TZ=":/etc/localtime"` to your `~/.profile` | ||
- run `TZ=":/etc/localtime" make term` | ||
- to set set `TZ` in riot application as picolibc and newlib are able to respect that setting if `NAME+/-hh:mm:ss` | ||
(-time is added, +time is subtracted from UTC (+ pointing WEST England towards America) see `man timezone` | ||
eg.: `IST-5:30` or `TZ="NZST-12NZDT-13,M10.1.0,M3.3.0"` or `TZ="CET-1CEST-2,M3.5.0,M10.5.0"` or `TZ="ACST-9:30ACDT-10:30,M10.1.0,M4.1.0"` |
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.
Thanks for the detailed documentation! It's a lot though now, and I'd say it warrants a separate subsection.
55466d4
to
f73e6cc
Compare
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.
Thanks for the documentation, some formulation suggestions below.
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.
One last round, then I'd be satisfied :)
c1ffdbb
to
8f8c136
Compare
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.
LGTM now, thanks!
Contribution description
board/native: set env TZ to UTC by default
also fix the failing minema test - that assumend to be run in Berlin/Paris/Hamburg/Rom/Wien
most (all) embedded libc do not care for TZ and time functions don't do timezone conversion,
making native use UTC for time.h functions does the same
you can still force localtime timezone
TZ=":/etc/localtime" <elf_file>
orTZ=":/etc/localtime" make term or test
orexport TZ=":/etc/localtime"
oror another timezone
export TZ="LEET+1:33:7"
(timezone name and offset from UTC optional DSTTesting procedure
run the minema test in Berlin and see that the time stamp is now UTC
Issues/PRs references
#20018 #20005