Skip to content

Extract any Python datetime into some chrono type with abi3 feature enabled #4019

Answered by davidhewitt
124C41p asked this question in Questions
Discussion options

You must be logged in to vote

Hello, good question.

I think the problem with automatic conversion of naive to timezone-aware date times is that it's quite common for users to not think hard about what their naive datetime means. I think you're right in the code above that it's now typically treated as local but it feels like this is still a space where it's easy to introduce a footgun.

The code you wrote above looks correct. You could package this up into a newtype and implement FromPyObject for that type (or use #[pyo3(from_py_with = "extract_dt")] to avoid needing to take &Bound<'_, PyAny> as your function argument.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@124C41p
Comment options

@davidhewitt
Comment options

Answer selected by 124C41p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants