-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from stenjo/10-feat-vis-dato-for-hendelser-mer…
…-enn-1-uke-fram feat: vis dato for hendelser mer enn 1 uke fram
- Loading branch information
Showing
6 changed files
with
114 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__pycache__/* | ||
**/__pycache__/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import datetime | ||
|
||
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.datetime.today()): | ||
|
||
weekday = ['Mandag', 'Tirsdag', 'Onsdag', 'Torsdag', 'Fredag','Lørdag','Søndag'] | ||
text = '' | ||
dt = datetime.datetime.fromisoformat(event['start'].get('dateTime', event['start'].get('date'))) | ||
# today = datetime.datetime.today() | ||
tomorrow = today + datetime.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import datetime | ||
|
||
from dateHandling import dayText, isNowInTimePeriod | ||
|
||
def test_isNowInTimePeriod(): | ||
startTime = datetime.datetime.strptime("2023-10-22T10:12", "%Y-%m-%dT%H:%M") | ||
endTime = datetime.datetime.strptime("2023-10-25T10:12", "%Y-%m-%dT%H:%M") | ||
today = datetime.datetime.strptime("2023-10-23T10:12", "%Y-%m-%dT%H:%M") | ||
before = datetime.datetime.strptime("2023-10-22T10:11", "%Y-%m-%dT%H:%M") | ||
after = datetime.datetime.strptime("2023-10-25T10:13", "%Y-%m-%dT%H:%M") | ||
|
||
assert isNowInTimePeriod(startTime, endTime, today) == True | ||
assert isNowInTimePeriod(startTime, endTime, before) == False | ||
assert isNowInTimePeriod(startTime, endTime, after) == False | ||
|
||
|
||
today = datetime.datetime.strptime("2023-10-23T10:12", "%Y-%m-%dT%H:%M") | ||
|
||
def test_dayText_tomorrow(): | ||
event = { | ||
'start': { | ||
'date': '2023-10-24' | ||
}, | ||
'summary': 'Event summary' | ||
} | ||
|
||
assert dayText(event, today) == "I morgen: Event summary" | ||
|
||
def test_dayText_today(): | ||
event = { | ||
'start': { | ||
'date': '2023-10-23' | ||
}, | ||
'summary': 'Event summary' | ||
} | ||
|
||
assert dayText(event, today) == "I dag: Event summary" | ||
|
||
def test_dayText_today_with_time(): | ||
event = { | ||
'start': { | ||
'date': '2023-10-23', | ||
'dateTime': '2023-10-23T10:22:18' | ||
}, | ||
'summary': 'Event summary' | ||
} | ||
|
||
assert dayText(event, today) == "I dag: Event summary kl. 10:22" | ||
|
||
def test_dayText_friday(): | ||
event = { | ||
'start': { | ||
'date': '2023-10-27' | ||
}, | ||
'summary': 'Event summary' | ||
} | ||
|
||
assert dayText(event, today) == "Fredag: Event summary" | ||
|
||
def test_dayText_friday_plus_one_week(): | ||
event = { | ||
'start': { | ||
'date': '2023-11-03' | ||
}, | ||
'summary': 'Event summary' | ||
} | ||
|
||
assert dayText(event, today) == "Fredag 03/11: Event summary" | ||
|