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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ffe8077058c9c24b X-Google-Attributes: gid103376,public From: tmoran@bix.com Subject: Re: Conversion to UNIX time Date: 2000/07/20 Message-ID: #1/1 X-Deja-AN: 648509303 References: X-Complaints-To: abuse@pacbell.net X-Trace: news.pacbell.net 964076179 206.170.2.244 (Wed, 19 Jul 2000 23:56:19 PDT) Organization: SBC Internet Services NNTP-Posting-Date: Wed, 19 Jul 2000 23:56:19 PDT Newsgroups: comp.lang.ada Date: 2000-07-20T00:00:00+00:00 List-Id: >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;