datetime.sgml
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:20k
源码类别:

数据库系统

开发平台:

Unix_Linux

  1. <!--
  2. $Header: /usr/local/cvsroot/pgsql/doc/src/sgml/datetime.sgml,v 2.4 1999/06/23 06:17:51 thomas Exp $
  3. Date/time details
  4. $Log: datetime.sgml,v $
  5. Revision 2.4  1999/06/23 06:17:51  thomas
  6. Clarify input/output timezone information.
  7. Add detail on exact interpretation of "concatenated date"
  8.  for various lengths.
  9. Revision 2.3  1999/05/26 17:30:28  thomas
  10. Add chapters on CVS access, MVCC, SQL theory to the docs.
  11. Add an appendix with more details on date/time attributes and handling.
  12. Update most references to Postgres version numbers to 6.5,
  13.  *except* for the porting list which will require a report
  14.  from a successful installation to be updated.
  15. Revision 2.2  1999/05/22 02:27:23  thomas
  16. Finish initial markup of cvs.sgml, and include it in the programmer's guide
  17.  and the integrated doc. Clean up other markup.
  18. -->
  19. <appendix label="UG1" id="datetime-appendix">
  20.  <title id="datetime-appendix-title">Date/Time Support</title>
  21.  <sect1>
  22.   <title>Time Zones</title>
  23.   <para>
  24.    <productname>Postgres</productname> must have internal tabular
  25.    information for time zone decoding, since there is no *nix standard
  26.    system interface to provide access to general, cross-timezone
  27.    information. The underlying OS <emphasis>is</emphasis> used to
  28.    provide time zone information for <emphasis>output</emphasis>.
  29.    <table tocentry="1">
  30.     <title><productname>Postgres</productname> Recognized Time Zones</title>
  31.     <titleabbrev>Time Zones</titleabbrev>
  32.     <tgroup cols="3">
  33.      <thead>
  34.       <row>
  35.        <entry>Time Zone</entry>
  36.        <entry>Offset from UTC</entry>
  37.        <entry>Description</entry>
  38.       </row>
  39.      </thead>
  40.      <tbody>
  41.       <row>
  42.        <entry>NZDT</entry>
  43.        <entry>+13:00</entry>
  44.        <entry>New Zealand Daylight Time</entry>
  45.       </row>
  46.       <row>
  47.        <entry>IDLE</entry>
  48.        <entry>+12:00</entry>
  49.        <entry>International Date Line, East</entry>
  50.       </row>
  51.       <row>
  52.        <entry>NZST</entry>
  53.        <entry>+12:00</entry>
  54.        <entry>New Zealand Std Time</entry>
  55.       </row>
  56.       <row>
  57.        <entry>NZT</entry>
  58.        <entry>+12:00</entry>
  59.        <entry>New Zealand Time</entry>
  60.       </row>
  61.       <row>
  62.        <entry>AESST</entry>
  63.        <entry>+11:00 </entry>
  64.        <entry>Australia Eastern Summer Std Time</entry>
  65.       </row>
  66.       <row>
  67.        <entry>ACSST</entry>
  68.        <entry>+10:30 </entry>
  69.        <entry>Central Australia Summer Std Time</entry>
  70.       </row>
  71.       <row>
  72.        <entry>CADT</entry>
  73.        <entry>+10:30 </entry>
  74.        <entry>Central Australia Daylight Savings Time</entry>
  75.       </row>
  76.       <row>
  77.        <entry>SADT</entry>
  78.        <entry>+10:30</entry>
  79.        <entry>South Australian Daylight Time</entry>
  80.       </row>
  81.       <row>
  82.        <entry>AEST</entry>
  83.        <entry>+10:00 </entry>
  84.        <entry>Australia Eastern Std Time</entry>
  85.       </row>
  86.       <row>
  87.        <entry>EAST</entry>
  88.        <entry>+10:00 </entry>
  89.        <entry>East Australian Std Time</entry>
  90. </row>
  91.       <row>
  92.        <entry>GST</entry>
  93.        <entry>+10:00</entry>
  94.        <entry>Guam Std Time, USSR Zone 9</entry>
  95.       </row>
  96.       <row>
  97.        <entry>LIGT</entry>
  98.        <entry>+10:00</entry>
  99.        <entry>Melbourne, Australia</entry>
  100.       </row>
  101.       <row>
  102.        <entry>ACST</entry>
  103.        <entry>+09:30 </entry>
  104.        <entry>Central Australia Std Time</entry>
  105.       </row>
  106.       <row>
  107.        <entry>CAST</entry>
  108.        <entry>+09:30 </entry>
  109.        <entry>Central Australia Std Time</entry>
  110.       </row>
  111.       <row>
  112.        <entry>SAT</entry>
  113.        <entry>+9:30</entry>
  114.        <entry>South Australian Std Time</entry>
  115.       </row>
  116.       <row>
  117.        <entry>AWSST</entry>
  118.        <entry>+9:00 </entry>
  119.        <entry>Australia Western Summer Std Time</entry>
  120.       </row>
  121.       <row>
  122.        <entry>JST</entry>
  123.        <entry>+9:00</entry>
  124.        <entry>Japan Std Time,USSR Zone 8</entry>
  125.       </row>
  126.       <row>
  127.        <entry>KST</entry>
  128.        <entry>+9:00</entry>
  129.        <entry>Korea Standard Time</entry>
  130.       </row>
  131.       <row>
  132.        <entry>WDT</entry>
  133.        <entry>+9:00</entry>
  134.        <entry>West Australian Daylight Time</entry>
  135.       </row>
  136.       <row>
  137.        <entry>MT</entry>
  138.        <entry>+8:30</entry>
  139.        <entry>Moluccas Time</entry>
  140.       </row>
  141.       <row>
  142.        <entry>AWST</entry>
  143.        <entry>+8:00 </entry>
  144.        <entry>Australia Western Std Time</entry>
  145.       </row>
  146.       <row>
  147.        <entry>CCT</entry>
  148.        <entry>+8:00 </entry>
  149.        <entry>China Coastal Time</entry>
  150.       </row>
  151.       <row>
  152.        <entry>WADT</entry>
  153.  <entry>+8:00</entry>
  154.        <entry>West Australian Daylight Time</entry>
  155.       </row>
  156.       <row>
  157.        <entry>WST</entry>
  158.        <entry>+8:00</entry>
  159.        <entry>West Australian Std Time</entry>
  160.       </row>
  161.       <row>
  162.        <entry>JT</entry>
  163.        <entry>+7:30</entry>
  164.        <entry>Java Time</entry>
  165.       </row>
  166.       <row>
  167.        <entry>WAST</entry>
  168.        <entry>+7:00</entry>
  169.        <entry>West Australian Std Time</entry>
  170. </row>
  171.       <row>
  172.        <entry>IT</entry>
  173.  <entry>+3:30</entry>
  174.        <entry>Iran Time</entry>
  175.       </row>
  176.       <row>
  177.        <entry>BT</entry>
  178.        <entry>+3:00 </entry>
  179.        <entry>Baghdad Time</entry>
  180.       </row>
  181.       <row>
  182.        <entry>EETDST</entry>
  183.        <entry>+3:00 </entry>
  184.        <entry>Eastern Europe Daylight Savings Time</entry>
  185.       </row>
  186.       <row>
  187.        <entry>CETDST</entry>
  188.        <entry>+2:00 </entry>
  189.        <entry>Central European Daylight Savings Time</entry>
  190.       </row>
  191.       <row>
  192.        <entry>EET</entry>
  193.        <entry>+2:00 </entry>
  194.        <entry>Eastern Europe, USSR Zone 1</entry>
  195.       </row>
  196.       <row>
  197.        <entry>FWT</entry>
  198.        <entry>+2:00</entry>
  199.        <entry>French Winter Time</entry>
  200.       </row>
  201.       <row>
  202.        <entry>IST</entry>
  203.        <entry>+2:00</entry>
  204.        <entry>Israel Std Time</entry>
  205.       </row>
  206.       <row>
  207.        <entry>MEST</entry>
  208.        <entry>+2:00</entry>
  209.        <entry>Middle Europe Summer Time</entry>
  210.       </row>
  211. <row>
  212.        <entry>METDST</entry>
  213.        <entry>+2:00</entry>
  214.        <entry>Middle Europe Daylight Time</entry>
  215.       </row>
  216.       <row>
  217.        <entry>SST</entry>
  218.        <entry>+2:00</entry>
  219.        <entry>Swedish Summer Time</entry>
  220.       </row>
  221.       <row>
  222.        <entry>BST</entry>
  223.        <entry>+1:00 </entry>
  224.        <entry>British Summer Time</entry>
  225.       </row>
  226.       <row>
  227.        <entry>CET</entry>
  228.        <entry>+1:00 </entry>
  229.        <entry>Central European Time</entry>
  230.       </row>
  231.       <row>
  232.        <entry>DNT</entry>
  233.        <entry>+1:00 </entry>
  234.        <entry>Dansk Normal Tid</entry>
  235.       </row>
  236.       <row>
  237.        <entry>DST</entry>
  238.        <entry>+1:00 </entry>
  239.        <entry>Dansk Standard Time (?)</entry>
  240.       </row>
  241.       <row>
  242.        <entry>FST</entry>
  243.        <entry>+1:00 </entry>
  244.        <entry>French Summer Time</entry>
  245. </row>
  246.       <row>
  247.        <entry>MET</entry>
  248.        <entry>+1:00</entry>
  249.        <entry>Middle Europe Time</entry>
  250.       </row>
  251.       <row>
  252.        <entry>MEWT</entry>
  253.        <entry>+1:00</entry>
  254.        <entry>Middle Europe Winter Time</entry>
  255. </row>
  256.       <row>
  257.        <entry>MEZ</entry>
  258.        <entry>+1:00</entry>
  259.        <entry>Middle Europe Zone</entry>
  260.       </row>
  261.       <row>
  262.        <entry>NOR</entry>
  263.        <entry>+1:00</entry>
  264.        <entry>Norway Standard Time</entry>
  265.       </row>
  266.       <row>
  267.        <entry>SET</entry>
  268.        <entry>+1:00</entry>
  269.        <entry>Seychelles Time</entry>
  270.       </row>
  271.       <row>
  272.        <entry>SWT</entry>
  273.        <entry>+1:00</entry>
  274.        <entry>Swedish Winter Time</entry>
  275.       </row>
  276.       <row>
  277.        <entry>WETDST</entry>
  278.        <entry>+1:00</entry>
  279.        <entry>Western Europe Daylight Savings Time</entry>
  280.       </row>
  281.       <row>
  282.        <entry>GMT</entry>
  283.        <entry>0:00</entry>
  284.        <entry>Greenwish Mean Time</entry>
  285.       </row>
  286.       <row>
  287.        <entry>WET</entry>
  288.        <entry>0:00</entry>
  289.        <entry>Western Europe</entry>
  290.       </row>
  291.       <row>
  292.        <entry>WAT</entry>
  293.        <entry>-1:00</entry>
  294.        <entry>West Africa Time</entry>
  295.       </row>
  296.       <row>
  297.        <entry>NDT</entry>
  298.        <entry>-2:30</entry>
  299.        <entry>Newfoundland Daylight Time</entry>
  300.       </row>
  301.       <row>
  302.        <entry>ADT</entry>
  303.        <entry>-03:00 </entry>
  304.        <entry>Atlantic Daylight Time</entry>
  305.       </row>
  306.       <row>
  307.        <entry>NFT</entry>
  308.        <entry>-3:30</entry>
  309.        <entry>Newfoundland Standard Time</entry>
  310.       </row>
  311.       <row>
  312.        <entry>NST</entry>
  313.        <entry>-3:30</entry>
  314.        <entry>Newfoundland Standard Time</entry>
  315.       </row>
  316.       <row>
  317.        <entry>AST</entry>
  318.        <entry>-4:00 </entry>
  319.        <entry>Atlantic Std Time (Canada)</entry>
  320.       </row>
  321.       <row>
  322.        <entry>EDT</entry>
  323.        <entry>-4:00 </entry>
  324.        <entry>Eastern Daylight Time</entry>
  325.       </row>
  326.       <row>
  327.        <entry>ZP4</entry>
  328.        <entry>-4:00</entry>
  329.        <entry>GMT +4 hours</entry>
  330.       </row>
  331.       <row>
  332.        <entry>CDT</entry>
  333.        <entry>-5:00 </entry>
  334.        <entry>Central Daylight Time</entry>
  335.       </row>
  336.       <row>
  337.        <entry>EST</entry>
  338.        <entry>-5:00 </entry>
  339.        <entry>Eastern Standard Time</entry>
  340.       </row>
  341.       <row>
  342.        <entry>ZP5</entry>
  343.        <entry>-5:00</entry>
  344.        <entry>GMT +5  hours</entry>
  345.       </row>
  346.       <row>
  347.        <entry>CST</entry>
  348.        <entry>-6:00 </entry>
  349.        <entry>Central Std Time</entry>
  350.       </row>
  351.       <row>
  352.        <entry>MDT</entry>
  353.        <entry>-6:00</entry>
  354.        <entry>Mountain Daylight Time</entry>
  355.       </row>
  356.       <row>
  357.        <entry>ZP6</entry>
  358.        <entry>-6:00</entry>
  359.        <entry>GMT +6  hours</entry>
  360.       </row>
  361.       <row>
  362.        <entry>MST</entry>
  363.        <entry>-7:00</entry>
  364.        <entry>Mountain Standard Time</entry>
  365.       </row>
  366.       <row>
  367.        <entry>PDT</entry>
  368.        <entry>-7:00</entry>
  369.        <entry>Pacific Daylight Time</entry>
  370.       </row>
  371.       <row>
  372.        <entry>PST</entry>
  373.        <entry>-8:00</entry>
  374.        <entry>Pacific Std Time</entry>
  375.       </row>
  376.       <row>
  377.        <entry>YDT</entry>
  378.        <entry>-8:00</entry>
  379.        <entry>Yukon Daylight Time</entry>
  380.       </row>
  381.       <row>
  382.        <entry>HDT</entry>
  383.        <entry>-9:00</entry>
  384.        <entry>Hawaii/Alaska Daylight Time</entry>
  385.       </row>
  386.       <row>
  387.        <entry>YST</entry>
  388.        <entry>-9:00</entry>
  389.        <entry>Yukon Standard Time</entry>
  390.       </row>
  391.       <row>
  392.        <entry>AHST</entry>
  393.        <entry>-10:00 </entry>
  394.        <entry>Alaska-Hawaii Std Time</entry>
  395.       </row>
  396.       <row>
  397.        <entry>CAT</entry>
  398.        <entry>-10:00 </entry>
  399.        <entry>Central Alaska Time</entry>
  400.       </row>
  401.       <row>
  402.        <entry>NT</entry>
  403.        <entry>-11:00</entry>
  404.        <entry>Nome Time</entry>
  405.       </row>
  406.       <row>
  407.        <entry>IDLW</entry>
  408.  <entry>-12:00</entry>
  409.        <entry>International Date Line, West</entry>
  410.       </row>
  411.      </tbody>
  412.     </tgroup>
  413.    </table>
  414.    <note>
  415.     <para>
  416.      If the compiler option USE_AUSTRALIAN_RULES is set 
  417.      then <literal>EST</literal> refers to Australia Eastern Std Time,
  418.      which has an offset of +10:00 hours from UTC.
  419.     </para>
  420.    </note>
  421.   </para>
  422.   <para>
  423.    Australian time zones and their naming variants
  424.    account for fully one quarter of all time zones in the 
  425.    <productname>Postgres</productname> time zone lookup table.
  426.   </para>
  427.   <procedure>
  428.    <title>Date/Time Input Interpretation</title>
  429.    <para>
  430.     The date/time types are all decoded using a common set of routines.
  431.    </para>
  432.    <step>
  433.     <para>
  434.      Break the input string into tokens and categorize each token as
  435.      a string, time, time zone, or number.
  436.     </para>
  437.     <substeps>
  438.      <step>
  439.       <para>
  440.        If the token contains a colon (":"), this is a time string.
  441.       </para>
  442.      </step>
  443.      <step>
  444.       <para>
  445.        If the token contains a dash ("-"), slash ("/"), or dot ("."),
  446.        this is a date string which may have a text month.
  447.       </para>
  448.      </step>
  449.      <step>
  450.       <para>
  451.        If the token is numeric only, then it is either a single field
  452.        or an ISO-8601 concatenated date (e.g. "19990113" for January 13, 1999)
  453.        or time (e.g. 141516 for 14:15:16).
  454.       </para>
  455.      </step>
  456.      <step>
  457.       <para>
  458.        If the token starts with a plus ("+") or minus ("-"),
  459.        then it is either a time zone or a special field.
  460.       </para>
  461.      </step>
  462.     </substeps>
  463.    </step>
  464.    <step>
  465.     <para>
  466.      If the token is a text string, match up with possible strings.
  467.     </para>
  468.     
  469.     <substeps>
  470.      <step>
  471.       <para>
  472.        Do a binary-search table lookup for the token
  473.        as either a special string (e.g. <literal>today</literal>),
  474.        day (e.g. <literal>Thursday</literal>),
  475.        month (e.g. <literal>January</literal>), or noise word (e.g. <literal>on</literal>).
  476.       </para>
  477.       <para>
  478.        Set field values and bit mask for fields.
  479.        For example, set year, month, day for <literal>today</literal>, and additionally
  480.        hour, minute, second for <literal>now</literal>.
  481.       </para>
  482.      </step>
  483.      
  484.      <step>
  485.       <para>
  486.        If not found, do a similar binary-search table lookup to match
  487.        the token with a time zone.
  488.       </para>
  489.      </step>
  490.      <step>
  491.       <para>
  492.        If not found, throw an error.
  493.       </para>
  494.      </step>
  495.     </substeps>
  496.    </step>
  497.    
  498.    <step>
  499.     <para>
  500.      The token is a number or number field.
  501.     </para>
  502.     <substeps>
  503.      <step>
  504.       <para>
  505.        If there are more than 4 digits, 
  506.        and if no other date fields have been previously read, then interpret 
  507.        as a "concatenated date" (e.g. <literal>19990118</literal>). 8
  508.        and 6 digits are interpreted as year, month, and day, while 7
  509.        and 5 digits are interpreted as year, day of year.
  510.       </para>
  511.      </step>
  512.      <step>
  513.       <para>
  514.        If the token is three digits
  515.        and a year has already been decoded, then interpret as day of year.
  516.       </para>
  517.      </step>
  518.      
  519.      <step>
  520.       <para>
  521.        If longer than two digits, then interpret as a year.
  522.       </para>
  523.      </step>
  524.      <step>
  525.       <para>
  526.        If in European date mode, and if the day field has not yet been read,
  527.        and if the value is less than or equal to 31, then interpret as a day.
  528.       </para>
  529.      </step>
  530.      <step>
  531.       <para>
  532.        If in non-European (US) date mode, and if the month field has not yet been read,
  533.        and if the value is less than or equal to 12, then interpret as a month.
  534.       </para>
  535.      </step>
  536.      <step>
  537.       <para>
  538.        If the day field has not yet been read,
  539.        and if the value is less than or equal to 31, then interpret as a month.
  540. </para>
  541.        </step>
  542.      <step>
  543.       <para>
  544.        If the month field has not yet been read,
  545.        and if the value is less than or equal to 12, then interpret as a month.
  546.       </para>
  547.      </step>
  548.      <step>
  549.       <para>
  550.        Otherwise, interpret as a year.
  551.       </para>
  552.      </step>
  553.     </substeps>
  554.    </step>
  555.    <step>
  556.     <para>
  557.      If BC has been specified, negate the year and offset by one for
  558.      internal storage
  559.      (there is no year zero in the Gregorian calendar, so numerically
  560.      1BC becomes year zero).
  561.     </para>
  562.    </step>
  563.    <step>
  564.     <para>
  565.      If BC was not specified, and if the year field was two digits in length, then
  566.      adjust the year to 4 digits. If the field was less than 70, then add 2000;
  567.      otherwise, add 1900.
  568.      <tip>
  569.       <para>
  570.        Gregorian years 1-99AD may be entered by using 4 digits with leading
  571.        zeros (e.g. 0099 is 99AD). Three digits are also accepted as a
  572.        year under most circumstances, though depending on position the
  573.        numeric string may
  574.        be interpreted as doy instead.
  575.       </para>
  576.      </tip>
  577.     </para>
  578.    </step>
  579.   </procedure>
  580.  </sect1>
  581.  <sect1>
  582.   <title>History</title>
  583.   <note>
  584.    <para>
  585.     Contributed by 
  586.     <ulink url="jose@sferacarta.com">Jos