From 84d8c3de085d126fb893f3a7ecd63e9d94329173 Mon Sep 17 00:00:00 2001 From: Carey Metcalfe Date: Tue, 4 Apr 2023 22:14:39 -0400 Subject: [PATCH] Fix pendulum.parse('now', tz='...') ignoring the time zone --- pendulum/parser.py | 2 +- tests/test_parsing.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pendulum/parser.py b/pendulum/parser.py index 77900e20..7c34c1dc 100644 --- a/pendulum/parser.py +++ b/pendulum/parser.py @@ -37,7 +37,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) diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 0e5308c8..811524f2 100644 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -125,8 +125,11 @@ def test_parse_interval(): def test_parse_now(): - dt = pendulum.parse("now") + pendulum.parse("now").timezone_name == "UTC" + 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()