From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7f5b20ce91c7fdaf X-Google-Attributes: gid103376,public From: Gautier.DeMontmollin@maths.unine.ch (Gautier) Subject: Re: Julian Dates package? Date: 1997/01/09 Message-ID: <1997Jan9.114643.5493@news>#1/1 X-Deja-AN: 208679355 references: <32CFFA13.5BF8@ibm.net> <01bbfb55$c9dcbfe0$5e2d5c8b@jerryware> organization: University of Neuchatel, Switzerland reply-to: Gautier.deMontmollin@Maths.UniNe.CH newsgroups: comp.lang.ada Date: 1997-01-09T00:00:00+00:00 List-Id: In article <01bbfb55$c9dcbfe0$5e2d5c8b@jerryware>, "Jerry van Dijk" writes: > Jay Joiner wrote in article > <32CFFA13.5BF8@ibm.net>... > >> I am interested in doing a Biorythm calculator in Ada and I need an > Ada >> package that can take the difference between two dates (birthdate and >> today). > > I thought Julian dates were mainly used for astronomy and such ? > > Jerry. Julian dates are used for hydrological data and I guess many applications of this type, where cyclical phenomena do not depend of the existence of a 29 february in the year... Here is a "minimal" package, adapted from one of my toolbox in another language that works well, but not yet tested in Ada: ----------------------------------------------------------------------------- with Calendar; package Julian_Calendar is type Julian_time is record day,sec: Long_integer; end record; function Julian_time_of(t:Calendar.Time) return Julian_time; function Time_of(j:Julian_time) return Calendar.Time; end Julian_Calendar; ----------------------------------------------------------------------------- package body Julian_Calendar is use Calendar; function Time_of(j:Julian_time) return Time is IY: Year_Number; IM: Month_Number; ID: Day_Number; jules: Long_integer; BEGIN jules := j.day-1721119; IY:= Year_Number((4*jules-1) / 146097); jules := (4*jules-1) MOD 146097; ID := Day_Number(jules / 4); jules := Long_integer((4*ID+3) / 1461); ID := (4*ID+3) MOD 1461; ID := (ID+4) / 4; IM := (5*ID-3) / 153; -- month ID := (5*ID-3) MOD 153; ID := (ID+5) / 5 ; -- day IY := Year_Number(100*Long_integer(IY) + jules); -- year IF IM<10 THEN IM:=IM+3; ELSE IM:=IM-9; IY:=IY+1; END IF; return Calendar.Time_of(IY,IM,ID,Day_Duration(j.sec)); END; function Julian_time_of(t:Time) return Julian_time is IY: Year_Number; IM: Month_Number; ID: Day_Number; LY,LM,LD: Long_integer; S: Day_Duration; BEGIN Split(t, IY,IM,ID,S); LY:= Long_integer(IY); LM:= Long_integer(IM); LD:= Long_integer(ID); return (day=> (LM*3057) / 100 + LD + ((5-LM / 3) / 5) * (2 - (4 - LY MOD 4) / 4 + (100 - LY MOD 100) / 100 - (400 - LY MOD 400) / 400) + 1721028 + LY*365 + LY / 4 - LY / 100 + LY / 400, sec=> Long_integer(S)); END; end Julian_Calendar;