forked from Kartones/flask-calendar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgregorian_calendar.py
43 lines (35 loc) · 1.46 KB
/
gregorian_calendar.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
from calendar import Calendar, monthrange
from datetime import date, datetime, timedelta
from typing import Iterable, List, Tuple
class GregorianCalendar:
MONTH_NAMES = ["January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"]
@staticmethod
def previous_month_and_year(year: int, month: int) -> Tuple[int, int]:
previous_month_date = date(year, month, 1) - timedelta(days=2)
return previous_month_date.month, previous_month_date.year
@staticmethod
def next_month_and_year(year: int, month: int) -> Tuple[int, int]:
last_day_of_month = monthrange(year, month)[1]
next_month_date = date(year, month, last_day_of_month) + timedelta(days=2)
return next_month_date.month, next_month_date.year
@staticmethod
def current_date() -> Tuple[int, int, int]:
today_date = datetime.date(datetime.now())
return today_date.day, today_date.month, today_date.year
@staticmethod
def month_days(year: int, month: int) -> Iterable[date]:
return Calendar().itermonthdates(year, month)
@staticmethod
def month_days_with_weekday(year: int, month: int) -> List[List[int]]:
return Calendar().monthdayscalendar(year, month)