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
No TimeZone information in toIso8601String of DateTime #43391
Comments
The format used for local time is https://en.wikipedia.org/wiki/ISO_8601#Local_time_(unqualified), which means that it has no time zone designation. Dart's |
Can you advise an alternative for |
The Dart If you want a text representation of the local time and the local time zone, you can do That's the real distinction between UTC-times and local times:
The wall-clock time is found by looking up the time-zone offset at the absolute point in time in the local time zone information. That information covers all past, present and future time-zone changes at the current location, but not at any other location. It basically assigns a unique local time-zone offset to any UTC time. If you store the So, if you want to store local wall-clock time and time-zone offset, which you obviously can do yourself, be aware that Dart's About the system changing time zones (the Traveling Laptop Problem), that follows directly from the above. Daylight saving time isn't an issue, the locale can have a full history of the current location's offsets at any time in the past, it just doesn't know anything about any other time zones. If you actually change the time zone, manually or because the OS detects that you have moved, you get a new complete history of local time zones So, always use UTC times if you need to pass points in time between computers, to record when something happened, or even to keep them on the same computer for any extended duration. Only use local time for displaying locally, not for storage. String myOwnTimeZoneFormatter(Duration offset) =>
"${offset.isNegative ? "-": "+"}${offset.inHours.toString().padLeft(2, "0")}:${
(offset.inMinutes - offset.inHours * 60).toString().padLeft(2, "0")}"; |
Thanks, it makes sense |
Published code snippet doesn't work with negative timezones (it produces Fixed code: String myOwnTimeZoneFormatter(Duration offset) =>
"${offset.isNegative ? "-" : "+"}${offset.inHours.abs().toString().padLeft(2, "0")}:${(offset.inMinutes - offset.inHours * 60).toString().padLeft(2, "0")}"; |
Published code snippet doesn't work with negative timezones which has half an hour offset (It could be located in Newfoundland where the timezone is -2:30). Fixed code: String myOwnTimeZoneFormatter(Duration offset) =>
"${offset.isNegative ? "-" : "+"}${offset.inHours.abs().toString().padLeft(2, "0")}:${(offset.inMinutes - offset.inHours * 60).abs().toString().padLeft(2, "0")}"; |
So why do I use |
That's the desired behaviour! In our app, we can have a situation when users are in the different time zones, and the 1st user sends his local time to the server, which converts it to UTC, and the 2nd user receives it and converts to his local time. Consider adding a parameter |
@subzero911 Just do everything in UTC and only convert to local in the very end |
this only works if you're not interested in the timezone where the event was recorded e.g. you log the time somebody went for a bike ride. If you show that bike ride in your app it wouldn't make much sense to show it in the middle of the night just because the user went on holiday. |
What about storing bike rides in a database? It will have to be UTC anyway, so you don't really have other options but saving timezone separately and then converting from UTC to local in your frontend. |
If you do this you're showing the time of the bike ride in the user's current timezone, not the timezone where they recorded the activity. |
Hej all, in our case, the offset gives georeferenced information about where the record was created, which in turn is necessarily needed to determine the day and the difference from 00:00 in the corresponding timezone. But actually we want: BTW: For this reason we always store the DateTime object in our database with origin time zone. |
My company works on an asset tracking system. Everything is time zone aware. The database, the complete backend written in Go and the web client. Our API accepts only RFC3339 compliant timestamps which requires a timezone. It's a little bit annoying to be required to ensure DateTime instances are in UTC. |
A possible workaround, put this in main.dart
|
Is there a reason why the toIso8601 Code not contains the ISO8601 Timezone information?
Code
I wondering why not
2020-09-10T09:03:00.000+02:00
?The difference between UTC is stored in
timeZoneOffset
and it would be ISO8601 standard.The text was updated successfully, but these errors were encountered: