Last active
January 4, 2019 09:52
-
-
Save StefanMich/3dd769b3b09b675e8919201f77abe7e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import datetime | |
| def break_duration(work_report): | |
| total = total_duration(work_report) | |
| if total is None: | |
| return None | |
| if None in (work_report.start_time, work_report.end_time): | |
| return 0.0 | |
| return total - float(work_report.amount) | |
| def total_duration(work_report): | |
| if work_report.work_type is None: return None | |
| # Due to an app bug, we have work reports with report_interval = False and | |
| # bogus start_time and end_time values. Exclude those (for now...) :-\ | |
| if None in (work_report.start_time, work_report.end_time): | |
| return float(work_report.amount) | |
| s = datetime.combine(work_report.start_date, work_report.start_time) | |
| e = datetime.combine(work_report.end_date, work_report.end_time) | |
| return (e - s).total_seconds() / 3600 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment