2

If I do:

>>> datetime.max.astimezone(pytz.UTC)
datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, tzinfo=<UTC>)
>>> datetime.min.astimezone(pytz.UTC)
ValueError: year 0 is out of range

However:

datetime.min.replace(tzinfo=pytz.UTC)
datetime.datetime(1, 1, 1, 0, 0, tzinfo=<UTC>)

From this and this answers, it seems a conversion issue.

Is this a bug or an intended behaviour, and why?

2
  • Why would you have to use astimezone? if you just need datetime.min / .max as a placeholder as aware datetime, replace does the trick. Python's naive datetime resembling something like local time brings some complications with it, this is one of them IIUC. One could argue about if this was a good design decision or not. But a bug existing still in 3.11 suggests there's no easy solution on the way. Commented Sep 8, 2023 at 13:40
  • This question is similar to: Convert datetime.min into offset aware datetime. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Aug 3 at 22:41

1 Answer 1

2

It is a bug, still open in Python 3.8: https://github.com/python/cpython/issues/75395

Sign up to request clarification or add additional context in comments.

2 Comments

the comments on this issue still don't answer your question why I think ;-)
Bug still open in python 3.12.4 😭

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.