Epoch time conversion

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: https://technical.swissmicros.com/decoders/dm42/

You can then copy/paste the listing and post it in "code" tags.
User avatar
salvomic
Posts: 186
Joined: Sat Dec 30, 2017 10:09 am
Location: Ragusa, Sicily
Contact:

Re: Epoch time conversion

Post by salvomic »

whuyse wrote:
Thu Oct 08, 2020 12:24 pm
No, I said "step 18 onwards", so:

Code: Select all

18 3600
19 STO 00
20 1.01197
21 STO 01
22 86400
23 STO 02
24 SF 27
Werner
ah, ok.
Simply I put a short menu before the initial lines of the original program, that was:

Code: Select all

01 LBL "EPOCH"
02    3600   
03 STO 00
04  1.01197  
05 STO 01
06 86400    
07 STO 02
08 SF 27
I wonder why, after a few calculation with Statistic and Matrix (resetting registers and statistic), the value 1.01197 wasn't stored in 01 apparently causing the misfunctioning.
Maybe I've too many programs loaded in DM42 :-)

Salvo
∫aL√0mic (IT9CLU) :: DM42 (SN: 00881), DM41X (SN 00523), DM16, HP Prime, 50g, 41CX, 42s, 71b, 15C, 12C, 35s, WP34s -- Free42
User avatar
salvomic
Posts: 186
Joined: Sat Dec 30, 2017 10:09 am
Location: Ragusa, Sicily
Contact:

Re: Epoch time conversion

Post by salvomic »

I have installed the last firmware (3.20) just now. Ok.
After that, the Epoch program showed the message "Invalid data" and I had to store manually the three values (3600, 1.01197, 86400 in STO 00, 01, 02) as the program couldn't do it by itself.
Surely I'm wrong in something. But: where? :)

Salvo

EDIT: I think to have found the solution, putting the storage of registers first of the Menu routine, so 00, 01, 02 registers are now actually initialised.
the new code (updated in the first post):

Code: Select all

00 { 139-Byte Prgm }
01▸LBL "EPOCH"
02 3600
03 STO 00
04 1.01197
05 STO 01
06 86400
07 STO 02
08 SF 27
09▸LBL H
10 "CUR"
11 KEY 1 XEQ A
12 "DT→E"
13 KEY 2 XEQ B
14 "E→DT"
15 KEY 3 XEQ C
16 KEY 9 GTO 99
17 MENU
18▸LBL 20
19 STOP
20 GTO 20
21▸LBL 99
22 CLMENU
23 EXITALL
24 RTN
25▸LBL A
26 DATE
27 TIME
28▸LBL B
29 X<>Y
30 RCL 01
31 X<>Y
32 DDAYS
33 RCL 02
34 ×
35 X<>Y
36 →HR
37 3600
38 ×
39 +
40 RCL 00
41 -
42 RTN
43▸LBL C
44 RCL 00
45 +
46 ENTER
47 ENTER
48 RCL 02
49 ÷
50 IP
51 RCL 01
52 X<>Y
53 DATE+
54 CLA
55 ADATE
56 AVIEW
57 PSE
58 X<>Y
59 RCL 02
60 MOD
61 3600
62 ÷
63 →HMS
64 CLA
65 ATIME
66 AVIEW
67 END
∫aL√0mic (IT9CLU) :: DM42 (SN: 00881), DM41X (SN 00523), DM16, HP Prime, 50g, 41CX, 42s, 71b, 15C, 12C, 35s, WP34s -- Free42
Thomas Okken
Posts: 1100
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: Epoch time conversion

Post by Thomas Okken »

The problem in your program as originally posted was that the initialization code, starting at line 18, was never executed, because it was unreachable.
User avatar
salvomic
Posts: 186
Joined: Sat Dec 30, 2017 10:09 am
Location: Ragusa, Sicily
Contact:

Re: Epoch time conversion

Post by salvomic »

