general refactoring

This commit is contained in:
Michał Kalinowski
2024-10-21 15:33:30 +02:00
parent b22adf75b0
commit 38f138d950
2 changed files with 83 additions and 98 deletions

View File

@@ -1,43 +1,23 @@
import datetime
#code of month branch
def get_days_of_month(previous_month=False):
today = datetime.date.today()
start_of_month = today.replace(day=1)
end_of_month = today.replace(day=28)+datetime.timedelta(days=4)
end_of_month -= datetime.timedelta(days=end_of_month.day)
def get_days_of_month(months_back=0):
# set the current day to the first day of the current month
# and loop for the days until the month changes
current_day = datetime.datetime.today().replace(day=1)
current_month = current_day.month
days = []
while months_back:
current_day = datetime.datetime.today().replace(day=1)
current_day -= datetime.timedelta(days=1)
current_day = current_day.replace(day=1)
current_month = current_day.month
months_back -= 1
while current_day.month == current_month:
days.append(str(current_day).split(' ')[0])
current_day += datetime.timedelta(days=1)
# minus one month
if previous_month == True:
start_of_month -= datetime.timedelta(days=1)
start_of_month = start_of_month.replace(day=1)
end_of_month = start_of_month
end_of_month = today.replace(day=28)+datetime.timedelta(days=4)
end_of_month -= datetime.timedelta(days=end_of_month.day)
days.append(str(start_of_month))
while start_of_month != end_of_month:
start_of_month += datetime.timedelta(days=1)
days.append(str(start_of_month))
# returns all days of current month
return days
def get_month_tickets(worklogs, days, previous_month=False):
this_month_tickets = []
for worklog in worklogs:
worklog_date = datetime.datetime.strptime(
worklog["date"].split('T')[0], '%Y-%m-%d').date()
current_month = datetime.date.today().month
# minus one month
if previous_month == True:
current_month -= 1
worklog_month = str(worklog_date).split('-')[1]
if str(worklog_date) in days and int(worklog_month) == current_month:
this_month_tickets.append(worklog)
return this_month_tickets
def get_month_view(worklogs):
@@ -50,7 +30,7 @@ def get_month_view(worklogs):
week_number_end = week_number_start+datetime.timedelta(days=6)
week_iso = week.isocalendar().week
omnimat_string = worklogs[0]["author"]
month_view = worklogs[0]["author"]
for worklog in worklogs:
ticket = worklog["ticket_id"]
@@ -59,13 +39,12 @@ def get_month_view(worklogs):
week_day = datetime.datetime.strptime(date, '%Y-%m-%d').date()
if (week_day.isocalendar().week == week_iso):
omnimat_string += "\nWeek " + str(week_iso)+"\tfrom "+week_number_start.__str__() + \
month_view += "\nWeek " + str(week_iso)+"\tfrom "+week_number_start.__str__() + \
"\tto "+week_number_end.__str__()+"\n\n"
week_iso += 1
week_number_start += datetime.timedelta(days=7)
week_number_end += datetime.timedelta(days=7)
omnimat_string += ticket+'\tdate '+date+'\ttime '+timespent + '\n'
month_view += ticket+'\tdate '+date+'\ttime '+timespent + '\n'
return omnimat_string
#end of code month branch
return month_view