-
Notifications
You must be signed in to change notification settings - Fork 778
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
IntoPy
does not properly respect chrono_tz::Tz
timezones
#3266
Comments
@Psykopear @pickfire Do you have the bandwidth to look into this? |
FWIW I wound up implementing this in my own code like:
and then to convert the
You can probably think of something more pythonic or efficient here, but if not, feel free to steal from this |
IntoPy
does not properly respect chrono_tz::Tz
timezonesIntoPy
does not properly respect chrono_tz::Tz
timezones
Hello! I have recently started using Rust and PyO3 and have come across this issue. I'm simply using a custom conversion function in my code to deal with it for now, but I'd love to see it addressed in the official repo. Does someone have a general outline of what the solution might look like here? If not, I've shared my thoughts below. I'm still learning Rust so I might be off-base here, but based on my understanding the core issue here was that PyO3 didn't want to assume which timezone implementation was being used in Python (makes sense).
However, the So it seems like the simplest (though maybe not cleanest?) path forward here would be to update the conversions for What do others think of this plan? I'd think that anyone using the |
Help would be welcome here. I think you're in the right direction, though it might be simpler than you fear. I think this implementation pyo3/src/conversions/chrono.rs Line 439 in 06d2aff
needs to be changed so that instead of converting the timezone to fixed offset, it should instead require the timezone type implement impl<'a, 'py, Tz: TimeZone> IntoPyObject<'py> for &'a DateTime<Tz>
where &'a Tz: IntoPyObject<'py> { ... and then the |
Ah, I wasn't sure about an approach like that since it seemed like more of a breaking change since we'd be ditching the default implementation with offsets entirely (unless I'm misunderstanding). I agree that would be a cleaner implementation though! If you are okay with that direction, I can work on a PR in the next couple of days. |
The
IntoPy
implementation forchrono::DateTime
is implemented generically for anyT: TimeZone
by converting everything to fixed offsets. This means it loses theTz
information in a timezone likeAmerica/Los Angeles
and just converts it toUTC-8
which is a lossy conversion (due to daylight savings, etc).PyO3 should probably provide two different implements, one for
DateTime<FixedOffset>
and another forDateTime<chrono_tz::Tz>
that creates a pythonZoneInfo
object.This is technically a bug since this should be a lossless conversion but I have filed it under feature request since it doesn't match the bug template very well.
The text was updated successfully, but these errors were encountered: