Post Reply 
epoch Prime
01-06-2018, 03:45 PM (This post was last modified: 01-06-2018 04:16 PM by salvomic.)
Post: #29
RE: epoch Prime
(01-06-2018 03:28 PM)pier4r Wrote:  Little nitpick.

When one use constants, like 86400, at first it is ok to plaster them all over to get things done, but then (as you realized) a little typo may produce problems.

...

Edit: of course, I assume you are typing your programs from a computer with a real keyboard. If you type them on the prime or on a touchscreen, I understand completely the short variables and the limited comments.

yes, this last paragraph of your post is the real explanation of why most of us here use short vars and few comments...
I understand your thoughts and appreciate, however just now the program is still not finished, so the most important thing is if it works and how, then we can refactor variables and put in some other comments...
As I wrote in the first post, our goal is to make a program the more concise (and, if possible, as you wrote, the more user-friendly).

First of all we must solve some problems:
• to use less parameters (I mean reuse the parameters for date and time without "magic numbers" for the case in which the user wants to use the current date and time or he/she wants to input another date)
• to decide if it is important (or not so important) to give also "local time" epoch, or only (and always) GMT/UTC epoch (as it is now in the program).
• to decide if there is a reason to "complicate" the program, with calculation of leap seconds or other important considerations or not...

Salvo

EDIT:
as pier4r suggested, the version without "magic constants" it:
Code:

// Epoch Unix time from 1970 Jan 1. Inspired by a Bill Duncan's program for HP-41CX
// Thanks to Dieter, Didier Lachieze, Stephen G1CMZ, pier4r...

// Epoch seconds in UTC time
// Input: da = date (i.e. 2018.0523), ti = time (i.e. 13°15'30''), zone UTC (0 GMT)
// -1 as current date and current time
EXPORT epoch(da,ti, zone)
BEGIN
LOCAL sec_in_day:=86400;
LOCAL sec_in_hour:=3600;
LOCAL unix_epoch_start_time:=1970.0101;
IF da==-1 THEN da:=Date; END;
IF ti==-1 THEN ti:=Time; ELSE ti:=HMS→(ti); END;
ti:=ti-zone;
RETURN sec_in_day*(DDAYS(unix_epoch_start_time,da))+sec_in_hour*HMS→(ti);
END;

// Given an epoch and a time zone, the program returns date and time
EXPORT epoch2date(epoc, zone)
BEGIN
LOCAL sec_in_day:=86400;
LOCAL sec_in_hour:=3600;
LOCAL unix_epoch_start_time:=1970.0101;
local da, ti;
epoc:=epoc+sec_in_hour*zone;
da:=DATEADD(unix_epoch_start_time, IP(epoc/sec_in_day));
ti:=(epoc MOD sec_in_day)/sec_in_hour;
RETURN({da, →HMS(ti)});
END;

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website 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: 1 Guest(s)