Simple routine for unix epoch time conversions using hp41 with time module (or 41CX et al). Useful if you're offline (on a train?) looking at log files..
Be sure to use a constant for reg 00 that is appropriate for your time zone and daylight savings time. (Seconds relative to GMT. Time zone given is Eastern Standard Time.)
Initialize constants by running start of program. Uses local labels in user mode.
"A" to get current epoch time.
Enter: Date [Enter] Time "B" to get epoch time for any given date/time.
The "C" routine will translate an epoch time to date/time values.
Test in user mode by pressing "A" then "C". This should get you the current date/time.
Cheers.
Code:
01 LBL "EPOCH"
02 18000 STO 00
04 1.01197 STO 01
06 86400 STO 02
08 SF 27
09 LBL A
10 DATE
11 TIME
12 LBL B
13 X<>Y
14 RCL 01
15 X<>Y
16 DDAYS
17 RCL 02
18 *
19 X<>Y
20 HR
21 3600
22 *
23 +
24 RCL 00
25 
26 RTN
27 LBL C
28 RCL 00
29 +
30 ENTER
31 ENTER
32 RCL 02
33 /
34 INT
35 RCL 01
36 X<>Y
37 DATE+
38 CLA
39 ADATE
40 AVIEW
41 PSE
42 X<>Y
43 RCL 02
44 MOD
45 3600
46 /
47 HMS
48 CLA
49 ATIME
50 AVIEW
51 END
For what machine(s)?
Appears to be for a 41, but could be others too...
Sorry, yes, HP41 with a time module (or 41cx etc.)
The Unix epoch time is the number of seconds past midnight, January 1st, 1970. Unlike real 32bit Unix/Linux (which will have problems in 2038 with signed int being 2^31 seconds), this should be good until the year 2286..
Note that the Time zone info for Register 00 is in seconds relative to GMT. The constant given is Eastern Standard time.
Should work in Free42 and DM42 as well.
Nice post! I have something like this in Free42 at work; very handy when dealing with logs that show raw Unix time stamps, debugging Unix C code, etc. I use it a lot but never thought to post it.
I've updated. Often all I want is the current epoch time, so I replaced the RTN after the setup into a "SF 27"; so now it falls through into the first routine. More useful I think.
Cheers, and Happy New Year.
(12312017 02:30 AM)Thomas Okken Wrote: [ > ]Should work in Free42 and DM42 as well.
...
Any help to encode in raw for Free42 (or DM42)?
I'm using the
SM encoder and I get this error "Invalid instruction ' 18000 STO 00' in line 01".
Thank you!
Salvo
(12312017 04:29 PM)salvomic Wrote: [ > ] (12312017 02:30 AM)Thomas Okken Wrote: [ > ]Should work in Free42 and DM42 as well.
...
Any help to encode in raw for Free42 (or DM42)?
I'm using the SM encoder and I get this error "Invalid instruction ' 18000 STO 00' in line 01".
Thank you!
Salvo
Look at the line number on the left, he just optimized it for the post
Code:
01 LBL "EPOCH"
02 18000
03 STO 00
04 1.01197
05 STO 01
06 86400
07 STO 02
08 SF 27
...
Thank you Bill for this nice routine and Happy New Year!
Sylvain
Yes, sorry Salvo.. I often put several lines of code on one line if I feel that it helps the clarity of the program. Obviously in this case it didn't, or I should've warned everyone anyway..
Cheers.
(12312017 04:36 PM)Sylvain Cote Wrote: [ > ]...
Look at the line number on the left, he just optimized it for the post
...
Thank you Bill for this nice routine and Happy New Year!
Sylvain
(12312017 05:17 PM)Bill Duncan Wrote: [ > ]Yes, sorry Salvo.. I often put several lines of code on one line if I feel that it helps the clarity of the program. Obviously in this case it didn't, or I should've warned everyone anyway..
Cheers.
Thank you Sylvain and Bill!
It worked deleting line numbers, as in this code:
Code:
LBL "EPOCH"
18000 STO 00
1.01197 STO 01
86400 STO 02
SF 27
LBL A
DATE
TIME
LBL B
X<>Y
RCL 01
X<>Y
DDAYS
RCL 02
*
X<>Y
HR
3600
*
+
RCL 00

