-
Notifications
You must be signed in to change notification settings - Fork 0
/
listDate.py
38 lines (33 loc) · 1013 Bytes
/
listDate.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
#!/usr/bin/python3
import calendar
from datetime import datetime
def dates(startYear, endYear, startMonth, endMonth):
year = startYear
month = startMonth
while(year < endYear or (year == endYear and month < endMonth)):
days = calendar.monthrange(year, month)[1]
for day in range(1, days + 1):
weekDay = datetime(year, month, day).weekday() + 1
a = str(year)
b = str(month)
if len(b) == 1:
b = '0' + b
c = str(day)
if len(c) == 1:
c = '0' + c
yield (a, b, c, str(weekDay))
month += 1
if month > 12:
month = 1
year += 1
def beforeDate(year, month, day):
year = int(year)
month = int(month)
day = int(day)
if day > 1:
return (year, month, day - 1)
if month > 1:
day = calendar.monthrange(year, month - 1)[1]
month -= 1
return (year, month, day)
return (year - 1, 12, 31)