comp.lang.ada
 help / color / mirror / Atom feed
* Re: calander package - Proposal for dates
@ 2001-03-19  6:50 Christoph Grein
  0 siblings, 0 replies; 25+ messages in thread
From: Christoph Grein @ 2001-03-19  6:50 UTC (permalink / raw)
  To: comp.lang.ada

Robert A Duff <bobduff@world.std.com> wrote:
> Christoph Grein <christoph.grein@eurocopter.de> writes:
> 
> >   Standard_Names: Month_Names := (To_Unbounded_String ("January"),  
> >                                   To_Unbounded_String ("February"),  
> >                                   To_Unbounded_String ("March"),  
> >                                   To_Unbounded_String ("April"),  
> >...
> 
> Why not use an enumerated type, and use 'Image to map to strings?
> (You have to write a Capitalize function if you don't like shouting.)
> 
> - Bob

I thought it was clear:

  -- Text formats use names for months. To allow for language specific
  -- names, they are defined with a (non-constant) array of (unbounded)
  -- strings.

How else can you provide for French, German, Italian ... names?

Christoph





^ permalink raw reply	[flat|nested] 25+ messages in thread
[parent not found: <000201c0ae3b$b27cca00$039697d4@d1>]
* Re: calander package - Proposal for dates
@ 2001-03-16  8:49 Christoph Grein
  2001-03-16 17:21 ` Robert A Duff
  2001-03-17  2:55 ` Jeffrey Carter
  0 siblings, 2 replies; 25+ messages in thread
From: Christoph Grein @ 2001-03-16  8:49 UTC (permalink / raw)
  To: comp.lang.ada

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;





^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2001-03-24  6:27 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <200103160849.JAA00680@bulgaria.otn.eurocopter.de>
2001-03-16  9:31 ` calander package - Proposal for dates Hans-Olof Danielsson
2001-03-17 20:18   ` Georg Bauhaus
2001-03-24  6:27   ` David Thompson
2001-03-19  6:50 Christoph Grein
     [not found] <000201c0ae3b$b27cca00$039697d4@d1>
2001-03-16 23:46 ` Robert C. Leif, Ph.D.
  -- strict thread matches above, loose matches on Subject: below --
2001-03-16  8:49 Christoph Grein
2001-03-16 17:21 ` Robert A Duff
2001-03-17  2:55 ` Jeffrey Carter
2001-03-17 10:16   ` Pascal Obry
2001-03-17 18:11     ` Ehud Lamm
2001-03-19 14:26       ` Ted Dennison
2001-03-19 17:30         ` Ehud Lamm
2001-03-20  6:30       ` Wilhelm Spickermann
2001-03-20 11:45         ` Martin Dowie
2001-03-20 13:48           ` Wilhelm Spickermann
2001-03-21 13:37             ` John English
2001-03-20 14:15           ` Marin David Condic
2001-03-20 15:25           ` Ted Dennison
2001-03-19 22:03     ` Jeffrey Carter
2001-03-20 18:34       ` Pascal Obry
2001-03-20 23:01         ` Jeffrey Carter
2001-03-21  8:17           ` Pascal Obry
2001-03-19 16:07   ` Marin David Condic
2001-03-19 17:24     ` Ted Dennison
2001-03-19 17:34       ` Ehud Lamm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox