Skip to content
This repository has been archived by the owner on Sep 23, 2018. It is now read-only.

Commit

Permalink
Add configurable date and time to output of status command (fixes j…
Browse files Browse the repository at this point in the history
  • Loading branch information
SpotlightKid committed Oct 20, 2015
1 parent 28cc75d commit 9159a95
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions watson/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
))


Expand Down
4 changes: 2 additions & 2 deletions watson/watson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9159a95

Please sign in to comment.