Page 1 of 1

Overflow in time.localtime()

Posted: Thu Jun 04, 2020 10:30 am
by MrRobot
So I had a bug in my code that produced an invalid timestamp.

I solved the bug but thought it was strange that there's a max int for locatime()

What is the maximum value you can pass to localtime() ?

Running on stable build 1.12 on Pyboard D SF6W

Bug below:

time.localtime(2366758325)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: overflow converting long int to machine word

Re: Overflow in time.localtime()

Posted: Thu Jun 04, 2020 11:46 pm
by jcw

Code: Select all

MicroPython v1.12 on 2019-12-20; PYBLITEv1.0 with STM32F411RE
Type "help()" for more information.
>>> import time
>>> time.localtime(1<<30)
(2034, 1, 9, 13, 37, 4, 0, 9)
>>> time.localtime((1<<31)-1)
(2068, 1, 19, 3, 14, 7, 3, 19)
>>> time.localtime(1<<31)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: overflow converting long int to machine word
>>> 1<<31
2147483648
>>>

Re: Overflow in time.localtime()

Posted: Thu May 09, 2024 7:33 pm
by Yannick
Hello

I have get exatcly the same issue on NUCLEO-WB55 :

Code: Select all

MicroPython v1.22.2 on 2024-02-22; NUCLEO-WB55 with STM32WB55RGV6
Type "help()" for more information.
>>> from time import localtime
>>> localtime(2208988800)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: overflow converting long int to machine word
>>>
Best regards

Yannick