RTN
LBL C
RCL 00
+
ENTER
ENTER
RCL 02
/
INT
RCL 01
X<>Y
DATE+
CLA
ADATE
AVIEW
PSE
X<>Y
RCL 02
MOD
3600
/
HMS
CLA
ATIME
AVIEW
END
I got the .raw for HP42/Free42 (DM42), that' this code:
Code:
00 { 94Byte Prgm }
01▸LBL "EPOCH"
02 18000
03 STO 00
04 1.01197
05 STO 01
06 86400
07 STO 02
08 SF 27
09▸LBL A
10 DATE
11 TIME
12▸LBL B
13 X<>Y
14 RCL 01
15 X<>Y
16 DDAYS
17 RCL 02
18 ×
19 X<>Y
20 →HR
21 3600
22 ×
23 +
24 RCL 00
25 
26 RTN
27▸LBL C
28 RCL 00
29 +
30 ENTER
31 ENTER
32 RCL 02
33 ÷
34 IP
35 RCL 01
36 X<>Y
37 DATE+
38 CLA
39 ADATE
40 AVIEW
41 PSE
42 X<>Y
43 RCL 02
44 MOD
45 3600
46 ÷
47 →HMS
48 CLA
49 ATIME
50 AVIEW
51 END
To use the attached file, delete the .txt extension.
I wonder how to simulate in Free42 the "user mode" (HP41CX) and A, B, C.
I'm testing it only executing XEQ "EPOCH" for now...
The raw is not good in the emulator i41CX however. Is there a tool to get raw files from text for HP41CX, like the tool by Swiss Micros?
Thank you,
HNY!
Salvo
I thought I'd try my hand in doing an HP48GX RPL version. Haven't used RPL for awhile, so excuse me if it isn't optimal..
The nice things about the RPL version is that it can test the depth of the stack (so use the current date/time if you haven't entered anything) and, of course it can display the entire date/time string on a single line..
>EPOCH
Code:
<<
DEPTH IF 2 < THEN
DATE TIME
END
> D T
<<
1.01197 D DDAYS
86400 *
T HMS>
3600 * + 18000 + IP
>>
>>
and..
EPOCH>
Code:
<<
18000  DUP
86400 / IP 1.01197 SWAP DATE+
SWAP 86400 MOD
3600 / >HMS
DUP2 TSTR CLLCD
7 DISP 7 FREEZE
>>
The last routine leaves the date and time in the stack as well as displaying the string.
As in the original version, 18000 is for EST (Eastern Standard Time) and is the number of seconds relative to GMT or UTC. I've put several instructions on a single line for clarity. You should be able to test one against the other by executing ">EPOCH" then translating back with "EPOCH>".
Hope these routines are useful to other unix/linux sysadmins..
Cheers.
(12312017 06:50 PM)salvomic Wrote: [ > ]I wonder how to simulate in Free42 the "user mode" (HP41CX) and A, B, C.
That was replaced by the CUSTOM menu.
You could alter "EPOCH" so that it not only sets up the constants used but also puts in place a custom menu.
(12312017 07:28 PM)grsbanks Wrote: [ > ]That was replaced by the CUSTOM menu.
You could alter "EPOCH" so that it not only sets up the constants used but also puts in place a custom menu.
Well, thank you.
I'll try it asap.
Salvo
2017 had a nice round number of 1,500,000,000 epoch seconds back on July 13th..
Happy 2018 everyone..
(01012018 06:26 AM)Bill Duncan Wrote: [ > ]2017 had a nice round number of 1,500,000,000 epoch seconds back on July 13th..
Happy 2018 everyone..
Indeed...
Happy New Year, Buon anno, Bonne et heureuse année!
Bill,
I've put
here the version for HP Prime.
Enjoy!
Salvo
hi,
I've modified the program for DM42 and Free42 (not HP 42s, as it miss the date), 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).
Code:
00 { 139Byte Prgm }
01▸LBL "EPOCH"
02▸LBL H
03 "CUR"
04 KEY 1 XEQ A
05 "DT→E"
06 KEY 2 XEQ B
07 "E→DT"
08 KEY 3 XEQ C
09 KEY 9 GTO 99
10 MENU
11▸LBL 20
12 STOP
13 GTO 20
14▸LBL 99
15 CLMENU
16 EXITALL
17 RTN
18 3600
19 STO 00
20 1.01197
21 STO 01
22 86400
23 STO 02
24 SF 27
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 obtain the ".raw" version using the
SwissMicros' tool.
Enjoy!