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

DateTime<Tz>'s implementation for FromPyObject does not consider Pythons's datetime.fold attribute #4722

Open
elied opened this issue Nov 21, 2024 · 0 comments · May be fixed by #4791
Open

Comments

@elied
Copy link

elied commented Nov 21, 2024

When extracting an ambiguous time from DateTime<Tz>, PyO3 will raise a ValueError. Snippet from chrono.rs:

let naive_dt = NaiveDateTime::new(py_date_to_naive_date(dt)?, py_time_to_naive_time(dt)?);
naive_dt.and_local_timezone(tz).single().ok_or_else(|| {
    PyValueError::new_err(format!(
        "The datetime {:?} contains an incompatible or ambiguous timezone",
        dt
     ))
})

So if your Python datetime is datetime(2024, 11, 3, 1, 30, 0, tzinfo=ZoneInfo("America/Chicago"), fold=1), PyO3 will raise the ValueError.

However, in PEP 495 (added in Python 3.6), all time and datetime objects contain a fold attribute to disambiguate ambiguous times. So the above example should not be ambiguous.

We should be able to easily handle this by using chrono's LocalResult.Ambiguous enum.

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

Successfully merging a pull request may close this issue.

1 participant