Thomas Okken wrote:
Sat Oct 10, 2020 12:12 am
The problem in your program as originally posted was that the initialization code, starting at line 18, was never executed, because it was unreachable.
hi Thomas,
yes, you are right.
The new version corrects this problem, but it is still not perfect, there are other errors maybe: I should avoid to print the default values in the registers 00 01 02 first of executing the routine A.

Salvo
∫aL√0mic (IT9CLU) :: DM42 (SN: 00881), DM41X (SN 00523), DM16, HP Prime, 50g, 41CX, 42s, 71b, 15C, 12C, 35s, WP34s -- Free42
User avatar
craig
Posts: 5
Joined: Mon Mar 08, 2021 1:06 am
Location: Los Angeles, California
Contact:

Re: Epoch time conversion

Post by craig »

I made a couple of modifications to your program and it seems to be working okay:
- Displays the date and time on one line (requires a longer alpha than old 42s though).
- Loads from a global timezone variable the hour offset from UTC. (For instance, for me in America/Los_Angeles, it's -8 right now during standard time.) This helps give the correct epoch time even if your calculator isn't set to UTC time.
- Using YYYY-MM-DD date format.
- Did away with the constants stored in slots 00, 01, and 02 in favor of just using the constants inline.

Code: Select all

00 { 172-Byte Prgm }
01▸LBL "EPOCH"
02 CLMENU
03 SF 27
04 "CUR"
05 KEY 1 XEQ A
06 "DT→E"
07 KEY 2 XEQ B
08 "E→DT"
09 KEY 3 XEQ C
10 KEY 9 GTO 99
11 MENU
12▸LBL 20
13 STOP
14 GTO 20
15▸LBL 99
16 CLMENU
17 EXITALL
18 RTN
19▸LBL A
20 DATE
21 TIME
22▸LBL B
23 RCL "TIMEZON"
24 -
25 X<>Y
26 1970.0101
27 X<>Y
28 DDAYS
29 86400
30 ×
31 X<>Y
32 →HR
33 3600
34 ×
35 +
36 RTN
37▸LBL C
38 3600
39 RCL "TIMEZON"
40 ×
41 +
42 ENTER
43 ENTER
44 86400
45 ÷
46 IP
47 1970.0101
48 X<>Y
49 DATE+
50 CLA
51 ADATE
52 ├" "
53 X<>Y
54 86400
55 MOD
56 3600
57 ÷
58 →HMS
59 ATIME
60 AVIEW
61 END
Attachments
epoch.raw
(175 Bytes) Downloaded 120 times
Last edited by craig on Tue Mar 09, 2021 6:18 pm, edited 1 time in total.
User avatar
salvomic
Posts: 186
Joined: Sat Dec 30, 2017 10:09 am
Location: Ragusa, Sicily
Contact:

Re: Epoch time conversion

Post by salvomic »

craig wrote:
Tue Mar 09, 2021 5:18 am
I made a couple of modifications to your program and it seems to be working okay:
...
Well, thank you!
I'll try your version soon.

Salvo
∫aL√0mic (IT9CLU) :: DM42 (SN: 00881), DM41X (SN 00523), DM16, HP Prime, 50g, 41CX, 42s, 71b, 15C, 12C, 35s, WP34s -- Free42
User avatar
salvomic
Posts: 186
Joined: Sat Dec 30, 2017 10:09 am
Location: Ragusa, Sicily
Contact:

Re: Epoch time conversion

Post by salvomic »

craig wrote:
Tue Mar 09, 2021 5:18 am
I made a couple of modifications to your program and it seems to be working okay:
...
I'm trying in Free42 3.0.1.
I put 1 STO "TIMEZON" (Italy), then XEQ EPOCH and I get "Invalid data" for every three functions with my custom "date format"...

I'm not using YYYY-MM-DD but DD-MM-YYYY (normal here). Another improvement could be to permit using different modes for date.


Salvo
∫aL√0mic (IT9CLU) :: DM42 (SN: 00881), DM41X (SN 00523), DM16, HP Prime, 50g, 41CX, 42s, 71b, 15C, 12C, 35s, WP34s -- Free42
Post Reply