diff --git a/arrow/factory.py b/arrow/factory.py index 5787dcf0..aad4af8b 100644 --- a/arrow/factory.py +++ b/arrow/factory.py @@ -9,6 +9,7 @@ import calendar from datetime import date, datetime from datetime import tzinfo as dt_tzinfo +from decimal import Decimal from time import struct_time from typing import Any, List, Optional, Tuple, Type, Union, overload @@ -218,6 +219,8 @@ def get(self, *args: Any, **kwargs: Any) -> Arrow: if arg_count == 1: arg = args[0] + if isinstance(arg, Decimal): + arg = float(arg) # (None) -> raises an exception if arg is None: diff --git a/tests/test_factory.py b/tests/test_factory.py index 4bb81e87..53bba20d 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -1,5 +1,6 @@ import time from datetime import date, datetime +from decimal import Decimal import pytest from dateutil import tz @@ -263,6 +264,13 @@ def test_one_arg_bool(self): with pytest.raises(TypeError): self.factory.get(True) + def test_one_arg_decimal(self): + result = self.factory.get(Decimal(1577836800.26843)) + + assert result._datetime == datetime( + 2020, 1, 1, 0, 0, 0, 268430, tzinfo=tz.tzutc() + ) + def test_two_args_datetime_tzinfo(self): result = self.factory.get(datetime(2013, 1, 1), tz.gettz("US/Pacific"))