Browse Source

Enhancement in CLI output & bugfix in time comparison

- Now the short_result_cli is used if no --group given
- Fixed the special case where a workday ends at midnight and night work
- Adds testcase for a workday ending at midnight and night work
Yann Weber 1 year ago
parent
commit
276140c29a
2 changed files with 33 additions and 1 deletions
  1. 5
    1
      git_oh.py
  2. 28
    0
      test.py

+ 5
- 1
git_oh.py View File

52
         return
52
         return
53
 
53
 
54
     if args.csv_output is None:
54
     if args.csv_output is None:
55
-        if args.group_by or args.details:
55
+        if args.group_by:
56
             print(result_cli(commit_stats, args.details))
56
             print(result_cli(commit_stats, args.details))
57
         else:
57
         else:
58
             print(short_result_cli(commit_stats))
58
             print(short_result_cli(commit_stats))
90
     if moment.weekday() in weekend:
90
     if moment.weekday() in weekend:
91
         return False
91
         return False
92
     localtime = moment.time()
92
     localtime = moment.time()
93
+    if stophour == datetime.time(0,0):
94
+        return starthour <= localtime
95
+    if stophour < starthour:
96
+        return localtime >= starthour or localtime <= stophour
93
     return starthour <= localtime <= stophour
97
     return starthour <= localtime <= stophour
94
 
98
 
95
 
99
 

+ 28
- 0
test.py View File

193
             self.assertTrue(git_oh.in_office_hours(moment,
193
             self.assertTrue(git_oh.in_office_hours(moment,
194
                 starthour, stophour, weekend=weekend))
194
                 starthour, stophour, weekend=weekend))
195
 
195
 
196
+    def test_office_hours_midnight(self):
197
+        """ Test in_office_hours special case for daystop at midnight """
198
+        starthour = datetime.time(12,0)
199
+        stophour = datetime.time(0,0)
200
+
201
+        moment = datetime.datetime.fromisoformat("2023-11-01T09:00+0200")
202
+        self.assertFalse(git_oh.in_office_hours(moment, starthour, stophour))
203
+
204
+        moment = datetime.datetime.fromisoformat("2023-11-01T13:00+0200")
205
+        self.assertTrue(git_oh.in_office_hours(moment, starthour, stophour))
206
+
207
+    def test_office_hours_nightwork(self):
208
+        """ Testing in_office_hours when daystop < daystart """
209
+        starthour = datetime.time(20,0)
210
+        stophour = datetime.time(8,0)
211
+
212
+        moment = datetime.datetime.fromisoformat("2023-11-01T00:00+0200")
213
+        self.assertTrue(git_oh.in_office_hours(moment, starthour, stophour))
214
+
215
+        moment = datetime.datetime.fromisoformat("2023-11-01T05:00+0200")
216
+        self.assertTrue(git_oh.in_office_hours(moment, starthour, stophour))
217
+
218
+        moment = datetime.datetime.fromisoformat("2023-11-01T23:00+0200")
219
+        self.assertTrue(git_oh.in_office_hours(moment, starthour, stophour))
220
+
221
+        moment = datetime.datetime.fromisoformat("2023-11-01T12:00+0200")
222
+        self.assertFalse(git_oh.in_office_hours(moment, starthour, stophour))
223
+
196
     def test_office_hours_tz_drop(self):
224
     def test_office_hours_tz_drop(self):
197
         """ Checks that in_office_hours do not use tzinfo to compare
225
         """ Checks that in_office_hours do not use tzinfo to compare
198
             moment with start & stop hours
226
             moment with start & stop hours

Loading…
Cancel
Save