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

Implement parsing offset without colon #204

Open
spacemanspiff2007 opened this issue Feb 7, 2025 · 4 comments
Open

Implement parsing offset without colon #204

spacemanspiff2007 opened this issue Feb 7, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@spacemanspiff2007
Copy link

from whenever import OffsetDateTime

OffsetDateTime.parse_common_iso('2025-02-07T07:44:00.000+01:00')    # works
OffsetDateTime.parse_common_iso('2025-02-07T07:44:00.000+0100')     # without colon is doesn't
ValueError: Invalid format: '2025-02-07T07:44:00.000+0100'

I think the offset +0100 is pretty close to +01:00 and one of the more common formats so this seems to be worth supporting

@BurntSushi
Copy link

FWIW, Temporal does support this:

Temporal.Instant.from('2025-02-07T07:44:00.000+01:00').toString()
"2025-02-07T06:44:00Z"
Temporal.Instant.from('2025-02-07T07:44:00.000+0100').toString()
"2025-02-07T06:44:00Z" 

@ariebovenberg
Copy link
Owner

I think the offset +0100 is pretty close to +01:00 and one of the more common formats so this seems to be worth supporting

Fair point. It definitely is "common", and I agree most users will expect it to be parsed. My only concern is of course that we need to draw the line somewhere about what ISO is parsed, and what isn't.

yes yes slipperly slope but do we support...

  • omitting seconds?
  • two-digit offsets? (e.g. +05 instead of +05:00

@BurntSushi does Jiff draw the line at the same place as Temporal?

@BurntSushi
Copy link

Hmmm, do you know about Temporal's ISO 8601 grammar? That's what Jiff implements sans a few minor differences. The Temporal folks already did the (very) hard work of identifying the "good" parts of ISO 8601, while remaining compatible with RFC 3339 and RFC 9557. So I deferred strongly to them.

But yes, Jiff supports this too. These assertions pass:

use jiff::Timestamp;

fn main() -> anyhow::Result<()> {
    let ts: Timestamp = "2025-02-07T07:44:00.000+01:00".parse()?;
    assert_eq!(ts.to_string(), "2025-02-07T06:44:00Z");

    let ts: Timestamp = "2025-02-07T07:44:00.000+0100".parse()?;
    assert_eq!(ts.to_string(), "2025-02-07T06:44:00Z");

    Ok(())
}

@BurntSushi
Copy link

And see also tc39/proposal-temporal#2843

@ariebovenberg ariebovenberg added the enhancement New feature or request label Feb 8, 2025
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

3 participants