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

Allow floating point, negative, and second unit times for start param… #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

digitalmacgyver
Copy link

This change allows the the --start parameter to take on:

values starting with + or -
floating point values with . in them
values denominated in seconds

like:

'-1 min ago' (1 minute in the future)
'2.5 weeks ago'
'+.125 s' (1/8th of a second ago)

It does not allow numbers with a terminal . like: 123.

@coveralls
Copy link

coveralls commented Jun 24, 2017

Coverage Status

Coverage decreased (-0.6%) to 90.78% when pulling ed2d026 on digitalmacgyver:master into 0bc5fe3 on jorgebastida:master.

@jorgebastida
Copy link
Owner

What is the use case of querying for events in the future?

@digitalmacgyver
Copy link
Author

digitalmacgyver commented Jul 30, 2017 via email

@@ -248,13 +248,16 @@ def parse_datetime(self, datetime_text):
if not datetime_text:
return None

ago_regexp = r'(\d+)\s?(m|minute|minutes|h|hour|hours|d|day|days|w|weeks|weeks)(?: ago)?'
ago_regexp = r'([+-]?([0-9]*[.])?[0-9]+)\s?(s|sec|secs|second|seconds|m|minute|minutes|h|hour|hours|d|day|days|w|weeks|weeks)(?: ago)?'
Copy link
Contributor

@Code0x58 Code0x58 Nov 23, 2018

Choose a reason for hiding this comment

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

I think I agree that the +/- is redundant.

The digit pattern may be a bit more efficient (not a practical concern) as ([0-9]+(?:\.[0-9]+)?) - it would also avoid the additional matching group, so you just have (amount, unit) again.

To be consistent the additional time spans would be s|second|seconds, as there's nothing like hr|hrs.

The line is getting long (enough to cause the linter to kick off in Travis), a change to s|seconds?|m|minutes?|… seems reasonable.

p.s. it looks like there was a bug previously, was the pattern ends with weeks|weeks instead of week|weeks. It would also be good to add $ to the end of the pattern.

Copy link
Owner

Choose a reason for hiding this comment

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

  • I agree the +/- is a bit too much.
  • I do agree with @Code0x58 about the regexp and s|second|seconds

amount = int(amount)
unit = {'m': 60, 'h': 3600, 'd': 86400, 'w': 604800}[unit[0]]
amount, whole_part, unit = ago_match.groups()
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

This try/except block could be replaced with just amount = float(amount) as the precision is good enough for this application regardless.

Copy link
Owner

Choose a reason for hiding this comment

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

Agree

Copy link
Owner

@jorgebastida jorgebastida left a comment

Choose a reason for hiding this comment

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

It is a long while since the PR was sent (sorry). @Code0x58 @digitalmacgyver would any of you mind updating and sending this PR again ?

@@ -248,13 +248,16 @@ def parse_datetime(self, datetime_text):
if not datetime_text:
return None

ago_regexp = r'(\d+)\s?(m|minute|minutes|h|hour|hours|d|day|days|w|weeks|weeks)(?: ago)?'
ago_regexp = r'([+-]?([0-9]*[.])?[0-9]+)\s?(s|sec|secs|second|seconds|m|minute|minutes|h|hour|hours|d|day|days|w|weeks|weeks)(?: ago)?'
Copy link
Owner

Choose a reason for hiding this comment

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

  • I agree the +/- is a bit too much.
  • I do agree with @Code0x58 about the regexp and s|second|seconds

amount = int(amount)
unit = {'m': 60, 'h': 3600, 'd': 86400, 'w': 604800}[unit[0]]
amount, whole_part, unit = ago_match.groups()
try:
Copy link
Owner

Choose a reason for hiding this comment

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

Agree

@Code0x58
Copy link
Contributor

I'm long gone, so can't offer any more time on this project. This could be a nice improvement

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