Skip to content

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

Open
digitalmacgyver wants to merge 1 commit into
jorgebastida:masterfrom
digitalmacgyver:master
Open

Allow floating point, negative, and second unit times for start param…#140
digitalmacgyver wants to merge 1 commit into
jorgebastida:masterfrom
digitalmacgyver:master

Conversation

@digitalmacgyver

Copy link
Copy Markdown

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

coveralls commented Jun 24, 2017

Copy link
Copy Markdown

Coverage Status

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

@jorgebastida

Copy link
Copy Markdown
Owner

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

@digitalmacgyver

digitalmacgyver commented Jul 30, 2017 via email

Copy link
Copy Markdown
Author

Comment thread awslogs/core.py
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)?'

@Code0x58 Code0x58 Nov 23, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

Comment thread awslogs/core.py
amount = int(amount)
unit = {'m': 60, 'h': 3600, 'd': 86400, 'w': 604800}[unit[0]]
amount, whole_part, unit = ago_match.groups()
try:

Copy link
Copy Markdown
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
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Agree

@jorgebastida jorgebastida left a comment

Copy link
Copy Markdown
Owner

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 ?

Comment thread awslogs/core.py
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
Copy Markdown
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

Comment thread awslogs/core.py
amount = int(amount)
unit = {'m': 60, 'h': 3600, 'd': 86400, 'w': 604800}[unit[0]]
amount, whole_part, unit = ago_match.groups()
try:

Copy link
Copy Markdown
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
Copy Markdown
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