Skip to content
Snippets Groups Projects
Verified Commit 04b1a0fa authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Support also dates for TimePeriod's methods get_datetime_start/_end

parent 20a4e32e
No related branches found
No related tags found
1 merge request!197Support also dates for TimePeriod's methods get_datetime_start/_end
Pipeline #33201 passed with warnings
......@@ -6,6 +6,14 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog`_,
and this project adheres to `Semantic Versioning`_.
Unreleased
----------
Changed
~~~~~~~
* Support dates for ``TimePeriod.get_datetime_start`` and ``TimePeriod.get_datetime_end``.
`2.0rc2`_ - 2021-08-01
----------
......
......@@ -161,14 +161,24 @@ class TimePeriod(ValidityRangeRelatedExtensibleModel):
return wanted_week[self.weekday]
def get_datetime_start(self, week: Optional[Union[CalendarWeek, int]] = None) -> datetime:
def get_datetime_start(
self, date_ref: Optional[Union[CalendarWeek, int, date]] = None
) -> datetime:
"""Get datetime of lesson start in a specific week."""
day = self.get_date(week)
if isinstance(date_ref, date):
day = date_ref
else:
day = self.get_date(date_ref)
return datetime.combine(day, self.time_start)
def get_datetime_end(self, week: Optional[Union[CalendarWeek, int]] = None) -> datetime:
def get_datetime_end(
self, date_ref: Optional[Union[CalendarWeek, int, date]] = None
) -> datetime:
"""Get datetime of lesson end in a specific week."""
day = self.get_date(week)
if isinstance(date_ref, date):
day = date_ref
else:
day = self.get_date(date_ref)
return datetime.combine(day, self.time_end)
@classmethod
......
......@@ -36,13 +36,13 @@ def period_to_date(week: CalendarWeek, period) -> date:
@register.simple_tag
def period_to_time_start(week: CalendarWeek, period) -> date:
return period.get_datetime_start(week)
def period_to_time_start(date_ref: Union[CalendarWeek, int, date], period) -> date:
return period.get_datetime_start(date_ref)
@register.simple_tag
def period_to_time_end(week: Union[CalendarWeek, int], period) -> date:
return period.get_datetime_end(week)
def period_to_time_end(date_ref: Union[CalendarWeek, int, date], period) -> date:
return period.get_datetime_end(date_ref)
@register.simple_tag
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment