Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pendulum.parse('now', tz='...') ignoring the time zone #701

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/pendulum/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _parse(text: str, **options: t.Any) -> Date | DateTime | Time | Duration | I
"""
# Handling special cases
if text == "now":
return pendulum.now()
return pendulum.now(tz=options.get("tz", UTC))

parsed = base_parse(text, **options)

Expand Down
7 changes: 6 additions & 1 deletion tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@ def test_parse_interval() -> None:


def test_parse_now() -> None:
dt = pendulum.parse("now")
assert pendulum.parse("now").timezone_name == "UTC"
assert (
pendulum.parse("now", tz="America/Los_Angeles").timezone_name
== "America/Los_Angeles"
)

dt = pendulum.parse("now", tz="local")
assert dt.timezone_name == "America/Toronto"

mock_now = pendulum.yesterday()
Expand Down
Loading