-
Notifications
You must be signed in to change notification settings - Fork 542
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
Improvements to parsing into Utc, converting from other timezones to Utc #263
Comments
I came here, looking for help, found this issue so I'll post my experiences. I was trying to convert date in The timezone/offset conversions are very confusing and very hard to discover. Some of the traits involved don't even make sense to me: like offset vs timezone. Also, what is Some simple conversion functions between dates in different timezone, would be greatly appreciated. :) |
Hey, sorry about the delay! I think that the most fundamental question is why there are no I believe that when I last gave it a go the design of the Tz traits was such that it was really awkward to implement conversions pleasantly, but I'm not super confident that that's true. I agree that |
No problem. Thanks for replying! I started working on this in #271 but I'm pretty sure I'm doing something wrong because the approach I took ( Note that it's not possible to implement the conversion in a single |
As discussed in chronotope#263. Note that this breaks existing code that did not explicitly specify the offset in calls to `DateTime::parse_from_*`, as they are now ambiguous. Relies on chronotope#271 for conversion back into `DateTime<Utc>` from `DateTime<FixedOffset>` as the latter is used under the hood.
As discussed in chronotope#263. Note that this breaks existing code that did not explicitly specify the offset in calls to `DateTime::parse_from_*`, as they are now ambiguous. Relies on chronotope#271 for conversion back into `DateTime<Utc>` from `DateTime<FixedOffset>` as the latter is used under the hood.
As discussed in chronotope#263. Note that this breaks existing code that did not explicitly specify the offset in calls to `DateTime::parse_from_*`, as they are now ambiguous. Relies on chronotope#271 for conversion back into `DateTime<Utc>` from `DateTime<FixedOffset>` as the latter is used under the hood.
As discussed in chronotope#263. Note that this breaks existing code that did not explicitly specify the offset in calls to `DateTime::parse_from_*`, as they are now ambiguous. Relies on chronotope#271 for conversion back into `DateTime<Utc>` from `DateTime<FixedOffset>` as the latter is used under the hood.
- Creates a global Error enum - Breaks backwards compatiblility mainly because of promoting fallable functions (chronotope#263) - Some tests still fall - Not all doctests are fixed - to_naive_datetime_with_offset function is broken and needs fixing - serde related stuff is not checked properly This is a rebase of chronotope#817 onto the 0.5 main branch. Main differences: - Unify three different error structs - Removed ErrorKind - Adapted a lot of unit tests - Removed some commits from presumably unrelated branches (chronotope#829) or mainlined commits (chronotope#271) Co-authored-by: John-John Tedro <udoprog@tedro.se>
More tests for combinations of `DateTime::into`. Follow-up to Pull Request chronotope#271. Issue chronotope#263
Fixed in #271. Since then you can write: let created: DateTime<Utc> = DateTime::parse_from_rfc3339("1996-12-19T16:39:57-08:00").into(); |
Thanks for making dealing with dates and times in rust easier and for providing what has become the defacto standard for date-based operations.
I do believe there is room for improvement however when it comes to dealing with
DateTime<Utc>
instances; unless I'm mistaken and there's actually an easier way, this is what my code currently looks like to parse a timestamp from a string into aDateTime<Utc>
instance:Aside from the fact that it isn't very pretty or terse, I think it's also extremely undiscoverable. In particular, the usage of DateTime::from_utc to convert to a
DateTime<Utc>
object is unexpected (I understand why it works).It would be extremely helpful if
DateTime<FixedOffset>
had ato_utc()
helper method or some other means of converting more intuitively betweenDateTime
flavors.Is there a fundamental reason why there are no
std::convert
impls to facilitate conversion between these types? Since in the code above there is only the first.unwrap()
and all other operations are not expected to ever produce an error, I imagine it would be possible to usestd::convert
in its current form (vs waiting forstd::convert::TryFrom
to finally stabilize).If
std::convert::From<chrono::DateTime<chrono::FixedOffset>>
were implemented forchrono::DateTime<chrono::Utc>
(orstd::convert::Into<chrono::DateTime<chrono::Utc>>
implemented forchrono::DateTime<chrono::FixedOffset>
if one type isn't aware of the other) the code above could be simplified considerably:(Although I would still suggest that
parse_from_rfcxxxx
be implemented forDateTime<Utc>
in all cases.)The text was updated successfully, but these errors were encountered: