-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
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
don't seem to play well
There was a problem hiding this 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.
beets/dbcore/query.py
Outdated
days = cls.relative[timespan] | ||
date = datetime.now() + \ | ||
timedelta(days=int(quantity) * days) * multiplier | ||
string = date.strftime(cls.date_formats[5][0]) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
beets/dbcore/query.py
Outdated
@@ -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} |
There was a problem hiding this comment.
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
.
beets/dbcore/query.py
Outdated
@@ -606,6 +637,8 @@ def open_right_endpoint(self): | |||
""" | |||
precision = self.precision | |||
date = self.date | |||
if 'relative' == self.precision: | |||
return date |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, no use
docs/reference/query.rst
Outdated
@@ -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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, corrected
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.
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! 🚀 |
Thanks to you for the amazing cli 😎.
I lacked time to look really into it, but the smartplaylist will need some
adaptation to handle correctly playlists containing relative dates.
The last time I tested some with songs added last week for instance (-1w),
the refresh wasn't handled appropriately.
Can't promise I will, but that would be cool to tackle that issue.
Le 16 juin 2017 17:49, "Adrian Sampson" <notifications@github.com> a écrit :
… 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! 🚀
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2598 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABDZPj2DYveWapmmQai2J9WbjWaagU-9ks5sEqQSgaJpZM4N70E4>
.
|
Cool! Let me know if you need a hand looking into that issue. |
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.