HP Forums
Date from DOY. (A.Pouplier) - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Date from DOY. (A.Pouplier) (/thread-2838.html)



Date from DOY. (A.Pouplier) - ggauny@live.fr - 01-11-2015 07:08 PM

Code:
(              1 D A T E _ D U _ D O Y     2  E X P O R T   D A T E _ D U _ D O Y ( N , A N ) 
 B E G I N 
 L O C A L   K : = 2 , M , J , J D , J U L : = 0 , C R ; 
 C A S E 
 I F   ( A N > 1 5 8 2 )   A N D   ( N O T ( A N   M O D   4 )   A N D   A N   M O D   1 0 0 )   
 O R   ( N O T ( A N   M O D   4 0 0 ) )   T H E N   K : = 1   E N D ; 
 
 I F   ( A N < 1 5 8 2 )   A N D   i r e m ( A N , 4 ) = = 0   T H E N 
         K : = 1 ; E N D ; 
 E N D ; 
 
 M : = I P [ ( 9 * ( K + N ) / 2 7 5 ) + . 9 8 ] ; 
 I F   N < 3 2   T H E N   1 ¶%M   E N D ; 
 J : = N - I P ( ( 2 7 5 * M ) / 9 ) + K * I P ( ( M + 9 ) / 1 2 ) + 3 0 ; 
 
 / / A : = I P ( A N / 1 0 0 ) ; C R : = 2 - A + I P ( A / 4 ) ; 
 
 / / I F ( A N + M / 1 0 0 + J / 1 0 0 0 0 ) < 1 5 8 2 . 1 0 1 4 5 
     / / T H E N   1 ¶%J U L ; 
 
 / / I F   J U L = = 1   T H E N   0 ¶%C R   E N D ; 
 / / J D : = I P ( 3 6 5 . 2 5 * ( A N + 4 7 1 6 ) ) + I P ( 3 0 . 6 0 0 1 * ( M + 1 ) ) 
         / / + J + C R - 1 5 2 4 . 5 ; 
 / / J D : = J D + 1 . 5 ; 
 / / J D : = i r e m ( J D , 7 ) ; 
 
   
 R E T U R N ( J + " / " + M + " / " + A N ) ; 
 
 
 E N D ;

For exemple : 291....0732 give 17/10/732 LEAP
290....0733 give 17/10/733

245....1948 give 1/9/1948 LEAP
244....1947 give 1/9/1947

Cheers


RE: Date from DOY. (A.Pouplier) - Marcus von Cube - 01-11-2015 08:15 PM

You somehow messed up the code. How did you paste it into the forum?


RE: Date from DOY. (A.Pouplier) - danielmewes - 01-12-2015 02:11 AM

This looks like UTF-16.
Maybe try pasting it into another editor first, like notepad or wordpad, and from there to the forum?


RE: Date from DOY. (A.Pouplier) - Wolfgang - 01-12-2015 02:57 PM

... And here is number date to day number...

@at this time i've about 15 date functions in one program, this and other will be published next time...

Wolfgang


Code:


// 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;

[code]
[code]



RE: Date from DOY. (A.Pouplier) - ggauny@live.fr - 01-12-2015 04:07 PM

(01-11-2015 08:15 PM)Marcus von Cube Wrote:  You somehow messed up the code. How did you paste it into the forum?

Hi, i have done as you me said. My code compressed in a zip.file, after i open
the file, it is marked xxx.hppgm. I open that file et copy it on #icon. Am i wrong ?


RE: Date from DOY. (A.Pouplier) - ggauny@live.fr - 01-12-2015 04:50 PM

(01-12-2015 02:57 PM)Wolfgang Wrote:  ... And here is number date to day number...

@at this time i've about 15 date functions in one program, this and other will be published next time...

Wolfgang


Code:


// 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;

[code]
[code]

Hi,
For me i use this code because all is automatic, leap year or not, grégorian or julian. I hope pasting will be correct, i discovery only the forum. [/code] 1 D O Y | E X P O R T D O Y ( D A T E )
B E G I N
L O C A L B : = 2 , A N , M , J ;
I P ( D A T E ) ¶%J ;
I P ( F P ( D A T E ) * 1 0 0 ) ¶%M ;
I P ( F P ( F P ( D A T E ) * 1 0 0 ) * 1 0 0 0 0 ) ¶%A N ;
/ / L E A P Y E A R ?
C A S E
I F ( N O T ( A N M O D 4 ) A N D A N M O D 1 0 0 )
O R ( N O T ( A N M O D 4 0 0 ) )
T H E N B : = 1 ; / / L E A P
E N D ;

I F A N < 1 5 8 2 A N D i r e m ( A N , 4 ) = = 0
T H E N B : = 1 ; / / L E A P
E N D ;
E N D ;

R E T U R N I P ( 2 7 5 * M / 9 ) - B * I P ( ( M + 9 ) / 1 2 ) + J - 3 0 ;
E N D ;
[code]


By the occasion, how doyou do to paste a code into forum.
Please explain step by step. Thank you.

Gérard.


RE: Date from DOY. (A.Pouplier) - Wolfgang - 01-12-2015 05:04 PM

Dear Gerard,

danke for your quick response with another code which is automatic detecting leaf year! Nice! I have to analyze it asap!

:-)


I use the sharp-code '#' - meaning "inserting formatted code" to the begin and twice to the end of my source. I don't know, if this action is the very correct doing. but it still works!

bonne soirée de Berlin
Wolfgang

edit: i use notepad++ , http://notepad-plus-plus.org/


RE: Date from DOY. (A.Pouplier) - Han - 01-12-2015 05:06 PM

I think what the other people are referring to is the additional space inserted between each character in your code. It may be a browser or text editor issue. For example, your code appears like this: w o r d. Normally, it should appear as: word (without spaces between w,o,r, and d).


RE: Date from DOY. (A.Pouplier) - Didier Lachieze - 01-12-2015 05:12 PM

(01-12-2015 04:50 PM)ggauny@live.fr Wrote:  By the occasion, how doyou do to paste a code into forum.
Please explain step by step. Thank you.

First open the Connectivity kit and the Prime Emulator or connect your physical Prime, select your program on the left, and then in the windows on the right you should see your code:

[Image: a0newp]

Then select your code and Copy it (Ctrl C or right click/Copy), go to your post in the forum and click on the "#" icon, this will open the Code tag :

[Image: a0newo]

Then Paste your code (Ctrl V or right click Paste), and click again on the "#" icon to close the Code tag:

[Image: a0nefb]

Click Preview Post to view the code:

[Image: a0newq]


RE: Date from DOY. (A.Pouplier) - ggauny@live.fr - 01-12-2015 05:44 PM

Code:
EXPORT DOY(DATE)
BEGIN
LOCAL B:=2,AN,M,J;
IP(DATE)▶J;
IP(FP(DATE)*100)▶M;
IP(FP(FP(DATE)*100)*10000)▶AN;
//LEAP YEAR ?
CASE
IF (NOT(AN MOD 4) AND AN MOD 100)
 OR(NOT(AN MOD 400))
  THEN B:=1; // LEAP
  END;

IF AN<1582 AND irem(AN,4)==0
   THEN B:=1; //LEAP
   END;
END;

RETURN IP(275*M/9)-B*IP((M+9)/12)+J-30;
END;

I thing i have finded a way to paste correctely codes, yes i hope...
Gérard.


RE: Date from DOY. (A.Pouplier) - ggauny@live.fr - 01-12-2015 05:54 PM

Hello,

I really thank you all for the help, with you i progress. My first hp was HP25 not C !
So i am not really "new in box" ! And my brain not too...

Thank you again Friends.
Gérard.


RE: Date from DOY. (A.Pouplier) - Marcus von Cube - 01-12-2015 07:58 PM

(01-12-2015 04:07 PM)ggauny@live.fr Wrote:  
(01-11-2015 08:15 PM)Marcus von Cube Wrote:  You somehow messed up the code. How did you paste it into the forum?

Hi, i have done as you me said. My code compressed in a zip.file, after i open
the file, it is marked xxx.hppgm. I open that file et copy it on #icon. Am i wrong ?

I was referring to the "Attach file" option of the forum where you can add a file to your post for downloading by other forum members. Only a few file formats are allowed here, amongst them ZIP. Just put everything you want to share in a ZIP archive and attach the file as is to your post.


RE: Date from DOY. (A.Pouplier) - ggauny@live.fr - 01-13-2015 12:07 PM

(01-12-2015 07:58 PM)Marcus von Cube Wrote:  
(01-12-2015 04:07 PM)ggauny@live.fr Wrote:  Hi, i have done as you me said. My code compressed in a zip.file, after i open
the file, it is marked xxx.hppgm. I open that file et copy it on #icon. Am i wrong ?

I was referring to the "Attach file" option of the forum where you can add a file to your post for downloading by other forum members. Only a few file formats are allowed here, amongst them ZIP. Just put everything you want to share in a ZIP archive and attach the file as is to your post.

Guten Tag,
Oh, Verzeihung ! Untschuldigen Sie, Jetzt Versteheich.
Bis bald. Viele liebe GrüBe.
Gérard.