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

time only support for watson add #282

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

jdckr
Copy link

@jdckr jdckr commented May 12, 2019

Improve usability of watson add (issue #278)

@jdckr jdckr changed the title Add time only time only support for watson add May 12, 2019
@jmaupetit
Copy link
Contributor

Looks like we finally have our first CLI tests 😉

@jmaupetit jmaupetit assigned jmaupetit and unassigned jmaupetit May 17, 2019
@jmaupetit jmaupetit self-requested a review May 17, 2019 17:22
@k4nar
Copy link
Collaborator

k4nar commented May 22, 2019

Do you know why Github is displaying such a long diff for docs/user-guide/commands.md? Did you by any chance generate it on Windows? If so, I think there is a way to avoid committing the \r\n: https://help.github.com/en/articles/dealing-with-line-endings

watson/cli.py Outdated

def getMergedDateTime(date_time, time_string):
hours, minutes = time_string.split(":")
return date_time.shift(hours=int(hours), minutes=int(minutes))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those functions should probably go to the utils module (and be unit tested ;) ).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. 5729d3e

to = getMergedDateTime(from_.floor("day"), to)
elif isTime(from_) and isTime(to):
from_ = getDateTimeToday(from_)
to = getDateTimeToday(to)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if Arrow doesn't provide something to help with that. It feels a bit tedious to introduce our own regexp to parse the date & times.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked the api and didn't find s.th. appropriate. But I am open for suggestions.

Copy link
Contributor

@davidag davidag May 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been looking into it and there's something I don't understand: why are there two different click types Date and Time in cli.py?

It turns out that both accept the full date, but using different formats!

  • TimeParamType (aka, Time) is only used in watson stop:
$ watson stop --at 09:00
$ watson stop --at 2019-05-23T12:00
  • DateParamType (aka, Date) is used in every other place where a date is required:
$ watson report -f 2019-05-23
$ watson report -f "2019-05-23 12:00"
$ watson report -f "2019-05-23T12:00"

In my opinion, the following changes might solve issue #278 in a simpler way:

  1. Rename Date to DateTime which is more appropriate to what it does. Of course, rename also the corresponding ParamType classes.
  2. Allow DateTime to receive time only dates, which is precisely what the Time type does. You could reuse the code.
  3. Use DateTime where Time was used (i.e. watson stop).
  4. Remove Time and TimeParamType.

Please, remember that I'm not a member of this project, so I might be missing important stuff!! :-) what do you think @k4nar?

I think date/time input format is one of the aspects where Watson could get a nice improvement, so it's great that there's someone working on it!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea. I didn't dive deep so I was not aware of TimeParamType which is basically doing what I implemented to handle time only.
I also couldn't agree more that the api is not consistent for the different cmds and it felt like adding another balcony.
The only drawback I see so far is that it will be hard to handle the case where we want to reuse the date specified for --from for --to as the parameter processing would be done without the knowledge about the other parameter.

@jdckr
Copy link
Author

jdckr commented May 22, 2019

Do you know why Github is displaying such a long diff for docs/user-guide/commands.md? Did you by any chance generate it on Windows? If so, I think there is a way to avoid committing the \r\n: https://help.github.com/en/articles/dealing-with-line-endings

Yes I am on Windows. I use checkout-as-is and commit-as-is which suits most cases very well. Have pushed a new commit fixing the line endings.

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

Successfully merging this pull request may close these issues.

4 participants