DateHelper fix
This commit is contained in:
parent
7902a6fbeb
commit
a59a496bb5
@ -1,4 +1,6 @@
|
|||||||
from datetime import date, datetime, timedelta, time
|
from datetime import date, datetime, timedelta, time
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
# Monday - 0
|
# Monday - 0
|
||||||
# Tuesday - 1
|
# Tuesday - 1
|
||||||
@ -30,6 +32,8 @@ def convert_UTC_to_timestamp(date):
|
|||||||
|
|
||||||
|
|
||||||
def get_day_of_week_number(day):
|
def get_day_of_week_number(day):
|
||||||
|
if day == 'dziś' or day == 'dzisiaj':
|
||||||
|
return get_current_day_of_week()
|
||||||
if day == 'poniedziałek':
|
if day == 'poniedziałek':
|
||||||
return 0
|
return 0
|
||||||
elif day == 'wtorek':
|
elif day == 'wtorek':
|
||||||
@ -72,8 +76,33 @@ def get_datetime_from_day(day, hours, minutes):
|
|||||||
date = get_current_date() + timedelta(days=(7 - abs(current_day_of_week-input_date_of_week)))
|
date = get_current_date() + timedelta(days=(7 - abs(current_day_of_week-input_date_of_week)))
|
||||||
return datetime.combine(date, input_time)
|
return datetime.combine(date, input_time)
|
||||||
|
|
||||||
# print(get_current_datetime('niedziela', 22, 21))
|
|
||||||
print(get_datetime_from_day('niedziela', 22, 21))
|
def get_date(date, time):
|
||||||
print(get_datetime_from_day('niedziela', 18, 21))
|
# parsowanie czasu
|
||||||
print(get_datetime_from_day('poniedziałek', 18, 21))
|
if re.match(r'^[0-2][0-9]$', time):
|
||||||
print(get_datetime_from_day('wtorek', 18, 21))
|
hours = int(time)
|
||||||
|
minutes = 00
|
||||||
|
elif re.match(r'^[0-2][0-9].[0-9][0-9]$', time):
|
||||||
|
m = re.search(r'^([0-2][0-9]).([0-9][0-9])$', time)
|
||||||
|
hours = int(m.group(1))
|
||||||
|
minutes = int(m.group(2))
|
||||||
|
|
||||||
|
|
||||||
|
# TODO jeżeli jeszcze jakieś dziwne formaty to obsłużyć przypadki
|
||||||
|
if re.match(r'^[0-3][0-9]\.[0-1][0-9]\.20[0-9]{2}$', date):
|
||||||
|
date = datetime.strptime(date, '%d.%m.%Y').date()
|
||||||
|
return datetime.combine(date, get_time_from_hours_minutes(hours, minutes))
|
||||||
|
else:
|
||||||
|
return get_datetime_from_day(date, hours, minutes)
|
||||||
|
|
||||||
|
|
||||||
|
# Tests
|
||||||
|
# print(get_datetime_from_day('niedziela', 22, 21))
|
||||||
|
# print(get_datetime_from_day('niedziela', 18, 21))
|
||||||
|
# print(get_datetime_from_day('poniedziałek', 18, 21))
|
||||||
|
# print(get_datetime_from_day('wtorek', 18, 21))
|
||||||
|
|
||||||
|
# print(get_date("07.06.2021", "12:00"))
|
||||||
|
# print(get_date("sobota", "00:00"))
|
||||||
|
# print(get_date("wtorek", "12:00"))
|
||||||
|
# print(get_date("12.06.2021", "23"))
|
||||||
|
Loading…
Reference in New Issue
Block a user