-
Notifications
You must be signed in to change notification settings - Fork 0
/
cal.py
52 lines (47 loc) · 1.41 KB
/
cal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from django.utils import timezone
import calendar
class Day:
def __init__(self, number, past, month, year):
self.number = number
self.past = past
self.month = month
self.year = year
def __str__(self):
return str(self.number)
class Calendar(calendar.Calendar):
def __init__(self, year, month):
super().__init__(firstweekday=6)
self.year = year
self.month = month
self.day_names = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
self.months = (
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
)
def get_days(self):
weeks = self.monthdays2calendar(self.year, self.month)
days = []
for week in weeks:
for day, _ in week:
now = timezone.now()
today = now.day
month = now.month
past = False
if month == self.month:
if day <= today:
past = True
new_day = Day(number=day, past=past, month=self.month, year=self.year)
days.append(new_day)
return days
def get_month(self):
return self.months[self.month - 1]