Skip to content

Commit daa6306

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 64c5065 commit daa6306

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
@@ -5275,11 +5275,11 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
52755275
</row>
52765276
<row>
52775277
<entry><literal>Y,YYY</literal></entry>
5278-
<entry>year (4 and more digits) with comma</entry>
5278+
<entry>year (4 or more digits) with comma</entry>
52795279
</row>
52805280
<row>
52815281
<entry><literal>YYYY</literal></entry>
5282-
<entry>year (4 and more digits)</entry>
5282+
<entry>year (4 or more digits)</entry>
52835283
</row>
52845284
<row>
52855285
<entry><literal>YYY</literal></entry>
@@ -5295,19 +5295,19 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
52955295
</row>
52965296
<row>
52975297
<entry><literal>IYYY</literal></entry>
5298-
<entry>ISO year (4 and more digits)</entry>
5298+
<entry>ISO 8601 week-numbering year (4 or more digits)</entry>
52995299
</row>
53005300
<row>
53015301
<entry><literal>IYY</literal></entry>
5302-
<entry>last 3 digits of ISO year</entry>
5302+
<entry>last 3 digits of ISO 8601 week-numbering year</entry>
53035303
</row>
53045304
<row>
53055305
<entry><literal>IY</literal></entry>
5306-
<entry>last 2 digits of ISO year</entry>
5306+
<entry>last 2 digits of ISO 8601 week-numbering year</entry>
53075307
</row>
53085308
<row>
53095309
<entry><literal>I</literal></entry>
5310-
<entry>last digit of ISO year</entry>
5310+
<entry>last digit of ISO 8601 week-numbering year</entry>
53115311
</row>
53125312
<row>
53135313
<entry><literal>BC</literal>, <literal>bc</literal>,
@@ -5377,35 +5377,35 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
53775377
</row>
53785378
<row>
53795379
<entry><literal>IDDD</literal></entry>
5380-
<entry>ISO day of year (001-371; day 1 of the year is Monday of the first ISO week.)</entry>
5380+
<entry>day of ISO 8601 week-numbering year (001-371; day 1 of the year is Monday of the first ISO week)</entry>
53815381
</row>
53825382
<row>
53835383
<entry><literal>DD</literal></entry>
53845384
<entry>day of month (01-31)</entry>
53855385
</row>
53865386
<row>
53875387
<entry><literal>D</literal></entry>
5388-
<entry>day of the week, Sunday(<literal>1</>) to Saturday(<literal>7</>)</entry>
5388+
<entry>day of the week, Sunday (<literal>1</>) to Saturday (<literal>7</>)</entry>
53895389
</row>
53905390
<row>
53915391
<entry><literal>ID</literal></entry>
5392-
<entry>ISO day of the week, Monday(<literal>1</>) to Sunday(<literal>7</>)</entry>
5392+
<entry>ISO 8601 day of the week, Monday (<literal>1</>) to Sunday (<literal>7</>)</entry>
53935393
</row>
53945394
<row>
53955395
<entry><literal>W</literal></entry>
5396-
<entry>week of month (1-5) (The first week starts on the first day of the month.)</entry>
5396+
<entry>week of month (1-5) (the first week starts on the first day of the month)</entry>
53975397
</row>
53985398
<row>
53995399
<entry><literal>WW</literal></entry>
5400-
<entry>week number of year (1-53) (The first week starts on the first day of the year.)</entry>
5400+
<entry>week number of year (1-53) (the first week starts on the first day of the year)</entry>
54015401
</row>
54025402
<row>
54035403
<entry><literal>IW</literal></entry>
5404-
<entry>ISO week number of year (01 - 53; the first Thursday of the new year is in week 1.)</entry>
5404+
<entry>week number of ISO 8601 week-numbering year (01-53; the first Thursday of the year is in week 1)</entry>
54055405
</row>
54065406
<row>
54075407
<entry><literal>CC</literal></entry>
5408-
<entry>century (2 digits) (The twenty-first century starts on 2001-01-01.)</entry>
5408+
<entry>century (2 digits) (the twenty-first century starts on 2001-01-01)</entry>
54095409
</row>
54105410
<row>
54115411
<entry><literal>J</literal></entry>
@@ -5585,16 +5585,16 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
55855585

