I am using datetime
I have a list of users timesheets, which are selected for the week (Sunday through until Saturday)
timesheet_entries = [entry for entry in timesheet_entries if within_dates(datetime.datetime.strptime(entry["work_performed_on"], "%Y-%m-%d").date())]
I need to retrieve the time that has been submitted for each entry each day (there can be more than one entry per day). entry["work"] returns the amount of time the member has spent for that entry.
Any ideas? I’m not exactly looking for a code answer here but more of the logic of doing it.
For example I could ask for each days entries like monday = [entry for entry in timesheet_entries if within_dates (monday etc)] And then loop through caclulating the time and doing the same for each day.
Its not clear how you want to go through the results. Assuming you want a tally of the total number of hours (time) worked on each day of the week, try this approach.
Since the days of the week are fixed, simply loop through the days of the week. For each day, filter the entries for that day and then collect the time(s). You could use a
defaultdictwith the key being the week day and each entry being a list of all the times of that day.Assuming here
within_datestakes a day number.Now, to get the totals: