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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,45c857e19c4ee2df X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-27 06:01:47 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!howland.erols.net!news-out.worldnet.att.net.MISMATCH!wn3feed!worldnet.att.net!135.173.83.71!wnfilter1!worldnet-localpost!bgtnsc05-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3B39D9C1.9B00424E@worldnet.att.net> From: James Rogers X-Mailer: Mozilla 4.76 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada95 calendar package question References: <9hbb9n$g14$1@fang.dsto.defence.gov.au> <3B395724.6B4B9B67@worldnet.att.net> <9hc5n4$jl$1@infosun2.rus.uni-stuttgart.de> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 27 Jun 2001 13:01:46 GMT NNTP-Posting-Host: 12.86.33.37 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 993646906 12.86.33.37 (Wed, 27 Jun 2001 13:01:46 GMT) NNTP-Posting-Date: Wed, 27 Jun 2001 13:01:46 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:9138 Date: 2001-06-27T13:01:46+00:00 List-Id: Peter Hermann wrote: > > James Rogers wrote: > > Vladimir Bednikov wrote: > >> Mon, Tue, Wed, Thu, Fri, Sat and Sun for days of the week and > >> Jan, Feb, Mar, Apr .... for the month of the year. > > -- This generic package works when Sunday is declared to be the > > -- first day of the week. It must be the first value of the > > Sorry James, but: > I very much prefer Monday as the first day of the week, > simply because it is the first day of the week :-) Ah, more cultural differences. American calendars usually start the week with Sunday. There are two solutions to the problem. Simply alter the algorithm to add one to the number generated before calculating the enumeration value. Follow that up by using the updated version listed below. Upon further testing I found the calculation had a Year 2000 defect in it. I translated the original formulas from an ancient C text. Those formulas (formulae ?) were only good through 1999. ----------------------------------------------------------------------- -- Day of the Week Package for any date after January 1, 1901 -- -- This generic package works when Sunday is declared to be the -- first day of the week. It must be the first value of the -- enumerated type used in the actual generic parameter. ----------------------------------------------------------------------- with Ada.Calendar; generic type weekdays is (<>); package Day_Conversion is function Day_Of_Week (Date : Ada.Calendar.Time) return weekdays; end Day_Conversion; ----------------------------------------------------------------------- -- Day of the Week Package for any date after January 1, 1901 ----------------------------------------------------------------------- package body Day_Conversion is function Day_Of_Week (Date : Ada.Calendar.Time) return weekdays is year_diff : Natural; The_Month : Ada.Calendar.Month_Number; The_Year : Ada.Calendar.Year_Number; The_Day : Ada.Calendar.Day_Number; The_Day_Number : Natural := 0; Month_Days : array(Ada.Calendar.Month_Number) of Natural := (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 ); begin The_Month := Ada.Calendar.Month(Date); The_Year := Ada.Calendar.Year(Date); The_Day := Ada.Calendar.Day(Date); Year_Diff := The_Year - 1901; The_Day_Number := (Year_Diff * 365) + (( Year_Diff / 4 ) + Natural(Month_Days(The_Month)) + Natural(The_Day) - 1); if The_Year >= 2000 then The_Day_Number := The_Day_Number - ((The_Year - 2000)/ 100); The_Day_Number := The_Day_Number + ((The_Year - 2000) / 400); end if; if (The_Year mod 4 = 0) and (The_Month > 2) then The_Day_Number := The_Day_Number + 1; end if; return Weekdays'Val((The_Day_Number + 2) mod 7); end Day_Of_Week; end Day_Conversion; I apologize for the original error. Jim Rogers Colorado Springs, Colorado USA