Skip to content

Commit eaae3fb

Browse files
committed
Merge branch 'relativedate'
2 parents 01cf0d0 + 93f064f commit eaae3fb

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

beets/dbcore/query.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ class Period(object):
562562
('%Y-%m-%dT%H:%M', '%Y-%m-%d %H:%M'), # minute
563563
('%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S') # second
564564
)
565-
relative = {'y': 365, 'm': 30, 'w': 7, 'd': 1}
565+
relative_units = {'y': 365, 'm': 30, 'w': 7, 'd': 1}
566566
relative_re = '(?P<sign>[+|-]?)(?P<quantity>[0-9]+)' + \
567567
'(?P<timespan>[y|m|w|d])'
568568

@@ -618,10 +618,10 @@ def find_date_and_format(string):
618618
# Add or subtract the given amount of time from the current
619619
# date.
620620
multiplier = -1 if sign == '-' else 1
621-
days = cls.relative[timespan]
621+
days = cls.relative_units[timespan]
622622
date = datetime.now() + \
623623
timedelta(days=int(quantity) * days) * multiplier
624-
string = date.strftime(cls.date_formats[5][0])
624+
return cls(date, cls.precisions[5])
625625

626626
# Check for an absolute date.
627627
date, ordinal = find_date_and_format(string)
@@ -637,8 +637,6 @@ def open_right_endpoint(self):
637637
"""
638638
precision = self.precision
639639
date = self.date
640-
if 'relative' == self.precision:
641-
return date
642640
if 'year' == self.precision:
643641
return date.replace(year=date.year + 1, month=1)
644642
elif 'month' == precision:

docs/reference/query.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ and day are optional. If you leave out the day, for example, you will get
165165
matches for the whole month.
166166

167167
You can also use relative dates to the current time.
168-
A relative date begins with an ``@``.
169-
It looks like ``@-3w``, ``@2m`` or ``@-4d`` which means the date 3 weeks ago,
168+
It looks like ``-3w``, ``2m`` or ``-4d`` which means the date 3 weeks ago,
170169
the date 2 months from now and the date 4 days ago.
171170
A relative date consists of three parts:
172171
- ``+`` or ``-`` sign is optional and defaults to ``+``. The ``+`` sign will

0 commit comments

Comments
 (0)