Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Convert Unix to Localtime
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Convert Unix to Localtime

by powersoft on Mon Aug 31, 2020 11:29 am

I wont to convert a unixtimestamp to localtime in circuit python.
This is the simple code:

unix_correction = 946684800 # correct to 01-01-2000
timezone = 7200
t=1598887049

def convertUnixTime(t,timezone):
dummy=time.localtime(t-unix_correction+timezone)
return "%4d-%02d-%02d %02d:%02d" % (dummy[0],dummy[1],dummy[2],dummy[3],dummy[4])

Running it I get the error message:

"timestamp out of range for platform time_t"

could not found a solution for this problem (it is working well in micropython!)

thank for any help.
cheers,
Jan

powersoft
 
Posts: 46
Joined: Tue Aug 30, 2011 1:01 am

Re: Convert Unix to Localtime

by tannewt on Mon Aug 31, 2020 4:16 pm

This sounds like a bug! Would you mind filing an issue here: https://github.com/adafruit/circuitpython/issues ?

tannewt
 
Posts: 1784
Joined: Thu Oct 06, 2016 8:48 pm

Re: Convert Unix to Localtime

by powersoft on Tue Sep 01, 2020 6:10 am

Have send it the link

powersoft
 
Posts: 46
Joined: Tue Aug 30, 2011 1:01 am

Re: Convert Unix to Localtime

by tannewt on Tue Sep 01, 2020 7:28 pm

I saw the issue. Thank you! That will be a good first issue.

tannewt
 
Posts: 1784
Joined: Thu Oct 06, 2016 8:48 pm

Re: Convert Unix to Localtime

by powersoft on Wed Sep 02, 2020 7:36 am

How will this proceed?

powersoft
 
Posts: 46
Joined: Tue Aug 30, 2011 1:01 am

Re: Convert Unix to Localtime

by tannewt on Wed Sep 02, 2020 11:31 am

We won't be looking at fixing it immediately because we're currently working on other things.

I'm hoping someone will pick it up because it should be a simple fix. Would you like to give it a try?

The error is coming from here: https://github.com/adafruit/circuitpyth ... t__.c#L252

tannewt
 
Posts: 1784
Joined: Thu Oct 06, 2016 8:48 pm

Re: Convert Unix to Localtime

by powersoft on Thu Sep 03, 2020 4:37 am

Okee, I will give it a try.
Can You tel me where to find the source code of MicroPython. So I can compare the pieces of code.
I'm not a professional programmer so I will do my best to figure it out.

Cheers,
Jan

powersoft
 
Posts: 46
Joined: Tue Aug 30, 2011 1:01 am

Re: Convert Unix to Localtime

by tannewt on Thu Sep 03, 2020 2:14 pm

Awesome! Thank you. Our Discord is a great place to get help hacking on CircuitPython: https://adafru.it/discord

Looks like time.localtime is implemented in each MicroPython port. Here is a search for it: https://github.com/micropython/micropyt ... =localtime

tannewt
 
Posts: 1784
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.