Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

status should also report the exact start date/time #33

Closed
SpotlightKid opened this issue Oct 17, 2015 · 8 comments
Closed

status should also report the exact start date/time #33

SpotlightKid opened this issue Oct 17, 2015 · 8 comments

Comments

@SpotlightKid
Copy link
Contributor

Information like an hour ago may be pretty but often isn't very useful or accurate.

Currently you have to manually open the state file any then convert the unix timestamp to see the exact start time of a running frame. Or did I miss another way to do this?

@SpotlightKid
Copy link
Contributor Author

Here's a possible implementation:

diff --git a/watson/cli.py b/watson/cli.py
index 5ca2442..dcb635a 100644
--- a/watson/cli.py
+++ b/watson/cli.py
@@ -195,10 +195,16 @@ def status(watson):
         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', 'YYYY-MM-DD')
+    timefmt = options.get('time_format', 'HH:mm:ssZ')
+    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'].format(datefmt)),
+        style('time', current['start'].format(timefmt))
     ))

@SpotlightKid
Copy link
Contributor Author

Unfortunately arrow doesn't seem to provide a way to escape formatting characters, so this doesn't work as expected:

$ watson config options.date_format DD.MM.YYY
$ watson config options.time_format 'HH:mm Uhr'
$ watson status
Project watson [issues] started 43 minutes ago (17.10.2015 23:39 U11r)

(Notice the "U11r" at the end.)

@willdurand
Copy link
Contributor

@SpotlightKid what do you mean by "doesn't seem to provide a way to escape formatting characters"? To me, it is just that neither U nor r are valid tokens (cf. http://crsmithdev.com/arrow/#tokens).

What did you expect? Because, your patch looks good to me.

@SpotlightKid
Copy link
Contributor Author

"Uhr" means "o'clock" in German and is normally part of a time specification here. I wanted to include it in in the time format string but with arrow.Arrow.format() I can't. Maybe it would be better to use arrow.Arrow.strftime()? This would work (just tested it), but has disadvantages too:

  • two different ways to specify date/time formats in watson
  • in the config file you would have to use two percent signs, e.g. time_format = %%H:%%M Uhr to prevent configparser from trying to interpret them

Update: Sidenote: Does watson really need configparser.SafeConfigParser? Wouldn't RawConfigParser resp. ConfigParser(interpolation=None) suffice?

@SpotlightKid
Copy link
Contributor Author

For the sake of completeness, here's the version using strftime:

diff --git a/watson/cli.py b/watson/cli.py
index 5ca2442..55161bf 100644
--- a/watson/cli.py
+++ b/watson/cli.py
@@ -195,10 +195,16 @@ def status(watson):
         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))
     ))

@willdurand
Copy link
Contributor

ah, right. Didn't think about it, sorry :/

There is an issue for supporting escaping chars with format(): arrow-py/arrow#35.

@SpotlightKid
Copy link
Contributor Author

So, which branch should I use as a base for creating a pull request, develop or master?

SpotlightKid added a commit to SpotlightKid/Watson that referenced this issue Oct 19, 2015
@willdurand
Copy link
Contributor

@SpotlightKid develop, I know it is misleading.. Sorry for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants