[work] Add start time argument

This commit is contained in:
lara 2020-04-15 10:22:14 -04:00
parent 95e4562b29
commit a8c10982fb

View file

@ -132,13 +132,17 @@ def work(args):
def work_start(args): def work_start(args):
fields = get_today_fields() fields = get_today_fields()
hour = start_time.strftime("%H:%M") try:
hour = datetime.strptime(args.time, "%H:%M")
except ValueError:
die("Error: {} is not a valid time".format(args.time))
if fields: if fields:
die("You already started working") die("You already started working")
with open(TODAY_FILE, "a") as f: with open(TODAY_FILE, "a") as f:
f.write("{},{}".format( f.write("{},{}".format(
start_time.strftime("%Y-%m-%d"), hour)) start_time.strftime("%Y-%m-%d"),
log("Started working at {}".format(hour)) hour.strftime("%H:%M")))
log("Started working at {}".format(hour.strftime("%H:%M")))
def work_pause(args): def work_pause(args):
@ -249,9 +253,10 @@ if __name__ == "__main__":
parse_parser = commands.add_parser("parse") parse_parser = commands.add_parser("parse")
start_parser.set_defaults(func=work_start) start_parser.set_defaults(func=work_start)
start_parser.add_argument("time", nargs="?", default=datetime.now().strftime("%H:%M"))
pause_parser.set_defaults(func=work_pause) pause_parser.set_defaults(func=work_pause)
end_parser.add_argument("description")
end_parser.set_defaults(func=work_end) end_parser.set_defaults(func=work_end)
end_parser.add_argument("description")
export_parser.set_defaults(func=work_export) export_parser.set_defaults(func=work_export)
parse_parser.set_defaults(func=work_parse) parse_parser.set_defaults(func=work_parse)
parse_parser.add_argument("file") parse_parser.add_argument("file")