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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,34e6505a3616fb21 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-17 01:38:53 PST Path: nntp.stanford.edu!newsfeed.stanford.edu!news.tele.dk!213.56.195.71!fr.usenet-edu.net!usenet-edu.net!enst!enst.fr!not-for-mail From: Christoph Grein Newsgroups: comp.lang.ada Subject: Re: calander package - Proposal for dates Date: Fri, 16 Mar 2001 09:49:50 +0100 (MET) Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii X-Trace: avanie.enst.fr 984733031 53619 137.194.161.2 (16 Mar 2001 08:57:11 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Fri, 16 Mar 2001 08:57:11 +0000 (UTC) To: comp.lang.ada@ada.eu.org Return-Path: Content-MD5: Mm9meyLQfyQhODi7AfdHRg== X-Mailer: dtmail 1.2.1 CDE Version 1.2.1 SunOS 5.6 sun4u sparc Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0 Precedence: bulk X-Reply-To: Christoph Grein List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: nntp.stanford.edu comp.lang.ada:91504 Date: 2001-03-16T09:49:50+01:00 I've created a set of packages with specification. There's also an implementation with test program. It's not perfect (it's only for dates, not for times, and the Is_Leap_Year function is maybe misplaced) but it might serve as a start. I use two child packages, because otherwise the functions are not resolvable when defaults are used. (The mailer might ruin the indentation.) ------------------------------------------------------------------------ with Ada.Calendar; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; package Calendar_Format is --==================================================================== -- Author Christoph Grein -- Version 0.0 -- Date 15 March 2001 --==================================================================== -- Various date formats are defined. -- -- Numeric formats consists of all numbers for days, months, and -- years. -- Text formats use names for months. To allow for language specific -- names, they are defined with a (non-constant) array of (unbounded) -- strings. -- -- Numeric Formats: -- ---------------- -- -- These formats are described by enumeration literals where D stands -- for a day digit, M for a month digit, and Y for a year digit. -- A single character D or M signifies that only as much digits will -- be used as needed, DD or MM signifies that always two digits will -- be used. -- YYYY signifies that all four digits of a year will be used, YY -- signifies the abbreviate form. -- -- Examples: -- -- 10-12-1815 Lady Ada's birthday with -- DD_MM_YYYY and '-' separator -- 12/10/80 First Ada Standard DOD-MIL-STD 1815 with -- MM_DD_YY and '/' separator -- 1.1.2001 The begin of the new millenium with -- D_M_YYYY or M_D_YYYY and '.' separator -- 01.01.01 The same date with with DD_MM_YY or MM_DD_YY -- -- Text Formats: -- ------------- -- -- There are tow formats differing only in the placement of day and -- month. In day, month, year sequence, the values are separated by -- one blank character, in month, day, year sequence, an additional -- comma is inserted between day and year value. The day value uses -- one or two digits as appropriate. -- Additionally an ordinal separator may be inserted after the day -- value. -- -- Examples: -- -- 10 December 1815 Day_Month_Year with None separator -- 10. December 1980 Day_Month_Year with '.' separator -- December 10, 1980 Month_Day_Year with None separator -- December 10th, 1980 Month_Day_Year with English_Ordinal separator -- 1st January 2001 Day_Month_Year with English_Ordinal separator --==================================================================== -- History -- Author Version Date Reason for change -- C.G. 0.0 15.03.2001 PDL --==================================================================== use Ada; function Is_Leap_Year (Year: Calendar.Year_Number) return Boolean; -- Numeric Formats: type Numeric_Date_Format is (D_M_YY, D_M_YYYY, DD_MM_YY, DD_MM_YYYY, MM_DD_YY, MM_DD_YYYY, YYYY_MM_DD); Standard_Numeric_Date_Format: Numeric_Date_Format := D_M_YYYY; type Numeric_Date_Separator is ('-', '.', '/'); Standard_Numeric_Separator: Numeric_Date_Separator := '.'; -- Text Formats: type Text_Date_Format is (Day_Month_Year, Month_Day_Year); Standard_Text_Date_Format: Text_Date_Format := Day_Month_Year; type Text_Date_Separator is (None, English_Ordinal, '.'); Standard_Text_Date_Separator: Text_Date_Separator := '.'; type Month_Names is array (Calendar.Month_Number) of Unbounded_String; Standard_Names: Month_Names := (To_Unbounded_String ("January"), To_Unbounded_String ("February"), To_Unbounded_String ("March"), To_Unbounded_String ("April"), To_Unbounded_String ("May"), To_Unbounded_String ("June"), To_Unbounded_String ("July"), To_Unbounded_String ("August"), To_Unbounded_String ("September"), To_Unbounded_String ("October"), To_Unbounded_String ("November"), To_Unbounded_String ("December")); end Calendar_Format; ------------------------------------------------------------------------ package Calendar_Format.Numeric is --==================================================================== -- Author Christoph Grein -- Version 0.0 -- Date 15 March 2001 --==================================================================== -- Calculate the date image in the requested format. -- -- There are two overloaded functions: One takes a Calendar.Time as -- input, the other a year, month and day number. --==================================================================== -- History -- Author Version Date Reason for change -- C.G. 0.0 15.03.2001 PDL --==================================================================== function Date_Image (Date : Calendar.Time; Format : Numeric_Date_Format := Standard_Numeric_Date_Format; Separator: Numeric_Date_Separator := Standard_Numeric_Separator) return String; function Date_Image (Year : Calendar.Year_Number; Month : Calendar.Month_Number; Day : Calendar.Day_Number; Format : Numeric_Date_Format := Standard_Numeric_Date_Format; Separator: Numeric_Date_Separator := Standard_Numeric_Separator) return String; end Calendar_Format.Numeric; ------------------------------------------------------------------------ package Calendar_Format.Text is --==================================================================== -- Author Christoph Grein -- Version 0.0 -- Date 15 March 2001 --==================================================================== -- Calculate the date image in the requested format. -- -- There are two overloaded functions: One takes a Calendar.Time as -- input, the other a year, month and day number. --==================================================================== -- History -- Author Version Date Reason for change -- C.G. 0.0 15.03.2001 PDL --==================================================================== function Date_Image (Date : Calendar.Time; Format : Text_Date_Format := Standard_Text_Date_Format; Separator: Text_Date_Separator := Standard_Text_Date_Separator; Names : Month_Names := Standard_Names) return String; function Date_Image (Year : Calendar.Year_Number; Month : Calendar.Month_Number; Day : Calendar.Day_Number; Format : Text_Date_Format := Standard_Text_Date_Format; Separator: Text_Date_Separator := Standard_Text_Date_Separator; Names : Month_Names := Standard_Names) return String; end Calendar_Format.Text;