Package: Util.Calendars.Gregorian

Dependencies

with Util.Calendars.Western;
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:
Provides a Gregorian calendar. The Gregorian calendar is the one that is used throughout the world today. It had been introduced by the papal bull of pope Gregory XIII on 24-FEB-1582 (Julian!). This bull decreed that the day following 4-OCT-1582 (Julian) would be 15-OCT-1582. The latter is thus the base date for the Gregorian calendar (Julian day number 2299161).

As an aside, please note that the weekday was left unaffected by this change! 4-OCT-1582 was a Thursday, and the next day was a Friday, irrespective of the calendar used!

The Gregorian calendar differs from the Julian calendar in the way leap years are determined and in the way the easter date is calculated.

Not all countries and regions changed that day from the Julian to the new Gregorian calendars. Many countries adopted the Gregorian calendar only in the 20th century! This implementation ignores all these differences; if you need a localized calendar that takes account of all the very complicated and illogical calendarical changes as they really happened, you can always construct your own calendar from the Julian and Gregorian ones. See the Calendar FAQ for some change dates. Also see Util.Calendars.Universal for a calendar that combines the Julian and the Gregorian calendars, and that allows you to define the date the swicth occurred.

This is not a proleptic calendar: trying to use it on dates before Julian day 2299161 will result in a Date_Error exception.

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

Header

package Util.Calendars.Gregorian 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:  Week
Inherited Operations:  Add_Months, Day, Image, Image, Is_Leap_Year, Month, Split, Split, Sub_Months, Time_Of, Year

Other Items:

type Calendar is new Util.Calendars.Western.Calendar with null record;

subtype Year_Number  is Util.Calendars.Western.Year_Number;

subtype Month_Number is Util.Calendars.Western.Month_Number;

subtype Day_Number   is Util.Calendars.Western.Day_Number;

function Is_Leap_Year
  (Base : in Calendar;
   Year : in Year_Number)
  return Boolean;
Raises Date_Error if Year < 1582.

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;
Raises Date_Error if the date is before 15-OCT-1582.

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);
Raises Date_Error if the date is before 15-OCT-1582.

function Day_In_Year
  (Base : in Calendar;
   Date : in Util.Times.Time)
  return Util.Calendars.Western.Day_Count;
Raises Date_Error if the date is before 15-OCT-1582. Note that 1582 is a tricky year for this, because in the Gregorian calendar it is 10 days shorter than other years.

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;
Raises Date_Error if Day = 366 and Is_Leap_Year (Year) = False or if the date is before 15-OCT-1582, or if the year is 1582 and Day > 355.

function Easter
  (Base : in Calendar;
   Year : in Year_Number)
  return Util.Times.Time;
Returns midnight on easter in the given year. Raises Date_Error if Year < 1583.

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

subtype Week_Number is Natural range 1 .. 53;
A week always starts on a Monday.

procedure Week
  (Base : in     Calendar;
   Date : in     Util.Times.Time;
   Year :    out Year_Number;
   Week :    out Week_Number);
Calculates the ISO 8601 week-based year. Week #1 is the week that includes both January 4 and the first Thursday of the year. If the first Monday is January 2nd, 3rd, or 4th, the preceeding days are part of the last week of the preceeding year. (Example: Sat, 2-JAN-1999 is week #53 of year 1998.) If Dec 29, 30, or 31 is a Monday, it and the following days are part of week #1 of the next year. (Example: Tue, 30-DEC-1997 is week #1 of year 1998.)

Raises Date_Error if the date is before 15-OCT-1582.

end Util.Calendars.Gregorian;