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

Support for RFC 3339 in target time zone #376

Closed
bsidhom opened this issue Feb 23, 2024 · 7 comments · Fixed by #378
Closed

Support for RFC 3339 in target time zone #376

bsidhom opened this issue Feb 23, 2024 · 7 comments · Fixed by #378
Labels
bug Something isn't working

Comments

@bsidhom
Copy link

bsidhom commented Feb 23, 2024

I'm not able to get times to print in RFC 3339 using the format_datetime function:

>>> get_local_timezone()

  get_local_timezone()

    = America/Los_Angeles    [String]

>>> format_datetime("%Y-%m-%dT%H:%M:%S%:z", local(now()))

  format_datetime("%Y-%m-%dT%H:%M:%S%:z", local(now()))

    = 2024-02-23T22:01:52+00:00    [String]

>>> now()

  now()

    = Fri, 23 Feb 2024 14:01:54 -0800    [DateTime]

According to the chrono docs, %z and friends should give the local offset relative to UTC. However, it looks like the TZ info is getting dropped before being sent to the formatter and it's always displaying in UTC. (I would also like to add formatters/parsers for the reference format to the prelude, but I'm not sure if others would find that useful.)

@sharkdp sharkdp added the bug Something isn't working label Feb 23, 2024
@bsidhom
Copy link
Author

bsidhom commented Feb 23, 2024

Sorry, looks like parsing already works as expected via the datetime function. So it’s only formatting that’s currently broken.

@sharkdp
Copy link
Owner

sharkdp commented Feb 23, 2024

Thank you for reporting this. I believe I have a fix in #378, but it needs some testing.

sharkdp added a commit that referenced this issue Feb 23, 2024
@sharkdp
Copy link
Owner

sharkdp commented Feb 23, 2024

Also, there's no need to do now() -> local or local(now()). now() will return a datetime in the local timezone.

@bsidhom
Copy link
Author

bsidhom commented Feb 23, 2024

Yeah, I tried that first but noted that it displayed in UTC. Didn’t realize that was unexpected behavior.

@sharkdp
Copy link
Owner

sharkdp commented Feb 23, 2024

For datetime(…), do we want to return the datetime object in the specified timezone (current behavior in #378), or in the local timezone (current behavior on master)?

sharkdp added a commit that referenced this issue Feb 23, 2024
sharkdp added a commit that referenced this issue Feb 23, 2024
@bsidhom
Copy link
Author

bsidhom commented Feb 23, 2024

I think it’s best to return the specified TZ offset for consistency. Users can always convert to local after parsing, but it’s otherwise difficult to recover the original offset.

@sharkdp
Copy link
Owner

sharkdp commented Feb 23, 2024

This should now be fixed: https://numbat.dev/?q=format_datetime%28%22%25Y-%25m-%25dT%25H%3A%25M%3A%25S%25%3Az%22%2C+now%28%29%29%E2%8F%8E

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants