Skip to content

Commit

Permalink
Fix pendulum.parse('now', tz='...') ignoring the time zone
Browse files Browse the repository at this point in the history
  • Loading branch information
pR0Ps committed Sep 9, 2024
1 parent 3e3fec6 commit 3313f1b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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

0 comments on commit 3313f1b

Please sign in to comment.