2019-03-27 18:26:45 +01:00
|
|
|
from settings import hours, language
|
2019-04-05 22:07:33 +02:00
|
|
|
from datetime import timedelta, datetime, timezone
|
2019-05-06 11:05:10 +02:00
|
|
|
from DictionaryMapper import get_text
|
|
|
|
from Dictionary import multiday_events, allday_events
|
2019-03-26 22:30:19 +01:00
|
|
|
|
|
|
|
first_occurrence_char = '['
|
|
|
|
middle_occurrence_char = '|'
|
|
|
|
last_occurrence_char = ']'
|
2019-04-05 22:23:01 +02:00
|
|
|
multiday_begin_character = ' >'
|
|
|
|
multiday_end_character = '< '
|
2019-04-05 22:24:09 +02:00
|
|
|
until_character = ' - '
|
2019-04-05 22:23:01 +02:00
|
|
|
allday_character = "•"
|
2019-04-07 12:54:34 +02:00
|
|
|
multiday_character = allday_character + allday_character
|
2019-03-26 22:30:19 +01:00
|
|
|
|
|
|
|
def time_str (dt):
|
|
|
|
if hours is "12":
|
2019-03-27 18:26:45 +01:00
|
|
|
return dt.strftime("%I:%M%p")
|
2019-03-26 22:30:19 +01:00
|
|
|
elif hours is "24":
|
|
|
|
return dt.strftime("%H:%M")
|
|
|
|
else:
|
|
|
|
return str(dt)
|
|
|
|
|
2019-04-05 22:23:01 +02:00
|
|
|
def event_prefix_str_md_dif (event, relative_date=None):
|
2019-03-26 22:30:19 +01:00
|
|
|
if relative_date is None:
|
|
|
|
relative_date = event.begin_datetime.date()
|
|
|
|
|
2019-04-08 15:29:09 +02:00
|
|
|
if event.multiday is False:
|
2019-03-26 22:30:19 +01:00
|
|
|
return event_time_summary(event)
|
|
|
|
|
|
|
|
#Relative to
|
|
|
|
#First day
|
2019-04-05 22:07:33 +02:00
|
|
|
elif __equal__(event.begin_datetime, relative_date):
|
2019-04-05 22:23:01 +02:00
|
|
|
return event_time_summary(event) + multiday_begin_character
|
2019-03-26 22:30:19 +01:00
|
|
|
|
|
|
|
#Last day
|
2019-04-05 22:07:33 +02:00
|
|
|
elif __equal__(event.end_datetime, relative_date) or \
|
|
|
|
(__day_duration__(event.end_datetime) == timedelta(0) and __equal__(relative_date + timedelta(1), event.end_datetime)):
|
2019-04-05 22:23:01 +02:00
|
|
|
return multiday_end_character + event_time_summary(event)
|
2019-03-26 22:30:19 +01:00
|
|
|
|
|
|
|
#Some day
|
|
|
|
else:
|
|
|
|
event.allday = True
|
2019-04-05 22:23:01 +02:00
|
|
|
return multiday_end_character + event_time_summary(event) + multiday_begin_character
|
|
|
|
|
|
|
|
def event_prefix_str (event, relative_date=None):
|
|
|
|
if relative_date is None:
|
|
|
|
relative_date = event.begin_datetime.date()
|
|
|
|
|
2019-04-08 15:29:09 +02:00
|
|
|
if event.multiday:
|
2019-05-06 11:05:10 +02:00
|
|
|
return get_text(multiday_events)
|
2019-04-05 22:23:01 +02:00
|
|
|
else:
|
2019-04-05 22:24:09 +02:00
|
|
|
return event_time_detailed(event)
|
2019-03-26 22:30:19 +01:00
|
|
|
|
2019-04-07 12:54:34 +02:00
|
|
|
def event_prefix_str_sum (event, relative_date=None):
|
|
|
|
if relative_date is None:
|
|
|
|
relative_date = event.begin_datetime.date()
|
|
|
|
|
2019-04-08 15:29:09 +02:00
|
|
|
if event.multiday:
|
2019-04-07 12:54:34 +02:00
|
|
|
return multiday_character
|
|
|
|
else:
|
|
|
|
return event_time_summary(event)
|
|
|
|
|
2019-03-26 22:30:19 +01:00
|
|
|
def event_time_summary (event):
|
|
|
|
if event.allday:
|
2019-04-05 22:23:01 +02:00
|
|
|
return allday_character
|
2019-03-26 22:30:19 +01:00
|
|
|
else:
|
|
|
|
return time_str(event.begin_datetime)
|
|
|
|
|
2019-03-27 18:26:45 +01:00
|
|
|
def event_time_detailed (event):
|
|
|
|
if event.allday:
|
2019-05-06 11:05:10 +02:00
|
|
|
return get_text(allday_events)
|
2019-03-27 18:26:45 +01:00
|
|
|
else:
|
2019-04-05 22:07:33 +02:00
|
|
|
return time_str(event.begin_datetime) + until_character + time_str(event.end_datetime)
|
2019-03-27 18:26:45 +01:00
|
|
|
|
2019-03-26 22:30:19 +01:00
|
|
|
def date_str(dt):
|
2019-04-05 11:37:41 +02:00
|
|
|
return remove_leading_zero(dt.strftime('%d. %b'))
|
2019-03-26 22:30:19 +01:00
|
|
|
|
|
|
|
def remove_leading_zero (text):
|
|
|
|
while text[0] is '0':
|
|
|
|
text = text[1:]
|
2019-03-27 18:26:45 +01:00
|
|
|
return text
|
|
|
|
|
|
|
|
def date_summary_str(dt):
|
2019-04-05 22:23:01 +02:00
|
|
|
day = remove_leading_zero(dt.strftime("%d"))
|
|
|
|
if language is "en":
|
|
|
|
return dt.strftime('%a ' + day + '. %b')
|
|
|
|
elif language is "de":
|
|
|
|
return dt.strftime(day + '. %b., %a')
|
|
|
|
else:
|
|
|
|
return dt.strftime('%a ' + day + '. %b')
|
2019-04-05 22:07:33 +02:00
|
|
|
|
|
|
|
def __equal__(dt1, dt2):
|
|
|
|
return dt1.day == dt2.day and \
|
|
|
|
dt1.month == dt2.month and \
|
|
|
|
dt1.year == dt2.year
|
|
|
|
|
|
|
|
def __day_duration__(dt):
|
|
|
|
day_begin = datetime(dt.year, dt.month, dt.day, 0, 0, 0, 0, timezone.utc)
|
|
|
|
return dt - day_begin
|