mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-02 16:32:51 +01:00
Fix unified_timestamp
This commit is contained in:
parent
0ed9a73a73
commit
a43ba2eff6
|
@ -421,6 +421,10 @@ def test_unified_timestamps(self):
|
||||||
self.assertEqual(unified_timestamp('Wednesday 31 December 1969 18:01:26 MDT'), 86)
|
self.assertEqual(unified_timestamp('Wednesday 31 December 1969 18:01:26 MDT'), 86)
|
||||||
self.assertEqual(unified_timestamp('12/31/1969 20:01:18 EDT', False), 78)
|
self.assertEqual(unified_timestamp('12/31/1969 20:01:18 EDT', False), 78)
|
||||||
self.assertEqual(unified_timestamp('2023-03-09T18:01:33.646Z', with_milliseconds=True), 1678384893.646)
|
self.assertEqual(unified_timestamp('2023-03-09T18:01:33.646Z', with_milliseconds=True), 1678384893.646)
|
||||||
|
# ISO8601 spec says that if no timezone is specified, we should use local timezone;
|
||||||
|
# but yt-dlp uses UTC to keep things consistent
|
||||||
|
self.assertEqual(unified_timestamp('2023-03-11T06:48:34.008'), 1678517314)
|
||||||
|
|
||||||
|
|
||||||
def test_determine_ext(self):
|
def test_determine_ext(self):
|
||||||
self.assertEqual(determine_ext('http://example.com/foo/bar.mp4/?download'), 'mp4')
|
self.assertEqual(determine_ext('http://example.com/foo/bar.mp4/?download'), 'mp4')
|
||||||
|
|
|
@ -1868,8 +1868,9 @@ def unified_timestamp(date_str, day_first=True, with_milliseconds=False):
|
||||||
|
|
||||||
for expression in date_formats(day_first):
|
for expression in date_formats(day_first):
|
||||||
with contextlib.suppress(ValueError):
|
with contextlib.suppress(ValueError):
|
||||||
dt = datetime.datetime.strptime(date_str, expression) - timezone + datetime.timedelta(hours=pm_delta)
|
dt = datetime.datetime.strptime(date_str, expression) + datetime.timedelta(hours=pm_delta)
|
||||||
return calendar.timegm(dt.timetuple()) + (dt.microsecond / 1e6 if with_milliseconds else 0)
|
dt_tz_aware = dt.replace(tzinfo=datetime.timezone(timezone))
|
||||||
|
return dt_tz_aware.timestamp() if with_milliseconds else int(dt_tz_aware.timestamp())
|
||||||
|
|
||||||
timetuple = email.utils.parsedate_tz(date_str)
|
timetuple = email.utils.parsedate_tz(date_str)
|
||||||
if timetuple:
|
if timetuple:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user