Skip to content
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

Parsing timezone allows minutes to be missing or present #133

Open
tisonkun opened this issue Sep 19, 2024 · 1 comment
Open

Parsing timezone allows minutes to be missing or present #133

tisonkun opened this issue Sep 19, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@tisonkun
Copy link

chrono supports:

Spec. Example Description
%#z +09 Parsing only: Same as %z but allows minutes to be missing or present.

in strptime - https://docs.rs/chrono/latest/chrono/format/strftime/index.html.

jiff's %#z is identical to %z that accepts only [+-]HHMM[SS].

Is it possible to add similar support? The format seems what PostgreSQL's timestamptz uses and now blocks launchbadge/sqlx#3511.

@BurntSushi
Copy link
Owner

I think we should do this, but I think what you're doing in that sqlx PR is not quite right. You're using strptime in the first place because parsing a Zoned requires the time zone annotation. But if you parse into a Timestamp without strptime at all, then it will work just fine. And a Timestamp more accurately models what PostgreSQL is giving you. You generally should only use a Zoned when you have a time zone.

I think I'd prefer not adding more format specifiers for this, and instead just make the existing %z and %:z specifiers parse successfully when minutes aren't present. I guess the downside there is that you might specifically want there to be four digits if you're trying to match an existing format. Or when you're printing. So maybe we can't do that and we do indeed need additional specifiers. Sigh. But this will also apply to %V too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants