Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## Unreleased

### Fixed
- Preserve the DST fold when removing timezone information with `DateTime.naive()`.

## [3.3.0] - 2026-10-12

### Added
Expand Down
5 changes: 3 additions & 2 deletions docs/docs/instantiation.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ and each has their time value set to `00:00:00`.
```

Pendulum enforces timezone aware datetimes, and using them is the preferred and recommended way
of using the library. However, if you really need a **naive** `DateTime` object, the `naive()` helper
is there for you.
of using the library. If you need a **naive** `DateTime` object, `naive()` removes the timezone
and preserves the local time and its `fold` value. During a clock rollback, this distinguishes the
first occurrence of a local time from the second.

```python
>>> import pendulum
Expand Down
3 changes: 2 additions & 1 deletion src/pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def time(self) -> Time:

def naive(self) -> Self:
"""
Return the DateTime without timezone information.
Return the DateTime without timezone information, preserving the fold.
"""
return self.__class__(
self.year,
Expand All @@ -327,6 +327,7 @@ def naive(self) -> Self:
self.minute,
self.second,
self.microsecond,
fold=self.fold,
)

def on(self, year: int, month: int, day: int) -> Self:
Expand Down
23 changes: 23 additions & 0 deletions tests/datetime/test_naive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import pytest

import pendulum

from tests.conftest import assert_datetime
Expand Down Expand Up @@ -76,3 +78,24 @@ def test_naive_method():
assert dt.tzinfo is None
assert dt.timezone is None
assert dt.timezone_name is None


@pytest.mark.parametrize("fold", [0, 1])
@pytest.mark.parametrize(
"tz, year, month, day, hour, minute",
[
("America/New_York", 2024, 11, 3, 1, 30),
("Australia/Lord_Howe", 2024, 4, 7, 1, 45),
],
)
def test_naive_method_preserves_fold(tz, year, month, day, hour, minute, fold):
dt = pendulum.datetime(year, month, day, hour, minute, 12, 345678, tz=tz, fold=fold)

naive = dt.naive()

assert isinstance(naive, pendulum.DateTime)
assert_datetime(naive, year, month, day, hour, minute, 12, 345678)
assert naive.tzinfo is None
assert naive.fold == fold
assert naive.replace(tzinfo=dt.tzinfo).timestamp() == dt.timestamp()
assert naive.naive().fold == fold