Skip to content

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

@ltowarek

Description

@ltowarek
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions