comp.lang.ada
 help / color / mirror / Atom feed
From: Richard D Riehle <laoXhai@ix.netcom.com>
Subject: Re: date format (was: Re: Confusing language...)
Date: 1999/12/04
Date: 1999-12-04T01:15:11+00:00	[thread overview]
Message-ID: <829puv$s3m$1@nntp6.atl.mindspring.net> (raw)
In-Reply-To: Pine.LNX.4.10.9911181636120.829-100000@lexis.di.fct.unl.pt

In article <Pine.LNX.4.10.9911181636120.829-100000@lexis.di.fct.unl.pt>,
	Mario Amado Alves <maa@di.fct.unl.pt> wrote:

>Package Ada.Calendar is fairly complete with respect to the resources
>necessary to convert to/from any representation. The extensions could be
>child packages Ada.Calendar.HTML, Ada.Calendar.IEEE (say), etc. (I assume
>it possible to create children of predefined packages.) When I have this I
>in my ADALIB I'll be happy to share.

We have the following package that seems to work pretty well.  If anyone
wants the package body, I will be happy to supply it.  Or maybe we should
just send it to David Botton for his library of stuff.

-- =================================================================
-- Calendar_Formatter.Ads
-- by Richard Riehle, AdaWorks Software Engineering 
-- http://www.adaworks.com
-- This package allows a client to create time in a variety of
-- formats. It is based on Ada.Calendar as defined in Chapter 9
-- of the Ada Language Reference Manual.  You may first get the 
-- Time using one of the two  Get functions. Then get the formatted 
-- time by calling one of the formatted time functions.
-- This package is not warranted by the author.  There are no
-- guarantees either implied or specified.  It is available for
-- experimentation and student use.  If you plan to use it in any
-- production quality software, you should test it thoroughly and
-- make corrections as you require.
--                 Richard Riehle
-- NOTE: Not all functions are implemented in this version. Future
-- versions will contain full implementation along with more features
-- such as child packages for doing comparisons and calculations.
-- =================================================================
package Calendar_Formatter is

   type Formatted_Time is private;  -- cannot be limited in this design
because
                                    -- one function returns object of the
type and
                                    -- requires an assignment statement
   type Time_Reference is access all Formatted_Time;
   type Month_1 is (January,   February, March,    April,
                    May,       June,     July,     August,
                    September, October,  November, December);
   type Month_2 is (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov,
Dec);

   type Day_1   is (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday);
   type Day_2   is (Sun, Mon, Tue, Wed, Thu, Fri, Sat);
   subtype Work_Day_1 is Day_1 range Monday..Friday;
   subtype Work_Day_2 is Day_2 range Mon..Fri;
   function Get_Time return Formatted_Time;
   function Get_Time return Time_Reference;
   function YY   (FT : Formatted_Time)    return String;      -- two
character string for year
   function YYYY (FT : Formatted_Time)    return String;      -- four
character string for year
   function DD   (FT : Formatted_Time)    return String;      -- two
character string for day
   function MM   (FT : Formatted_Time)    return String;      -- two
character string for month
   function Hour12 (FT : Formatted_Time)  return String;      -- two
character string 12 hour clock hour
   function AMPM   (FT : Formatted_Time)  return String;      -- two
character string;  AM or PM
   function Hour24 (FT : Formatted_Time)  return String;      -- two
character string 24 hour clock hour
   function Minute (FT : Formatted_Time)  return String;      -- two
character string minute
   function Month  (FT : Formatted_Time)  return String;      -- Month fully
spelled out
   function Month  (FT : Formatted_Time)  return Month_1;     -- Month in
format of the Type;
--   function Month (FT : Formatted_Time)   return Month_2;     -- Not yet
implemented
--   function Day   (FT : Formatted_Time)   return Day_1;       -- Not yet
implemented
--   function Day   (FT : Formatted_Time)   return Day_2;       -- Not yet
implemented
   function Format_1 (FT : Formatted_Time) return Formatted_Time;  --
Returns a copy of the private type
   function Format_2 (FT : Formatted_Time) return String;      -- formatted
MM-DD-YY
   function Format_3 (FT : Formatted_Time) return String;      -- formatted
MM-DD-YYYY HH:MM:SS
   function Format_4 (FT : Formatted_Time) return String;      -- e.g., July
21, 1999
   function Total_Seconds (FT : Formatted_Time) return String; -- Raw number
of seconds in Time

   Time_Format_Error : exception;
private

   type Formatted_Time is
     record
        Year       : String(1..4) := (others => ' ');
        Month      : String(1..2) := (others => ' ');
        Day        : String(1..2) := (others => ' ');
        Hour24     : String(1..2) := (others => ' ');
        Hour12     : String(1..2) := (others => ' ');
        Minute     : String(1..2) := (others => ' ');
        Seconds    : String(1..2) := (others => ' ');
        AMPM       : String(1..2) := (others => ' ');
        Noon_Mid   : String(1..8) := "Midnight";   -- or "Noon    ";
        Month_Name : Month_1;
        Day_Name   : Day_1;
        Holiday    : String(1..15) := (others => ' ');
     end record;

end Calendar_Formatter;





      parent reply	other threads:[~1999-12-04  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <199911181536.PAA06025@ns.di.fct.unl.pt>
1999-11-18  0:00 ` date format (was: Re: Confusing language...) Mario Amado Alves
1999-11-25  0:00   ` Keith Thompson
1999-12-04  0:00   ` Richard D Riehle [this message]
replies disabled

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