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

str(pendulum.DateTime) != str(datetime.datetime) #662

Closed
2 tasks done
ltowarek opened this issue Oct 4, 2022 · 1 comment · Fixed by #733
Closed
2 tasks done

str(pendulum.DateTime) != str(datetime.datetime) #662

ltowarek opened this issue Oct 4, 2022 · 1 comment · Fixed by #733

Comments

@ltowarek
Copy link

ltowarek commented Oct 4, 2022

  • I am on the latest Pendulum version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: Ubuntu 20.04
  • Pendulum version: 2.1.2

Issue

I have found out that pendulum.DateTime is not a drop-in replacement for datetime.datetime when we are talking about conversion to strings:

>>> import datetime
>>> x = datetime.datetime(2022, 10, 23, 8, 30)
>>> str(x)
'2022-10-23 08:30:00'
>>> import pendulum
>>> y = pendulum.instance(x)
>>> str(y)
'2022-10-23T08:30:00+00:00'
>>> str(x) == str(y)
False

Is there a reason why pendulum.DateTime.__str__ is implemented in this way? Can it behave just like datetime.datetime.__str__?
https://github.com/sdispater/pendulum/blob/7f6d069d8eee0b022dac276e7d6ef7545e78220e/pendulum/datetime.py#L441-L442

@intiocean
Copy link

I think the difference you're seeing is due to pendulum datetimes having timezones (and that being UTC when a timezone isn't specified).

In [1]: import datetime

In [2]: import pytz

In [3]: str(datetime.datetime(2022, 10, 23, 8, 30, tzinfo=pytz.utc))
Out[3]: '2022-10-23 08:30:00+00:00'

@sdispater sdispater mentioned this issue Aug 15, 2023
2 tasks
Secrus pushed a commit that referenced this issue Aug 15, 2023
* Ensure string representations match the standard library

Fixes #662

* Fix deepcopy of durations

Fixes #714

* Default to UTC if not local timezone can be found

Fixes #715
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.

2 participants