comp.lang.ada
 help / color / mirror / Atom feed
From: Gautier.DeMontmollin@maths.unine.ch (Gautier)
Subject: Re: Julian Dates package?
Date: 1997/01/09
Date: 1997-01-09T00:00:00+00:00	[thread overview]
Message-ID: <1997Jan9.114643.5493@news> (raw)
In-Reply-To: 01bbfb55$c9dcbfe0$5e2d5c8b@jerryware


In article <01bbfb55$c9dcbfe0$5e2d5c8b@jerryware>, "Jerry van Dijk" <jvandyk@ibm.net> writes:
> Jay Joiner <jjoiner@ibm.net> 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;






  parent reply	other threads:[~1997-01-09  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-05  0:00 Julian Dates package? Jay Joiner
     [not found] ` <01bbfb55$c9dcbfe0$5e2d5c8b@jerryware>
1997-01-06  0:00   ` Mike Stark
1997-01-09  0:00   ` Gautier [this message]
1997-01-13  0:00     ` Michael & Amy Hartsough
1997-01-08  0:00 ` Fintan
1997-01-08  0:00 ` Keith Thompson
1997-01-08  0:00   ` Mike Stark
1997-01-08  0:00     ` Robert Dewar
1997-01-09  0:00 ` Mats Weber
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox