mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Support to show the schedule for a requested day AFTER holidays
This commit is contained in:
parent
ee3ee5284d
commit
54d31c943a
6 changed files with 211 additions and 55 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from datetime import datetime, timedelta
|
||||
from timeFormatters import dateTimeNow, weekdayToInt
|
||||
from functions.timeFormatters import dateTimeNow, weekdayToInt, forward_to_weekday, skip_weekends
|
||||
from typing import Optional
|
||||
|
||||
|
||||
|
|
@ -28,31 +28,3 @@ def find_target_date(arg: Optional[str]) -> datetime:
|
|||
day = skip_weekends(day)
|
||||
|
||||
return day
|
||||
|
||||
|
||||
def skip_weekends(day: datetime) -> datetime:
|
||||
"""
|
||||
Increment the current date if it's not a weekday
|
||||
"""
|
||||
weekday = day.weekday()
|
||||
|
||||
# Friday is weekday 4
|
||||
if weekday > 4:
|
||||
return day + timedelta(days=(7 - weekday))
|
||||
|
||||
return day
|
||||
|
||||
|
||||
def forward_to_weekday(day: datetime, weekday: int) -> datetime:
|
||||
"""
|
||||
Increment a date until the weekday is the same as the one provided
|
||||
Finds the "next" [weekday]
|
||||
"""
|
||||
current = day.weekday()
|
||||
|
||||
# This avoids negative numbers below, and shows
|
||||
# next week in case the days are the same
|
||||
if weekday >= current:
|
||||
weekday += 7
|
||||
|
||||
return day + timedelta(days=(weekday - current))
|
||||
|
|
|
|||
|
|
@ -138,13 +138,15 @@ def getPlural(amount, unit):
|
|||
return dic[unit.lower()]["s" if amount == 1 else "p"]
|
||||
|
||||
|
||||
def weekdayToInt(day) -> int:
|
||||
def weekdayToInt(day: str) -> int:
|
||||
days = {"maandag": 0, "dinsdag": 1, "woensdag": 2, "donderdag": 3, "vrijdag": 4, "zaterdag": 5, "zondag": 6}
|
||||
|
||||
if day.lower() not in days:
|
||||
return -1
|
||||
# Allow abbreviations
|
||||
for d, i in days.items():
|
||||
if d.startswith(day):
|
||||
return i
|
||||
|
||||
return days[day.lower()]
|
||||
return -1
|
||||
|
||||
|
||||
def intToWeekday(day):
|
||||
|
|
@ -164,3 +166,31 @@ def fromArray(data: List[int]) -> datetime:
|
|||
year = str(data[2])
|
||||
|
||||
return fromString(f"{day}/{month}/{year}")
|
||||
|
||||
|
||||
def skip_weekends(day: datetime) -> datetime:
|
||||
"""
|
||||
Increment the current date if it's not a weekday
|
||||
"""
|
||||
weekday = day.weekday()
|
||||
|
||||
# Friday is weekday 4
|
||||
if weekday > 4:
|
||||
return day + datetime.timedelta(days=(7 - weekday))
|
||||
|
||||
return day
|
||||
|
||||
|
||||
def forward_to_weekday(day: datetime, weekday: int) -> datetime:
|
||||
"""
|
||||
Increment a date until the weekday is the same as the one provided
|
||||
Finds the "next" [weekday]
|
||||
"""
|
||||
current = day.weekday()
|
||||
|
||||
# This avoids negative numbers below, and shows
|
||||
# next week in case the days are the same
|
||||
if weekday <= current:
|
||||
weekday += 7
|
||||
|
||||
return day + datetime.timedelta(days=(weekday - current))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue