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,
T_FILL_THIS_FORM_SHORT autolearn=ham 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 02:20:07 PST
Path:
supernews.google.com!sn-xit-03!supernews.com!freenix!wanadoo.fr!not-for-mail
From: Pascal Obry
Newsgroups: comp.lang.ada
Subject: Re: calander package - Proposal for dates
Date: 17 Mar 2001 11:16:20 +0100
Organization: Home - http://perso.wanadoo.fr/pascal.obry
Message-ID:
References:
<3AB2D1EF.B2CA8117@acm.org>
NNTP-Posting-Host: mix-velizy-107-2-41.abo.wanadoo.fr
X-Trace: wanadoo.fr 984823580 14161 193.249.45.41 (17 Mar 2001 10:06:20 GMT)
X-Complaints-To: abuse@wanadoo.fr
NNTP-Posting-Date: 17 Mar 2001 10:06:20 GMT
X-Newsreader: Gnus v5.7/Emacs 20.7
Xref: supernews.google.com comp.lang.ada:5796
Date: 2001-03-17T10:06:20+00:00
List-Id:
Jeffrey Carter writes:
> This proposal limits you to a fixed set of formats. If the format you
> need is not in that set, you are out of luck.
Indeed. Please have a look at the GNAT.Calendar.Time_IO package which is very
flexible. Well let me post the spec of GNAT.Calendar and
GNAT.Calendar.Time_IO. These are certainly a good start for this discussion :)
<<
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- G N A T . C A L E N D A R --
-- --
-- S p e c --
-- --
-- $Revision: 1.4 $
-- --
-- Copyright (C) 1999-2000 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
-- This package extends Ada.Calendar to handle Hour, Minute, Second,
-- Second_Duration and Day_Of_Week and Day_In_Year from Calendar.Time.
-- Second_Duration precision depends on the target clock precision.
--
-- GNAT.Calendar provides the same kind of abstraction found in
-- Ada.Calendar. It provides Split and Time_Of to build and split a Time
-- data. And it provides accessor functions to get only one of Hour, Minute,
-- Second, Second_Duration. Other functions are to access more advanced
-- valueas like Day_Of_Week, Day_In_Year and Week_In_Year.
with Ada.Calendar;
with Interfaces.C;
package GNAT.Calendar is
type Day_Name is
(Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
subtype Hour_Number is Natural range 0 .. 23;
subtype Minute_Number is Natural range 0 .. 59;
subtype Second_Number is Natural range 0 .. 59;
subtype Second_Duration is Ada.Calendar.Day_Duration range 0.0 .. 1.0;
subtype Day_In_Year_Number is Positive range 1 .. 366;
subtype Week_In_Year_Number is Positive range 1 .. 53;
function Hour (Date : Ada.Calendar.Time) return Hour_Number;
function Minute (Date : Ada.Calendar.Time) return Minute_Number;
function Second (Date : Ada.Calendar.Time) return Second_Number;
function Sub_Second (Date : Ada.Calendar.Time) return Second_Duration;
-- Hour, Minute, Sedond and Sub_Second returns the complete time data for
-- the Date (H:M:S.SS). See Ada.Calendar for Year, Month, Day accessors.
-- Second_Duration precision depends on the target clock precision.
function Day_Of_Week (Date : Ada.Calendar.Time) return Day_Name;
-- Return the day name.
function Day_In_Year (Date : Ada.Calendar.Time) return Day_In_Year_Number;
-- Returns the day number in the year. (1st January is day 1 and 31st
-- December is day 365 or 366 for leap year).
function Week_In_Year (Date : Ada.Calendar.Time) return Week_In_Year_Number;
-- Returns the week number in the year with Monday as first day of week
procedure Split
(Date : Ada.Calendar.Time;
Year : out Ada.Calendar.Year_Number;
Month : out Ada.Calendar.Month_Number;
Day : out Ada.Calendar.Day_Number;
Hour : out Hour_Number;
Minute : out Minute_Number;
Second : out Second_Number;
Sub_Second : out Second_Duration);
-- Split the standard Ada.Calendar.Time data in date data (Year, Month,
-- Day) and Time data (Hour, Minute, Second, Sub_Second)
function Time_Of
(Year : Ada.Calendar.Year_Number;
Month : Ada.Calendar.Month_Number;
Day : Ada.Calendar.Day_Number;
Hour : Hour_Number;
Minute : Minute_Number;
Second : Second_Number;
Sub_Second : Second_Duration := 0.0)
return Ada.Calendar.Time;
-- Returns an Ada.Calendar.Time data built from the date and time values.
-- C timeval conversion
-- C timeval represent a duration (used in Select for example). This
-- structure is composed of a number of seconds and a number of micro
-- seconds. The timeval structure is not exposed here because its
-- definition is target dependent. Interface to C programs is done via a
-- pointer to timeval structure.
type timeval is private;
function To_Duration (T : access timeval) return Duration;
function To_Timeval (D : Duration) return timeval;
private
-- This is a dummy declaration that should be the largest possible timeval
-- structure of all supported targets.
type timeval is array (1 .. 2) of Interfaces.C.long;
function Julian_Day
(Year : Ada.Calendar.Year_Number;
Month : Ada.Calendar.Month_Number;
Day : Ada.Calendar.Day_Number)
return Integer;
-- Compute Julian day number.
--
-- The code of this function is a modified version of algorithm
-- 199 from the Collected Algorithms of the ACM.
-- The author of algorithm 199 is Robert G. Tantzen.
end GNAT.Calendar;
>>
<<
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- G N A T . C A L E N D A R . T I M E _ I O --
-- --
-- S p e c --
-- --
-- $Revision: 1.3 $
-- --
-- Copyright (C) 1999 Ada Core Technologies, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
-- apply solely to the contents of the part following the private keyword. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
-- --
------------------------------------------------------------------------------
-- This package augments standard Ada.Text_IO with facilities for input
-- and output of time values in standardized format.
package GNAT.Calendar.Time_IO is
Picture_Error : exception;
type Picture_String is new String;
-- This is a string to describe date and time output format. The string is
-- a set of standard character and special tag that are replaced by the
-- corresponding values. It follows the GNU Date specification. Here are
-- the recognized directives :
--
-- % a literal %
-- n a newline
-- t a horizontal tab
--
-- Time fields:
--
-- %H hour (00..23)
-- %I hour (01..12)
-- %k hour ( 0..23)
-- %l hour ( 1..12)
-- %M minute (00..59)
-- %p locale's AM or PM
-- %r time, 12-hour (hh:mm:ss [AP]M)
-- %s seconds since 1970-01-01 00:00:00 UTC
-- (a nonstandard extension)
-- %S second (00..59)
-- %T time, 24-hour (hh:mm:ss)
--
-- Date fields:
--
-- %a locale's abbreviated weekday name (Sun..Sat)
-- %A locale's full weekday name, variable length
-- (Sunday..Saturday)
-- %b locale's abbreviated month name (Jan..Dec)
-- %B locale's full month name, variable length
-- (January..December)
-- %c locale's date and time (Sat Nov 04 12:02:33 EST 1989)
-- %d day of month (01..31)
-- %D date (mm/dd/yy)
-- %h same as %b
-- %j day of year (001..366)
-- %m month (01..12)
-- %U week number of year with Sunday as first day of week
-- (00..53)
-- %w day of week (0..6) with 0 corresponding to Sunday
-- %W week number of year with Monday as first day of week
-- (00..53)
-- %x locale's date representation (mm/dd/yy)
-- %y last two digits of year (00..99)
-- %Y year (1970...)
--
-- By default, date pads numeric fields with zeroes. GNU date
-- recognizes the following nonstandard numeric modifiers:
--
-- - (hyphen) do not pad the field
-- _ (underscore) pad the field with spaces
ISO_Date : constant Picture_String;
US_Date : constant Picture_String;
European_Date : constant Picture_String;
function Image
(Date : Ada.Calendar.Time;
Picture : Picture_String)
return String;
-- Return Date as a string with format Picture.
-- raise Picture_Error if picture string is wrong
procedure Put_Time
(Date : Ada.Calendar.Time;
Picture : Picture_String);
-- Put Date with format Picture.
-- raise Picture_Error if picture string is wrong
private
ISO_Date : constant Picture_String := "%Y/%m/%d";
US_Date : constant Picture_String := "%m/%d/%y";
European_Date : constant Picture_String := "%d/%m/%y";
end GNAT.Calendar.Time_IO;
>>
Pascal.
--
--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"