comp.lang.ada
 help / color / mirror / Atom feed
* Date & time formatting operations for review
@ 2001-03-20 15:53 Jeffrey Carter
  2001-03-20 19:03 ` Ted Dennison
  2001-03-26 19:15 ` End of line delimited comments versus multiple line comments (was Date & time formatting operations for review) Colin Paul Gloster
  0 siblings, 2 replies; 8+ messages in thread
From: Jeffrey Carter @ 2001-03-20 15:53 UTC (permalink / raw)


Here is the spec of a package with some date & time formatting
operations, as promised in an earlier post. As far as I know, any
possible date/time format desired can be easily constructed from these
operations, in any language that uses the Latin-1 character set. If
anyone is aware of any format that can't be achieved with these
operations, please let me know.

Currently this package is unconditionally copyrighted and may not be
used without permission, but once we're satisfied with them, and have
tested them more thoroughly, they'll be folded into
PragmARC.Date_Handler and made available under the GMLGPL.

Jeff

Code follows (some lines may have wrapped):

-- Experimental date-formatting operations

-- This would be part of PragmARC.Date_Handler, which provides a Split
operation
-- to obtain Hour, Minute, and Seconds

-- By combining the image functions provided here, the client should be
able to create any
-- date or time format desired.

-- For example, given
--   Year    = 1953
--   Month   =   12
--   Day     =   28
--   Hour    =    7
--   Minute  =   25
--   Seconds =   31.75284
-- to obtain "31.75S07H25M@28/001953-December", use
-- Seconds_Image (Seconds, True, 2) &
-- 'S'                              &
-- Hour_Image_24 (Hour)             &
-- 'H'                              &
-- Minute_Image (Minute)            &
-- "M@"                             &
-- Day_Image (Day)                  &
-- '/'                              &
-- Year_Image_Long (Year, True, 6)  &
-- '-'                              &
-- Month_Image_Long (Month)

-- A client will usually create a date-formatting function for its
desired format from these functions.

-- Copyright (C) 2001 by PragmAda Software Engineering.  All rights
reserved.

with Ada.Calendar;
with Ada.Strings.Unbounded;

use Ada;
use Ada.Strings.Unbounded;
package Date_Formatting is
   -- Copied from Date_Handler:
   subtype Hour_Number     is Integer range 0 .. 23;
   subtype Minute_Number   is Integer range 0 .. 59;
   subtype Minute_Duration is Calendar.Day_Duration range 0.0 .. 60.0;
   
   -- Image functions with a Zero_Fill parameter may have extra leading
characters in the result.
   -- If Zero_Fill, these will be '0'; otherwise they will be ' '.

   -- Provide the image of any year CE:
   function Year_Image_Short (Year : Positive; Zero_Fill : Boolean :=
True) return String;
   -- Returns the decimal image of Year rem 100.
   -- If Zero_Fill, result will always be 2 characters long. Otherwise,
result will be 1 or 2 characters long.
   
   function Year_Image_Long  (Year : Positive; Zero_Fill : Boolean :=
True; Width : Positive := 4) return String;
   -- Returns the decimal image of Year. Result will be large enough to
hold this image, or Width characters long,
   -- whichever is larger.

   type Case_Selection is (Lower, Mixed, Upper, As_Is); -- Determines
the formatting of month names

   type Name_List is array (Calendar.Month_Number) of Unbounded_String;
-- Used to provide month names

   Default_Short_Name : constant Name_List := (01 => To_Unbounded_String
("Jan"), 02 => To_Unbounded_String ("Feb"),
                                               03 => To_Unbounded_String
("Mar"), 04 => To_Unbounded_String ("Apr"),
                                               05 => To_Unbounded_String
("May"), 06 => To_Unbounded_String ("Jun"),
                                               07 => To_Unbounded_String
("Jul"), 08 => To_Unbounded_String ("Aug"),
                                               09 => To_Unbounded_String
("Sep"), 10 => To_Unbounded_String ("Oct"),
                                               11 => To_Unbounded_String
("Nov"), 12 => To_Unbounded_String ("Dec") );
                                               -- Default "short" month
names
                                               
   Default_Long_Name  : constant Name_List := (01 => To_Unbounded_String
("January"),
                                               02 => To_Unbounded_String
("February"),
                                               03 => To_Unbounded_String
("March"),
                                               04 => To_Unbounded_String
("April"),
                                               05 => To_Unbounded_String
("May"),
                                               06 => To_Unbounded_String
("June"),
                                               07 => To_Unbounded_String
("July"),
                                               08 => To_Unbounded_String
("August"),
                                               09 => To_Unbounded_String
("September"),
                                               10 => To_Unbounded_String
("October"),
                                               11 => To_Unbounded_String
("November"),
                                               12 => To_Unbounded_String
("December") );
                                               -- Default "long" month
names

   function Month_Image_Numeric (Month : Calendar.Month_Number;
Zero_Fill : Boolean := True) return String;
   -- Returns the decimal image of Month.
   -- If Zero_Fill, result will always be 2 characters long. Otherwise,
result will be 1 or 2 characters long.
   
   function Month_Image_Alpha (Month : Calendar.Month_Number; Casing :
Case_Selection := Mixed; Name : Name_List) return String;
   -- Returns To_String (Name (Month) ), formatted as directed by
Casing.
   
   -- Renamings for default month names:
   function Month_Image_Short
      (Month : Calendar.Month_Number; Casing : Case_Selection := Mixed;
Name : Name_List := Default_Long_Name)
   return String renames Month_Image_Alpha;
   function Month_Image_Long
      (Month : Calendar.Month_Number; Casing : Case_Selection := Mixed;
Name : Name_List := Default_Long_Name)
   return String renames Month_Image_Alpha;

   function Day_Image (Day : Calendar.Day_Number; Zero_Fill : Boolean :=
True) return String;
   -- Returns the decimal image of Day.
   -- If Zero_Fill, result will always be 2 characters long. Otherwise,
result will be 1 or 2 characters long.

   type AM_PM_ID is (AM, PM);
   type AM_PM_List is array (AM_PM_ID) of Unbounded_String;

   Default_AM_PM_Name : constant AM_PM_List := (AM =>
To_Unbounded_String (" am"), PM => To_Unbounded_String (" pm") );

   function Hour_Image_12 (Hour : Hour_Number; AM_PM : AM_PM_List :=
Default_AM_PM_Name; Zero_Fill : Boolean := True) return String;
   -- If Hour = 0, Image is "12". If Hour in 1 .. 12, Image is image of
Hour. Otherwise, Image is image of Hour - 12.
   -- If Hour < 12, returns Image & To_String (AM_PM (AM) ). Otherwise,
returns Image & To_String (AM_PM (PM) ).
   -- If Zero_Fill, Image will always be 2 characters long. Otherwise,
Image will be 1 or 2 characters long.
   
   function Hour_Image_24 (Hour : Hour_Number; Zero_Fill : Boolean :=
True) return String;
   -- Returns the decimal image of Hour.
   -- If Zero_Fill, result will always be 2 characters long. Otherwise,
result will be 1 or 2 characters long.

   function Minute_Image (Minute : Minute_Number; Zero_Fill : Boolean :=
True) return String;
   -- Returns the decimal image of Minute.
   -- If Zero_Fill, result will always be 2 characters long. Otherwise,
result will be 1 or 2 characters long.

   function Seconds_Image (Seconds : Minute_Duration; Zero_Fill :
Boolean := True; Aft : Natural := 0) return String;
   -- Returns the decimal image of Seconds, with Aft digits after the
decimal point.
   -- If Aft = 0, result will not contain a decimal point.
   -- If Aft = 0 and Zero_Fill, result will always be 2 characters long.
   -- If Aft = 0 and not Zero_Fill, result will be 1 or 2 characters
long.
   -- If Aft > 0 and Zero_Fill, the portion of result left of the
decimal point will always be 2 characters long.
   -- Otherwise, the portion of result left of the decimal point may be
1 or 2 characters long.
   -- If Seconds >= Minute_Duration'Last, returns Seconds_Image
(Minute_Duration'First, Zero_Fill, Aft); if this
   -- occurs, you should increment Minute. This could result in changing
every part of the time and date.
end Date_Formatting;



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

* Re: Date & time formatting operations for review
  2001-03-20 15:53 Date & time formatting operations for review Jeffrey Carter
@ 2001-03-20 19:03 ` Ted Dennison
  2001-03-20 22:58   ` Jeffrey Carter
  2001-03-26 19:15 ` End of line delimited comments versus multiple line comments (was Date & time formatting operations for review) Colin Paul Gloster
  1 sibling, 1 reply; 8+ messages in thread
From: Ted Dennison @ 2001-03-20 19:03 UTC (permalink / raw)


In article <3AB77D0C.4492D7A5@boeing.com>, Jeffrey Carter says...
>
>Here is the spec of a package with some date & time formatting
>operations, as promised in an earlier post. As far as I know, any
>possible date/time format desired can be easily constructed from these
>operations, in any language that uses the Latin-1 character set. If
>anyone is aware of any format that can't be achieved with these
>operations, please let me know.

I don't see anything in there for retrieving the day of the week. Other than
that, it looks pretty good.


---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

* Re: Date & time formatting operations for review
  2001-03-20 19:03 ` Ted Dennison
@ 2001-03-20 22:58   ` Jeffrey Carter
  2001-03-23  1:45     ` singlespeeder
  0 siblings, 1 reply; 8+ messages in thread
From: Jeffrey Carter @ 2001-03-20 22:58 UTC (permalink / raw)


Ted Dennison wrote:
> 
> I don't see anything in there for retrieving the day of the week. Other than
> that, it looks pretty good.

PragmARC.Date_Handler already has a day-of-week function, so it isn't
new. The algorithm (by Zeller, 1887) relies on taking a modulus, rather
than a remainder. Numerous implementations in Pascal didn't work without
fudging because "mod" was really "rem".

Jeff



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

* Re: Date & time formatting operations for review
  2001-03-20 22:58   ` Jeffrey Carter
@ 2001-03-23  1:45     ` singlespeeder
  2001-03-23 15:45       ` Jeffrey Carter
  0 siblings, 1 reply; 8+ messages in thread
From: singlespeeder @ 2001-03-23  1:45 UTC (permalink / raw)


Internationalisation?

nick





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

* Re: Date & time formatting operations for review
  2001-03-23  1:45     ` singlespeeder
@ 2001-03-23 15:45       ` Jeffrey Carter
  0 siblings, 0 replies; 8+ messages in thread
From: Jeffrey Carter @ 2001-03-23 15:45 UTC (permalink / raw)


singlespeeder wrote:
> 
> Internationalisation?
> 
> nick

Could you be precise as to what results you think the package should be
able to provide that it does not?

Jeff



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

* End of line delimited comments versus multiple line comments (was Date & time formatting operations for review)
  2001-03-20 15:53 Date & time formatting operations for review Jeffrey Carter
  2001-03-20 19:03 ` Ted Dennison
@ 2001-03-26 19:15 ` Colin Paul Gloster
  2001-03-27  4:12   ` Simon Wright
  1 sibling, 1 reply; 8+ messages in thread
From: Colin Paul Gloster @ 2001-03-26 19:15 UTC (permalink / raw)


A fine example to show up end of line delimited comments methinks.

In article <3AB77D0C.4492D7A5@boeing.com>, Jeffrey Carter showed us:
"[..]
Code follows (some lines may have wrapped):

[..]
-- This would be part of PragmARC.Date_Handler, which provides a Split
operation

[..]

-- By combining the image functions provided here, the client should be
able to create any
[..]
-- A client will usually create a date-formatting function for its
desired format from these functions.

-- Copyright (C) 2001 by PragmAda Software Engineering.  All rights
reserved.

[..]   
   -- Image functions with a Zero_Fill parameter may have extra leading
characters in the result.
[..]
   -- If Zero_Fill, result will always be 2 characters long. Otherwise,
result will be 1 or 2 characters long.
[..]
   -- Returns the decimal image of Year. Result will be large enough to
hold this image, or Width characters long,
[..]
   type Case_Selection is (Lower, Mixed, Upper, As_Is); -- Determines
the formatting of month names

   type Name_List is array (Calendar.Month_Number) of Unbounded_String;
-- Used to provide month names
[..]
   -- If Zero_Fill, result will always be 2 characters long. Otherwise,
result will be 1 or 2 characters long.
   
[..]
   -- Returns To_String (Name (Month) ), formatted as directed by
Casing.
[..]
   -- If Zero_Fill, result will always be 2 characters long. Otherwise,
result will be 1 or 2 characters long.
[..]
   -- If Hour = 0, Image is "12". If Hour in 1 .. 12, Image is image of
Hour. Otherwise, Image is image of Hour - 12.
   -- If Hour < 12, returns Image & To_String (AM_PM (AM) ). Otherwise,
returns Image & To_String (AM_PM (PM) ).
   -- If Zero_Fill, Image will always be 2 characters long. Otherwise,
Image will be 1 or 2 characters long.
[..]
   -- If Zero_Fill, result will always be 2 characters long. Otherwise,
result will be 1 or 2 characters long.

[..]
   -- If Zero_Fill, result will always be 2 characters long. Otherwise,
result will be 1 or 2 characters long.

[..]
   -- Returns the decimal image of Seconds, with Aft digits after the
decimal point.
[..]
   -- If Aft = 0 and not Zero_Fill, result will be 1 or 2 characters
long.
   -- If Aft > 0 and Zero_Fill, the portion of result left of the
decimal point will always be 2 characters long.
   -- Otherwise, the portion of result left of the decimal point may be
1 or 2 characters long.
   -- If Seconds >= Minute_Duration'Last, returns Seconds_Image
(Minute_Duration'First, Zero_Fill, Aft); if this
   -- occurs, you should increment Minute. This could result in changing
every part of the time and date.
[..]"

You have almost reached the end. Well done to me and ye.
Colin Paul Gloster
-- 
This signature file is included in protest against the hosting of Nazi
facist propaganda "Mein Kampf" written by Adolf Hitler on the Dublin City
University Networking Society (committee@RedBrick.DCU.Ie, DCU Networking
Society, c/o Clubs and Socs Office, The Hub, DCU, Glasnevin, Dublin 9,
Ireland) website at HTTP://WWW.RedBrick.DCU.Ie/~mellow/Adolf/ by
R. O'Brien whose username is mellow. On 22nd March 2001 Dublin City
University webmaster Niall O'Leary (niall.oleary@DCU.Ie, +353-1-700 5864, 
Room C203, Computer Services Department, Henry Grattan Building, DCU,
Glasnevin, Dublin 9, Ireland) authorised "Mein Kampf" to be on the
Internet via DCU and HEAnet (info@HEAnet.Ie, +353-1-6623412, HEAnet Ltd.,
Ground Floor, Marine House, Clanwilliam Court, Dublin 2, 
Ireland) resources. Please also complain to The President's Office, DCU,
Glasnevin, Dublin 9, Ireland, dcupres@DCU.Ie.



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

* Re: End of line delimited comments versus multiple line comments (was Date & time formatting operations for review)
  2001-03-26 19:15 ` End of line delimited comments versus multiple line comments (was Date & time formatting operations for review) Colin Paul Gloster
@ 2001-03-27  4:12   ` Simon Wright
  2001-03-29  8:54     ` Colin Paul Gloster
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Wright @ 2001-03-27  4:12 UTC (permalink / raw)


Colin_Paul_Gloster@ACM.org (Colin Paul Gloster) writes:

> A fine example to show up end of line delimited comments methinks.
> 
> In article <3AB77D0C.4492D7A5@boeing.com>, Jeffrey Carter showed us:
> "[..]
> Code follows (some lines may have wrapped):
> 
> [..]
> -- This would be part of PragmARC.Date_Handler, which provides a Split
> operation

Yes!

(1) Emacs ada-mode has a very nice comment formatter/justifier (M-q)

(2) with GNAT, use -gnatym or -gnatyM79 to check:

package Lines is

  -- this is a comment whose line-length is more than 79 characters (the limit check for -gnatym)

end Lines;

smaug[30]$ gnatgcc -gnatv -gnatyM100 -c lines.ads 

GNAT 3.13p  (20000509) Copyright 1992-2000 Free Software Foundation, Inc.

Compiling: lines.ads (source file time stamp: 2001-03-27 04:07:10)
 6 lines: No errors
smaug[31]$ gnatgcc -gnatv -gnatym lines.ads 

GNAT 3.13p  (20000509) Copyright 1992-2000 Free Software Foundation, Inc.

Compiling: lines.ads (source file time stamp: 2001-03-27 04:07:10)

     3.   -- this is a comment whose line-length is more than 79 characters (the limit check for -gnatym)
                                                                                       |
        >>> (style) this line is too long

 6 lines: 1 error



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

* Re: End of line delimited comments versus multiple line comments (was Date & time formatting operations for review)
  2001-03-27  4:12   ` Simon Wright
@ 2001-03-29  8:54     ` Colin Paul Gloster
  0 siblings, 0 replies; 8+ messages in thread
From: Colin Paul Gloster @ 2001-03-29  8:54 UTC (permalink / raw)


In article <x7vu24f3l66.fsf@smaug.pushface.org>, Simon Wright wrote:
"Colin_Paul_Gloster@ACM.org (Colin Paul Gloster) writes:

> A fine example to show up end of line delimited comments methinks.
> 
> In article <3AB77D0C.4492D7A5@boeing.com>, Jeffrey Carter showed us:
> "[..]
> Code follows (some lines may have wrapped):
[..]

Yes!

(1) Emacs ada-mode has a very nice comment formatter/justifier (M-q)

(2) with GNAT, use -gnatym or -gnatyM79 to check:

[..]"

Excellent. Thanks for letting me know about those.
Colin Paul Gloster
-- 
This signature file is included in protest against the hosting of Nazi
facist propaganda "Mein Kampf" written by Adolf Hitler on the Dublin City
University Networking Society (committee@RedBrick.DCU.Ie, DCU Networking
Society, c/o Clubs and Socs Office, The Hub, DCU, Glasnevin, Dublin 9,
Ireland) website at HTTP://WWW.RedBrick.DCU.Ie/~mellow/Adolf/ by
R. O'Brien whose username is mellow. On 22nd March 2001 Dublin City
University webmaster Niall O'Leary (niall.oleary@DCU.Ie, +353-1-700 5864, 
Room C203, Computer Services Department, Henry Grattan Building, DCU,
Glasnevin, Dublin 9, Ireland) authorised "Mein Kampf" to be on the
Internet via DCU and HEAnet (info@HEAnet.Ie, +353-1-6623412, HEAnet Ltd.,
Ground Floor, Marine House, Clanwilliam Court, Dublin 2, 
Ireland) resources. Please also complain to The President's Office, DCU,
Glasnevin, Dublin 9, Ireland, dcupres@DCU.Ie.



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

end of thread, other threads:[~2001-03-29  8:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-20 15:53 Date & time formatting operations for review Jeffrey Carter
2001-03-20 19:03 ` Ted Dennison
2001-03-20 22:58   ` Jeffrey Carter
2001-03-23  1:45     ` singlespeeder
2001-03-23 15:45       ` Jeffrey Carter
2001-03-26 19:15 ` End of line delimited comments versus multiple line comments (was Date & time formatting operations for review) Colin Paul Gloster
2001-03-27  4:12   ` Simon Wright
2001-03-29  8:54     ` Colin Paul Gloster

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