Skip to content

Commit

Permalink
Add a date query precision of ‘minute’
Browse files Browse the repository at this point in the history
  • Loading branch information
discopatrick committed Apr 25, 2017
1 parent 5f2c47e commit ba324df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions beets/dbcore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ class Period(object):
instants of time during January 2014.
"""

precisions = ('year', 'month', 'day', 'hour')
date_formats = ('%Y', '%Y-%m', '%Y-%m-%d', '%Y-%m-%dT%H')
precisions = ('year', 'month', 'day', 'hour', 'minute')
date_formats = ('%Y', '%Y-%m', '%Y-%m-%d', '%Y-%m-%dT%H', '%Y-%m-%dT%H:%M')

def __init__(self, date, precision):
"""Create a period with the given date (a `datetime` object) and
Expand Down Expand Up @@ -584,6 +584,8 @@ def open_right_endpoint(self):
return date + timedelta(days=1)
elif 'hour' == precision:
return date + timedelta(hours=1)
elif 'minute' == precision:
return date + timedelta(minutes=1)
else:
raise ValueError(u'unhandled precision {0}'.format(precision))

Expand Down
12 changes: 12 additions & 0 deletions test/test_datequery.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ def test_hour_precision_intervals(self):
self.assertExcludes('2000-01-01T12..2000-01-01T13',
'2000-01-01T14:30:00')

def test_minute_precision_intervals(self):
self.assertExcludes('2000-01-01T12:30..2000-01-01T12:31',
'2000-01-01T12:29:59')
self.assertContains('2000-01-01T12:30..2000-01-01T12:31',
'2000-01-01T12:30:00')
self.assertContains('2000-01-01T12:30..2000-01-01T12:31',
'2000-01-01T12:30:30')
self.assertContains('2000-01-01T12:30..2000-01-01T12:31',
'2000-01-01T12:30:59')
self.assertExcludes('2000-01-01T12:30..2000-01-01T12:31',
'2000-01-01T12:31:00')

def test_unbounded_endpoints(self):
self.assertContains('..', date=datetime.max)
self.assertContains('..', date=datetime.min)
Expand Down

0 comments on commit ba324df

Please sign in to comment.