|
555 | 555 |
|
556 | 556 | </sect1>
|
557 | 557 |
|
| 558 | + <sect1 id="datetime-posix-timezone-specs"> |
| 559 | + <title><acronym>POSIX</acronym> Time Zone Specifications</title> |
| 560 | + |
| 561 | + <indexterm zone="datetime-posix-timezone-specs"> |
| 562 | + <primary>time zone</primary> |
| 563 | + <secondary><acronym>POSIX</acronym>-style specification</secondary> |
| 564 | + </indexterm> |
| 565 | + |
| 566 | + <para> |
| 567 | + <acronym>PostgreSQL</acronym> can accept time zone specifications that |
| 568 | + are written according to the <acronym>POSIX</acronym> standard's rules |
| 569 | + for the <varname>TZ</varname> environment |
| 570 | + variable. <acronym>POSIX</acronym> time zone specifications are |
| 571 | + inadequate to deal with the complexity of real-world time zone history, |
| 572 | + but there are sometimes reasons to use them. |
| 573 | + </para> |
| 574 | + |
| 575 | + <para> |
| 576 | + A POSIX time zone specification has the form |
| 577 | +<synopsis> |
| 578 | +<replaceable>STD</replaceable> <replaceable>offset</replaceable> <optional> <replaceable>DST</replaceable> <optional> <replaceable>dstoffset</replaceable> </optional> <optional> , <replaceable>rule</replaceable> </optional> </optional> |
| 579 | +</synopsis> |
| 580 | + (For readability, we show spaces between the fields, but spaces should |
| 581 | + not be used in practice.) The fields are: |
| 582 | + <itemizedlist> |
| 583 | + <listitem> |
| 584 | + <para> |
| 585 | + <replaceable>STD</replaceable> is the zone abbreviation to be used |
| 586 | + for standard time. |
| 587 | + </para> |
| 588 | + </listitem> |
| 589 | + <listitem> |
| 590 | + <para> |
| 591 | + <replaceable>offset</replaceable> is the zone's standard-time offset |
| 592 | + from UTC. |
| 593 | + </para> |
| 594 | + </listitem> |
| 595 | + <listitem> |
| 596 | + <para> |
| 597 | + <replaceable>DST</replaceable> is the zone abbreviation to be used |
| 598 | + for daylight-savings time. If this field and the following ones are |
| 599 | + omitted, the zone uses a fixed UTC offset with no daylight-savings |
| 600 | + rule. |
| 601 | + </para> |
| 602 | + </listitem> |
| 603 | + <listitem> |
| 604 | + <para> |
| 605 | + <replaceable>dstoffset</replaceable> is the daylight-savings offset |
| 606 | + from UTC. This field is typically omitted, since it defaults to one |
| 607 | + hour less than the standard-time <replaceable>offset</replaceable>, |
| 608 | + which is usually the right thing. |
| 609 | + </para> |
| 610 | + </listitem> |
| 611 | + <listitem> |
| 612 | + <para> |
| 613 | + <replaceable>rule</replaceable> defines the rule for when daylight |
| 614 | + savings is in effect, as described below. |
| 615 | + </para> |
| 616 | + </listitem> |
| 617 | + </itemizedlist> |
| 618 | + </para> |
| 619 | + |
| 620 | + <para> |
| 621 | + In this syntax, a zone abbreviation can be a string of letters, such |
| 622 | + as <literal>EST</literal>, or an arbitrary string surrounded by angle |
| 623 | + brackets, such as <literal><UTC-05></literal>. |
| 624 | + Note that the zone abbreviations given here are only used for output, |
| 625 | + and even then only in some timestamp output formats. The zone |
| 626 | + abbreviations recognized in timestamp input are determined as explained |
| 627 | + in <xref linkend="datetime-config-files"/>. |
| 628 | + </para> |
| 629 | + |
| 630 | + <para> |
| 631 | + The offset fields specify the hours, and optionally minutes and seconds, |
| 632 | + difference from UTC. They have the format |
| 633 | + <replaceable>hh</replaceable><optional><literal>:</literal><replaceable>mm</replaceable><optional><literal>:</literal><replaceable>ss</replaceable></optional></optional> |
| 634 | + optionally with a leading sign (<literal>+</literal> |
| 635 | + or <literal>-</literal>). The positive sign is used for |
| 636 | + zones <emphasis>west</emphasis> of Greenwich. (Note that this is the |
| 637 | + opposite of the ISO-8601 sign convention used elsewhere in |
| 638 | + <acronym>PostgreSQL</acronym>.) <replaceable>hh</replaceable> can have |
| 639 | + one or two digits; <replaceable>mm</replaceable> |
| 640 | + and <replaceable>ss</replaceable> (if used) must have two. |
| 641 | + </para> |
| 642 | + |
| 643 | + <para> |
| 644 | + The daylight-savings transition <replaceable>rule</replaceable> has the |
| 645 | + format |
| 646 | +<synopsis> |
| 647 | +<replaceable>dstdate</replaceable> <optional> <literal>/</literal> <replaceable>dsttime</replaceable> </optional> <literal>,</literal> <replaceable>stddate</replaceable> <optional> <literal>/</literal> <replaceable>stdtime</replaceable> </optional> |
| 648 | +</synopsis> |
| 649 | + (As before, spaces should not be included in practice.) |
| 650 | + The <replaceable>dstdate</replaceable> |
| 651 | + and <replaceable>dsttime</replaceable> fields define when daylight-savings |
| 652 | + time starts, while <replaceable>stddate</replaceable> |
| 653 | + and <replaceable>stdtime</replaceable> define when standard time |
| 654 | + starts. (In some cases, notably in zones south of the equator, the |
| 655 | + former might be later in the year than the latter.) The date fields |
| 656 | + have one of these formats: |
| 657 | + <variablelist> |
| 658 | + <varlistentry> |
| 659 | + <term><replaceable>n</replaceable></term> |
| 660 | + <listitem> |
| 661 | + <para> |
| 662 | + A plain integer denotes a day of the year, counting from zero to |
| 663 | + 364, or to 365 in leap years. |
| 664 | + </para> |
| 665 | + </listitem> |
| 666 | + </varlistentry> |
| 667 | + <varlistentry> |
| 668 | + <term><literal>J</literal><replaceable>n</replaceable></term> |
| 669 | + <listitem> |
| 670 | + <para> |
| 671 | + In this form, <replaceable>n</replaceable> counts from 1 to 365, |
| 672 | + and February 29 is not counted even if it is present. (Thus, a |
| 673 | + transition occurring on February 29 could not be specified this |
| 674 | + way. However, days after February have the same numbers whether |
| 675 | + it's a leap year or not, so that this form is usually more useful |
| 676 | + than the plain-integer form for transitions on fixed dates.) |
| 677 | + </para> |
| 678 | + </listitem> |
| 679 | + </varlistentry> |
| 680 | + <varlistentry> |
| 681 | + <term><literal>M</literal><replaceable>m</replaceable><literal>.</literal><replaceable>n</replaceable><literal>.</literal><replaceable>d</replaceable></term> |
| 682 | + <listitem> |
| 683 | + <para> |
| 684 | + This form specifies a transition that always happens during the same |
| 685 | + month and on the same day of the week. <replaceable>m</replaceable> |
| 686 | + identifies the month, from 1 to 12. <replaceable>n</replaceable> |
| 687 | + specifies the <replaceable>n</replaceable>'th occurrence of the |
| 688 | + weekday identified by <replaceable>d</replaceable>. |
| 689 | + <replaceable>n</replaceable> is a number between 1 and 4, or 5 |
| 690 | + meaning the last occurrence of that weekday in the month (which |
| 691 | + could be the fourth or the fifth). <replaceable>d</replaceable> is |
| 692 | + a number between 0 and 6, with 0 indicating Sunday. |
| 693 | + For example, <literal>M3.2.0</literal> means <quote>the second |
| 694 | + Sunday in March</quote>. |
| 695 | + </para> |
| 696 | + </listitem> |
| 697 | + </varlistentry> |
| 698 | + </variablelist> |
| 699 | + </para> |
| 700 | + |
| 701 | + <note> |
| 702 | + <para> |
| 703 | + The <literal>M</literal> format is sufficient to describe many common |
| 704 | + daylight-savings transition laws. But note that none of these variants |
| 705 | + can deal with daylight-savings law changes, so in practice the |
| 706 | + historical data stored for named time zones (in the IANA time zone |
| 707 | + database) is necessary to interpret past time stamps correctly. |
| 708 | + </para> |
| 709 | + </note> |
| 710 | + |
| 711 | + <para> |
| 712 | + The time fields in a transition rule have the same format as the offset |
| 713 | + fields described previously, except that they cannot contain signs. |
| 714 | + They define the current local time at which the change to the other |
| 715 | + time occurs. If omitted, they default to <literal>02:00:00</literal>. |
| 716 | + </para> |
| 717 | + |
| 718 | + <para> |
| 719 | + If a daylight-savings abbreviation is given but the |
| 720 | + transition <replaceable>rule</replaceable> field is omitted, |
| 721 | + <productname>PostgreSQL</productname> attempts to determine the |
| 722 | + transition times by consulting the <filename>posixrules</filename> file |
| 723 | + in the IANA time zone database. This file has the same format as a |
| 724 | + full time zone entry, but only its transition timing rules are used, |
| 725 | + not its UTC offsets. Typically, this file has the same contents as the |
| 726 | + <literal>US/Eastern</literal> file, so that POSIX-style time zone |
| 727 | + specifications follow USA daylight-savings rules. If needed, you can |
| 728 | + adjust this behavior by replacing the <filename>posixrules</filename> |
| 729 | + file. |
| 730 | + </para> |
| 731 | + |
| 732 | + <note> |
| 733 | + <para> |
| 734 | + The facility to consult a <filename>posixrules</filename> file has |
| 735 | + been deprecated by IANA, and it is likely to go away in the future. |
| 736 | + One bug in this feature, which is unlikely to be fixed before it |
| 737 | + disappears, is that it fails to apply DST rules to dates after 2038. |
| 738 | + </para> |
| 739 | + </note> |
| 740 | + |
| 741 | + <para> |
| 742 | + If the <filename>posixrules</filename> file is not present, |
| 743 | + the fallback behavior is to use the |
| 744 | + rule <literal>M3.2.0,M11.1.0</literal>, which corresponds to USA |
| 745 | + practice as of 2020 (that is, spring forward on the second Sunday of |
| 746 | + March, fall back on the first Sunday of November, both transitions |
| 747 | + occurring at 2AM prevailing time). |
| 748 | + </para> |
| 749 | + |
| 750 | + <para> |
| 751 | + As an example, <literal>CET-1CEST,M3.5.0,M10.5.0/3</literal> describes |
| 752 | + current (as of 2020) timekeeping practice in Paris. This specification |
| 753 | + says that standard time has the abbreviation <literal>CET</literal> and |
| 754 | + is one hour ahead (east) of UTC; daylight savings time has the |
| 755 | + abbreviation <literal>CEST</literal> and is implicitly two hours ahead |
| 756 | + of UTC; daylight savings time begins on the last Sunday in March at 2AM |
| 757 | + CET and ends on the last Sunday in October at 3AM CEST. |
| 758 | + </para> |
| 759 | + |
| 760 | + <para> |
| 761 | + One should be wary that it is easy to misspell a POSIX-style time zone |
| 762 | + specification, since there is no check on the reasonableness of the |
| 763 | + zone abbreviation(s). For example, <literal>SET TIMEZONE TO |
| 764 | + FOOBAR0</literal> will work, leaving the system effectively using a |
| 765 | + rather peculiar abbreviation for UTC. |
| 766 | + </para> |
| 767 | + |
| 768 | + </sect1> |
| 769 | + |
558 | 770 | <sect1 id="datetime-units-history">
|
559 | 771 | <title>History of Units</title>
|
560 | 772 |
|
|
0 commit comments