← index #1274Issue #11148
Related · medium · value 0.537
QUERY · ISSUE

Need to address inconsistencies between mktime and localtime.

openby dhylandsopened 2015-05-20updated 2024-09-08
needs-info

Currently, if I do:

>>> time.localtime(-1072915200)
(1966, 1, 1, 0, 0, 0, 5, 1)
>>> time.mktime((1966, 1, 1, 0, 0, 0, 5, 1))
3222052096
>>> time.localtime(3222052096)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: overflow converting long int to machine word
>>> hex(3222052096)
'0xc00c9d00'
>>> hex(0x80000000 - 1072915200)
'0x400c9d00'

I think that time.mktime((1966, 1, 1, 0, 0, 0, 5, 1)) should return the negative representation. However, I noticed that timeutils_seconds_since_2000 returns an mp_uint_t rather than an mp_int_t

So a couple of questions came to mind:
1 - Do we want to support times from 1966 to 2000 (which is the -ve small int range)?
2 - Should we support mpz ints?
3 - Adding full support for mpz ints seems like overkill, but we could get 1 extra bit by allowing mpz ints in the full 32-bit range to be supported. Then we'd be able to support dates from 2000 +/- 68 years. This would only require a slightly different conversion into and out of the timeutils functions. The actual code itself wouldn't need to change.

Thoughts?

CANDIDATE · ISSUE

docs: for time.localtime()

closedby hasenradballopened 2023-03-29updated 2024-07-13

Hi Together,

I would remark that this description in the Doc is a little bit missleading.

'''
time.mktime()
https://docs.micropython.org/en/latest/library/time.html
This is inverse function of localtime. It’s argument is a full 8-tuple which expresses a time as per localtime. It returns an integer which is the number of seconds since Jan 1, 2000.
''''

Because on the Pico W the RTC works with the epoch since 1970.
Maybe a small redesign of this description would be perfect, my opinion.

A other point is that I want to aks what the actual status is about:
time.gmtime()
time.localtime()

Is there actually a Timezone information available in micropython?
If not Iam right that these two functions leads to the same result in time structure?

Thanks
Frank

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied