diff --git a/arrow/factory.py b/arrow/factory.py index 0913bfe1..eaa8d7cf 100644 --- a/arrow/factory.py +++ b/arrow/factory.py @@ -189,6 +189,7 @@ def get(self, *args: Any, **kwargs: Any) -> Arrow: arg_count = len(args) locale = kwargs.pop("locale", DEFAULT_LOCALE) tz = kwargs.get("tzinfo", None) + has_tzinfo_kwarg = "tzinfo" in kwargs normalize_whitespace = kwargs.pop("normalize_whitespace", False) # if kwargs given, send to constructor unless only tzinfo provided @@ -196,7 +197,7 @@ def get(self, *args: Any, **kwargs: Any) -> Arrow: arg_count = 3 # tzinfo kwarg is not provided - if len(kwargs) == 1 and tz is None: + if len(kwargs) == 1 and not has_tzinfo_kwarg: arg_count = 3 # () -> now, @ tzinfo or utc diff --git a/arrow/parser.py b/arrow/parser.py index fc3774b0..ce618b5d 100644 --- a/arrow/parser.py +++ b/arrow/parser.py @@ -166,7 +166,7 @@ class DateTimeParser: _TZ_NAME_RE: ClassVar[Pattern[str]] = re.compile(r"\w[\w+\-/]+") # NOTE: timestamps cannot be parsed from natural language strings (by removing the ^...$) because it will # break cases like "15 Jul 2000" and a format list (see issue #447) - _TIMESTAMP_RE: ClassVar[Pattern[str]] = re.compile(r"^\-?\d+\.?\d+$") + _TIMESTAMP_RE: ClassVar[Pattern[str]] = re.compile(r"^[-+]?\d+(?:\.\d+)?$") _TIMESTAMP_EXPANDED_RE: ClassVar[Pattern[str]] = re.compile(r"^\-?\d+$") _TIME_RE: ClassVar[Pattern[str]] = re.compile( r"^(\d{2})(?:\:?(\d{2}))?(?:\:?(\d{2}))?(?:([\.\,])(\d+))?$" @@ -725,7 +725,7 @@ def _build_datetime(parts: _Parts) -> datetime: timestamp = parts.get("timestamp") if timestamp is not None: - return datetime.fromtimestamp(timestamp, tz=timezone.utc) + return datetime.fromtimestamp(float(timestamp), tz=timezone.utc) expanded_timestamp = parts.get("expanded_timestamp") diff --git a/tests/test_factory.py b/tests/test_factory.py index 056cee41..1942cb65 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -137,6 +137,12 @@ def test_kwarg_tzinfo(self): self.factory.get(tzinfo=ZoneInfo("US/Pacific")), self.expected ) + def test_kwarg_tzinfo_none(self): + assert_datetime_equality( + self.factory.get(tzinfo=None), + datetime.now(timezone.utc).replace(tzinfo=timezone.utc), + ) + def test_kwarg_tzinfo_string(self): self.expected = ( datetime.now(timezone.utc) @@ -287,6 +293,11 @@ def test_two_args_str_str(self): assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.tzutc()) + def test_two_args_str_str_tzinfo_none(self): + result = self.factory.get("2013-01-01", "YYYY-MM-DD", tzinfo=None) + + assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.tzutc()) + def test_two_args_str_tzinfo(self): result = self.factory.get("2013-01-01", tzinfo=ZoneInfo("US/Pacific"))