[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

DateTime modules (revisited)



I've incorporated some changes and bug fixes as suggested by Michael van
Acken.  The new version has been uploaded to cognac.informatik.uni-kl.de
in /pub/ooc/incoming/lib/DateTime.tar.gz.

Please email me at grieblm@inforamp.net between 21 Dec '96 and 6 Jan '97.

Have a good Christmas everyone,
			
	Michael Griebling

-----------------------------------------------------------------------------

I've included a simple demonstration program called Cal which duplicates most of
the functionality of the UNIX cal utility.  It shows how many of the date/time
functions operate in a practical application and might be able to better answer
any questions about how to interface to the modules shown below.  If you happen
to try the following: "Cal 9 1752" the resulting month IS NOT a mistake but is
a result of the switch from the Julian to the Gregorian calendars.  Of course
if you change the Gregorian switch-over date, you'll have a different abbreviated
month somewhere else.

Here are some Date/Time modules: DateTimeConv, SysClock, DateTime, and DateTimeStr.  

---------------------------------------------------------------------------------

DateTimeConv provides a number of conversions to/from DateTime to the following
time types:

   Julian day   -- number of days since 31 Dec 4714 BC.
   Seconds      -- used for setting the system clock (general use not recommended)
   Milliseconds -- for short-duration time durations < 1 day
   TimeStamp    -- compressed version of DateTime type using GMT with mS res.

Any of these converted units also allow simple calculations on the date/time 
format.  

Several other facilities are also located in this module which determine the
start date of the Gregorian calendar, whether the Gregorigan or Julian calendars
should be used, and whether time zones are supported for your system.  The main
reason for putting these configuration style parameters here is that they
really belong in a Localization module but we don't have one yet.

This module is system-dependent but should be portable to most UNIX systems.

---------------------------------------------------------------------------------

SysClock.Mod is an ISO M2 compliant implementation of the system date/time
setting and acquisition functions.  This module is system-dependent but
should be portable to most UNIX systems.

---------------------------------------------------------------------------------

TimeDate.Mod is an invention of mine based somewhat on the o2c Time module
except TimeDate is system independent and thus is recommended in place of
the Time module.  A few routines have been added which were not in the
Time module which make it simpler to do some date calculations such as:

  1) Finding the day of the week (DayOfWeek)
  2) Determining leap years (LeapYear)
  3) Adding/subtracting a number of days (Inc)
  4) Changing a date/time (ChangeDate/ChangeTime)
  5) Finding nth day of the week in a month or year (FindDate)
  6) Determining a weeknumber of a date (WeekNumber)
  7) Finding the day of year from 1 to 366 (DayOfYear)

The Cmp function in this module has also been changed so it makes more
sense (to me at least) over the Time.Cmp function.

---------------------------------------------------------------------------------

TimeDateStr.Mod converts the TimeDate type to/from a string representation
based on a template.  The template definitions are similar to those found
in the Unix strftime/strptime functions with a few additions.  Here are
the possible template items:

    `%a'  The abbreviated weekday name according to the current locale.
    `%A'  The full weekday name according to the current locale.
    `%b'  The abbreviated month name according to the current locale.
    `%B'  The full month name according to the current locale.
    `%c'  The preferred date and time representation for the current
          locale.
    `%d'  The day of the month as a decimal number (range `01' to `31').
    `%D'  The day of the month as above but no leading zero.
    `%H'  The hour as a decimal number, using a 24-hour clock (range
          `00' to `23').
    `%I'  The hour as a decimal number, using a 12-hour clock (range
          `01' to `12').
     %i'  The hour as a decimal number, using a 12-hour clock with
          no leading zero.
    `%j'  The day of the year as a decimal number (range `001' to
          `366').
    `%m'  The month as a decimal number (range `01' to `12').
    `%M'  The minute as a decimal number.
    `%p'  Either `am' or `pm', according to the given time value; or the
          corresponding strings for the current locale.
    `%S'  The second as a decimal number.
    `%U'  The week number of the current year as a decimal number,
          starting with the first Sunday as the first day of the first
          week.
    `%W'  The week number of the current year as a decimal number,
          starting with the first Monday as the first day of the first
          week.
    `%w'  The day of the week as a decimal number, Sunday being `0'.
    `%x'  The preferred date representation for the current locale, but
          without the time.
    `%X'  The preferred time representation for the current locale, but
          with no date.
    `%y'  The year as a decimal number, but without a century (range
          `00' to `99').
    `%Y'  The year as a decimal number, including the century.
    `%Z'  The time zone or name or abbreviation (empty if the time zone
          can't be determined).
    `%%'  A literal `%' character.

   Therefore the pattern "%A, %D %b %Y" produces "Sunday, 12 Oct 1993"

---------------------------------------------------------------------------------

Changes this release:

1) Fixed a couple of small bugs in the DateTimeStr.DateToStr procedure
   which were spotted by Michael van Acken.

2) Totally revamped DateTimeConv.DaysToDate and DateTimeConv.DateToDays
   to distinguish between Julian and Gregorian calendars and automatically
   switch between them when necessary.  Also removed some bugs caused
   by the use of REAL numbers when LONGREAL were necessary.  

3) Added a new TimeStamp to the DateTimeConv module at Michael Van Acken's
   request.  I really don't like the limitations inherent in the Unix
   time stamp so I defined my own which is the same size as the Unix
   time stamp and can represent almost any date/time.

4) Removed extraneous stuff from SysClock, again at Michael's request.

5) Added comments throughout and formatted them to display in 80 columns.

6) Changed DateTimeStr.StrToDate to return a TRUE value if the string
   parsing was successful.

7) Changed the default patterns for %X, %x, and %c to be in line with
   the Unix/POSIX defaults.

8) Compensate for daylight savings time (if in effect) when converting
   to/from GMT times.

9) Added a procedure to DateTimeConv which returns the local time
   zone abbreviation.

10)Also added the capability of setting the change-over date when the
   Gregorian calendar was adopted since this date is not the same for
   every country.  The default is the British adoption which occurred
   3 Sep 1752 (according to the Julian calendar).

Most changes above are due to Michael van Acken who has really helped
me in refining these modules to be consistent and to better meet more
of the needs of the OOC project.

<Michael Griebling grieblm@inforamp.net>