Skip to content

Commit

Permalink
allowing plural 'name' arguments to _get_frames (#735)
Browse files Browse the repository at this point in the history
* added tests for allowing plural frames into _get_frames

* implemented parsing plural arguments in _get_frames

* Fixed arrow.get with a timestamp and a timezone string and added comments.

* Remove unnecessary additional attribute in shift function.

Co-authored-by: Jad Chaar <[email protected]>
  • Loading branch information
JunhwanK and jadchaar committed Jan 1, 2020
1 parent b1b37ce commit b12f4a6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
17 changes: 15 additions & 2 deletions arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,13 +1437,26 @@ def _get_frames(cls, name):

if name in cls._ATTRS:
return name, "{}s".format(name), 1

elif name[-1] == "s" and name[:-1] in cls._ATTRS:
return name[:-1], name, 1
elif name in ["week", "weeks"]:
return "week", "weeks", 1
elif name in ["quarter", "quarters"]:
return "quarter", "months", 3

supported = ", ".join(cls._ATTRS + ["week", "weeks"] + ["quarter", "quarters"])
supported = ", ".join(
[
"year(s)",
"month(s)",
"day(s)",
"hour(s)",
"minute(s)",
"second(s)",
"microsecond(s)",
"week(s)",
"quarter(s)",
]
)
raise AttributeError(
"range/span over frame {} not supported. Supported frames: {}".format(
name, supported
Expand Down
30 changes: 30 additions & 0 deletions tests/arrow_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,36 @@ def test_day(self):
],
)

def test_days(self):

result = list(
arrow.Arrow.span_range(
"days", datetime(2013, 1, 1, 12), datetime(2013, 1, 4, 12)
)
)

self.assertEqual(
result,
[
(
arrow.Arrow(2013, 1, 1, 0),
arrow.Arrow(2013, 1, 1, 23, 59, 59, 999999),
),
(
arrow.Arrow(2013, 1, 2, 0),
arrow.Arrow(2013, 1, 2, 23, 59, 59, 999999),
),
(
arrow.Arrow(2013, 1, 3, 0),
arrow.Arrow(2013, 1, 3, 23, 59, 59, 999999),
),
(
arrow.Arrow(2013, 1, 4, 0),
arrow.Arrow(2013, 1, 4, 23, 59, 59, 999999),
),
],
)

def test_hour(self):

result = list(
Expand Down

0 comments on commit b12f4a6

Please sign in to comment.