From 6264a46212a1eeb753d0e2386705085736c64145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 21 Apr 2019 16:22:53 +0200 Subject: [PATCH] use 'utcfromtimestamp()' 'fromtimestamp()' converts its results to the local timezone and causes problems when running tests on a different machine. --- gallery_dl/extractor/twitter.py | 6 +++--- gallery_dl/text.py | 2 +- test/test_text.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gallery_dl/extractor/twitter.py b/gallery_dl/extractor/twitter.py index f364f4b8..0af70c74 100644 --- a/gallery_dl/extractor/twitter.py +++ b/gallery_dl/extractor/twitter.py @@ -134,7 +134,7 @@ class TwitterTimelineExtractor(TwitterExtractor): test = ("https://twitter.com/PicturesEarth", { "range": "1-40", "url": "2f4d51cbba81e56c1c755677b3ad58fc167c9771", - "keyword": "d406beda07f6f644abd460ddb9af2469ee65c187", + "keyword": "46f680d81a59e4d0e8b4ac25411bc3ec94c73a93", }) def tweets(self): @@ -167,13 +167,13 @@ class TwitterTweetExtractor(TwitterExtractor): test = ( ("https://twitter.com/PicturesEarth/status/672897688871018500", { "url": "d9e68d41301d2fe382eb27711dea28366be03b1a", - "keyword": "64353df74105fa8814319fdcd3c34575195c39cc", + "keyword": "da59634e33a7210bd24f9152af9ac560f6b1b601", "content": "a1f2f04cb2d8df24b1afa7a39910afda23484342", }), # 4 images ("https://twitter.com/perrypumas/status/894001459754180609", { "url": "c8a262a9698cb733fb27870f5a8f75faf77d79f6", - "keyword": "6616de44cf8f87226047ef673e528233f76735d0", + "keyword": "43d98ab448193f0d4f30aa571a4b6bda9b6a5692", }), # video ("https://twitter.com/perrypumas/status/1065692031626829824", { diff --git a/gallery_dl/text.py b/gallery_dl/text.py index bccdbf0e..7cb5e9f9 100644 --- a/gallery_dl/text.py +++ b/gallery_dl/text.py @@ -218,7 +218,7 @@ def parse_query(qs): def parse_timestamp(ts, default=None): """Create a datetime object from a unix timestamp""" try: - return datetime.datetime.fromtimestamp(int(ts)) + return datetime.datetime.utcfromtimestamp(int(ts)) except (TypeError, ValueError, OverflowError): return default diff --git a/test/test_text.py b/test/test_text.py index 1ff890e1..450e57f3 100644 --- a/test/test_text.py +++ b/test/test_text.py @@ -338,8 +338,8 @@ class TestText(unittest.TestCase): self.assertEqual(f(value), {}) def test_parse_timestamp(self, f=text.parse_timestamp): - null = datetime.datetime.fromtimestamp(0) - value = datetime.datetime.fromtimestamp(1555816235) + null = datetime.datetime.utcfromtimestamp(0) + value = datetime.datetime.utcfromtimestamp(1555816235) self.assertEqual(f(0) , null) self.assertEqual(f("0") , null)