Skip to content
Merged
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
12 changes: 12 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
- name: Upgrade pip
run: |
source $HOME/.poetry/env
poetry run python -m pip install pip -U
- name: Install dependencies
run: |
source $HOME/.poetry/env
Expand Down Expand Up @@ -86,6 +90,10 @@ jobs:
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-fix-${{ hashFiles('**/poetry.lock') }}
- name: Upgrade pip
run: |
source $HOME/.poetry/env
poetry run python -m pip install pip -U
- name: Install dependencies
run: |
source $HOME/.poetry/env
Expand Down Expand Up @@ -127,6 +135,10 @@ jobs:
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
- name: Upgrade pip
run: |
$env:Path += ";$env:Userprofile\.poetry\bin"
poetry run python -m pip install pip -U
- name: Install dependencies
run: |
$env:Path += ";$env:Userprofile\.poetry\bin"
Expand Down
12 changes: 11 additions & 1 deletion pendulum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,17 @@ def now(tz=None): # type: (Optional[Union[str, _Timezone]]) -> DateTime
tz = _safe_timezone(tz)
dt = tz.convert(dt)

return instance(dt, tz)
return DateTime(
dt.year,
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second,
dt.microsecond,
tzinfo=dt.tzinfo,
fold=dt.fold if _HAS_FOLD else 0,
)


def today(tz="local"): # type: (Union[str, _Timezone]) -> DateTime
Expand Down
47 changes: 38 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pytest = "^4.6"
pytest-cov = "^2.5"
pytz = ">=2018.3"
babel = "^2.5"
cleo = "^0.7.5"
cleo = "^0.8.1"
tox = "^3.0"
black = { version = "^19.3b0", markers = "python_version >= '3.6' and python_version < '4.0' and implementation_name != 'pypy'" }
isort = { version = "^4.3.21", markers = "python_version >= '3.6' and python_version < '4.0'" }
Expand All @@ -41,6 +41,7 @@ mkdocs = { version = "^1.0", python = "^3.5" }
pymdown-extensions = "^6.0"
pygments = "^2.2"
markdown-include = "^0.5.1"
freezegun = "^0.3.15"


[tool.isort]
Expand All @@ -62,6 +63,7 @@ known_third_party = [
"babel",
"cleo",
"dateutil",
"freezegun",
"pytzdata",
]

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 @@ -3,13 +3,15 @@
from datetime import datetime

from dateutil import tz
from freezegun import freeze_time

import pendulum
import pytest
import pytz

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_dst_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_dst_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_dst_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_dst_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