Skip to content

Commit 453151a

Browse files
committed
Docs: improve descriptions of ISO week-numbering date features.
Use the phraseology "ISO 8601 week-numbering year" in place of just "ISO year", and make related adjustments to other terminology. The point of this change is that it seems some people see "ISO year" and think "standard year", whereupon they're surprised when constructs like to_char(..., "IYYY-MM-DD") produce nonsensical results. Perhaps hanging a few more adjectives on it will discourage them from jumping to false conclusions. I put in an explicit warning against that specific usage, too, though the main point is to discourage people who haven't read this far down the page. In passing fix some nearby markup and terminology inconsistencies.
1 parent 7582cce commit 453151a

File tree

1 file changed

+52
-35
lines changed

1 file changed

+52
-35
lines changed

doc/src/sgml/func.sgml

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5489,11 +5489,11 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
54895489
</row>
54905490
<row>
54915491
<entry><literal>Y,YYY</literal></entry>
5492-
<entry>year (4 and more digits) with comma</entry>
5492+
<entry>year (4 or more digits) with comma</entry>
54935493
</row>
54945494
<row>
54955495
<entry><literal>YYYY</literal></entry>
5496-
<entry>year (4 and more digits)</entry>
5496+
<entry>year (4 or more digits)</entry>
54975497
</row>
54985498
<row>
54995499
<entry><literal>YYY</literal></entry>
@@ -5509,19 +5509,19 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
55095509
</row>
55105510
<row>
55115511
<entry><literal>IYYY</literal></entry>
5512-
<entry>ISO year (4 and more digits)</entry>
5512+
<entry>ISO 8601 week-numbering year (4 or more digits)</entry>
55135513
</row>
55145514
<row>
55155515
<entry><literal>IYY</literal></entry>
5516-
<entry>last 3 digits of ISO year</entry>
5516+
<entry>last 3 digits of ISO 8601 week-numbering year</entry>
55175517
</row>
55185518
<row>
55195519
<entry><literal>IY</literal></entry>
5520-
<entry>last 2 digits of ISO year</entry>
5520+
<entry>last 2 digits of ISO 8601 week-numbering year</entry>
55215521
</row>
55225522
<row>
55235523
<entry><literal>I</literal></entry>
5524-
<entry>last digit of ISO year</entry>
5524+
<entry>last digit of ISO 8601 week-numbering year</entry>
55255525
</row>
55265526
<row>
55275527
<entry><literal>BC</literal>, <literal>bc</literal>,
@@ -5591,35 +5591,35 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
55915591
</row>
55925592
<row>
55935593
<entry><literal>IDDD</literal></entry>
5594-
<entry>ISO day of year (001-371; day 1 of the year is Monday of the first ISO week.)</entry>
5594+
<entry>day of ISO 8601 week-numbering year (001-371; day 1 of the year is Monday of the first ISO week)</entry>
55955595
</row>
55965596
<row>
55975597
<entry><literal>DD</literal></entry>
55985598
<entry>day of month (01-31)</entry>
55995599
</row>
56005600
<row>
56015601
<entry><literal>D</literal></entry>
5602-
<entry>day of the week, Sunday(<literal>1</>) to Saturday(<literal>7</>)</entry>
5602+
<entry>day of the week, Sunday (<literal>1</>) to Saturday (<literal>7</>)</entry>
56035603
</row>
56045604
<row>
56055605
<entry><literal>ID</literal></entry>
5606-
<entry>ISO day of the week, Monday(<literal>1</>) to Sunday(<literal>7</>)</entry>
5606+
<entry>ISO 8601 day of the week, Monday (<literal>1</>) to Sunday (<literal>7</>)</entry>
56075607
</row>
56085608
<row>
56095609
<entry><literal>W</literal></entry>
5610-
<entry>week of month (1-5) (The first week starts on the first day of the month.)</entry>
5610+
<entry>week of month (1-5) (the first week starts on the first day of the month)</entry>
56115611
</row>
56125612
<row>
56135613
<entry><literal>WW</literal></entry>
5614-
<entry>week number of year (1-53) (The first week starts on the first day of the year.)</entry>
5614+
<entry>week number of year (1-53) (the first week starts on the first day of the year)</entry>
56155615
</row>
56165616
<row>
56175617
<entry><literal>IW</literal></entry>
5618-
<entry>ISO week number of year (01 - 53; the first Thursday of the new year is in week 1.)</entry>
5618+
<entry>week number of ISO 8601 week-numbering year (01-53; the first Thursday of the year is in week 1)</entry>
56195619
</row>
56205620
<row>
56215621
<entry><literal>CC</literal></entry>
5622-
<entry>century (2 digits) (The twenty-first century starts on 2001-01-01.)</entry>
5622+
<entry>century (2 digits) (the twenty-first century starts on 2001-01-01)</entry>
56235623
</row>
56245624
<row>
56255625
<entry><literal>J</literal></entry>
@@ -5801,16 +5801,16 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
58015801

58025802
<listitem>
58035803
<para>
5804-
An ISO week date (as distinct from a Gregorian date) can be
5805-
specified to <function>to_timestamp</function> and
5804+
An ISO 8601 week-numbering date (as distinct from a Gregorian date)
5805+
can be specified to <function>to_timestamp</function> and
58065806
<function>to_date</function> in one of two ways:
58075807
<itemizedlist>
58085808
<listitem>
58095809
<para>
5810-
Year, week, and weekday: for example <literal>to_date('2006-42-4',
5811-
'IYYY-IW-ID')</literal> returns the date
5812-
<literal>2006-10-19</literal>. If you omit the weekday it
5813-
is assumed to be 1 (Monday).
5810+
Year, week number, and weekday: for
5811+
example <literal>to_date('2006-42-4', 'IYYY-IW-ID')</literal>
5812+
returns the date <literal>2006-10-19</literal>.
5813+
If you omit the weekday it is assumed to be 1 (Monday).
58145814
</para>
58155815
</listitem>
58165816
<listitem>
@@ -5822,13 +5822,25 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
58225822
</itemizedlist>
58235823
</para>
58245824
<para>
5825-
Attempting to construct a date using a mixture of ISO week and
5826-
Gregorian date fields is nonsensical, and will cause an error. In the
5827-
context of an ISO year, the concept of a <quote>month</> or <quote>day
5828-
of month</> has no meaning. In the context of a Gregorian year, the
5829-
ISO week has no meaning. Users should avoid mixing Gregorian and
5830-
ISO date specifications.
5825+
Attempting to enter a date using a mixture of ISO 8601 week-numbering
5826+
fields and Gregorian date fields is nonsensical, and will cause an
5827+
error. In the context of an ISO 8601 week-numbering year, the
5828+
concept of a <quote>month</> or <quote>day of month</> has no
5829+
meaning. In the context of a Gregorian year, the ISO week has no
5830+
meaning.
58315831
</para>
5832+
<caution>
5833+
<para>
5834+
While <function>to_date</function> will reject a mixture of
5835+
Gregorian and ISO week-numbering date
5836+
fields, <function>to_char</function> will not, since output format
5837+
specifications like <literal>YYYY-MM-DD (IYYY-IDDD)</> can be
5838+
useful. But avoid writing something like <literal>IYYY-MM-DD</>;
5839+
that would yield surprising results near the start of the year.
5840+
(See <xref linkend="functions-datetime-extract"> for more
5841+
information.)
5842+
</para>
5843+
</caution>
58325844
</listitem>
58335845

58345846
<listitem>
@@ -6877,8 +6889,8 @@ SELECT EXTRACT(DECADE FROM TIMESTAMP '2001-02-16 20:38:40');
68776889
<term><literal>dow</literal></term>
68786890
<listitem>
68796891
<para>
6880-
The day of the week as Sunday(<literal>0</>) to
6881-
Saturday(<literal>6</>)
6892+
The day of the week as Sunday (<literal>0</>) to
6893+
Saturday (<literal>6</>)
68826894
</para>
68836895

68846896
<screen>
@@ -6960,8 +6972,8 @@ SELECT EXTRACT(HOUR FROM TIMESTAMP '2001-02-16 20:38:40');
69606972
<term><literal>isodow</literal></term>
69616973
<listitem>
69626974
<para>
6963-
The day of the week as Monday(<literal>1</>) to
6964-
Sunday(<literal>7</>)
6975+
The day of the week as Monday (<literal>1</>) to
6976+
Sunday (<literal>7</>)
69656977
</para>
69666978

69676979
<screen>
@@ -6980,7 +6992,8 @@ SELECT EXTRACT(ISODOW FROM TIMESTAMP '2001-02-18 20:38:40');
69806992
<term><literal>isoyear</literal></term>
69816993
<listitem>
69826994
<para>
6983-
The <acronym>ISO</acronym> 8601 year that the date falls in (not applicable to intervals)
6995+
The <acronym>ISO</acronym> 8601 week-numbering year that the date
6996+
falls in (not applicable to intervals)
69846997
</para>
69856998

69866999
<screen>
@@ -6991,7 +7004,11 @@ SELECT EXTRACT(ISOYEAR FROM DATE '2006-01-02');
69917004
</screen>
69927005

69937006
<para>
6994-
Each <acronym>ISO</acronym> year begins with the Monday of the week containing the 4th of January, so in early January or late December the <acronym>ISO</acronym> year may be different from the Gregorian year. See the <literal>week</literal> field for more information.
7007+
Each <acronym>ISO</acronym> 8601 week-numbering year begins with the
7008+
Monday of the week containing the 4th of January, so in early
7009+
January or late December the <acronym>ISO</acronym> year may be
7010+
different from the Gregorian year. See the <literal>week</literal>
7011+
field for more information.
69957012
</para>
69967013
<para>
69977014
This field is not available in PostgreSQL releases prior to 8.3.
@@ -7157,14 +7174,14 @@ SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
71577174
<term><literal>week</literal></term>
71587175
<listitem>
71597176
<para>
7160-
The number of the week of the year that the day is in. By definition
7161-
(<acronym>ISO</acronym> 8601), weeks start on Mondays and the first
7177+
The number of the <acronym>ISO</acronym> 8601 week-numbering week of
7178+
the year. By definition, ISO weeks start on Mondays and the first
71627179
week of a year contains January 4 of that year. In other words, the
71637180
first Thursday of a year is in week 1 of that year.
71647181
</para>
71657182
<para>
7166-
In the ISO definition, it is possible for early-January dates to be
7167-
part of the 52nd or 53rd week of the previous year, and for
7183+
In the ISO week-numbering system, it is possible for early-January
7184+
dates to be part of the 52nd or 53rd week of the previous year, and for
71687185
late-December dates to be part of the first week of the next year.
71697186
For example, <literal>2005-01-01</> is part of the 53rd week of year
71707187
2004, and <literal>2006-01-01</> is part of the 52nd week of year

0 commit comments

Comments
 (0)