From 8d054f3656aa74762d9473dec67cdc39ea9d471c Mon Sep 17 00:00:00 2001 From: euri10 Date: Sat, 28 Jan 2017 21:40:26 +0100 Subject: [PATCH] tests flake8 issues added some doc --- docs/reference/query.rst | 15 +++++++++++++++ test/test_datequery.py | 14 +++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/reference/query.rst b/docs/reference/query.rst index 2f3366d4c..c2a5cdf0a 100644 --- a/docs/reference/query.rst +++ b/docs/reference/query.rst @@ -162,6 +162,20 @@ 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. +Relative dates begin by the ``@`` character, followed by an optional ``+`` or +``-`` sign that will increment or decrement now, followed by the time quantity +that will be represented as an integer followed by either ``d`` for days, ``w`` +for weeks, ``m`` for months and finally ``y`` for year. + +Here is an example that finds all the albums added between now and last week:: + + $ beet ls -a 'added:@-1w..@0d' + +Find all items added in a 2 weeks period 4 weeks ago:: + + $ beet ls -a 'added:@-6w..@-2w' + Date *intervals*, like the numeric intervals described above, are separated by two dots (``..``). You can specify a start, an end, or both. @@ -186,6 +200,7 @@ Find all items with a file modification time between 2008-12-01 and $ beet ls 'mtime:2008-12-01..2008-12-02' + .. _not_query: Query Term Negation diff --git a/test/test_datequery.py b/test/test_datequery.py index 4b01edd2c..e2d1d23a3 100644 --- a/test/test_datequery.py +++ b/test/test_datequery.py @@ -123,6 +123,7 @@ class DateQueryTest(_common.LibTestCase): matched = self.lib.items(query) self.assertEqual(len(matched), 0) + class DateQueryTestRelative(_common.LibTestCase): def setUp(self): super(DateQueryTestRelative, self).setUp() @@ -135,7 +136,9 @@ class DateQueryTestRelative(_common.LibTestCase): self.assertEqual(len(matched), 1) def test_single_month_nonmatch_fast(self): - query = DateQuery('added', (datetime.now()+relativedelta(months=1)).strftime('%Y-%m')) + query = DateQuery('added', + (datetime.now() + relativedelta(months=1)).strftime( + '%Y-%m')) matched = self.lib.items(query) self.assertEqual(len(matched), 0) @@ -144,7 +147,9 @@ class DateQueryTestRelative(_common.LibTestCase): self.assertTrue(query.match(self.i)) def test_single_month_nonmatch_slow(self): - query = DateQuery('added', (datetime.now()+relativedelta(months=1)).strftime('%Y-%m')) + query = DateQuery('added', + (datetime.now() + relativedelta(months=1)).strftime( + '%Y-%m')) self.assertFalse(query.match(self.i)) def test_single_day_match_fast(self): @@ -153,10 +158,13 @@ class DateQueryTestRelative(_common.LibTestCase): self.assertEqual(len(matched), 1) def test_single_day_nonmatch_fast(self): - query = DateQuery('added', (datetime.now()+ relativedelta(days=1)).strftime('%Y-%m-%d')) + query = DateQuery('added', + (datetime.now() + relativedelta(days=1)).strftime( + '%Y-%m-%d')) matched = self.lib.items(query) self.assertEqual(len(matched), 0) + class DateQueryConstructTest(unittest.TestCase): def test_long_numbers(self): DateQuery('added', '1409830085..1412422089')