49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
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
|