From b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 4 Apr 2023 16:18:33 +0200 Subject: ... --- flake.lock | 21 ++++----------------- flake.nix | 2 +- overlays/worktime/worktime/__main__.py | 32 ++++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/flake.lock b/flake.lock index d6a01a8f..97488fa3 100644 --- a/flake.lock +++ b/flake.lock @@ -25,7 +25,6 @@ }, "ca-util": { "inputs": { - "leapseconds": "leapseconds", "mach-nix": [ "mach-nix" ], @@ -37,16 +36,16 @@ ] }, "locked": { - "lastModified": 1680595497, - "narHash": "sha256-JequPwdfjSFlX4XY5hz5CZ0KVPFJ99c85eacSyZ3VpU=", + "lastModified": 1680609133, + "narHash": "sha256-1XpMskoVuRaQ0m+sezbsLXyrZjRNWNZTFbZyRN5R90w=", "owner": "gkleen", "repo": "ca", - "rev": "0634fa9f9a0e01e26d860ad02324c1afbd3a6c1f", + "rev": "2fec64bb3e069eb97ab7569c4e2e8cd761452f34", "type": "gitlab" }, "original": { "owner": "gkleen", - "ref": "v2.0.2", + "ref": "v2.0.3", "repo": "ca", "type": "gitlab" } @@ -222,18 +221,6 @@ "type": "github" } }, - "leapseconds": { - "flake": false, - "locked": { - "narHash": "sha256-Me9RN6L5jCnhL17bl4I77dRbG5r7/1n/BCUBDSt1R4A=", - "type": "file", - "url": "https://www.ietf.org/timezones/data/leap-seconds.list" - }, - "original": { - "type": "file", - "url": "https://www.ietf.org/timezones/data/leap-seconds.list" - } - }, "mach-nix": { "inputs": { "flake-utils": [ diff --git a/flake.nix b/flake.nix index 29d98950..35934c64 100644 --- a/flake.nix +++ b/flake.nix @@ -111,7 +111,7 @@ type = "gitlab"; owner = "gkleen"; repo = "ca"; - ref = "v2.0.2"; + ref = "v2.0.3"; inputs = { nixpkgs.follows = "nixpkgs"; mach-nix.follows = "mach-nix"; diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index fa357d09..c91d73aa 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py @@ -424,6 +424,26 @@ class Worktime(object): self.time_worked += api.get_billable_hours(self.start_date, self.now, rounding = config.get("WORKTIME", {}).get("rounding", True)) +def format_days(worktime, days, date_format=None): + if not date_format: + config = Worktime.config() + date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d') + + groups = list(map(lambda kv: list(kv[1]), groupby( + map( + lambda kv: list(map(lambda t: t[1], kv[1])), + groupby(enumerate(days), lambda kv: kv[0] - worktime.ordinal_workday(kv[1])) + ), + lambda days: frozenset(map(lambda day: (day.isocalendar().year, day.isocalendar().week), days)) + ))) + def format_group(group): + if len(group) > 1: + return group[0].strftime(date_format) + '--' + group[-1].strftime(date_format) + else: + return group[0].strftime(date_format) + return ', '.join(map(lambda group: ','.join(map(format_group, group)), groups)) + + def worktime(**args): worktime = Worktime(**args) @@ -597,14 +617,7 @@ def leave(year, table, **args): for year, offset in leave_budget.items(): leave_days = sorted([day for day in worktime.leave_days if day.year == year]) would_be_workdays = [day for day in days if day.year == year and worktime.would_be_workday(day)] - groups = [] - for _, group in groupby(enumerate(leave_days), lambda kv: kv[0] - worktime.ordinal_workday(kv[1])): - group = list(map(lambda kv: kv[1], group)) - if len(group) > 1: - groups.append(group[0].strftime('%m-%d') + '--' + group[-1].strftime('%m-%d')) - else: - groups.append(group[0].strftime('%m-%d')) - table_data += [[year, offset, f"{len(leave_days)}/{len(list(would_be_workdays))}", ','.join(groups)]] + table_data += [[year, offset, f"{len(leave_days)}/{len(list(would_be_workdays))}", format_days(worktime, leave_days, date_format='%m-%d')]] print(tabulate(table_data, tablefmt="plain")) else: print(leave_budget[year if year else def_year]) @@ -690,8 +703,7 @@ def classification(classification_name, table, **args): else: row_data.append(f"{len(classified)}/{len(year_classification[year])}") - groups = map(lambda kv: kv[1], groupby(classified, lambda v: (v.isocalendar().year, v.isocalendar().week))) - row_data.append(', '.join(map(lambda group: ','.join(map(lambda day: day.strftime('%m-%d'), sorted(group))), groups))) + row_data.append(format_days(worktime, classified, date_format='%m-%d')) table_data.append(row_data) print(tabulate(table_data, tablefmt="plain")) -- cgit v1.2.3