From: Jaime Marquínez Ferrándiz Date: Sun, 28 Apr 2013 09:39:37 +0000 (+0200) Subject: Allow to use relative dates in the format (now|today)[+-][0-9](day|week|month|year... X-Git-Url: http://git.oshgnacknak.de/?a=commitdiff_plain;h=37254abc36695692649348099fae0ed8f73fd3d1;p=youtube-dl 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. --- 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