Skip to content

Commit

Permalink
use full timestamps, no cutoff at 2011, fixes #46
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Apr 12, 2016
1 parent 838f5d9 commit 9981a90
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions itsdangerous.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ def dumps(self, obj):
compact_json = _CompactJSON()


# 2011/01/01 in UTC
EPOCH = 1293840000


def want_bytes(s, encoding='utf-8', errors='strict'):
if isinstance(s, text_type):
s = s.encode(encoding, errors)
Expand Down Expand Up @@ -393,13 +389,13 @@ def get_timestamp(self):
"""Returns the current timestamp. This implementation returns the
seconds since 1/1/2011. The function must return an integer.
"""
return int(time.time() - EPOCH)
return int(time.time())

def timestamp_to_datetime(self, ts):
"""Used to convert the timestamp from `get_timestamp` into a
datetime object.
"""
return datetime.utcfromtimestamp(ts + EPOCH)
return datetime.utcfromtimestamp(ts)

def sign(self, value):
"""Signs the given string and also attaches a time information."""
Expand Down
4 changes: 2 additions & 2 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class TimedSerializerTestCase(SerializerTestCase):

def setUp(self):
self._time = time.time
time.time = lambda: idmod.EPOCH
time.time = lambda: 0

def tearDown(self):
time.time = self._time
Expand All @@ -140,7 +140,7 @@ def test_decode_with_timeout(self):
self.assertNotEqual(ts, idmod.Serializer(secret_key).dumps(value))

self.assertEqual(s.loads(ts), value)
time.time = lambda: idmod.EPOCH + 10
time.time = lambda: 10
self.assertEqual(s.loads(ts, max_age=11), value)
self.assertEqual(s.loads(ts, max_age=10), value)
self.assertRaises(
Expand Down

0 comments on commit 9981a90

Please sign in to comment.