]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[utils] Fix unified_timestamp for formats parsed by parsedate_tz()
authorYen Chi Hsuan <yan12125@gmail.com>
Fri, 5 Aug 2016 03:41:55 +0000 (11:41 +0800)
committerYen Chi Hsuan <yan12125@gmail.com>
Fri, 5 Aug 2016 03:41:55 +0000 (11:41 +0800)
test/test_utils.py
youtube_dl/utils.py

index 2273b5a1072259bf6b9e60cca85360f3bfac1fe6..5a2ae4a1e336bdb0779f1b669d2717daa035d731 100644 (file)
@@ -308,6 +308,7 @@ class TestUtil(unittest.TestCase):
         self.assertEqual(unified_timestamp('25-09-2014'), 1411603200)
         self.assertEqual(unified_timestamp('27.02.2016 17:30'), 1456594200)
         self.assertEqual(unified_timestamp('UNKNOWN DATE FORMAT'), None)
+        self.assertEqual(unified_timestamp('May 16, 2016 11:15 PM'), 1463440500)
 
     def test_determine_ext(self):
         self.assertEqual(determine_ext('http://example.com/foo/bar.mp4/?download'), 'mp4')
index f5cd6819b4b51942e3fa273d1987debb6f8333ed..97ddd988398993e7858651b77bf19ef72efe3a7c 100644 (file)
@@ -1101,7 +1101,7 @@ def unified_timestamp(date_str, day_first=True):
 
     date_str = date_str.replace(',', ' ')
 
-    pm_delta = datetime.timedelta(hours=12 if re.search(r'(?i)PM', date_str) else 0)
+    pm_delta = 12 if re.search(r'(?i)PM', date_str) else 0
     timezone, date_str = extract_timezone(date_str)
 
     # Remove AM/PM + timezone
@@ -1109,13 +1109,13 @@ def unified_timestamp(date_str, day_first=True):
 
     for expression in date_formats(day_first):
         try:
-            dt = datetime.datetime.strptime(date_str, expression) - timezone + pm_delta
+            dt = datetime.datetime.strptime(date_str, expression) - timezone + datetime.timedelta(hours=pm_delta)
             return calendar.timegm(dt.timetuple())
         except ValueError:
             pass
     timetuple = email.utils.parsedate_tz(date_str)
     if timetuple:
-        return calendar.timegm(timetuple.timetuple())
+        return calendar.timegm(timetuple) + pm_delta * 3600
 
 
 def determine_ext(url, default_ext='unknown_video'):