Skip to content

naive DateTime.diff fails when the input is a naive datetime object, as pendulum.instance converts it to a pendulum.DateTime with UTC tz #880

@NodeJSmith

Description

@NodeJSmith
  • 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 22.04.3 LTS (running in WSL2)

  • Pendulum version: 3.0.0

Issue

When a naive pendulum.DateTime calls diff with a stdlib datetime object the input is converted to a pendulum instance, but it defaults to having a timezone of UTC, causing a TypeError

TypeError: can't compare offset-naive and offset-aware datetimes

Repro

from datetime import datetime

import pendulum

pendulum_today = pendulum.today().naive()
stdlib_today = datetime.today()

print(pendulum_today.tzinfo)
print(stdlib_today.tzinfo)

pendulum_today.diff(stdlib_today)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions