Post Reply 
Date Functions
05-08-2014, 12:49 PM (This post was last modified: 05-08-2014 12:50 PM by Thomas_Sch.)
Post: #1
Date Functions
for missing date functions have a look at
http://forum.hp-prime.de/discussion/100/...ime#Item_7
"Datumsfunktionen für HP Prime" by Wolfgang, (in german)
Find all posts by this user
Quote this message in a reply
09-19-2014, 05:55 PM (This post was last modified: 09-19-2014 07:53 PM by Wolfgang.)
Post: #2
RE: Date Functions
Here the Date functions.


Wolfgang

I'm very sorry: you'll need this too: DF.TXT
1st please compile DF, 2nd compile DTFX
Wolfgang


Attached File(s)
.txt  DTFX.txt (Size: 14.49 KB / Downloads: 86)
.txt  DF.txt (Size: 1.21 KB / Downloads: 59)

HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more
Find all posts by this user
Quote this message in a reply
01-14-2015, 10:17 PM
Post: #3
RE: Date Functions
Here is a newer 'all in one' programm hull

Code:

#pragma mode( separator(.,;) integer(h32) )
//
//________________________________________________________________________________​__________ 
// AUTHOR: Wolfgang Kühn, Berlin, June 2014
// Version 1.2
// DFX is a multi functions program for HP PRIME simulating
// the HP50g's date functions DDAYS and Date+ (HP Prime = DPLUS).
// In addition there are further functions like JDN, N2J, DOW, CALD, DOE.
// DFX functions are designed to CALL THEM FROM CAS and HOME ENVIRONMENT,
// and via choosing prog functions with Softmenu-keys DTM!
// Caution: DESIGN of INPUT-SCREENS is bad.
// Algorithms and formulas are astronomical basics found in sources like
// - General Astronomy, H.Spencer Jones, London 1924
// - Berechnungsgrundlagen für Amateurastronomen, Otto Praxl or
// - Astronomical Algorithms, Jean Meeus or
// - Practical Astronomy with your Calculator, Duffet-Smith and Zwart,
// ...and others.....
//   New:   extended range for date now from January,1,-4712 to December,31,99999 
//      6 output date display formats triggered by user selectable global variable
//      2 input date display formats,
//      input check
// any errors, questions, hints,
// mailto: Wolfgang Kuehn <wolfgang.kuehn@vodafone.de>
//________________________________________________________________________________​_________
//
//
//________________________________________________________________________________​_________ 
// AUTHOR: Wolfgang Kühn, Berlin, April 2014
// Version 1.1
// DF is a program for HP PRIME setting the system variable for 
// triggering the Date I/O Format
//                        DFT
// D.MY                 I/O,   Standard,   e.g.    21.062014   
// D.MY  day number      O                        "21.062014  6"  
// D.MY  day text        O                        "21.062014 SAT" 
//
// M.DY  day number      O                         6.212014      
// M.DY  day number      O                        "6.212014  6"   
// M.DY  day text        O                        "6.212014  SAT"   
//
// Y.MD  day number      O                         2014.0621   
// Y.MD  day number      O                        "2014.0621  6"   
// Y.MD  day text        O                        "2014.0621  SAT"  
//________________________________________________________________________________​________
//
//
EXPORT DFT;
EXPORT DF()
BEGIN
CHOOSE(
DFT, "date format",
"D.MY",
"D.MY  day number",
"D.MY  day text",
"M.DY",
"M.DY  day number",
"M.DY  day text",
"Y.MD",
"Y.MD  day number",
"Y.MD  day text"
);
RETURN DFT;
END;
//________________________________________________________________________________​_________
//
//
//
//________________________________________________________________________________​_________
// JDN (Julian Date Number) Function for HP Prime
// Version 0.95, April 2014
// Wolfgang Kuehn <wolfgang.kuehn@vodafone.de>
// 
// Julian Date Number: Returns the Julian Date Number of an calendaric date 
// Range of allowable dates is from October, 15, 1582 to December 31, 9999
// CAS & Home @ algebraic and textbook mode: JDN(D,M,Y)
// example1 JDN(1,1,2000) returns 2451545
// example2 JDN(17,3,2014) returns 2456734
// example3 JDN(17,3,2014) - JDN(1,1,2000) returns 5189
// CAUTION: @this version there is no recycling of input errors

EXPORT JDN(D, M, Y)
BEGIN
   IF M <3 THEN
         RETURN FLOOR(365.25*(Y-1))+FLOOR(30.6001*(M+13))+FLOOR(((Y-1)/400))-FLOOR(((Y-1)/100))+1720997+D;
   ELSE
         RETURN FLOOR(365.25*Y)+FLOOR(30.6001*(M+1))+FLOOR((Y/400))-FLOOR((Y/100))+1720997+D;
         END;
END;
//________________________________________________________________________________​________________
//
//
//
//________________________________________________________________________________​________________
// N2J (Number Date to Julian Date Number) 
// Version 0.96, April 2014
// Wolfgang Kuehn <wolfgang.kuehn@vodafone.de>
// 
// Number Date to JDN: Returns the Julian Date Number of an calendaric number date 
// Range of allowable dates is from January 1, -4712 to December 31, 9999
// CAS & Home @ algebraic and textbook mode: N2J([-]dd.mmyyyy)
// negative number date means B.C. !!
// Example 1 N2J(14.052004) returns 2453140
// Example 2 N2J(1.012000) returns  2451545 
// Example 3 N2J(17.032014)-N2J(1,012) returns 5189
// Example 4 N2J(4.101582) returns 2299160
// Example 5 N2J(15.101582) returns 2299161
// Example 6 N2J(-1.014712) returns 0
// Note: @this version some input errors (e.g. limits of range) are checked
//
EXPORT N2J(nd)
BEGIN
LOCAL D,M,Y;

// nd in forbidden range
   CASE
      IF nd= 5.101582 THEN MSGBOX("Date between 5.101582 and 14.101582 not allowed, sorry!"); KILL;END;
      IF nd= 6.101582 THEN MSGBOX("Date between 5.101582 and 14.101582 not allowed, sorry!"); KILL;END;
      IF nd= 7.101582 THEN MSGBOX("Date between 5.101582 and 14.101582 not allowed, sorry!"); KILL;END;
      IF nd= 8.101582 THEN MSGBOX("Date between 5.101582 and 14.101582 not allowed, sorry!"); KILL;END;
      IF nd= 9.101582 THEN MSGBOX("Date between 5.101582 and 14.101582 not allowed, sorry!"); KILL;END;
      IF nd= 10.101582 THEN MSGBOX("Date between 5.101582 and 14.101582 not allowed, sorry!");KILL;END;
      IF nd= 11.101582 THEN MSGBOX("Date between 5.101582 and 14.101582 not allowed, sorry!");KILL;END;
      IF nd= 12.101582 THEN MSGBOX("Date between 5.101582 and 14.101582 not allowed, sorry!");KILL;END;
      IF nd= 13.101582 THEN MSGBOX("Date between 5.101582 and 14.101582 not allowed, sorry!");KILL;END;
      IF nd= 14.101582 THEN MSGBOX("Date between 5.101582 and 14.101582 not allowed, sorry!");KILL;END;
   END;
//
// nd is B.C.
//
   IF nd < 0 THEN
   nd:=nd*-1;
   D:=IP(nd);
   M:=IP(((nd-D)*100));
   Y:=((FP(((nd-D)*100))*10000)*-1);
         IF M <3 THEN
            RETURN FLOOR(365.25*(Y-1))+FLOOR(30.6001*(M+13))+(-2)+1720997+D;
         ELSE
            RETURN FLOOR(365.25*Y)+FLOOR(30.6001*(M+1))+(-2)+1720997+D;
         END;
      ELSE
// CASE nd is positive
   D:=IP(nd);
   M:=IP(((nd-D)*100));
    Y:=(FP(((nd-D)*100))*10000);
// Date < 15.10.1582
      IF JDN(D,M,Y) <2299161 THEN
            IF M <3 THEN
            RETURN FLOOR(365.25*(Y-1))+FLOOR(30.6001*(M+13))+(-2)+1720997+D;
            ELSE
            RETURN FLOOR(365.25*Y)+FLOOR(30.6001*(M+1))+(-2)+1720997+D;
            END;
// Date >15.10.1582 positive
         ELSE
            IF M <3 THEN
            RETURN FLOOR(365.25*(Y-1))+FLOOR(30.6001*(M+13))+FLOOR(((Y-1)/400))-FLOOR(((Y-1)/100))+1720997+D;
         ELSE
            RETURN FLOOR(365.25*Y)+FLOOR(30.6001*(M+1))+FLOOR((Y/400))-FLOOR((Y/100))+1720997+D;      
            END;
         END;
      END;
END;
//________________________________________________________________________________​______________________________
//
//
//
//________________________________________________________________________________​______________________________
// DOW Function (Day of Week) for HP Prime
// Version 0.96, April 2014
// Wolfgang Kuehn <wolfgang.kuehn@vodafone.de>
// 
// DOW Function: Returns the day of a week from 1(=Monday) to 7(=Sunday)
// CAS & Home @ algebraic and textbook mode: DOW(dd.mmyyyy)
// example1 DOW(5.042014) returns [6 (=Saturday)] "SAT"
// example2 DOW(8.051945) returns [2 (=Tuesday)] "TUE"
// 
//________________________________________________________________________________​______________________________
// 
EXPORT DOW(edn)
BEGIN
LOCAL tag;
tag:=FLOOR(N2J(edn)MOD7)+1;
IF DFT = 2 THEN RETURN tag;END;
IF DFT = 5 THEN RETURN tag;END;
CASE
    IF tag = 1 THEN RETURN "MON"; END;
    IF tag = 2 THEN RETURN "TUE"; END;
    IF tag = 3 THEN RETURN "WED"; END;
    IF tag = 4 THEN RETURN "THU"; END;
    IF tag = 5 THEN RETURN "FRI"; END;
    IF tag = 6 THEN RETURN "SAT"; END;
    IF tag = 7 THEN RETURN "SUN"; END;
END;
END;
//________________________________________________________________________________​___________________________
//
//
//
//________________________________________________________________________________​____________________________
// CALD (Calendaric Date) Function for HP Prime
// Version 0.95, April 2014
// Wolfgang Kuehn <wolfgang.kuehn@vodafone.de>
// 
// CALD Function: Returns the calendaric date of a Julian Date Number
// Range of allowable JDN'S is from January,1,-4712 (JDN=0) to December 31, 9999 (JDN=5373484)
//
// CAS & Home @ algebraic and textbook mode: CALD(jdn)
// RPN mode: jdn >ENTER< CALD >ENTER<
//
// example1 CALD(2456737) returns 20.032014      HP50g european format DD.MMYYYY
// example2 CALD(2456737) returns 3.202014       HP50g american format MM.DDYYYY
// example3 CALD(2456737) returns 20,3,2014 THU  advanced HP12C Format i.o. weekdaynumber-->weekday
//
// negative:   example 4a HP50g:               CALD(2451545) returns   1.012 
// better:      example 4b advanced HP12C form:      CALD(2451545) returns   "1,1,2000 SAT"  
// + + + + + + + + + Standard Return Date Format is DD.MMYYYY + + + + + + + + + 
//-------------------------------------------------------------------------------------------------------

EXPORT CALD(jdn)
BEGIN
LOCAL a,b,c,d,e,f;
LOCAL D,M,Y;
LOCAL edn;
IF jdn>5373484
            THEN MSGBOX("jdn > 5373484, sorry!");
            KILL;END;
IF jdn<0
            THEN MSGBOX("jdn < 0, sorry!");
            KILL;END;
   IF jdn<2299161 
   THEN
      a:= FLOOR(jdn+0.5);
      c:= a+1524.0;
      d:= FLOOR(((c-122.1)/365.25));
      e:= FLOOR(365.25*d);
      f:= FLOOR(((c-e)/30.6001));
      D:=c-e-(FLOOR(30.6001*f));
      M:=f-1-(12*FLOOR(f/14));
      Y:=d-4715-FLOOR((7+M)/10);
         IF jdn<1721058
                 THEN 
                 edn:=-1*(D+M/100+((Y*-1)/1000000));
         CASE
      IF DFT = 0 THEN RETURN edn; END;
      IF DFT > 6 THEN RETURN edn; END;
                    IF DFT = 1 THEN RETURN edn; END;
                    IF DFT = 2 THEN RETURN edn+" "+DOW(edn);END;
                    IF DFT = 3 THEN RETURN edn+" "+DOW(edn);END;
                    IF DFT = 4 THEN RETURN -1*(M+D/100+((Y*-1)/1000000)); END;
                    IF DFT = 5 THEN RETURN -1*(M+D/100+((Y*-1)/1000000))+"  "+DOW(edn);END;
                    IF DFT = 6 THEN RETURN -1*(M+D/100+((Y*-1)/1000000))+" "+DOW(edn);END;
            END;END;
         edn:=D+M/100+Y/1000000;
         CASE
               IF DFT = 0 THEN RETURN edn; END;
      IF DFT > 6 THEN RETURN edn; END;
                    IF DFT = 1 THEN RETURN edn; END;
                    IF DFT = 2 THEN RETURN edn+" "+DOW(edn);END;
                    IF DFT = 3 THEN RETURN edn+" "+DOW(edn);END;
                    IF DFT = 4 THEN RETURN M+D/100+Y/1000000; END;
                    IF DFT = 5 THEN RETURN M+D/100+Y/1000000+"  "+DOW(edn);END;
                    IF DFT = 6 THEN RETURN M+D/100+Y/1000000+" "+DOW(edn);END;
           END;END;
   
         a:= FLOOR(jdn+0.5);
         b:= FLOOR((a-1867216.25)/36524.25);
         c:= a+b-(FLOOR(b/4))+1525;
         d:= FLOOR(((c-122.1)/365.25));
         e:= FLOOR(365.25*d);
         f:= FLOOR(((c-e)/30.6001));
         D:=c-e-(FLOOR(30.6001*f));
         M:=f-1-(12*FLOOR(f/14));
         Y:=d-4715-FLOOR((7+M)/10);
         edn:=D+M/100+Y/1000000;
            CASE
      IF DFT = 0 THEN RETURN edn; END;
      IF DFT >6 THEN RETURN edn; END;
      IF DFT = 1 THEN RETURN edn; END;
      IF DFT = 2 THEN RETURN edn+" "+DOW(edn);END;
      IF DFT = 3 THEN RETURN edn+" "+DOW(edn);END;
      IF DFT = 4 THEN RETURN M+D/100+Y/1000000;END;
      IF DFT = 5 THEN RETURN M+D/100+Y/1000000+"  "+DOW(edn);END;
      IF DFT = 6 THEN RETURN M+D/100+Y/1000000+" "+DOW(edn);END;
            END;
         END;
//________________________________________________________________________________​_________________________________
//
//
//
//________________________________________________________________________________​_________________________________
//
// DDAYS Function for HP Prime
// Version 0.96, April 2014
// Wolfgang Kuehn <wolfgang.kuehn@vodafone.de>
// 
// Delta Days Function: Returns the number of days between two dates
// Caution: Change according to HP 50g, WP 34s:
// If the 1st date (edn1) is chronologically later the result is negative
// 
// Range of allowable dates is from January 1, -4712 to December 31,9999
// CAS & Home @ algebraic and textbook mode: DDAYS(edn1,edn2)
// example1 DDAYS(1.012,17.032014)      returns 5189
// example2 DDAYS(14.101962,1.061926)   returns -13284
// example3 DDAYS(15.101582,4.101582)   returns -1
// example4 DDAYS(1.012014,1.010)       returns -735601
// example5 DDAYS(1.010,-31.120001)       returns -1
// example6 DDAYS(-1.014712,-31.124711) returns 730    
// example7 DDAYS(-1.014712,31.129999)  returns 5373484
//________________________________________________________________________________​_________________________________
//
EXPORT DDAYS(edn1, edn2)
BEGIN
LOCAL xdays;
xdays:=N2J(edn2)-N2J(edn1);
RETURN xdays;
END;
//________________________________________________________________________________​_________________________________
//
//
//
//________________________________________________________________________________​_________________________________
// DPLUS(HP 50g: DATE+) Function (Date Addition Command) for HP Prime
// Version 0.96, April 2014
// Wolfgang Kuehn <wolfgang.kuehn@vodafone.de>
// 
// DPLUS Function: Returns a future or past date, given a date and a number of days
// Range of allowable dates is from October, 15, 1582 to December 31, 9999
// CAS & Home @ algebraic and textbook mode: DPLUS(dd.mmyyyy,xdays)
//
// example1 DPLUS(1.012,5189)    returns 17.032014
// example2 DPLUS(14.101962,-13284)    returns 1.061926
// example3 DPLUS(-1,014712,1)    returns -2.014712
// example4 DPLUS(1.012014,7)    returns 8.014712
//++++++++++ Output: standard date form is dd.mmyyyy +++++++++++++++++++++
//
//________________________________________________________________________________​__________________________________
//
//
EXPORT DPLUS(edn,xdays)
BEGIN
RETURN CALD((N2J(edn)+xdays));
END;
//________________________________________________________________________________​___________________________________
//
//
//
//________________________________________________________________________________​____________________________________
// DOE (Date of Easter) 
// Version 0.99, June 2014
// modified gaussian function for calculus of date of easter
// TEXOUT_P instead of PRINT  
// Example 1 DOE(2004) returns
// Jahr: 2004
// Rosenmontag: 23.022004 MON
// Ostersonntag: 11.042004 SUN
// CHr.Himmelfahrt: 20.052004 THU
// Pfingsten: 30.052004 SON
// Fronleichnam: 10.062004 THU
EXPORT DOE(yoe)
BEGIN
// ROSMON -48
// CHRIHIM +39
// PFING +49
// FRONLEI +60
LOCAL ODAT,ROSMON,CHRIHIM,PFING,FRONLEI;
LOCAL a,b,c,d,e,f,g;
LOCAL h,i,k,l,m,n,p;
   a:=irem(yoe,19);
   b:=iquo(yoe,100);
   c:=irem(yoe,100);
   d:=iquo(b,4);
   e:=irem(b,4);
   f:=iquo(b+8,25);
   g:=iquo(b-f+1,3);
   h:=irem(19*a+b-d-g+15,30);
   i:=iquo(c,4);
   k:=irem(c,4);
   l:=irem(32+2*e+2*i-h-k,7);
   m:=iquo(a+11*h+22*l,451);
   n:=iquo(h+l-7*m+114,31);
   p:=irem(h+l-7*m+114,31)+1;
//
   ODAT:=CALD(JDN(p,n,yoe));
   ROSMON:=CALD(JDN(p,n,yoe)-48);
   CHRIHIM:=CALD(JDN(p,n,yoe)+39);
   PFING:=CALD(JDN(p,n,yoe)+49);
   FRONLEI:=CALD(JDN(p,n,yoe)+60);
//
//
RECT();
TEXTOUT_P("Jahr:",0,2,0);
TEXTOUT_P("Rosenmontag:",0,22,0);
TEXTOUT_P("Ostersonntag:",0,42,0);
TEXTOUT_P("Chr. Himmelf.:",0,62,0);
TEXTOUT_P("Pfingsten:",0,82,0);
TEXTOUT_P("Fronleichnam:",0,102,0);

TEXTOUT_P(yoe,120,2,0,#000000,130,#FFFFFF);
TEXTOUT_P(ROSMON,120,22,0,#000000,130,#FFFFFF);
TEXTOUT_P(ODAT,120,42,0,#000000,130,#FFFFFF);
TEXTOUT_P(CHRIHIM,120,62,0,#000000,130,#FFFFFF);
TEXTOUT_P(PFING,120,82,0,#000000,130,#FFFFFF);
TEXTOUT_P(FRONLEI,120,102,0,#000000,130,#FFFFFF);
WAIT(-1);
// RETURN ODAT;
END;
//
//
//
//________________________________________________________________________________​_____________________________
//
// DT2DN Date to Day Number
// nd numberdate (dd.mmyyyy), Leafyear y/n? (0 or 1)
// example DT2DN(29.112014,0) returns 333
// WMWK 2014-11-12
//
EXPORT DT2DN(nd,L)
BEGIN
LOCAL D,M;
   
   D:=IP(nd);
   M:=IP(((nd-D)*100));
//   Y:=((FP(((nd-D)*100))*10000));
CASE
      IF M <3 THEN RETURN IP((M-1)*(63-L)/2)+D;END;
      IF M >2 THEN RETURN  D+(IP((M+1)*30.6)-(63-L)); END;
END;
END;
//________________________________________________________________________________​_______________________________
//
// DMS(ddd.mmss)
// sexagesimal 2 decimal
EXPORT DMS(dms)
BEGIN
LOCAL D,M,S,t;
 D:=IP(dms);
 M:=IP(((dms-D)*100));
 S:=FP((dms-D)*100)*100;


IF D==0 THEN
t:=1; 
ELSE
t:=SIGN(D);
END;
RETURN (ABS(D)+ABS(M/60)+ABS(S/3600))*t;
END; 
//________________________________________________________________________________​________________________________
//
// HMS(ddd.dddd)
// decimal 2 sexagesimal 
EXPORT HMS(ddeg)
BEGIN
LOCAL H,M,S;
H:=IP(ddeg);
   M:=IP(((ddeg-H)*60));
    S:=(((ddeg-H)*60)-M)*60;
RETURN H+M/100+S/10000;
END; 
//________________________________________________________________________________​________________________________
//AN2J Astronomical Number date including time (UTC!) to Julian date
//look at N2J
//usage: AN2J(DD.MMYYYY,hh.mmss) 
// IMPORTANT: Enter time in degrees!
// Enter UTC!
//Example: AN2J(13.112014,18.2045) returns 2456975.26441 - decimal output
//
EXPORT AN2J(nd,tim)
BEGIN
RETURN N2J(nd)+(DMS(tim)/24)-0.5;
END;
//
//________________________________________________________________________________​________________________________
//
// AJ2N Astronomical Julian Date including time (UTC!) to Number date
//usage: AJ2N(Ajdn.xxxxxx) 
// IMPORTANT: Enter AJDN in UTC!
// Example: AJ2N(2456975.66594) returns {14.112014,6.5857} - time is sexagesimal output
EXPORT AJ2N(ajdn)
BEGIN
LOCAL jdn,tme;
tme:=FP(ajdn)+0.5;
jdn:=IP(ajdn+0.5);
RETURN {CALD(jdn), ROUND(HMS(tme*24) MOD 24,4)};
END;
//
//
//________________________________________________________________________________​_______________________________
// DFX Main Menu
// WMWK 2014-09-19
EXPORT DTM
BEGIN

LOCAL m,m1,mx,my,n2ja,dd1,dd2,dp1;
LOCAL dp2, doey;

While Z ≠ 9999 DO
WHILE MOUSE(1)≥0 DO END;
RECT();
TEXTOUT_P("Date & time functions for Hp Prime V 0.97",1,1,3);

DRAWMENU("n2j","ddays","date+","doe","time","exit");


REPEAT
m:=MOUSE;
m1:=m(1);
UNTIL SIZE(m1)>0;
mx:=m1(1);
my:=m1(2);

IF my≥220 AND my≤239 THEN

IF mx≥0 AND mx≤51 THEN
INPUT (n2ja,"Number date to Julian Date number","dd.mmyyyy =", "Enter number date");
TEXTOUT_P("JDN = ",32,51,3);
TEXTOUT_P(N2J(n2ja),89,51,3);
WAIT(-1);
END;

IF mx≥53 AND mx≤104 THEN
INPUT ({dd1,dd2}, "Difference between two dates in days",{"1st Date","2nd Date"}, {"dd.mmyyyy =", "dd.mmyyyy ="});

TEXTOUT_P("DDAYS: ",5,81,3);
TEXTOUT_P(N2J(dd2)-N2J(dd1),65,81,3);
WAIT(-1);
END;

IF mx≥106 AND mx≤157 THEN
INPUT ({dp1,dp2},"Date+",{"date","xdays"},{"dd.mmyyyy =", "number"});

TEXTOUT_P("New Date:",1,81,3);
TEXTOUT_P(CALD((N2J(dp1)+dp2)),80,81,3);
WAIT(-1);
END;

IF mx≥159 AND mx≤210 THEN
INPUT (doey,"Year of Easter= ", "Enter year");
TEXTOUT_P(DOE(doey),1,161,3);
RECT();
WAIT(-1);
END;

IF mx≥212 AND mx≤263 THEN
RECT(); 

TEXTOUT_P("HONULULU: ",0,2,0);
TEXTOUT_P("LOS ANGELES: ",0,20,0);
TEXTOUT_P("CHICAGO: ",0,40,0);
TEXTOUT_P("NEW YORK: ",0,60,0);
TEXTOUT_P("UTC: ",0,80,0,#FF0000);
TEXTOUT_P("LONDON: ",0,100,0);
TEXTOUT_P("BERLIN: ",0,120,0);
TEXTOUT_P("MOSKAU: ",0,140,0);
TEXTOUT_P("PEKING: ",0,160,0);
TEXTOUT_P("TOKIO: ",0,180,0);
TEXTOUT_P("SYDNEY: ",0,200,0);
TEXTOUT_P("WELLINGTON: ",0,220,0);
TEXTOUT_P("ENTER to quit",225,220,0);
REPEAT
TEXTOUT_P(((Time-12) MOD 24),110,2,0,#000000,90,#FFFFFF);
TEXTOUT_P(((Time-9) MOD 24),110,20,0,#000000,90,#FFFFFF);
TEXTOUT_P(((Time-7) MOD 24),110,40,0,#000000,90,#FFFFFF);
TEXTOUT_P(((Time-6) MOD 24),110,60,0,#000000,90,#FFFFFF);
TEXTOUT_P(((Time-2) MOD 24),110,80,0,#FF0000,90,#FFFFFF);
TEXTOUT_P(((Time-1) MOD 24),110,100,0,#000000,90,#FFFFFF);
TEXTOUT_P(((Time+0) MOD 24),110,120,0,#000000,90,#FFFFFF);
TEXTOUT_P(((Time+2) MOD 24),110,140,0,#000000,90,#FFFFFF);
TEXTOUT_P(((Time+6) MOD 24),110,160,0,#000000,90,#FFFFFF);
TEXTOUT_P(((Time+7) MOD 24),110,180,0,#000000,90,#FFFFFF);
TEXTOUT_P(((Time+8) MOD 24),110,200,0,#000000,90,#FFFFFF);
TEXTOUT_P(((Time+10) MOD 24),110,220,0,#000000,90,#FFFFFF);
WAIT(1);
UNTIL GETKEY=30;
END;

END;

IF mx≥265 AND mx≤319 THEN

KILL;
END;
END;
END;

[code][code]

HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more
Find all posts by this user
Quote this message in a reply
01-15-2015, 08:16 AM
Post: #4
RE: Date Functions
why is there a forbidden range in the dates?
Find all posts by this user
Quote this message in a reply
01-15-2015, 08:35 AM
Post: #5
RE: Date Functions
presumably because of the calendar refinement in 1582 by Pope Gregory XIII.
(http://en.wikipedia.org/wiki/Gregorian_calendar ;
http://en.wikipedia.org/wiki/Adoption_of...n_calendar )
Find all posts by this user
Quote this message in a reply
01-15-2015, 08:38 AM
Post: #6
RE: Date Functions
Thank you for this info.
Find all posts by this user
Quote this message in a reply
01-15-2015, 01:21 PM (This post was last modified: 01-15-2015 01:22 PM by Dieter.)
Post: #7
RE: Date Functions
(01-15-2015 08:16 AM)ww63 Wrote:  why is there a forbidden range in the dates?

Simple – because these dates did not exist. The switch from the former Julian to the current Gregorian calendar occured after Thursday, 4 Oct 1582 (last Julian date) which was immediately followed by Friday, 15 Oct 1582 (first Gregorian date). So the 10 days in between do not exist by definition.

On the other hand, some countries all over the world adopted the new calendar earlier, some later, some not before the 20th century. For instance, Great Britain and its colonies did not change before 1752, so in these parts of the world the old Julian calendar still existed and there actually was a, say, 5 Oct 1582.

Dieter
Find all posts by this user
Quote this message in a reply
01-15-2015, 03:35 PM
Post: #8
RE: Date Functions
@Thomas and Dieter:

Thank you two for explaining, I didn't enter this section of our forums yesterday!

There is a lot of a Calendar Systems:

http://en.wikipedia.org/wiki/Calendar
or
http://de.wikipedia.org/wiki/Liste_der_Kalendersysteme

HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more
Find all posts by this user
Quote this message in a reply
01-15-2015, 07:49 PM (This post was last modified: 01-16-2015 06:45 AM by Dieter.)
Post: #9
RE: Date Functions
(01-15-2015 03:35 PM)Wolfgang Wrote:  @Thomas and Dieter:

Thank you two for explaining, (...)

You're welcome. May I suggest a bit of streamlining of your program collection that would vastly reduce its size?

You could write a unified Julian day number routine that would handle all possible cases so that the same formula (the one with 365.25 and 30.6001) would not have to appear numerous times in slighty different versions. In the end all possible calculations boil down to conversions between day/month/year and Julian day numbers. Additional routines could split input (nd values) into day, month and year. What do you think?

Checking for invalid dates during the switchover period in October 1582 can be handled in various ways. The most straightforward way could be coded in PASCAL like this:
Code:
if (frac(nd)=0.101582) and (int(nd) >= 5) and (int(nd) <= 14) then
    (* your error handler here *)
    end;

The DT2DN (Date to Day Number) routine uses a special way of determining the day of year for a given date. Why don't you simply evaluate the difference between this date and 1 January (plus 1) ?-)

Finally, since the program uses English dialogues, English names for the Easter-related holidays would make sense. Maybe users from various parts of the world can say which Easter-related holidays are important to them, e.g. Pentecost, Ascension Thursday etc.

Dieter
Find all posts by this user
Quote this message in a reply
01-15-2015, 10:37 PM
Post: #10
RE: Date Functions
Hi Dieter,


thank you very much for having a look to my code and your good suggestions! You are right, its quick and dirty.....

O.T.:
30 Years ago i coded COBOL and ASSEMBLER and C on Mainframes.
And i saw, that smart coding after compiling often ran with lower speed....
and NO, i wasn't paid for each column......



The DT2DN routine is independent from the other routines.
The purposes of 'my' routines are:
Orbit, position, distance, sunrise, sunset, twilight, and so on... of the sun.
(Thats the reason for AN2J and AJ2N)..

For the equation of time (coming soon) there are many ways leading to rome, too.
....

I'm sorry about my bad english, in german i could it explain much better.

There is no problem to make an american version of Date of Easter including the appropriate names.

Next time i'll take a critical look to the code (next weeks).

Everybody is invited to help me in a constructively way like this!

Thank you!

HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more
Find all posts by this user
Quote this message in a reply
01-16-2015, 08:40 AM (This post was last modified: 01-16-2015 04:57 PM by Dieter.)
Post: #11
RE: Date Functions
(01-15-2015 10:37 PM)Wolfgang Wrote:  30 Years ago i coded COBOL and ASSEMBLER and C on Mainframes.

At that time I tried my first programs in PL/I. ;-) But I soon switched to Pascal – never looked back.

Quote:And i saw, that smart coding after compiling often ran with lower speed....

I think we can have both elegant, readable and fast code.

Quote:Next time i'll take a critical look to the code (next weeks).
Everybody is invited to help me in a constructively way like this!

Here is a first suggestion for the N2J routine. It handles dates between 1 Jan 4713 BC and 31 Dec 9999. Input between 5 and 14 Oct 1582 (undefined) is rejected.

Caution! I never wrote a single line of code for the Prime calculator, so the following code most probably will cause syntax errors and will not run without more or less significant modifications. I assume the Prime uses something similar to Pascal, so I tried it this way. ;-)

Code:
EXPORT N2J(nd)
BEGIN
LOCAL B,D,M,Y,YMD;

D:=IP(ABS(nd));
M:=IP(100*FP(ABS(nd)));
Y:=SIGN(nd)*IP(10000*FP(100*ABS(nd)));

YMD:=10000*Y+100*M+D; // build YYYYMMDD

IF YMD < 15821015 THEN     // Julian date?
   BEGIN
   IF YMD > 15821004 THEN MSGBOX("Invalid date (undefined)"); KILL; END;     // invalid date during Jul-Greg transition
   IF Y < -4712 THEN MSGBOX("Invalid date (< 1 Jan 4713 B.C.)"); KILL; END;  // invalid date < 1 Jan 4713 B.C.
   B:=0;                   // no offset for Julian date
   END
ELSE
   B:=2-IP(Y/100)+IP(Y/400);  // offset for Gregorian date
END;

IF M<3 THEN Y:=Y-1; M:=M+12;
RETURN IP(365.25*(Y+4716)) + IP(30.6*(M+1)) + D + B - 1524;

END;

This is not much more than half the original size, and I think it's far more readable. Maybe you can give it a try.

Dieter
Find all posts by this user
Quote this message in a reply
01-18-2015, 06:25 PM (This post was last modified: 01-18-2015 08:40 PM by Dieter.)
Post: #12
RE: Date Functions
(01-16-2015 08:40 AM)Dieter Wrote:  Here is a first suggestion for the N2J routine. It handles dates between 1 Jan 4713 BC and 31 Dec 9999. Input between 5 and 14 Oct 1582 (undefined) is rejected.

Finally for the record:
Here is the VBA function I use in Excel (where the built-in functions have a very limited working range and may even return wrong results):

Code:

Const LastJulian = 2299160   ' last Julian date = 04 Oct 1582
Const FirstGregorian = LastJulian + 11  ' first Gregorian date = 15 Oct 1582

Function Date2JD(d, m, y)

If m < 3 Then m = m + 12: y = y - 1
JD = (1461 * (y + 4716)) \ 4 + (153 * (m + 1)) \ 5 + d - 1524

If JD > LastJulian Then
   If JD < FirstGregorian Then
      JD = -1   ' error marker - undefined date within transition period
   Else
      JD = JD + 2 - y \ 100 + y \ 400
   End If
End If

Date2JD = JD

End Function

In VBA, the backslash "\" stands for integer division, like IDIV or INT÷ on some HP calculators or DIV in some programming languages. Undefined dates (during the Julian/Gregorian transition) or dates before 4713 B.C. return negative results. An additional line of code could call an error handler.

Please note that the Julian/Gregorian transition point can be individually adjusted by the constants in the initial two lines. LastJulian is the Julian day number of the last date of the Julian calendar (here: 4 Oct 1582 = JD 2299160), while FirstGregorian represents the first date according to the Gregorian calendar (here: +11 days = 15 Oct 1582). So if you want to reflect the situation in Great Britain and its colonies where they switched from Wed, 2 Sep to Thu, 14 Sep 1752, simply set LastJulian=2361221 and FirstGregorian=LastJulian+12.

Dieter
Find all posts by this user
Quote this message in a reply
01-19-2015, 04:47 PM
Post: #13
RE: Date Functions
Quote:At that time I tried my first programs in PL/I. ;-) But I soon switched to Pascal – never looked back.

You don't have to look back if you are using COBOL; it is imperative, procedural and, since 2002, object-oriented. COBOL is primarily used in business, finance, and administrative systems for companies and governments....
You can i.e. use both COBOL and ORACLE, to handle a lot of data records in business environments. PASCAL is for teaching students and solving technical or scientific utilization. I think, today you can choose the most suitable programming language from a great pool.


Quote:YMD:=10000*Y+100*M+D; // build YYYYMMDD
Very good idea!!
Such as handling transition points, i will try code it.

Thank u very much, dieter. Becaue of your prename, do you speak german? (PM).

HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more
Find all posts by this user
Quote this message in a reply
01-19-2015, 08:25 PM (This post was last modified: 01-19-2015 09:20 PM by Dieter.)
Post: #14
RE: Date Functions
(01-19-2015 04:47 PM)Wolfgang Wrote:  You don't have to look back if you are using COBOL; it is imperative, procedural and, since 2002, object-oriented.

My last and only COBOL experience dates back to 1985. ;-)

(01-19-2015 04:47 PM)Wolfgang Wrote:  COBOL is primarily used in business, finance, and administrative systems for companies and governments....
You can i.e. use both COBOL and ORACLE, to handle a lot of data records in business environments. PASCAL is for teaching students and solving technical or scientific utilization.

I love PASCAL for its sheer elegance. I'm not a profossional programmer, I just love writing compact and elegant algorithms for mathematical applications. On the other hand I also like the challenges of more assembler-like languagues as they are used in classic HP RPN calculators. ;-)

(01-19-2015 04:47 PM)Wolfgang Wrote:  
Quote:YMD:=10000*Y+100*M+D; // build YYYYMMDD
Very good idea!!
Such as handling transition points, i will try code it.

There is a more elegant way that shines up in the last VBA example I posted. If the Julian day number is calculated anyway, you can also use it for comparing dates. The suggested version with a configurable transition point (via LastJulian and FirstGregorian) can be handled even simpler – like this:

Code:
Const LastJulian = 2299160           ' last Julian date = 04 Oct 1582

Function Date2JD(d, m, y)
If m < 3 Then m = m + 12: y = y - 1
JD = (1461 * (y + 4716)) \ 4 + (153 * (m + 1)) \ 5 + d - 1524
If JD > LastJulian Then              ' Gregorian date?
   JD = JD + 2 - y \ 100 + y \ 400   ' then adjust JD 
   If JD <= LastJulian Then JD = -1  ' error marker - undefined date within transition period
End If
Date2JD = JD
End Function

This version needs just one constant (LastJulian = Julian day number of the last date of the Julian calendar, here 2299160 = 4 Oct 1582). If the calculated JDN (according to the Julian calendar) is greater than this limit (i.e. the date belongs to the Gregorian period), it gets the Gregorian adjustment. If the new Gregorian JDN now is ≤ LastJulian, the entered date was within the transition period (here 5...14 Oct 1582) and thus is undefined.

(01-19-2015 04:47 PM)Wolfgang Wrote:  Thank u very much, dieter. Becaue of your prename, do you speak german? (PM).

You bet / aber klar doch. :-)
There is a substantial number of German speaking contributors here. But of course this is an international forum, so they all resort to today's lingua franca. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
04-09-2015, 03:03 PM
Post: #15
RE: Date Functions
(01-15-2015 10:37 PM)Wolfgang Wrote:  The DT2DN routine is independent from the other routines.
The purposes of 'my' routines are:
Orbit, position, distance, sunrise, sunset, twilight, and so on... of the sun.
...

hi Wolfgang,
I'm using the "all in one" program in post #3 and it's very impressive!
Thank you for sharing.
I'm searching also just for sunrise, sunset, twilight, effemeridi of sun and moon (other planets also?)...

Then, you should think to give an option to calc DDAYS with an option: to calculate with and without the "holidays days" included (like the banks sometimes require)...

Danke, ciao Smile
Salvo

∫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
04-10-2015, 06:38 PM
Post: #16
RE: Date Functions
Hi Salvo,

i'm very sorry about my late responding!

Thank you very much for using my date functions 'lib'!

I'm searching also just for sunrise, sunset, twilight, effemeridi of sun and moon (other planets also?)... ------> For Sun the algorithms are completed and i have only to code it.

DDAYS ---> holidays: Do you mean a single block like ferragosto in the middle of august?

Wolfgang

HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more
Find all posts by this user
Quote this message in a reply
04-10-2015, 07:27 PM
Post: #17
RE: Date Functions
(04-10-2015 06:38 PM)Wolfgang Wrote:  For Sun the algorithms are completed and i have only to code it.

DDAYS ---> holidays: Do you mean a single block like ferragosto in the middle of august?

hi,
I mean this and also to calculate the time without sundays and saturdays: time between minus Sun, Sat, Holidays (the most important, but I know that they are Country-related, like "Ferragosto" in Italy or Independence Day and so on...).

For Sun ok!
Also Moon Phases could make the Prime a companion of "little astronomer" Smile

ciao
Salvo

∫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
04-13-2015, 10:03 PM
Post: #18
RE: Date Functions
Hi Salvo,

please give me hyperlinks to real examples of excluding weekends or holidays for calculating credits. I did not find those kinds of charging interests in the WWW.


Moon (and planets and all others like DFX3):

My programs are programmed during rare free time sections [for HP Prime] and are for free and so there is for me - look @ Surefire - no hastle guarantee! - for further upgrades. BUT: You are all invited to improve my codes!

But if you can wait til this year: My personal roadmap will proceed this & more this year.

I like responds via PM.

Greetings Wolfgang

HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more
Find all posts by this user
Quote this message in a reply
04-13-2015, 10:17 PM
Post: #19
RE: Date Functions
(04-13-2015 10:03 PM)Wolfgang Wrote:  Hi Salvo,

please give me hyperlinks to real examples of excluding weekends or holidays for calculating credits. I did not find those kinds of charging interests in the WWW.
hi Wolfgang,
for now I found some ideas here or here...
(I "googled" "days interval holidays")...

Quote:Moon (and planets and all others like DFX3):

My programs are programmed during rare free time sections [for HP Prime] and are for free and so there is for me - look @ Surefire - no hastle guarantee! - for further upgrades. BUT: You are all invited to improve my codes!
But if you can wait til this year: My personal roadmap will proceed this & more this year.
I can wait, sure Smile
I can also try to test your code, hoping to improve it, if needed, but sure it's already good enough Smile

Have a nice day!

Salvo

∫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
04-13-2015, 10:50 PM
Post: #20
RE: Date Functions
Hi Salvo,

thank you very much for hyperlinking!

But (i have no anticipation):
This is real for charging interests?

Very interesting!


:-)

Tanti saluti da Berlino

Wolfgang

HP 33C 34C 11C 41CX 12C 15C HP71B 35s 50g Prime Rev. A, C, D. DM 41X, 42. TI 58C, 59, 74, 92-II, Voyage 200, nspire CX II-T, Sanyo ICC 82D and more
Find all posts by this user
Quote this message in a reply
Post Reply 




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