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

Relative date queries (continuation of #2418) #2598

Merged
merged 29 commits into from
Jun 16, 2017
Merged

Relative date queries (continuation of #2418) #2598

merged 29 commits into from
Jun 16, 2017

Conversation

sampsyo
Copy link
Member

@sampsyo sampsyo commented Jun 15, 2017

This adds relative dates to the query syntax for date-type fields. It's @euri10's work; I'm just opening the pull request to succeed #2418. 👻

And this time, I'm using a branch in the main repository.

euri10 and others added 23 commits January 28, 2017 19:15
added some doc
fixed an error with the weeks that didn't use the sign correctly
added more tests, this is where py.test fixtures would shine
corrected rst
fixed flake8 in test
corrected docs with correct example
added relative date usage to it
The previous version wasn't user-friendly enough and too technical.
A relative date doesn't need to be prefixed by @ anymore.
The relative date pattern now displays named groups.
Digits have been change to [0-9] to avoid other digit characters.
Removed the @ character in tests.
Updated subsequent documentation.
Solved conflicts with upstream of new parse classmethod of DateQuery

# Conflicts:
#	beets/dbcore/query.py
@sampsyo sampsyo mentioned this pull request Jun 15, 2017
Copy link
Member Author

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Looks like this is nearly ready to merge! Here are a few loose ends.

days = cls.relative[timespan]
date = datetime.now() + \
timedelta(days=int(quantity) * days) * multiplier
string = date.strftime(cls.date_formats[5][0])
Copy link
Member Author

Choose a reason for hiding this comment

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

@euri10: Turning things back into a string seems a little odd. Can we just return cls(date, something) here?

Copy link
Contributor

Choose a reason for hiding this comment

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

done, at first I didn't know if the ordinal was used anywhere, so turning things back into a string was a way to use the find_date_and_format function that already exists

@@ -562,6 +562,9 @@ class Period(object):
('%Y-%m-%dT%H:%M', '%Y-%m-%d %H:%M'), # minute
('%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S') # second
)
relative = {'y': 365, 'm': 30, 'w': 7, 'd': 1}
Copy link
Member Author

Choose a reason for hiding this comment

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

A better name might be relative_units.

@@ -606,6 +637,8 @@ def open_right_endpoint(self):
"""
precision = self.precision
date = self.date
if 'relative' == self.precision:
return date
Copy link
Member Author

Choose a reason for hiding this comment

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

Can self.precision ever be "relative" in this version? Is this possibly out of date?

Copy link
Contributor

Choose a reason for hiding this comment

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

indeed, no use

@@ -164,6 +164,29 @@ Dates are written separated by hyphens, like ``year-month-day``, but the month
and day are optional. If you leave out the day, for example, you will get
matches for the whole month.

You can also use relative dates to the current time.
A relative date begins with an ``@``.
It looks like ``@-3w``, ``@2m`` or ``@-4d`` which means the date 3 weeks ago,
Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like we need to remove the @ here.

Copy link
Contributor

Choose a reason for hiding this comment

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

yep, corrected

euri10 and others added 5 commits June 16, 2017 09:05
Changed the return in case of a relative date, by default precision is
to the second, aka 5
Removed old 'relative' precision that indeed isn't necessary anymore
Corrected doc according to current relative date format, no more @
It's important to introduce the .. syntax before we get here.
@sampsyo sampsyo merged commit d31a483 into master Jun 16, 2017
@sampsyo
Copy link
Member Author

sampsyo commented Jun 16, 2017

Awesome; thank you! I've made a few minor refinements to the docs and merged. ✨ This is a small but awesome feature to have; I, for one, will be using it all the time. Nice work, and thank you for your patience! 🚀

@euri10
Copy link
Contributor

euri10 commented Jun 16, 2017 via email

@sampsyo
Copy link
Member Author

sampsyo commented Jun 16, 2017

Cool! Let me know if you need a hand looking into that issue.

@arcresu arcresu deleted the relativedate branch April 24, 2019 05:03
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

Successfully merging this pull request may close these issues.

2 participants