-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix from_start_end: handle datetime first
- Loading branch information
Showing
2 changed files
with
38 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -590,27 +590,35 @@ def from_start_end(cls, start, end=None): | |
Convenient to ease backward compatibility, | ||
and to handle either hdays or datetimes. | ||
""" | ||
|
||
if isinstance(start, Range): | ||
assert end is None, "range and end are mutually exclusive" | ||
range = start | ||
else: | ||
if isinstance(start, hday): | ||
day = start | ||
start = day.start | ||
if end is None: | ||
end = day.end | ||
elif isinstance(start, pdt.date): | ||
# transition from legacy | ||
start = hday.from_pdt(start).start | ||
|
||
if isinstance(end, hday): | ||
end = end.end | ||
elif isinstance(end, pdt.date): | ||
end = hday.from_pdt(end).end | ||
|
||
range = Range(start, end) | ||
|
||
return range | ||
assert end is None, "end cannot be passed together with a Range" | ||
return cls(start.start, start.end) | ||
elif isinstance(start, datetime): | ||
# This one must come first, | ||
# because inheritance order is datetime < date < pdt.date. | ||
This comment has been minimized.
Sorry, something went wrong. |
||
pass | ||
elif isinstance(start, hday): | ||
# Idem, beware of the inheritance order; | ||
# hday < date < pdt.date. | ||
day = start | ||
start = day.start | ||
if end is None: | ||
end = day.end | ||
elif isinstance(start, pdt.date): | ||
# transition from legacy | ||
start = hday.from_pdt(start).start | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
mwilck
Contributor
|
||
if isinstance(end, datetime): | ||
# same as above | ||
pass | ||
elif isinstance(end, hday): | ||
end = end.end | ||
elif isinstance(end, pdt.date): | ||
# transition from legacy | ||
end = hday.from_pdt(end).end | ||
|
||
return cls(start, end) | ||
|
||
@classmethod | ||
def today(cls): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Nit wrt the comment: AFAICS,
datetime
inherits onlypdt.datetime
, notdate
.