<!--
$PostgreSQL: pgsql/doc/src/sgml/datetime.sgml,v 2.39 2003/12/01 20:34:53 tgl Exp $
-->

 <appendix id="datetime-appendix">
  <title>Date/Time Support</title>

  <para>
   <productname>PostgreSQL</productname> uses an internal heuristic
   parser for all date/time input support. Dates and times are input as
   strings, and are broken up into distinct fields with a preliminary
   determination of what kind of information may be in the
   field. Each field is interpreted and either assigned a numeric
   value, ignored, or rejected.
   The parser contains internal lookup tables for all textual fields,
   including months, days of the week, and time
   zones.
  </para>

  <para>
   This appendix includes information on the content of these
   lookup tables and describes the steps used by the parser to decode
   dates and times.
  </para>

  <sect1>
   <title>Date/Time Input Interpretation</title>

   <para>
    The date/time type inputs are all decoded using the following procedure.
   </para>

   <procedure>
    <step>
     <para>
      Break the input string into tokens and categorize each token as
      a string, time, time zone, or number.
     </para>

     <substeps>
      <step>
       <para>
	If the numeric token contains a colon (<literal>:</>), this is
	a time string. Include all subsequent digits and colons.
       </para>
      </step>

      <step>
       <para>
	If the numeric token contains a dash (<literal>-</>), slash
	(<literal>/</>), or two or more dots (<literal>.</>), this is
	a date string which may have a text month.
       </para>
      </step>

      <step>
       <para>
	If the token is numeric only, then it is either a single field
	or an ISO 8601 concatenated date (e.g.,
	<literal>19990113</literal> for January 13, 1999) or time
	(e.g., <literal>141516</literal> for 14:15:16).
       </para>
      </step>

      <step>
       <para>
	If the token starts with a plus (<literal>+</>) or minus
	(<literal>-</>), then it is either a time zone or a special
	field.
       </para>
      </step>
     </substeps>
    </step>

    <step>
     <para>
      If the token is a text string, match up with possible strings.
     </para>
     
     <substeps>
      <step>
       <para>
	Do a binary-search table lookup for the token
	as either a special string (e.g., <literal>today</literal>),
	day (e.g., <literal>Thursday</literal>),
	month (e.g., <literal>January</literal>),
	or noise word (e.g., <literal>at</literal>, <literal>on</literal>).
       </para>

       <para>
	Set field values and bit mask for fields.
	For example, set year, month, day for <literal>today</literal>,
	and additionally hour, minute, second for <literal>now</literal>.
       </para>
      </step>
      
      <step>
       <para>
	If not found, do a similar binary-search table lookup to match
	the token with a time zone.
       </para>
      </step>

      <step>
       <para>
	If still not found, throw an error.
       </para>
      </step>
     </substeps>
    </step>
    
    <step>
     <para>
      When the token is a number or number field:
     </para>

     <substeps>
      <step>
       <para>
	If there are eight or six digits,
	and if no other date fields have been previously read, then interpret 
	as a <quote>concatenated date</quote> (e.g.,
	<literal>19990118</literal> or <literal>990118</literal>).
	The interpretation is <literal>YYYYMMDD</> or <literal>YYMMDD</>.
       </para>
      </step>

      <step>
       <para>
	If the token is three digits
	and a year has already been read, then interpret as day of year.
       </para>
      </step>
      
      <step>
       <para>
	If four or six digits and a year has already been read, then
	interpret as a time (<literal>HHMM</> or <literal>HHMMSS</>).
       </para>
      </step>

      <step>
       <para>
	If three or more digits and no date fields have yet been found,
	interpret as a year (this forces yy-mm-dd ordering of the remaining
	date fields).
       </para>
      </step>

      <step>
       <para>
        Otherwise the date field ordering is assumed to follow the
	<varname>DateStyle</> setting: mm-dd-yy, dd-mm-yy, or yy-mm-dd.
	Throw an error if a month or day field is found to be out of range.
       </para>
      </step>
     </substeps>
    </step>

    <step>
     <para>
      If BC has been specified, negate the year and add one for
      internal storage.  (There is no year zero in the Gregorian
      calendar, so numerically 1 BC becomes year
      zero.)
     </para>
    </step>

    <step>
     <para>
      If BC was not specified, and if the year field was two digits in length, then
      adjust the year to four digits. If the field is less than 70, then add 2000,
      otherwise add 1900.

      <tip>
       <para>
	Gregorian years AD 1-99 may be entered by using 4 digits with leading
	zeros (e.g., <literal>0099</> is AD 99). Previous versions of
	<productname>PostgreSQL</productname> accepted years with three
	digits and with single digits, but as of version 7.0 the rules have
	been tightened up to reduce the possibility of ambiguity.
       </para>
      </tip>
     </para>
    </step>
   </procedure>
  </sect1>


  <sect1 id="datetime-keywords">
   <title>Date/Time Key Words</title>

   <para>
    <xref linkend="datetime-month-table"> shows the tokens that are
    permissible as abbreviations for the names of the month.
   </para>

    <table id="datetime-month-table">
     <title>Month Abbreviations</title>
     <tgroup cols="2">
      <thead>
       <row>
	<entry>Month</entry>
	<entry>Abbreviations</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>April</entry>
	<entry>Apr</entry>
       </row>
       <row>
	<entry>August</entry>
	<entry>Aug</entry>
       </row>
       <row>
	<entry>December</entry>
	<entry>Dec</entry>
       </row>
       <row>
	<entry>February</entry>
	<entry>Feb</entry>
       </row>
       <row>
	<entry>January</entry>
	<entry>Jan</entry>
       </row>
       <row>
	<entry>July</entry>
	<entry>Jul</entry>
       </row>
       <row>
	<entry>June</entry>
	<entry>Jun</entry>
       </row>
       <row>
	<entry>March</entry>
	<entry>Mar</entry>
       </row>
       <row>
	<entry>November</entry>
	<entry>Nov</entry>
       </row>
       <row>
	<entry>October</entry>
	<entry>Oct</entry>
       </row>
       <row>
	<entry>September</entry>
	<entry>Sep, Sept</entry>
       </row>
      </tbody>
     </tgroup>
    </table>

    <note>
     <para>
      The month May has no explicit abbreviation, for obvious reasons.
     </para>
    </note>

    <para>
     <xref linkend="datetime-dow-table"> shows the tokens that are
     permissible as abbreviations for the names of the days of the
     week.
    </para>

     <table id="datetime-dow-table">
      <title>Day of the Week Abbreviations</title>
      <tgroup cols="2">
       <thead>
	<row>
	 <entry>Day</entry>
	 <entry>Abbreviation</entry>
	</row>
       </thead>
       <tbody>
	<row>
	 <entry>Sunday</entry>
	 <entry>Sun</entry>
	</row>
	<row>
	 <entry>Monday</entry>
	 <entry>Mon</entry>
	</row>
	<row>
	 <entry>Tuesday</entry>
	 <entry>Tue, Tues</entry>
	</row>
	<row>
	 <entry>Wednesday</entry>
	 <entry>Wed, Weds</entry>
	</row>
	<row>
	 <entry>Thursday</entry>
	 <entry>Thu, Thur, Thurs</entry>
	</row>
	<row>
	 <entry>Friday</entry>
	 <entry>Fri</entry>
	</row>
	<row>
	 <entry>Saturday</entry>
	 <entry>Sat</entry>
	</row>
       </tbody>
      </tgroup>
     </table>

   <para>
    <xref linkend="datetime-mod-table"> shows the tokens that serve
    various modifier purposes.
   </para>

    <table id="datetime-mod-table">
     <title>Date/Time Field Modifiers</title>
     <tgroup cols="2">
      <thead>
       <row>
	<entry>Identifier</entry>
	<entry>Description</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry><literal>ABSTIME</literal></entry>
	<entry>Key word ignored</entry>
       </row>
       <row>
	<entry><literal>AM</literal></entry>
	<entry>Time is before 12:00</entry>
       </row>
       <row>
	<entry><literal>AT</literal></entry>
	<entry>Key word ignored</entry>
       </row>
       <row>
	<entry><literal>JULIAN</>, <literal>JD</>, <literal>J</></entry>
	<entry>Next field is Julian Day</entry>
       </row>
       <row>
	<entry><literal>ON</literal></entry>
	<entry>Key word ignored</entry>
       </row>
       <row>
	<entry><literal>PM</literal></entry>
	<entry>Time is on or after 12:00</entry>
       </row>
       <row>
	<entry><literal>T</literal></entry>
	<entry>Next field is time</entry>
       </row>
      </tbody>
     </tgroup>
    </table>

   <para>
    The key word <literal>ABSTIME</literal> is ignored for historical
    reasons: In very old releases of
    <productname>PostgreSQL</productname>, invalid values of type <type>abstime</type>
    were emitted as <literal>Invalid Abstime</literal>. This is no
    longer the case however and this key word will likely be dropped in
    a future release.
   </para>

   <indexterm>
    <primary>time zone</primary>
    <secondary>abbreviations</secondary>
   </indexterm>

   <para>
    <xref linkend="datetime-timezone-table"> shows the time zone
    abbreviations recognized by <productname>PostgreSQL</productname>
    in date/time input values.
    <productname>PostgreSQL</productname> uses internal tables
    for time zone input decoding, since there is no standard
    operating system interface to provide access to general,
    cross-time zone information. The underlying operating system
    <emphasis>is</emphasis> used to provide time zone information for
    <emphasis>output</emphasis>, however.
   </para>

   <para>
    Keep in mind also that the time zone names
    recognized by <command>SET TIMEZONE</> are operating-system
    dependent and may have little to do with <xref
    linkend="datetime-timezone-table">.  For example, some systems
    recognize values like <literal>'Europe/Rome'</> in <command>SET
    TIMEZONE</>.
   </para>

   <para>
    The table is organized by time zone offset from <acronym>UTC</>,
    rather than alphabetically.  This is intended to facilitate
    matching local usage with recognized abbreviations for cases where
    these might differ.
   </para>

    <table id="datetime-timezone-table">
     <title>Time Zone Abbreviations</title>
     <tgroup cols="3">
      <thead>
       <row>
	<entry>Time Zone</entry>
	<entry>Offset from UTC</entry>
	<entry>Description</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>NZDT</entry>
	<entry>+13:00</entry>
	<entry>New Zealand Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>IDLE</entry>
	<entry>+12:00</entry>
	<entry>International Date Line, East</entry>
       </row>
       <row>
	<entry>NZST</entry>
	<entry>+12:00</entry>
	<entry>New Zealand Standard Time</entry>
       </row>
       <row>
	<entry>NZT</entry>
	<entry>+12:00</entry>
	<entry>New Zealand Time</entry>
       </row>
       <row>
	<entry>AESST</entry>
	<entry>+11:00</entry>
	<entry>Australia Eastern Summer Standard Time</entry>
       </row>
       <row>
	<entry>ACSST</entry>
	<entry>+10:30</entry>
	<entry>Central Australia Summer Standard Time</entry>
       </row>
       <row>
	<entry>CADT</entry>
	<entry>+10:30</entry>
	<entry>Central Australia Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>SADT</entry>
	<entry>+10:30</entry>
	<entry>South Australian Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>AEST</entry>
	<entry>+10:00</entry>
	<entry>Australia Eastern Standard Time</entry>
       </row>
       <row>
	<entry>EAST</entry>
	<entry>+10:00</entry>
	<entry>East Australian Standard Time</entry>
       </row>
       <row>
	<entry>GST</entry>
	<entry>+10:00</entry>
	<entry>Guam Standard Time, Russia zone 9</entry>
       </row>
       <row>
	<entry>LIGT</entry>
	<entry>+10:00</entry>
	<entry>Melbourne, Australia</entry>
       </row>
       <row>
	<entry>SAST</entry>
	<entry>+09:30</entry>
	<entry>South Australia Standard Time</entry>
       </row>
       <row>
	<entry>CAST</entry>
	<entry>+09:30</entry>
	<entry>Central Australia Standard Time</entry>
       </row>
       <row>
	<entry>AWSST</entry>
	<entry>+09:00</entry>
	<entry>Australia Western Summer Standard Time</entry>
       </row>
       <row>
	<entry>JST</entry>
	<entry>+09:00</entry>
	<entry>Japan Standard Time, Russia zone 8</entry>
       </row>
       <row>
	<entry>KST</entry>
	<entry>+09:00</entry>
	<entry>Korea Standard Time</entry>
       </row>
       <row>
	<entry>MHT</entry>
	<entry>+09:00</entry>
	<entry>Kwajalein Time</entry>
       </row>
       <row>
	<entry>WDT</entry>
	<entry>+09:00</entry>
	<entry>West Australian Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>MT</entry>
	<entry>+08:30</entry>
	<entry>Moluccas Time</entry>
       </row>
       <row>
	<entry>AWST</entry>
	<entry>+08:00</entry>
	<entry>Australia Western Standard Time</entry>
       </row>
       <row>
	<entry>CCT</entry>
	<entry>+08:00</entry>
	<entry>China Coastal Time</entry>
       </row>
       <row>
	<entry>WADT</entry>
	<entry>+08:00</entry>
	<entry>West Australian Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>WST</entry>
	<entry>+08:00</entry>
	<entry>West Australian Standard Time</entry>
       </row>
       <row>
	<entry>JT</entry>
	<entry>+07:30</entry>
	<entry>Java Time</entry>
       </row>
       <row>
	<entry>ALMST</entry>
	<entry>+07:00</entry>
	<entry>Almaty Summer Time</entry>
       </row>
       <row>
	<entry>WAST</entry>
	<entry>+07:00</entry>
	<entry>West Australian Standard Time</entry>
       </row>
       <row>
	<entry>CXT</entry>
	<entry>+07:00</entry>
	<entry>Christmas (Island) Time</entry>
       </row>
       <row>
	<entry>MMT</entry>
	<entry>+06:30</entry>
	<entry>Myanmar Time</entry>
       </row>
       <row>
	<entry>ALMT</entry>
	<entry>+06:00</entry>
	<entry>Almaty Time</entry>
       </row>
       <row>
	<entry>MAWT</entry>
	<entry>+06:00</entry>
	<entry>Mawson (Antarctica) Time</entry>
       </row>
       <row>
	<entry>IOT</entry>
	<entry>+05:00</entry>
	<entry>Indian Chagos Time</entry>
       </row>
       <row>
	<entry>MVT</entry>
	<entry>+05:00</entry>
	<entry>Maldives Island Time</entry>
       </row>
       <row>
	<entry>TFT</entry>
	<entry>+05:00</entry>
	<entry>Kerguelen Time</entry>
       </row>
       <row>
	<entry>AFT</entry>
	<entry>+04:30</entry>
	<entry>Afghanistan Time</entry>
       </row>
       <row>
	<entry>EAST</entry>
	<entry>+04:00</entry>
	<entry>Antananarivo Summer Time</entry>
       </row>
       <row>
	<entry>MUT</entry>
	<entry>+04:00</entry>
	<entry>Mauritius Island Time</entry>
       </row>
       <row>
	<entry>RET</entry>
	<entry>+04:00</entry>
	<entry>Reunion Island Time</entry>
       </row>
       <row>
	<entry>SCT</entry>
	<entry>+04:00</entry>
	<entry>Mahe Island Time</entry>
       </row>
       <row>
	<entry>IRT, IT</entry>
	<entry>+03:30</entry>
	<entry>Iran Time</entry>
       </row>
       <row>
	<entry>EAT</entry>
	<entry>+03:00</entry>
	<entry>Antananarivo, Comoro Time</entry>
       </row>
       <row>
	<entry>BT</entry>
	<entry>+03:00</entry>
	<entry>Baghdad Time</entry>
       </row>
       <row>
	<entry>EETDST</entry>
	<entry>+03:00</entry>
	<entry>Eastern Europe Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>HMT</entry>
	<entry>+03:00</entry>
	<entry>Hellas Mediterranean Time (?)</entry>
       </row>
       <row>
	<entry>BDST</entry>
	<entry>+02:00</entry>
	<entry>British Double Standard Time</entry>
       </row>
       <row>
	<entry>CEST</entry>
	<entry>+02:00</entry>
	<entry>Central European Summer Time</entry>
       </row>
       <row>
	<entry>CETDST</entry>
	<entry>+02:00</entry>
	<entry>Central European Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>EET</entry>
	<entry>+02:00</entry>
	<entry>Eastern European Time, Russia zone 1</entry>
       </row>
       <row>
	<entry>FWT</entry>
	<entry>+02:00</entry>
	<entry>French Winter Time</entry>
       </row>
       <row>
	<entry>IST</entry>
	<entry>+02:00</entry>
	<entry>Israel Standard Time</entry>
       </row>
       <row>
	<entry>MEST</entry>
	<entry>+02:00</entry>
	<entry>Middle European Summer Time</entry>
       </row>
       <row>
	<entry>METDST</entry>
	<entry>+02:00</entry>
	<entry>Middle Europe Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>SST</entry>
	<entry>+02:00</entry>
	<entry>Swedish Summer Time</entry>
       </row>
       <row>
	<entry>BST</entry>
	<entry>+01:00</entry>
	<entry>British Summer Time</entry>
       </row>
       <row>
	<entry>CET</entry>
	<entry>+01:00</entry>
	<entry>Central European Time</entry>
       </row>
       <row>
	<entry>DNT</entry>
	<entry>+01:00</entry>
	<entry><foreignphrase>Dansk Normal Tid</foreignphrase></entry>
       </row>
       <row>
	<entry>FST</entry>
	<entry>+01:00</entry>
	<entry>French Summer Time</entry>
       </row>
       <row>
	<entry>MET</entry>
	<entry>+01:00</entry>
	<entry>Middle European Time</entry>
       </row>
       <row>
	<entry>MEWT</entry>
	<entry>+01:00</entry>
	<entry>Middle European Winter Time</entry>
       </row>
       <row>
	<entry>MEZ</entry>
	<entry>+01:00</entry>
	<entry><foreignphrase>Mitteleuropäische Zeit</></entry>
       </row>
       <row>
	<entry>NOR</entry>
	<entry>+01:00</entry>
	<entry>Norway Standard Time</entry>
       </row>
       <row>
	<entry>SET</entry>
	<entry>+01:00</entry>
	<entry>Seychelles Time</entry>
       </row>
       <row>
	<entry>SWT</entry>
	<entry>+01:00</entry>
	<entry>Swedish Winter Time</entry>
       </row>
       <row>
	<entry>WETDST</entry>
	<entry>+01:00</entry>
	<entry>Western European Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>GMT</entry>
	<entry>00:00</entry>
	<entry>Greenwich Mean Time</entry>
       </row>
       <row>
	<entry>UT</entry>
	<entry>00:00</entry>
	<entry>Universal Time</entry>
       </row>
       <row>
	<entry>UTC</entry>
	<entry>00:00</entry>
	<entry>Universal Coordinated Time</entry>
       </row>
       <row>
	<entry>Z</entry>
	<entry>00:00</entry>
	<entry>Same as UTC</entry>
       </row>
       <row>
	<entry>ZULU</entry>
	<entry>00:00</entry>
	<entry>Same as UTC</entry>
       </row>
       <row>
	<entry>WET</entry>
	<entry>00:00</entry>
	<entry>Western European Time</entry>
       </row>
       <row>
	<entry>WAT</entry>
	<entry>-01:00</entry>
	<entry>West Africa Time</entry>
       </row>
       <row>
	<entry>FNST</entry>
	<entry>-01:00</entry>
	<entry>Fernando de Noronha Summer Time</entry>
       </row>
       <row>
	<entry>FNT</entry>
	<entry>-02:00</entry>
	<entry>Fernando de Noronha Time</entry>
       </row>
       <row>
	<entry>BRST</entry>
	<entry>-02:00</entry>
	<entry>Brasilia Summer Time</entry>
       </row>
       <row>
	<entry>NDT</entry>
	<entry>-02:30</entry>
	<entry>Newfoundland Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>ADT</entry>
	<entry>-03:00</entry>
	<entry>Atlantic Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>AWT</entry>
	<entry>-03:00</entry>
	<entry>(unknown)</entry>
       </row>
       <row>
	<entry>BRT</entry>
	<entry>-03:00</entry>
	<entry>Brasilia Time</entry>
       </row>
       <row>
	<entry>NFT</entry>
	<entry>-03:30</entry>
	<entry>Newfoundland Standard Time</entry>
       </row>
       <row>
	<entry>NST</entry>
	<entry>-03:30</entry>
	<entry>Newfoundland Standard Time</entry>
       </row>
       <row>
	<entry>AST</entry>
	<entry>-04:00</entry>
	<entry>Atlantic Standard Time (Canada)</entry>
       </row>
       <row>
	<entry>ACST</entry>
	<entry>-04:00</entry>
	<entry>Atlantic/Porto Acre Summer Time</entry>
       </row>
       <row>
	<entry>EDT</entry>
	<entry>-04:00</entry>
	<entry>Eastern Daylight-Saving Time</entry>
       </row>
       <!--
      <row>
      <entry>ZP4</entry>
      <entry>-04:00</entry>
      <entry>GMT +4 hours</entry>
      </row>
       -->
       <row>
	<entry>ACT</entry>
	<entry>-05:00</entry>
	<entry>Atlantic/Porto Acre Standard Time</entry>
       </row>
       <row>
	<entry>CDT</entry>
	<entry>-05:00</entry>
	<entry>Central Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>EST</entry>
	<entry>-05:00</entry>
	<entry>Eastern Standard Time</entry>
       </row>
       <!--
      <row>
      <entry>ZP5</entry>
      <entry>-05:00</entry>
      <entry>GMT +5  hours</entry>
      </row>
       -->
       <row>
	<entry>CST</entry>
	<entry>-06:00</entry>
	<entry>Central Standard Time</entry>
       </row>
       <row>
	<entry>MDT</entry>
	<entry>-06:00</entry>
	<entry>Mountain Daylight-Saving Time</entry>
       </row>
       <!--
      <row>
      <entry>ZP6</entry>
      <entry>-06:00</entry>
      <entry>GMT +6  hours</entry>
      </row>
       -->
       <row>
	<entry>MST</entry>
	<entry>-07:00</entry>
	<entry>Mountain Standard Time</entry>
       </row>
       <row>
	<entry>PDT</entry>
	<entry>-07:00</entry>
	<entry>Pacific Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>AKDT</entry>
	<entry>-08:00</entry>
	<entry>Alaska Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>PST</entry>
	<entry>-08:00</entry>
	<entry>Pacific Standard Time</entry>
       </row>
       <row>
	<entry>YDT</entry>
	<entry>-08:00</entry>
	<entry>Yukon Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>AKST</entry>
	<entry>-09:00</entry>
	<entry>Alaska Standard Time</entry>
       </row>
       <row>
	<entry>HDT</entry>
	<entry>-09:00</entry>
	<entry>Hawaii/Alaska Daylight-Saving Time</entry>
       </row>
       <row>
	<entry>YST</entry>
	<entry>-09:00</entry>
	<entry>Yukon Standard Time</entry>
       </row>
       <row>
	<entry>MART</entry>
	<entry>-09:30</entry>
	<entry>Marquesas Time</entry>
       </row>
       <row>
	<entry>AHST</entry>
	<entry>-10:00</entry>
	<entry>Alaska/Hawaii Standard Time</entry>
       </row>
       <row>
	<entry>HST</entry>
	<entry>-10:00</entry>
	<entry>Hawaii Standard Time</entry>
       </row>
       <row>
	<entry>CAT</entry>
	<entry>-10:00</entry>
	<entry>Central Alaska Time</entry>
       </row>
       <row>
	<entry>NT</entry>
	<entry>-11:00</entry>
	<entry>Nome Time</entry>
       </row>
       <row>
	<entry>IDLW</entry>
	<entry>-12:00</entry>
	<entry>International Date Line, West</entry>
       </row>
      </tbody>
     </tgroup>
    </table>

  <formalpara>
   <title>Australian Time Zones</title>

   <para>
    There are three naming conflicts between Australian time zone
    names and time zone names commonly used in North and South America:
    <literal>ACST</literal>, <literal>CST</literal>, and
    <literal>EST</literal>.  If the run-time option
    <varname>australian_timezones</varname> is set to true then
    <literal>ACST</literal>, <literal>CST</literal>,
    <literal>EST</literal>, and <literal>SAT</literal> are interpreted
    as Australian time zone names, as shown in <xref
    linkend="datetime-oztz-table">. If it is false (which is the
    default), then <literal>ACST</literal>, <literal>CST</literal>,
    and <literal>EST</literal> are taken as American time zone names,
    and <literal>SAT</literal> is interpreted as a noise word
    indicating Saturday.
   </para>
  </formalpara>

    <table id="datetime-oztz-table">
     <title>Australian Time Zone Abbreviations</title>
     <tgroup cols="3">
      <thead>
       <row>
	<entry>Time Zone</entry>
	<entry>Offset from UTC</entry>
	<entry>Description</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>ACST</entry>
	<entry>+09:30</entry>
	<entry>Central Australia Standard Time</entry>
       </row>
       <row>
	<entry>CST</entry>
	<entry>+10:30</entry>
	<entry>Australian Central Standard Time</entry>
       </row>
       <row>
	<entry>EST</entry>
	<entry>+10:00</entry>
	<entry>Australian Eastern Standard Time</entry>
       </row>
       <row>
	<entry>SAT</entry>
	<entry>+09:30</entry>
	<entry>South Australian Standard Time</entry>
       </row>
      </tbody>
     </tgroup>
    </table>

  </sect1>

  <sect1 id="datetime-units-history">
  <title>History of Units</title>

  <para>
   The Julian Date was invented by the French scholar
   Joseph Justus Scaliger (1540-1609)
   and probably takes its name from Scaliger's father,
   the Italian scholar Julius Caesar Scaliger (1484-1558).
   Astronomers have used the Julian period to assign a unique number to
   every day since 1 January 4713 BC. This is the so-called Julian Date
   (JD). JD 0 designates the 24 hours from noon UTC on 1 January 4713 BC
   to noon UTC on 2 January 4713 BC.
  </para>

   <para>
   The <quote>Julian Date</quote> is different from the <quote>Julian
   Calendar</quote>.  The Julian calendar
   was introduced by Julius Caesar in 45 BC. It was in common use
   until the year 1582, when countries started changing to the Gregorian
   calendar.  In the Julian calendar, the tropical year is
   approximated as 365 1/4 days = 365.25 days. This gives an error of
   about 1 day in 128 years.
  </para>

  <para>   
   The accumulating calendar error prompted
   Pope Gregory XIII to reform the calendar in accordance with
   instructions from the Council of Trent.
   In the Gregorian calendar, the tropical year is approximated as
   365 + 97 / 400 days = 365.2425 days. Thus it takes approximately 3300
   years for the tropical year to shift one day with respect to the
   Gregorian calendar.
  </para>

  <para>
   The approximation 365+97/400 is achieved by having 97 leap years
   every 400 years, using the following rules:

   <simplelist>
    <member>
     Every year divisible by 4 is a leap year.
    </member>
    <member>
     However, every year divisible by 100 is not a leap year.
    </member>
    <member>
     However, every year divisible by 400 is a leap year after all.
    </member>
   </simplelist>

   So, 1700, 1800, 1900, 2100, and 2200 are not leap years. But 1600,
   2000, and 2400 are leap years.

   By contrast, in the older Julian calendar all years divisible by 4 are leap
   years.
  </para>

  <para>
   The papal bull of February 1582 decreed that 10 days should be dropped
   from October 1582 so that 15 October should follow immediately after
   4 October.
   This was observed in Italy, Poland, Portugal, and Spain. Other Catholic
   countries followed shortly after, but Protestant countries were
   reluctant to change, and the Greek orthodox countries didn't change
   until the start of the 20th century.

   The reform was observed by Great Britain and Dominions (including what is
   now the USA) in 1752.
   Thus 2 September 1752 was followed by 14 September 1752.

   This is why Unix systems have the <command>cal</command> program
   produce the following:

<screen>
$ <userinput>cal 9 1752</userinput>
   September 1752
 S  M Tu  W Th  F  S
       1  2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
</screen>
  </para>

   <note>
    <para>
     The SQL standard states that <quote>Within the definition of a
     <quote>datetime literal</quote>, the <quote>datetime
     value</quote>s are constrained by the natural rules for dates and
     times according to the Gregorian calendar</quote>.  Dates between
     1752-09-03 and 1752-09-13, although eliminated in some countries
     by Papal fiat, conform to <quote>natural rules</quote> and are
     hence valid dates.
    </para>
   </note>

  <para>
   Different calendars have been developed in various parts of the
   world, many predating the Gregorian system.

   For example,
   the beginnings of the Chinese calendar can be traced back to the 14th
   century BC. Legend has it that the Emperor Huangdi invented the
   calendar in 2637 BC.
   
   The People's Republic of China uses the Gregorian calendar
   for civil purposes. The Chinese calendar is used for determining
   festivals.
  </para>
 </sect1>
</appendix>

<!-- Keep this comment at the end of the file
Local variables:
mode:sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"./reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:("/usr/lib/sgml/catalog")
sgml-local-ecat-files:nil
End:
-->
