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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1ecbb8782fe5db1b,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!feeder2.cambrium.nl!feed.tweaknews.nl!130.161.131.100.MISMATCH!news.tudelft.nl!tudelft.nl!newsfeed.multikabel.nl!skynet.be!newspost001!tjb!not-for-mail Date: Mon, 06 Dec 2004 14:31:26 +0100 From: Adrien Plisson User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: fr-fr, fr-be, fr, en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Ada.Calendar and number of seconds in a day Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <41b45e45$0$9310$ba620e4c@news.skynet.be> Organization: -= Belgacom Usenet Service =- NNTP-Posting-Host: 95705b81.news.skynet.be X-Trace: 1102339653 news.skynet.be 9310 217.136.144.9:4969 X-Complaints-To: usenet-abuse@skynet.be Xref: g2news1.google.com comp.lang.ada:6799 Date: 2004-12-06T14:31:26+01:00 List-Id: hello, i'm using the package Ada.Calendar and have a little problem with the type Day_Duration. it is defined as: subtype Day_Duration is Duration range 0.0 .. 86_400.0; this makes 86401 different seconds. but if i count them right, i have: 60 s/min * 60 min/h * 24 h/day = 86400 this makes 86400 different seconds in a day. so, logically i should have: Time_Of( 2004, 12, 31, 86400 ) = Time_Of( 2005, 1, 1, 0.0 ); tested with GNAT, the above equality test is true, but if i store the time in separate components this way: type Date is record Year : Year_Number; Month : Month_Number; Day : Day_Number; Seconds : Day_Duration; end record; then I may encounter a problem since: Date'(2004, 12, 31, 86400) /= Date'(2005, 1, 1, 0.0); so what does this extra second mean in this package ? shouldn't Day_Duration be "subtype Day_Duration is Duration range 0.0 .. 86_399.0;" ? thanks for your enlightenment. below is a small program to test all this: .......................................... with Ada.Calendar, Ada.Text_IO; procedure Main is use Ada.Calendar; -- a Date type which holds a date in separate components type Date is record Year : Year_Number; Month : Month_Number; Day : Day_Number; Seconds : Day_Duration; end record; -- simple equality test for Date function "="( Left, Right : in Date ) return Boolean is begin return (Left.Year = Right.Year) and (Left.Month = Right.Month) and (Left.Day = Right.Day) and (Left.Seconds = Right.Seconds); end "="; -- convert a Date into a Time function To_Time( D : in Date ) return Time is begin return Time_Of( D.Year, D.Month, D.Day, D.Seconds ); end To_Time; -- return a string from a Time for suitable display function String_Time( T : in Time ) return String is Year : Year_Number; Month : Month_Number; Day : Day_Number; Seconds : Day_Duration; begin Split( T, Year, Month, Day, Seconds ); return Year_Number'Image( Year ) & "/" & Month_Number'Image( Month ) & "/" & Day_Number'Image( Day ) & ", " & Day_Duration'Image( Seconds ); end String_Time; -- return a string from a Date for suitable display function String_Date( D : in Date ) return String is begin return Year_Number'Image( D.Year ) & "/" & Month_Number'Image( D.Month ) & "/" & Day_Number'Image( D.Day ) & ", " & Day_Duration'Image( D.Seconds ); end String_Date; -- these are the 2 offending dates T1 : Date := Date'( 2004, 12, 31, 86400.0 ); T2 : Date := Date'( 2005, 01, 01, 0.0 ); begin -- test with Time Ada.Text_IO.Put_Line( "T1: " & String_Time( To_Time( T1 ) ) ); Ada.Text_IO.Put_Line( "T2: " & String_Time( To_Time( T2 ) ) ); if To_Time( T1 ) = To_Time( T2 ) then Ada.Text_IO.Put_Line( "T1 and T2 are equal in Time" ); else Ada.Text_IO.Put_Line( "T1 and T2 differ in Time" ); end if; -- test with Date Ada.Text_IO.Put_Line( "T1: " & String_Date( T1 ) ); Ada.Text_IO.Put_Line( "T2: " & String_Date( T2 ) ); if T1 = T2 then Ada.Text_IO.Put_Line( "T1 and T2 are equal in Date" ); else Ada.Text_IO.Put_Line( "T1 and T2 differ in Date" ); end if; end Main; .......................................... -- rien