Skip to content

Add ISO8601 +-HH:MM to formatting #241

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

Closed
Firstyear opened this issue Apr 5, 2020 · 8 comments
Closed

Add ISO8601 +-HH:MM to formatting #241

Firstyear opened this issue Apr 5, 2020 · 8 comments
Labels
C-feature-request Category: a new feature (not already implemented)

Comments

@Firstyear
Copy link

There are a large number of format strings supported by time (ie https://docs.rs/time/0.2.9/time/index.html#formatting ). %z outputs or parses a UTC offset with "[+-]HHMM". However in ISO8601 it is also valid to have "[+-]HH:MM", and in expected fashion, some other libraries only accept the ":" seperated format. It would be good if time could also output and parse this. Thanks!

@jhpratt
Copy link
Member

jhpratt commented Apr 5, 2020

See #236; there are planned improvements to the formatter & parser. Also note that there is actually support for RFC3339/ISO8601 formatting & parsing on master. I will likely create a 0.2.10 release with this functionality soon.

Do you need support for formatting & parsing with the colon on its own, or is RFC/ISO support sufficient for your use case?

@Firstyear
Copy link
Author

I think the ISO support is enough for my use case, thanks for the quick response and really appreciate your time (pun intended :) )

@jhpratt jhpratt added the C-feature-request Category: a new feature (not already implemented) label Apr 5, 2020
@jhpratt
Copy link
Member

jhpratt commented Apr 6, 2020

Closing this as your use case is already covered on master 🙂

@jhpratt jhpratt closed this as completed Apr 6, 2020
@Weasy666
Copy link

@jhpratt So...i need to ask a kinda dumb question...how can i parse ISO8601 with time 0.2.22? 😅
time::OffsetDateTime::parse("2039-01-01T00:00:00+00:00", "%FT%T%z").unwrap() throws an error

@jhpratt
Copy link
Member

jhpratt commented Nov 13, 2020

@Weasy666 As indicated in documentation, %z does not have a colon present. Instead of passing a %FT%T%z as the format description, you can pass time::Format::Rfc3339. This is compatible with ISO8601 (I'm fairly certain).

Probably wouldn't be a bad idea to add a doc alias for "ISO8601", which would let it show up in search results.

@Weasy666
Copy link

Ah...nice! Thanks for the quick reply. Rfc3339 works! Doc alias sounds like a good idea!

@jhpratt
Copy link
Member

jhpratt commented Nov 13, 2020

It's set to stabilize this coming Thursday! I don't like the #[cfg_attr] hack for doc_cfg that I use now, so I'd rather just wait a few days haha

@Weasy666
Copy link

Other people can search the issues and can see the solution here, so no hurry. I guess. 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: a new feature (not already implemented)
Projects
None yet
Development

No branches or pull requests

3 participants