From: tmoran@bix.com
Subject: Re: Conversion to UNIX time
Date: 2000/07/20
Date: 2000-07-20T00:00:00+00:00 [thread overview]
Message-ID: <noxd5.305$5l.149364@news.pacbell.net> (raw)
In-Reply-To: u4s5lop1z.fsf@gsfc.nasa.gov
>If you can convert time to an unsigned integer, you're all set.
Here's code to produce the a day number, with 1 being January 1,
in Ada.Calendar.Year_Number'first.
(Julian_Day(A_Time) - Julian_Day(First_Unix_Date))*24*60*60+Ada.Calendar.Seconds
with appropriate type conversions should give you a (large) unsigned integer.
type Day_Count is range
-366*(1+Ada.Calendar.Year_Number'last - Ada.Calendar.Year_Number'first)
..
366*(1+Ada.Calendar.Year_Number'last - Ada.Calendar.Year_Number'first);
subtype Is_Leap_Year is Boolean;
Days_Before : constant array(Is_Leap_Year, Ada.Calendar.Month_Number) of Day_Count
:= (False => (0,31,59,90,120,151,181,212,243,273,304,334),
True => (0,31,60,91,121,152,182,213,244,274,305,335));
subtype Day_Number_In_Era is Day_Count range 1 .. Day_Count'last;
-- 1 => 1/1/Ada.Calendar.Year_Number'first
function Julian_Day(T : Ada.Calendar.Time) return Day_Number_In_Era is
This_Year : constant Integer := Integer(Ada.Calendar.Year(T));
Base_Year : constant Integer := Integer(Ada.Calendar.Year_Number'first);
Leap_Year : constant Boolean :=
(This_Year mod 4) = 0
and ((This_Year mod 400) = 0 or (not (This_Year mod 100 = 0)));
begin
return Day_Count(This_Year - Base_Year)*365
+ Day_Count((This_Year-1)/4 - (Base_Year-1)/4)
- Day_Count((This_Year-1)/100 - (Base_Year-1)/100)
+ Day_Count((This_Year-1)/400 - (Base_Year-1)/400)
+ Day_Count(Ada.Calendar.Day(T))
+ Days_Before(Leap_Year, Ada.Calendar.Month(T));
end Julian_Day;
next prev parent reply other threads:[~2000-07-20 0:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-07-19 0:00 Conversion to UNIX time Tennisbb
2000-07-19 0:00 ` Stephen Leake
2000-07-20 0:00 ` tmoran [this message]
2000-07-20 0:00 ` Keith Thompson
2000-07-28 0:00 ` Robert I. Eachus
2000-07-27 0:00 ` Keith Thompson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox