This repository was archived by the owner on Apr 9, 2020. It is now read-only.
forked from erlend-axelsson/timerapport
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate_utility.py
More file actions
33 lines (26 loc) · 1.26 KB
/
date_utility.py
File metadata and controls
33 lines (26 loc) · 1.26 KB
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
import datetime
import calendar
from datetime import date, datetime, timedelta
def generate_week_number(d=date.today().day, m=date.today().month, y=date.today().year):
return "{0:0>2}".format(date(y,m,d).isocalendar()[1])
def generate_weeks(m=date.today().month, y=date.today().year):
weeks = []
for week in calendar.monthcalendar(y, m):
week_days = list(filter(lambda x: x > 0, week))
weeks.append(week_days)
return weeks
def week_range(m=date.today().month, y=date.today().year):
week_values = []
for week in generate_weeks(m,y):
week_number = generate_week_number(week[0],m,y)
date_range = "{0:0>2}/{2:0>2} - {1:0>2}/{2:0>2} - {3:0>4}".format(week[0],week[-1], m, y)
week_values.append((week_number , date_range, "0"))
return week_values
def today():
return [date.today().day, date.today().month, date.today().year]
def last_day(m=date.today().month, y=date.today().year):
return "{}".format(generate_weeks(m,y)[-1][-1])
def last_date(m=date.today().month, y=date.today().year):
return "{0:0>2}/{1:0>2} - {2:0>4}".format(last_day(m,y),m,y)
def month_range(m=date.today().month, y=date.today().year):
return "{0:0>2}/{2:0>2} - {1:0>2}/{2:0>2} - {3:0>4}".format(1,last_day(m,y), m, y)