Skip to content

Fix IsNow/IsDatetime unix_number comparison with timezone#127

Open
bysiber wants to merge 1 commit intosamuelcolvin:mainfrom
bysiber:fix-isnow-unix-tz
Open

Fix IsNow/IsDatetime unix_number comparison with timezone#127
bysiber wants to merge 1 commit intosamuelcolvin:mainfrom
bysiber:fix-isnow-unix-tz

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 22, 2026

Fixes #113.

IsNow(unix_number=True, tz="UTC") was failing because datetime.fromtimestamp() was called without a timezone, creating a naive datetime. When the approx datetime has timezone info (from the tz parameter), approx_equals() then sees a timezone mismatch and rejects the comparison.

The fix passes the approx datetime's timezone to fromtimestamp() so the converted timestamp gets the same timezone, making the comparison work correctly.

Added test assertions for IsNow(unix_number=True, tz='UTC') and IsNow(unix_number=True, tz=timezone.utc).

When using unix_number=True with a timezone (e.g. IsNow(unix_number=True,
tz="UTC")), datetime.fromtimestamp() was called without a timezone, producing
a naive datetime. This caused the comparison to fail because the approx
datetime had a timezone but the converted timestamp did not.

Pass the approx datetime's timezone to fromtimestamp() so both datetimes
have matching timezone info.
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 this pull request may close these issues.

Surprising behaviour of IsNow(unix_number=True, tz="UTC")

1 participant