From 1630ca5a6c87e824a0c5fefee0c6f185b935cec6 Mon Sep 17 00:00:00 2001 From: Maximilian Zettler Date: Fri, 21 Jan 2022 08:30:55 +0100 Subject: [PATCH] add timestamp override for smart-punch command --- timebot.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/timebot.py b/timebot.py index a17a9c4..f2c26d8 100644 --- a/timebot.py +++ b/timebot.py @@ -301,8 +301,9 @@ if __name__ == '__main__': help="use this command to auto punch in, punch out and create break " "entries; this command tries to detect your last action and will " "create entries in to following order: " - "punch_in(now) -> break_start(now) -> break_end(now) " - "-> punch_out(now)") + "punch_in -> break_start -> break_end -> punch_out") + parser_smart_punch.add_argument("-s", help=f"timestamp in format `{SIMPLE_DATETIME_FORMAT_HUMAN}` or `now`", + default="now") args = parser.parse_args() @@ -326,8 +327,11 @@ if __name__ == '__main__': )) getattr(tb, args.t)(punch_datetime) elif args.subparser_name == "smart-punch": - now = datetime.datetime.now() - last_punch = tb.get_entries(1, now.replace(hour=0, minute=0, second=0, microsecond=0)) + if args.s == "now": + punch_datetime = datetime.datetime.now() + else: + punch_datetime = datetime.datetime.strptime(args.s, SIMPLE_DATETIME_FORMAT) + last_punch = tb.get_entries(1, punch_datetime.replace(hour=0, minute=0, second=0, microsecond=0)) method = None if not last_punch: logger.debug("could not detect any time entry for today... punching in") @@ -350,10 +354,10 @@ if __name__ == '__main__': exit(1) logger.info("running `{}` with date `{}` and time `{}`".format( method, - now.strftime(SIMPLE_DATE_FORMAT), - now.strftime(SIMPLE_TIME_FORMAT), + punch_datetime.strftime(SIMPLE_DATE_FORMAT), + punch_datetime.strftime(SIMPLE_TIME_FORMAT), )) - getattr(tb, method)(now) + getattr(tb, method)(punch_datetime) elif args.subparser_name == "list-entries": end_date = None if args.end_date: