From 37254abc36695692649348099fae0ed8f73fd3d1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Sun, 28 Apr 2013 11:39:37 +0200 Subject: [PATCH] Allow to use relative dates in the format (now|today)[+-][0-9](day|week|month|year)(s)? (Closes #137) Also fix DateRange not accepting ranges of one day. --- test/test_utils.py | 2 +- youtube_dl/utils.py | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/test/test_utils.py b/test/test_utils.py index 343409a7a..c4b71362e 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -105,7 +105,7 @@ class TestUtil(unittest.TestCase): self.assertTrue("19690721" in _ac) _firstmilenium = DateRange(end="10000101") self.assertTrue("07110427" in _firstmilenium) - + def test_unified_dates(self): self.assertEqual(unified_strdate('December 21, 2010'), '20101221') self.assertEqual(unified_strdate('8/7/2009'), '20090708') diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 3a2f0022f..6c5b5df4c 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -586,7 +586,29 @@ def unified_strdate(date_str): return upload_date def date_from_str(date_str): - """Return a datetime object from a string in the format YYYYMMDD""" + """ + Return a datetime object from a string in the format YYYYMMDD or + (now|today)[+-][0-9](day|week|month|year)(s)?""" + today = datetime.date.today() + if date_str == 'now'or date_str == 'today': + return today + match = re.match('(now|today)(?P[+-])(?P