From 9159a9582615a93c290e606c9001367c12daf788 Mon Sep 17 00:00:00 2001 From: Christopher Arndt Date: Mon, 19 Oct 2015 11:56:56 +0200 Subject: [PATCH] Add configurable date and time to output of `status` command (fixes #33) --- README.md | 16 ++++++++++++++-- watson/cli.py | 24 ++++++++++++++++++++---- watson/watson.py | 4 ++-- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c9d85464..433023cd 100644 --- a/README.md +++ b/README.md @@ -84,11 +84,23 @@ be recorded. ### status -Display the time spent since the current project was started. +Display when the current project was started and the time spent since. + +You can configure how the date and time of when the project was started are +displayed by setting `options.date_format` and `options.time_format` in the +configuration. The syntax of these formatting strings and the supported +placeholders are the same as for the `strftime` method of Python's +[datetime.datetime][datetime] class. + +[datetime]: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior ``` $ watson status -Project apollo11 started seconds ago +Project apollo11 [brakes] started seconds ago (2014-05-19 14:32:41+0100) +$ watson config options.date_format %d.%m.%Y +$ watson config options.time_format "at %I:%M %p" +$ watson status +Project apollo11 [brakes] started a minute ago (19.05.2014 at 02:32 PM) ``` ### report diff --git a/watson/cli.py b/watson/cli.py index 80a01c86..4bca3794 100644 --- a/watson/cli.py +++ b/watson/cli.py @@ -183,22 +183,38 @@ def cancel(watson): @click.pass_obj def status(watson): """ - Display the time spent since the current project was started. + Display when the current project was started and the time spent since. + + You can configure how the date and time of when the project was started are + displayed by setting 'options.date_format' and 'options.time_format' in the + configuration. The syntax of these formatting strings and the supported + placeholders are the same as for the 'strftime' method of Python's + 'datetime.datetime' class. \b Example: $ watson status - Project apollo11 started seconds ago + Project apollo11 [brakes] started seconds ago (2014-05-19 14:32:41+0100) + $ watson config options.date_format %d.%m.%Y + $ watson config options.time_format "at %I:%M %p" + $ watson status + Project apollo11 [brakes] started a minute ago (19.05.2014 at 02:32 PM) """ if not watson.is_started: click.echo("No project started") return current = watson.current - click.echo("Project {} {} started {}".format( + options = (dict(watson.config.items('options')) + if watson.config.has_section('options') else {}) + datefmt = options.get('date_format', '%Y.%m.%d') + timefmt = options.get('time_format', '%H:%M:%S%z') + click.echo("Project {} {} started {} ({} {})".format( style('project', current['project']), style('tags', current['tags']), - style('time', current['start'].humanize()) + style('time', current['start'].humanize()), + style('date', current['start'].strftime(datefmt)), + style('time', current['start'].strftime(timefmt)) )) diff --git a/watson/watson.py b/watson/watson.py index 390adb49..53f85306 100644 --- a/watson/watson.py +++ b/watson/watson.py @@ -5,10 +5,10 @@ try: import configparser - from configparser import ConfigParser + from configparser import RawConfigParser as ConfigParser except ImportError: import ConfigParser as configparser # noqa - from ConfigParser import SafeConfigParser as ConfigParser # noqa + from ConfigParser import RawConfigParser as ConfigParser # noqa import arrow import click