From b5e70f5dc6992ea28f75b7d7baf32488dcb20b83 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Thu, 27 Mar 2014 14:24:49 -0700 Subject: [PATCH] timeutils: add sec_to_timestamp() func --- pywb/utils/timeutils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pywb/utils/timeutils.py b/pywb/utils/timeutils.py index c09e8d27..0dcc7e22 100644 --- a/pywb/utils/timeutils.py +++ b/pywb/utils/timeutils.py @@ -244,6 +244,7 @@ def timestamp_to_sec(string): >>> timestamp_to_sec('20131226095010') 1388051410 + # rounds to end of 2014 >>> timestamp_to_sec('2014') 1420070399 """ @@ -251,6 +252,18 @@ def timestamp_to_sec(string): return calendar.timegm(timestamp_to_datetime(string).utctimetuple()) +def sec_to_timestamp(secs): + """ + >>> sec_to_timestamp(1388051410) + '20131226095010' + + >>> sec_to_timestamp(1420070399) + '20141231235959' + """ + + return datetime_to_timestamp(datetime.datetime.utcfromtimestamp(secs)) + + def timestamp_to_http_date(string): """ >>> timestamp_to_http_date('20131226095000')