Content-Length: 299940 | pFad | http://github.com/micropython/micropython/issues/17340

BC GitHub · Where software is built
Skip to content

time.gmtime(), time.localtime() overflows with ints over 32 bit #17340

Open
@tobes

Description

@tobes

Port, board and/or hardware

ESP32

MicroPython version

MicroPython v1.24.1 on 2024-11-29; Generic ESP32 module with ESP32

Reproduction

>>> from time import gmtime
>>> gmtime(2147483647)  # max size of 32 bit int
(2068, 1, 19, 3, 14, 7, 3, 19)
>>> gmtime(2147483648) # max size of 32 bit int + 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: overflow converting long int to machine word

Expected behaviour

>>> from time import gmtime
>>> gmtime(2147483647)  # max size of 32 bit int
(2068, 1, 19, 3, 14, 7, 3, 19)
>>> gmtime(2147483648) # max size of 32 bit int + 1
(2068, 1, 19, 3, 14, 8, 3, 19)

Observed behaviour

>>> from time import gmtime
>>> gmtime(2147483647)  # max size of 32 bit int
(2068, 1, 19, 3, 14, 7, 3, 19)
>>> gmtime(2147483648) # max size of 32 bit int + 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: overflow converting long int to machine word

Additional Information

I see two solutions

Preferred

update the code to work with 64 bit ints

Alternative

update the documentation to include this limited behaviour

Code of Conduct

Yes, I agree

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: http://github.com/micropython/micropython/issues/17340

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy