Skip to content
Snippets Groups Projects
Commit c00cfcc3 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch 'feature/support-date-for-period-time-start-end' into 'master'

Support also dates for TimePeriod's methods get_datetime_start/_end

See merge request AlekSIS/official/AlekSIS-App-Chronos!197
parents dc8f32f2 6e733cf6
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,11 @@ and this project adheres to `Semantic Versioning`_.
Unreleased
----------
Changed
~~~~~~~
* Support dates for ``TimePeriod.get_datetime_start`` and ``TimePeriod.get_datetime_end``.
Fixed
~~~~~
......
......@@ -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