forked from gergely/calendar-social
Create a basic month view
This commit is contained in:
15
app/calendar_system/__init__.py
Normal file
15
app/calendar_system/__init__.py
Normal 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()
|
48
app/calendar_system/gregorian.py
Normal file
48
app/calendar_system/gregorian.py
Normal 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
|
Reference in New Issue
Block a user