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:

Epoch time conversion

Post by salvomic »

hi,
I've modified a program of Bill Duncan intended for HP 41CX to get Epoch Time from a date and convert Date/Time into Epoch Time.
In this post on MoHPC you can read the thread.
If you are interested, the version for HP Prime is in the Program Library MoHPC.

I've modified the program for DM42 and Free42 (not HP 42s, as it miss the date, as we know), adding a custom Menu:
[Cur] → Current Epoch time [DT→E] → Date and Time to Epoch [E→DT] → Epoch to Date and Time
The program set 3600 as Time Zone variables (Europe, -1), you can set your time/zone (i.e. -18000 as in the original Bill's program).
The code:

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
You can convert by yourself it in ".raw" with the SwissMicros tool. I include here a .raw already pretty for use.

Enjoy!

Salvo

EDIT 09 Oct 2020: changed the initial code, putting the initialisation of registers first of the Menu, otherwise they weren't initialised.
Attachments
Unix-epoch_3600.raw
(142 Bytes) Downloaded 151 times
20180209-23035508.jpg
20180209-23035508.jpg (32.18 KiB) Viewed 5751 times
Last edited by salvomic on Fri Oct 09, 2020 6:29 pm, edited 4 times in total.
∫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 »

the link https://www.swissmicros.com/dm42/decoder/ is now wrong, please, can you remind to me the correct one?
thanks
∫aL√0mic (IT9CLU) :: DM42 (SN: 00881), DM41X (SN 00523), DM16, HP Prime, 50g, 41CX, 42s, 71b, 15C, 12C, 35s, WP34s -- Free42
grsbanks
Posts: 1122
Joined: Tue Apr 25, 2017 11:23 am
Location: Preston, Lancs, UK
Contact:

Re: Epoch time conversion

Post by grsbanks »

There are only 10 kinds of people in the world: those who understand binary and those who do not.
User avatar
salvomic
Posts: 186
Joined: Sat Dec 30, 2017 10:09 am
Location: Ragusa, Sicily
Contact:

Re: Epoch time conversion

Post by salvomic »

grsbanks wrote:
Wed Oct 07, 2020 5:51 pm
Ciao Salvo,

viewtopic.php?f=2&t=2608
thank you for info!

I was too long absent from here :)
I'm come back slowly (I'm also waiting for DM41X, ordered today)...

However, my Epoch program by me works well in Free42 (iOS) but not in my DM42, as another program (Sort a matrix) use the LABEL "C" (then Epoch stops in that label), maybe I should rename the labels in Epoch program.
But... if I, e.g., rename Label A into Label "AA" I can see the AA item in the menu of XEQ...

Is there another way to solve? (already tried CF 21)

Salvo
∫aL√0mic (IT9CLU) :: DM42 (SN: 00881), DM41X (SN 00523), DM16, HP Prime, 50g, 41CX, 42s, 71b, 15C, 12C, 35s, WP34s -- Free42
whuyse
Posts: 197
Joined: Thu Dec 21, 2017 1:23 pm

Re: Epoch time conversion

Post by whuyse »

Labels A-J and a-e are local to a program, so you cannot do XEQ C in one and end up at the label C (without quotes, mind you) in another?
Cheers, Werner
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE, DM15L
Thomas Okken
Posts: 1098
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: Epoch time conversion

Post by Thomas Okken »

whuyse wrote:
Thu Oct 08, 2020 7:55 am
Labels A-J and a-e are local to a program, so you cannot do XEQ C in one and end up at the label C (without quotes, mind you) in another?
Cheers, Werner
Exactly. If it works in Free42, it should work in the DM42, and the labels should work fine. I'd make sure you didn't make a typo while entering the program.

Or you could use this program, which serves the same purpose but is a bit more Spartan: https://thomasokken.com/free42/42progs/unixtime.txt 8-)
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:
Thu Oct 08, 2020 8:45 am
whuyse wrote:
Thu Oct 08, 2020 7:55 am
Labels A-J and a-e are local to a program, so you cannot do XEQ C in one and end up at the label C (without quotes, mind you) in another?
Cheers, Werner
Exactly. If it works in Free42, it should work in the DM42, and the labels should work fine. I'd make sure you didn't make a typo while entering the program.

Or you could use this program, which serves the same purpose but is a bit more Spartan: https://thomasokken.com/free42/42progs/unixtime.txt 8-)
thanks both,
I know, but maybe there are some incompatibilities here.
Yesterday I made the program working. Today, after a matrices calculations, executing Epoch I get:
function A "Invalid data" and then X = 8.10202
function B "Invalid data"
function C "Divide by 0"

Strange workaround: if I input
1.01197 STO 01
it works.
But the program should do that automatically (see step 20 and 21)...

Salvo
∫aL√0mic (IT9CLU) :: DM42 (SN: 00881), DM41X (SN 00523), DM16, HP Prime, 50g, 41CX, 42s, 71b, 15C, 12C, 35s, WP34s -- Free42
whuyse
Posts: 197
Joined: Thu Dec 21, 2017 1:23 pm

Re: Epoch time conversion

Post by whuyse »

I can only go by the program you posted in your first post, and there, the initialisation (step 18 onwards) is after a RTN, and without a LBL so that is never executed?
Werner
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE, DM15L
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 11:22 am
I can only go by the program you posted in your first post, and there, the initialisation (step 18 onwards) is after a RTN, and without a LBL so that is never executed?
Werner
hi Werner,
do you mean this menu block?

Code: Select all

14▸LBL 99
15 CLMENU
16 EXITALL
17 RTN
That's the code when an user doesn't choose any of the three options, so that the program exit.
The real program after the menu starts at line 20, I believe...

Salvo
∫aL√0mic (IT9CLU) :: DM42 (SN: 00881), DM41X (SN 00523), DM16, HP Prime, 50g, 41CX, 42s, 71b, 15C, 12C, 35s, WP34s -- Free42
whuyse
Posts: 197
Joined: Thu Dec 21, 2017 1:23 pm

Re: Epoch time conversion

Post by whuyse »

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
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE, DM15L
Post Reply