Skip to content
Closed
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
17 changes: 16 additions & 1 deletion pendulum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,23 @@ def instance(
# on a fixed offset
tz = tz.utcoffset(dt).total_seconds() / 3600

transition_rule = POST_TRANSITION
if _HAS_FOLD:
if dt.fold is not None:
transition_rule = PRE_TRANSITION
if dt.fold:
transition_rule = POST_TRANSITION

return datetime(
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond, tz=tz
dt.year,
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second,
dt.microsecond,
tz=tz,
dst_rule=transition_rule,
)


Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ mkdocs = { version = "^1.0", python = "^3.5" }
pymdown-extensions = "^6.0"
pygments = "^2.2"
markdown-include = "^0.5.1"
freezegun = "^0.3.15"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So - before adding this, I noticed that the poetry.lock file was already out of date, so I didn't want to muck around with it (yet?).
So for now, just adding this dependency here in the pyproject.toml file.

Now.. I did actually have some issues adding this using poetry (latest version, installed via curling that install script into bash). Tho as far as I could see, I had the correct version of python (3.6.5). But it was complaining about black vs. python interoperability... At any rate - I figured you might want to straighten out poetry.lock on master anyway.



[tool.isort]
Expand Down
46 changes: 46 additions & 0 deletions tests/datetime/test_construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import pytest
import pytz

from freezegun import freeze_time
from pendulum import DateTime
from pendulum.tz import timezone
from pendulum.utils._compat import PY36

from ..conftest import assert_datetime

Expand Down Expand Up @@ -102,6 +104,50 @@ def test_now():
assert now.hour != in_paris.hour


@pytest.mark.skipif(not PY36, reason="fold attribute only present in Python 3.6+")
@freeze_time("2016-03-27 00:30:00")
def test_now_dls_off():
utc = pendulum.now("UTC")
in_paris = pendulum.now("Europe/Paris")
in_paris_from_utc = utc.in_tz("Europe/Paris")
assert in_paris.hour == 1
assert not in_paris.is_dst()
assert in_paris.isoformat() == in_paris_from_utc.isoformat()


@pytest.mark.skipif(not PY36, reason="fold attribute only present in Python 3.6+")
@freeze_time("2016-03-27 01:30:00")
def test_now_dls_transitioning_on():
utc = pendulum.now("UTC")
in_paris = pendulum.now("Europe/Paris")
in_paris_from_utc = utc.in_tz("Europe/Paris")
assert in_paris.hour == 3
assert in_paris.is_dst()
assert in_paris.isoformat() == in_paris_from_utc.isoformat()


@pytest.mark.skipif(not PY36, reason="fold attribute only present in Python 3.6+")
@freeze_time("2016-10-30 00:30:00")
def test_now_dls_on():
utc = pendulum.now("UTC")
in_paris = pendulum.now("Europe/Paris")
in_paris_from_utc = utc.in_tz("Europe/Paris")
assert in_paris.hour == 2
assert in_paris.is_dst()
assert in_paris.isoformat() == in_paris_from_utc.isoformat()


@pytest.mark.skipif(not PY36, reason="fold attribute only present in Python 3.6+")
@freeze_time("2016-10-30 01:30:00")
def test_now_dls_transitioning_off():
utc = pendulum.now("UTC")
in_paris = pendulum.now("Europe/Paris")
in_paris_from_utc = utc.in_tz("Europe/Paris")
assert in_paris.hour == 2
assert not in_paris.is_dst()
assert in_paris.isoformat() == in_paris_from_utc.isoformat()


def test_now_with_fixed_offset():
now = pendulum.now(6)

Expand Down