-
Notifications
You must be signed in to change notification settings - Fork 1
/
dateHandling.py
32 lines (25 loc) · 1.03 KB
/
dateHandling.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
from datetime import datetime, timezone, timedelta
def isNowInTimePeriod(startTime, endTime, nowTime):
if startTime < endTime:
return nowTime >= startTime and nowTime <= endTime
else:
#Over midnight:
return nowTime >= startTime or nowTime <= endTime
def dayText(event, today=datetime.now(timezone.utc)):
weekday = ['Mandag', 'Tirsdag', 'Onsdag', 'Torsdag', 'Fredag','Lørdag','Søndag']
text = ''
dt = datetime.fromisoformat(event['start'].get('dateTime', event['start'].get('date'))).replace(tzinfo=timezone.utc)
tomorrow = today + timedelta(1)
delta = dt - today
if dt.date() == today.date() :
text = text + 'I dag: '
elif dt.date() == tomorrow.date() :
text = text + 'I morgen: '
elif delta.days > 6:
text = text + weekday[dt.weekday()] + ' ' + dt.strftime('%d/%m') + ': '
else :
text = text + weekday[dt.weekday()] + ': '
text = text + event['summary']
if dt.hour > 0:
text = text + dt.strftime(' kl. %H:%M')
return text