Skip to content

Instantly share code, notes, and snippets.

@mandarg
Created February 10, 2016 02:32
Show Gist options
  • Save mandarg/6bdfff6b3f4e90607495 to your computer and use it in GitHub Desktop.
Save mandarg/6bdfff6b3f4e90607495 to your computer and use it in GitHub Desktop.
Funny bug in Python's datetime
{~/sandbox}$ cat ./find_newline.py
#! /usr/bin/env python
import time
tries = 40
upper = 2 ** 38
lower = 0
while tries >= 0:
mid = (upper + lower) / 2
if '\n' in time.ctime(mid):
upper = mid
else:
lower = mid
tries -= 1
print mid
{~/sandbox}$ ./find_newline.py
137438953472
206158430208
240518168576
257698037760
249108103168
253403070464
251255586816
252329328640
252866199552
253134635008
253268852736
253335961600
253369516032
253386293248
253394681856
253398876160
253400973312
253402021888
253402546176
253402284032
253402415104
253402349568
253402316800
253402300416
253402308608
253402304512
253402302464
253402301440
253402300928
253402300672
253402300800
253402300736
253402300768
253402300784
253402300792
253402300796
253402300798
253402300799
253402300799
253402300799
253402300799
{~/sandbox}$ python
>>> import time
>>> time.ctime(253402300799)
'Fri Dec 31 23:59:59 9999'
>>> time.ctime(253402300800)
'Sat Jan 1 00:00:00 10000\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment