diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2025-08-20 12:22:43 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2025-08-20 12:22:43 +0200 |
commit | 6f5dadf4c1c36d7ff26f1d1533d08399ccee79bf (patch) | |
tree | 9ce5c10a944890925261579dadc9e9ca7de2545e /overlays/worktime | |
parent | 1220da3f4e70f5cc6760536afb3059364c52f6a1 (diff) | |
download | nixos-6f5dadf4c1c36d7ff26f1d1533d08399ccee79bf.tar nixos-6f5dadf4c1c36d7ff26f1d1533d08399ccee79bf.tar.gz nixos-6f5dadf4c1c36d7ff26f1d1533d08399ccee79bf.tar.bz2 nixos-6f5dadf4c1c36d7ff26f1d1533d08399ccee79bf.tar.xz nixos-6f5dadf4c1c36d7ff26f1d1533d08399ccee79bf.zip |
...
Diffstat (limited to 'overlays/worktime')
-rwxr-xr-x | overlays/worktime/worktime/__main__.py | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index bf24bbec..6ce1331a 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py | |||
@@ -393,9 +393,29 @@ class Worktime(object): | |||
393 | start_day = self.start_date.date() | 393 | start_day = self.start_date.date() |
394 | end_day = self.end_date.date() | 394 | end_day = self.end_date.date() |
395 | 395 | ||
396 | self.extra_days_to_work = dict() | ||
397 | |||
396 | try: | 398 | try: |
397 | with open(Path(config_dir) / "pull-forward", 'r') as excused: | 399 | with open(Path(config_dir) / "days-to-work", 'r') as extra_days_to_work_file: |
398 | for line in excused: | 400 | for line in extra_days_to_work_file: |
401 | stripped_line = line.strip() | ||
402 | if stripped_line: | ||
403 | splitLine = stripped_line.split(' ') | ||
404 | if len(splitLine) == 2: | ||
405 | [hours, datestr] = splitLine | ||
406 | day = datetime.strptime(datestr, date_format).replace(tzinfo=tzlocal()).date() | ||
407 | self.extra_days_to_work[day] = timedelta(hours = float(hours)) | ||
408 | else: | ||
409 | day = datetime.strptime(stripped_line, date_format).replace(tzinfo=tzlocal()).date() | ||
410 | self.extra_days_to_work[day] = self.time_per_day(day) | ||
411 | except IOError as e: | ||
412 | if e.errno != 2: | ||
413 | raise e | ||
414 | |||
415 | |||
416 | try: | ||
417 | with open(Path(config_dir) / "pull-forward", 'r') as pull_forward: | ||
418 | for line in pull_forward: | ||
399 | stripped_line = line.strip() | 419 | stripped_line = line.strip() |
400 | if stripped_line: | 420 | if stripped_line: |
401 | [hours, datestr] = stripped_line.split(' ') | 421 | [hours, datestr] = stripped_line.split(' ') |
@@ -416,15 +436,18 @@ class Worktime(object): | |||
416 | if not d == datetime.strptime(c, date_format).replace(tzinfo=tzlocal()).date(): break | 436 | if not d == datetime.strptime(c, date_format).replace(tzinfo=tzlocal()).date(): break |
417 | else: | 437 | else: |
418 | if d >= self.end_date.date(): | 438 | if d >= self.end_date.date(): |
419 | self.pull_forward[d] = min(timedelta(hours = float(hours)), self.time_per_day(d) - (holidays[d] if d in holidays else timedelta())) | 439 | time_for_day = self.time_per_day(d) if d.isoweekday() in self.workdays else timedelta() |
440 | if d in self.extra_days_to_work: | ||
441 | time_for_day += self.extra_days_to_work[d] | ||
442 | self.pull_forward[d] = min(timedelta(hours = float(hours)), time_for_day) | ||
420 | except IOError as e: | 443 | except IOError as e: |
421 | if e.errno != 2: | 444 | if e.errno != 2: |
422 | raise e | 445 | raise e |
423 | 446 | ||
424 | self.days_to_work = dict() | 447 | self.days_to_work = dict() |
425 | 448 | ||
426 | if self.pull_forward: | 449 | # if self.pull_forward: |
427 | end_day = max(end_day, max(list(self.pull_forward))) | 450 | # end_day = max(end_day, max(self.pull_forward.keys())) |
428 | 451 | ||
429 | for day in [start_day + timedelta(days = x) for x in range(0, (end_day - start_day).days + 1)]: | 452 | for day in [start_day + timedelta(days = x) for x in range(0, (end_day - start_day).days + 1)]: |
430 | if day.isoweekday() in self.workdays: | 453 | if day.isoweekday() in self.workdays: |
@@ -432,26 +455,6 @@ class Worktime(object): | |||
432 | if time_to_work > timedelta(): | 455 | if time_to_work > timedelta(): |
433 | self.days_to_work[day] = time_to_work | 456 | self.days_to_work[day] = time_to_work |
434 | 457 | ||
435 | self.extra_days_to_work = dict() | ||
436 | |||
437 | try: | ||
438 | with open(Path(config_dir) / "days-to-work", 'r') as extra_days_to_work_file: | ||
439 | for line in extra_days_to_work_file: | ||
440 | stripped_line = line.strip() | ||
441 | if stripped_line: | ||
442 | splitLine = stripped_line.split(' ') | ||
443 | if len(splitLine) == 2: | ||
444 | [hours, datestr] = splitLine | ||
445 | day = datetime.strptime(datestr, date_format).replace(tzinfo=tzlocal()).date() | ||
446 | self.extra_days_to_work[day] = timedelta(hours = float(hours)) | ||
447 | else: | ||
448 | day = datetime.strptime(stripped_line, date_format).replace(tzinfo=tzlocal()).date() | ||
449 | self.extra_days_to_work[day] = self.time_per_day(day) | ||
450 | except IOError as e: | ||
451 | if e.errno != 2: | ||
452 | raise e | ||
453 | |||
454 | |||
455 | self.now_is_workday = self.is_workday(self.now.date()) | 458 | self.now_is_workday = self.is_workday(self.now.date()) |
456 | 459 | ||
457 | self.time_worked = timedelta() | 460 | self.time_worked = timedelta() |
@@ -467,7 +470,7 @@ class Worktime(object): | |||
467 | 470 | ||
468 | self.time_to_work = sum([self.days_to_work[day] for day in self.days_to_work.keys() if day <= self.end_date.date()], timedelta()) | 471 | self.time_to_work = sum([self.days_to_work[day] for day in self.days_to_work.keys() if day <= self.end_date.date()], timedelta()) |
469 | for day in [d for d in list(self.pull_forward) if d > self.end_date.date()]: | 472 | for day in [d for d in list(self.pull_forward) if d > self.end_date.date()]: |
470 | days_forward = set([d for d in self.days_to_work.keys() if d >= self.end_date.date() and d < day and (not d in self.pull_forward or d == self.end_date.date())]) | 473 | days_forward = set([d for d in [start_day + timedelta(days = x) for x in range(0, (max(end_day, max(self.pull_forward.keys())) - start_day).days + 1)] if d >= self.end_date.date() and d < day and (not d in self.pull_forward or d == self.end_date.date())]) |
471 | extra_days_forward = set([d for d in self.extra_days_to_work.keys() if d >= self.end_date.date() and d < day and (not d in self.pull_forward or d == self.end_date.date())]) | 474 | extra_days_forward = set([d for d in self.extra_days_to_work.keys() if d >= self.end_date.date() and d < day and (not d in self.pull_forward or d == self.end_date.date())]) |
472 | days_forward = days_forward.union(extra_days_forward) | 475 | days_forward = days_forward.union(extra_days_forward) |
473 | 476 | ||
@@ -483,7 +486,7 @@ class Worktime(object): | |||
483 | self.extra_days_to_work[extra_day] += extra_day_time * (day_time / extra_day_time_left) | 486 | self.extra_days_to_work[extra_day] += extra_day_time * (day_time / extra_day_time_left) |
484 | 487 | ||
485 | hours_per_day_forward = time_forward / len(days_forward) if len(days_forward) > 0 else timedelta() | 488 | hours_per_day_forward = time_forward / len(days_forward) if len(days_forward) > 0 else timedelta() |
486 | days_forward.discard(self.end_date.date()) | 489 | # days_forward.discard(self.end_date.date()) |
487 | 490 | ||
488 | self.time_pulled_forward += time_forward - hours_per_day_forward * len(days_forward) | 491 | self.time_pulled_forward += time_forward - hours_per_day_forward * len(days_forward) |
489 | 492 | ||