Skip to content
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
3 changes: 2 additions & 1 deletion arrow/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,15 @@ 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
if len(kwargs) > 1:
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
Expand Down
4 changes: 2 additions & 2 deletions arrow/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+))?$"
Expand Down Expand Up @@ -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")

Expand Down
11 changes: 11 additions & 0 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"))

Expand Down
Loading