Create a basic month view

This commit is contained in:
2018-06-25 09:01:13 +02:00
parent 448ae1bce0
commit 6c4eb97c01
5 changed files with 153 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
class CalendarSystem:
__has_months__ = False
__has_weeks__ = False
@property
def day_names(self):
raise NotImplementedError()
@property
def month(self):
raise NotImplementedError()
@property
def days(self):
raise NotImplementedError()

View File

@@ -0,0 +1,48 @@
from datetime import datetime, timedelta
from flask_babel import lazy_gettext as _
from . import CalendarSystem
class GregorianCalendar(CalendarSystem):
__name__ = _('Gregorian')
__has_months__ = True
START_DAY = 0
END_DAY = 7
day_names = (
_('Monday'),
_('Tuesday'),
_('Wednesday'),
_('Thursday'),
_('Friday'),
_('Saturday'),
_('Sunday'),
)
def __init__(self, timestamp):
self.timestamp = datetime.utcfromtimestamp(timestamp)
@property
def month(self):
return self.timestamp.strftime("%B, %Y")
@property
def days(self):
day_list = []
start_day = self.timestamp.replace(day=1)
while start_day.weekday() > self.START_DAY:
start_day -= timedelta(days=1)
day_list.append(start_day)
current_day = start_day
while current_day.weekday() < self.END_DAY and current_day.month <= self.timestamp.month:
current_day += timedelta(days=1)
day_list.append(current_day)
return day_list