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
16 changes: 9 additions & 7 deletions arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ def utcfromtimestamp(cls, timestamp: Union[int, float, str]) -> "Arrow":
)

@classmethod
def fromdatetime(cls, dt: dt_datetime, tzinfo: Optional[TZ_EXPR] = None) -> "Arrow":
def fromdatetime(
cls, dt: Union["Arrow", dt_datetime], tzinfo: Optional[TZ_EXPR] = None
) -> "Arrow":
"""Constructs an :class:`Arrow <arrow.arrow.Arrow>` object from a ``datetime`` and
optional replacement timezone.

Expand Down Expand Up @@ -643,8 +645,8 @@ def ceil(self, frame: _T_FRAMES, **kwargs: Any) -> "Arrow":
def span_range(
cls,
frame: _T_FRAMES,
start: dt_datetime,
end: dt_datetime,
start: Union["Arrow", dt_datetime],
end: Union["Arrow", dt_datetime],
tz: Optional[TZ_EXPR] = None,
limit: Optional[int] = None,
bounds: _BOUNDS = "[)",
Expand Down Expand Up @@ -725,8 +727,8 @@ def span_range(
def interval(
cls,
frame: _T_FRAMES,
start: dt_datetime,
end: dt_datetime,
start: Union["Arrow", dt_datetime],
end: Union["Arrow", dt_datetime],
interval: int = 1,
tz: Optional[TZ_EXPR] = None,
bounds: _BOUNDS = "[)",
Expand All @@ -736,8 +738,8 @@ def interval(
representing a series of intervals between two inputs.

:param frame: The timeframe. Can be any ``datetime`` property (day, hour, minute...).
:param start: A datetime expression, the start of the range.
:param end: (optional) A datetime expression, the end of the range.
:param start: A datetime or Arrow expression, the start of the range.
:param end: (optional) A datetime or Arrow expression, the end of the range.
Comment thread
inzamol marked this conversation as resolved.
:param interval: (optional) Time interval for the given time frame.
:param tz: (optional) A timezone expression. Defaults to UTC.
:param bounds: (optional) a ``str`` of either '()', '(]', '[)', or '[]' that specifies
Expand Down
42 changes: 42 additions & 0 deletions tests/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,48 @@ def test_correct(self):
),
]

def test_arrow_objects_input(self):
# start and end passed as Arrow instances instead of datetime
start = arrow.Arrow(2013, 5, 5, 12, 30)
end = arrow.Arrow(2013, 5, 5, 17, 15)
result = list(arrow.Arrow.interval("hour", start, end, 2))

assert result == [
(
arrow.Arrow(2013, 5, 5, 12),
arrow.Arrow(2013, 5, 5, 13, 59, 59, 999999),
),
(
arrow.Arrow(2013, 5, 5, 14),
arrow.Arrow(2013, 5, 5, 15, 59, 59, 999999),
),
(
arrow.Arrow(2013, 5, 5, 16),
arrow.Arrow(2013, 5, 5, 17, 59, 59, 999999),
),
]

def test_arrow_and_datetime_input(self):
# mixed types should also be accepted
start = arrow.Arrow(2013, 5, 5, 12, 30)
end = datetime(2013, 5, 5, 17, 15)
result = list(arrow.Arrow.interval("hour", start, end, 2))

assert result == [
(
arrow.Arrow(2013, 5, 5, 12),
arrow.Arrow(2013, 5, 5, 13, 59, 59, 999999),
),
(
arrow.Arrow(2013, 5, 5, 14),
arrow.Arrow(2013, 5, 5, 15, 59, 59, 999999),
),
(
arrow.Arrow(2013, 5, 5, 16),
arrow.Arrow(2013, 5, 5, 17, 59, 59, 999999),
),
]

def test_bounds_param_is_passed(self):
result = list(
arrow.Arrow.interval(
Expand Down
Loading