Overflow in time.localtime()

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
MrRobot
Posts: 31
Joined: Mon May 11, 2020 11:30 am

Overflow in time.localtime()

Post by MrRobot » Thu Jun 04, 2020 10:30 am

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

User avatar
jcw
Posts: 37
Joined: Sat Dec 21, 2019 12:08 pm
Location: CET/CEST

Re: Overflow in time.localtime()

Post by jcw » Thu Jun 04, 2020 11:46 pm

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
>>>

Yannick
Posts: 5
Joined: Mon Mar 15, 2021 5:51 pm

Re: Overflow in time.localtime()

Post by Yannick » Thu May 09, 2024 7:33 pm

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

Post Reply