55865586
<listitem>
55875587
<para>
5588-
An ISO week date (as distinct from a Gregorian date) can be
5589-
specified to <function>to_timestamp</function> and
5588+
An ISO 8601 week-numbering date (as distinct from a Gregorian date)
5589+
can be specified to <function>to_timestamp</function> and
55905590
<function>to_date</function> in one of two ways:
55915591
<itemizedlist>
55925592
<listitem>
55935593
<para>
5594-
Year, week, and weekday: for example <literal>to_date('2006-42-4',
5595-
'IYYY-IW-ID')</literal> returns the date
5596-
<literal>2006-10-19</literal>. If you omit the weekday it
5597-
is assumed to be 1 (Monday).
5594+
Year, week number, and weekday: for
5595+
example <literal>to_date('2006-42-4', 'IYYY-IW-ID')</literal>
5596+
returns the date <literal>2006-10-19</literal>.
5597+
If you omit the weekday it is assumed to be 1 (Monday).
55985598
</para>
55995599
</listitem>
56005600
<listitem>
@@ -5606,13 +5606,25 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
56065606
</itemizedlist>
56075607
</para>
56085608
<para>
5609-
Attempting to construct a date using a mixture of ISO week and
5610-
Gregorian date fields is nonsensical, and will cause an error. In the
5611-
context of an ISO year, the concept of a <quote>month</> or <quote>day
5612-
of month</> has no meaning. In the context of a Gregorian year, the
5613-
ISO week has no meaning. Users should avoid mixing Gregorian and
5614-
ISO date specifications.
5609+
Attempting to enter a date using a mixture of ISO 8601 week-numbering
5610+
fields and Gregorian date fields is nonsensical, and will cause an
5611+
error. In the context of an ISO 8601 week-numbering year, the
5612+
concept of a <quote>month</> or <quote>day of month</> has no
5613+
meaning. In the context of a Gregorian year, the ISO week has no
5614+
meaning.
56155615
</para>
5616+
<caution>
5617+
<para>
5618+
While <function>to_date</function> will reject a mixture of
5619+
Gregorian and ISO week-numbering date
5620+
fields, <function>to_char</function> will not, since output format
5621+
specifications like <literal>YYYY-MM-DD (IYYY-IDDD)</> can be
5622+
useful. But avoid writing something like <literal>IYYY-MM-DD</>;
5623+
that would yield surprising results near the start of the year.
5624+
(See <xref linkend="functions-datetime-extract"> for more
5625+
information.)
5626+
</para>
5627+
</caution>
56165628
</listitem>
56175629

56185630
<listitem>
@@ -6658,8 +6670,8 @@ SELECT EXTRACT(DECADE FROM TIMESTAMP '2001-02-16 20:38:40');
66586670
<term><literal>dow</literal></term>
66596671
<listitem>
66606672
<para>
6661-
The day of the week as Sunday(<literal>0</>) to
6662-
Saturday(<literal>6</>)
6673+
The day of the week as Sunday (<literal>0</>) to
6674+
Saturday (<literal>6</>)
66636675
</para>
66646676

66656677
<screen>
@@ -6741,8 +6753,8 @@ SELECT EXTRACT(HOUR FROM TIMESTAMP '2001-02-16 20:38:40');
67416753
<term><literal>isodow</literal></term>
67426754
<listitem>
67436755
<para>
6744-
The day of the week as Monday(<literal>1</>) to
6745-
Sunday(<literal>7</>)
6756+
The day of the week as Monday (<literal>1</>) to
6757+
Sunday (<literal>7</>)
67466758
</para>
67476759

67486760
<screen>
@@ -6761,7 +6773,8 @@ SELECT EXTRACT(ISODOW FROM TIMESTAMP '2001-02-18 20:38:40');
67616773
<term><literal>isoyear</literal></term>
67626774
<listitem>
67636775
<para>
6764-
The <acronym>ISO</acronym> 8601 year that the date falls in (not applicable to intervals)
6776+
The <acronym>ISO</acronym> 8601 week-numbering year that the date
6777+
falls in (not applicable to intervals)
67656778
</para>
67666779

67676780
<screen>
@@ -6772,7 +6785,11 @@ SELECT EXTRACT(ISOYEAR FROM DATE '2006-01-02');
67726785
</screen>
67736786

67746787
<para>
6775-
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.
6788+
Each <acronym>ISO</acronym> 8601 week-numbering year begins with the
6789+
Monday of the week containing the 4th of January, so in early
6790+
January or late December the <acronym>ISO</acronym> year may be
6791+
different from the Gregorian year. See the <literal>week</literal>
6792+
field for more information.
67766793
</para>
67776794
<para>
67786795
This field is not available in PostgreSQL releases prior to 8.3.
@@ -6938,14 +6955,14 @@ SELECT EXTRACT(SECOND FROM TIME '17:12:28.5');
69386955
<term><literal>week</literal></term>
69396956
<listitem>
69406957
<para>
6941-
The number of the week of the year that the day is in. By definition
6942-
(<acronym>ISO</acronym> 8601), weeks start on Mondays and the first
6958+
The number of the <acronym>ISO</acronym> 8601 week-numbering week of
6959+
the year. By definition, ISO weeks start on Mondays and the first
69436960
week of a year contains January 4 of that year. In other words, the
69446961
first Thursday of a year is in week 1 of that year.
69456962
</para>
69466963
<para>
6947-
In the ISO definition, it is possible for early-January dates to be
6948-
part of the 52nd or 53rd week of the previous year, and for
6964+
In the ISO week-numbering system, it is possible for early-January
6965+
dates to be part of the 52nd or 53rd week of the previous year, and for
69496966
late-December dates to be part of the first week of the next year.
69506967
For example, <literal>2005-01-01</> is part of the 53rd week of year
69516968
2004, and <literal>2006-01-01</> is part of the 52nd week of year

0 commit comments

Comments
 (0)