Package: Util.Calendars.Universal

Dependencies

with Util.Calendars.Western;
with Util.Calendars.Gregorian;
with Util.Times;

Description

Copyright © 2001, 2002 by Thomas Wolf.
This piece of software is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This software is distributed in the hope that it will be useful, but without 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 with this distribution, see file "GPL.txt". If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception from the GPL, 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 GPL. This exception does not however invalidate any other reasons why the executable file might be covered by the GPL.

Version: 1.1

Author:
Thomas Wolf (TW) <twolf AT acm DOT org>
Purpose:
This is a mixed proleptic Julian (for dates prior to and including 4-OCT-1582 A.D.) and Gregorian (for dates from 15-OCT-1582 on) calendar, i.e. the calendar used in the western world, if we ignore the chaotic differences in the times the Gregorian calendar was actually adopted and the Romans' early counting error that caused every third year from 45 B.C. to 8 B.C. be a leap year (which was then corrected by not having any leap years at all from 7 B.C. until 8 A.D., which again was a leap year).

By the way, note that the day of the week did not change in Oct 1582, Oct 4 was a Thursday, and Oct 15 was a Friday! (And so is, of course, Oct 5, 1582 A.D. in the Julian calendar.)

Because not all countries and regions adopted the Gregorian calendar in 1582 (notably many protestant areas switched much later, and some orthodox regions didn't switch until the 20th century), you can define the switch date. By default, it is set to 4-OCT-1582.

Tasking Semantics
Neither task- nor abortion-safe.
Storage Semantics
No dynamic storage allocation.

Header

package Util.Calendars.Universal is
 

Exceptions

Date_Error renames Util.Calendars.Date_Error

Type Summary

Calendar derived from Calendar
Overridden Operations:  Date, Day_In_Year, Day_Of_Week, Easter, Is_Leap_Year, Julian_Day, Time_Of
New Operations:  Set_Switch_Date, Set_Switch_Date, Switch_Date
Inherited Operations:  Add_Months, Day, Image, Image, Is_Leap_Year, Month, Split, Split, Sub_Months, Time_Of, Week, Year

Other Items:

type Calendar is new Util.Calendars.Gregorian.Calendar with private;

subtype Year_Number  is Util.Calendars.Gregorian.Year_Number;

subtype Month_Number is Util.Calendars.Gregorian.Month_Number;

subtype Day_Number   is Util.Calendars.Gregorian.Day_Number;

function Is_Leap_Year
  (Base : in Calendar;
   Year : in Year_Number)
  return Boolean;
Conversion routines.

function Julian_Day
  (Base  : in Calendar;
   Year  : in Year_Number;
   Month : in Util.Calendars.Western.Month_Number;
   Day   : in Util.Calendars.Western.Day_Number)
  return Util.Times.Julian_Day_Number;

procedure Date
  (Base       : in     Calendar;
   Julian_Day : in     Util.Times.Julian_Day_Number;
   Year       :    out Year_Number;
   Month      :    out Util.Calendars.Western.Month_Number;
   Day        :    out Util.Calendars.Western.Day_Number);
A system in which days are counted.

function Day_In_Year
  (Base : in Calendar;
   Date : in Util.Times.Time)
  return Util.Calendars.Western.Day_Count;

function Time_Of
  (Base    : in Calendar;
   Year    : in Year_Number;
   Day     : in Util.Calendars.Western.Day_Count;
   Seconds : in Util.Times.Day_Duration := 0.0)
  return Util.Times.Time;
Easter date

function Easter
  (Base : in Calendar;
   Year : in Year_Number)
  return Util.Times.Time;

function Day_Of_Week
  (Base : in Calendar;
   Date : in Util.Times.Time)
  return Util.Calendars.Western.Week_Day;

procedure Set_Switch_Date
  (Base : in out Calendar;
   Day  : in     Util.Times.Time);
Day is assumed to be the last day the Julian calendar was in effect. Note that this package does not allow more than one switch date to be defined: the pathological case of Sweden, which switched back and forth between the Julian and the Gregorian calendar in a most irregular fashion between 1700 and 1753 is not handled.

procedure Set_Switch_Date
  (Base : in out Calendar;
   Day  : in     Util.Times.Julian_Day_Number);
Day is assumed to be the last day the Julian calendar was in effect.

function Switch_Date
  (Base : in Calendar)
  return Util.Times.Julian_Day_Number;

private

   --  Implementation-defined ...
end Util.Calendars.Universal;