Post Reply 
epoch Prime
01-06-2018, 08:53 AM (This post was last modified: 01-06-2018 09:29 AM by Dieter.)
Post: #19
RE: epoch Prime
(01-05-2018 11:26 PM)salvomic Wrote:  
Code:
EXPORT epoch2date(ep)
BEGIN
local dd, da, hh, mm, ss;
local yy, mt, dy;
dd:=ep/86400;
da:=DATEADD(1970.0101, IP(dd));
hh:=IP(24*FP(dd));
mm:=IP(60*FP(24*FP(dd)));
ss:=IP(60*FP(60*FP(24*FP(dd))));
yy:=IP(da);
mt:=IP(100*(FP(da)));
dy:=IP(100*FP(100*FP(da)));
RETURN({yy,mt,dy,hh,mm,ss});
END;

maybe it's redundant a lot...

Maybe. But first of all you generally should not calculate a mod b by means of b*fp(a/b). This causes roundoff errors. There is a mod command that handles this exactly.

And then you do not have to calculate hours, minutes and seconds manually. Your method also works with fp(ep/86400) which again causes roundoff errors. I assume the Prime has a command that converts decimal hours to h.ms.

I would code it this way (you'll have to translate this to PPL):

yr = IP(da)
mt = IP(100 * da) mod 100
dy = IP(10000 * da) mod 100

And the same way for the time given as hh.mmss:

hours = (ep mod 86400)/3600
hhmmss = hms(hours)
hh = IP(hhmmss)
mm = IP(100 * hhmmss) mod 100
ss = IP(10000 * hhmmss) mod 100

BTW, does the Prime have a command for integer division? Like "DIV" or "\" in other programming languages?

(01-05-2018 11:26 PM)salvomic Wrote:  How to make an optional parameter to input (or not) the time zone in epoch()?
I would like to make a versatile function that accept optional parameters:

This can be answered by the Prime experts. I only can say how this could be done in VBA where parameters can be declared "optional". ;-)

(01-05-2018 11:26 PM)salvomic Wrote:  Then I'll see to return for epoch2date both a "pretty formatted date" and a "calc date" as {2018.0105, 23,9721} for date and time.fractional...

You may return time and date according to ISO 8601: 2018-01-06T10:29:35+01:00

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
epoch Prime - salvomic - 01-05-2018, 05:00 PM
RE: epoch Prime - pier4r - 01-05-2018, 06:03 PM
RE: epoch Prime - Dieter - 01-05-2018, 07:30 PM
RE: epoch Prime - salvomic - 01-05-2018, 07:42 PM
RE: epoch Prime - Dieter - 01-05-2018, 07:51 PM
RE: epoch Prime - salvomic - 01-05-2018, 08:07 PM
RE: epoch Prime - Dieter - 01-05-2018, 08:47 PM
RE: epoch Prime - salvomic - 01-05-2018, 09:10 PM
RE: epoch Prime - Dieter - 01-05-2018, 09:27 PM
RE: epoch Prime - salvomic - 01-05-2018, 09:36 PM
RE: epoch Prime - Dieter - 01-05-2018, 10:07 PM
RE: epoch Prime - salvomic - 01-05-2018, 10:16 PM
RE: epoch Prime - Dieter - 01-05-2018, 10:48 PM
RE: epoch Prime - pier4r - 01-05-2018, 09:40 PM
RE: epoch Prime - salvomic - 01-05-2018, 09:44 PM
RE: epoch Prime - Dieter - 01-05-2018, 09:56 PM
RE: epoch Prime - salvomic - 01-05-2018, 06:17 PM
RE: epoch Prime - salvomic - 01-05-2018, 11:26 PM
RE: epoch Prime - Dieter - 01-06-2018 08:53 AM
RE: epoch Prime - salvomic - 01-06-2018, 09:28 AM
RE: epoch Prime - Dieter - 01-06-2018, 09:41 AM
RE: epoch Prime - Didier Lachieze - 01-06-2018, 09:50 AM
RE: epoch Prime - StephenG1CMZ - 01-06-2018, 09:40 AM
RE: epoch Prime - pier4r - 01-06-2018, 10:46 AM
RE: epoch Prime - Dieter - 01-06-2018, 12:42 PM
RE: epoch Prime - salvomic - 01-06-2018, 01:07 PM
RE: epoch Prime - salvomic - 01-06-2018, 02:45 PM
RE: epoch Prime - Dieter - 01-06-2018, 06:26 PM
RE: epoch Prime - StephenG1CMZ - 01-06-2018, 08:26 PM
RE: epoch Prime - Dieter - 01-06-2018, 08:37 PM
RE: epoch Prime - pier4r - 01-06-2018, 09:59 PM
RE: epoch Prime - salvomic - 01-06-2018, 10:07 PM
RE: epoch Prime - pier4r - 01-06-2018, 10:55 PM
RE: epoch Prime - pier4r - 01-06-2018, 03:28 PM
RE: epoch Prime - salvomic - 01-06-2018, 03:45 PM
RE: epoch Prime - salvomic - 01-06-2018, 04:10 PM
RE: epoch Prime - StephenG1CMZ - 01-06-2018, 06:54 PM
RE: epoch Prime - salvomic - 01-06-2018, 07:58 PM
RE: epoch Prime - salvomic - 01-06-2018, 08:45 PM
RE: epoch Prime - Dieter - 01-06-2018, 08:59 PM
RE: epoch Prime - salvomic - 01-06-2018, 09:01 PM
RE: epoch Prime - Dieter - 01-06-2018, 11:07 PM
RE: epoch Prime - StephenG1CMZ - 01-06-2018, 11:24 PM
RE: epoch Prime - salvomic - 01-07-2018, 09:26 AM
RE: epoch Prime - Dieter - 01-07-2018, 06:22 PM
RE: epoch Prime - salvomic - 01-07-2018, 06:28 PM



User(s) browsing this thread: 2 Guest(s)