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-26 20:44:29 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!bgtnsc06-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3B395724.6B4B9B67@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> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 27 Jun 2001 03:44:28 GMT NNTP-Posting-Host: 12.86.35.96 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc06-news.ops.worldnet.att.net 993613468 12.86.35.96 (Wed, 27 Jun 2001 03:44:28 GMT) NNTP-Posting-Date: Wed, 27 Jun 2001 03:44:28 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:9131 Date: 2001-06-27T03:44:28+00:00 List-Id: Vladimir Bednikov wrote: > > Hi all, > > I'm using gnat3.13p on an sgi with gcc2.8.1 and am wondering if there is a > way of > getting the day of week and month in text format. I.E. > Mon, Tue, Wed, Thu, Fri, Sat and Sun for days of the week and > Jan, Feb, Mar, Apr .... for the month of the year. Ada does not provide such conversions as part of the Ada.Calendar package. Which representation for days of the week and month names is appropriate in all situations and cultures? Ada does allow you to calculate the results yourself. Converting month numbers to month names is simple. Create an enumerated type containing the month names you want, then convert the Ada.Calendar.Month_Number to the corresponding month name: type months is (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec); Month_Name : Months := Months'Val(Ada.Calendar.Month(Time_Value)); In this case Time_Value is a variable of type Ada.Calendar.Time. Converting to the names of the days of the week is a bit more work. The following generic package works for all the dates I have tested. Note that it expects an enumerated type for the generic parameter. The function Day_Of_Week will work only when the first day of the week is a representation of Sunday ----------------------------------------------------------------------- -- 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 ) - (Year_Diff / 100) + (Year_Diff / 400) + Natural(Month_Days(The_Month)) + Natural(The_Day) - 1); 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; Jim Rogers Colorado Springs, Colorado USA