Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd221e14

Browse files
author
Thomas G. Lockhart
committed
Fix (well, add) support for ISO "week" in date_part(). Needed for ODBC.
Fix spelling of "millennium". Thanks to Mika Nystrom <mika@camembert.cs.caltech.edu> for spotting this.
1 parent99cc10a commitd221e14

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

‎src/backend/utils/adt/datetime.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.46 2000/04/12 17:15:49 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.47 2000/04/1415:22:10 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -260,15 +260,14 @@ static datetkn deltatktbl[] = {
260260
{"hours",UNITS,DTK_HOUR},/* "hours" relative time units */
261261
{"hr",UNITS,DTK_HOUR},/* "hour" relative time units */
262262
{"hrs",UNITS,DTK_HOUR},/* "hours" relative time units */
263-
{INVALID,RESERV,DTK_INVALID},/* "invalid" reserved for invalid
264-
* time */
263+
{INVALID,RESERV,DTK_INVALID},/* reserved for invalid time */
265264
{"m",UNITS,DTK_MINUTE},/* "minute" relative time units */
266265
{"microsecon",UNITS,DTK_MICROSEC},/* "microsecond" relative
267266
* time units */
268-
{"mil",UNITS,DTK_MILLENIUM},/* "millenium" relative time units */
269-
{"mils",UNITS,DTK_MILLENIUM},/* "millenia" relative time units */
270-
{"millenia",UNITS,DTK_MILLENIUM},/* "millenia" relative time units */
271-
{DMILLENIUM,UNITS,DTK_MILLENIUM},/* "millenium" relative time units */
267+
{"mil",UNITS,DTK_MILLENNIUM},/* "millennium" relative time units */
268+
{"mils",UNITS,DTK_MILLENNIUM},/* "millennia" relative time units */
269+
{"millennia",UNITS,DTK_MILLENNIUM},/* "millennia" relative time units */
270+
{DMILLENNIUM,UNITS,DTK_MILLENNIUM},/* "millennium" relative time units */
272271
{"millisecon",UNITS,DTK_MILLISEC},/* relative time units */
273272
{"min",UNITS,DTK_MINUTE},/* "minute" relative time units */
274273
{"mins",UNITS,DTK_MINUTE},/* "minutes" relative time units */
@@ -1794,7 +1793,7 @@ DecodeDateDelta(char **field, int *ftype, int nf, int *dtype, struct tm * tm, do
17941793
tmask= ((fmask&DTK_M(YEAR)) ?0 :DTK_M(YEAR));
17951794
break;
17961795

1797-
caseDTK_MILLENIUM:
1796+
caseDTK_MILLENNIUM:
17981797
tm->tm_year+=val*1000;
17991798
if (fval!=0)
18001799
tm->tm_mon+= (fval*12000);

‎src/backend/utils/adt/timestamp.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.25 2000/04/12 17:15:51 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.26 2000/04/1415:22:10 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1621,7 +1621,7 @@ timestamp_trunc(text *units, Timestamp *timestamp)
16211621
{
16221622
switch (val)
16231623
{
1624-
caseDTK_MILLENIUM:
1624+
caseDTK_MILLENNIUM:
16251625
tm->tm_year= (tm->tm_year /1000)*1000;
16261626
caseDTK_CENTURY:
16271627
tm->tm_year= (tm->tm_year /100)*100;
@@ -1759,7 +1759,7 @@ interval_trunc(text *units, Interval *interval)
17591759
{
17601760
switch (val)
17611761
{
1762-
caseDTK_MILLENIUM:
1762+
caseDTK_MILLENNIUM:
17631763
tm->tm_year= (tm->tm_year /1000)*1000;
17641764
caseDTK_CENTURY:
17651765
tm->tm_year= (tm->tm_year /100)*100;
@@ -1927,6 +1927,38 @@ timestamp_part(text *units, Timestamp *timestamp)
19271927
*result= (tm->tm_mon /4)+1;
19281928
break;
19291929

1930+
caseDTK_WEEK:
1931+
{
1932+
intday0,day4,dayn;
1933+
dayn=date2j(tm->tm_year,tm->tm_mon,tm->tm_mday);
1934+
day4=date2j(tm->tm_year,1,4);
1935+
/* day0 == offset to first day of week (Monday) */
1936+
day0= (j2day(day4-1) %7);
1937+
/* We need the first week containing a Thursday,
1938+
* otherwise this day falls into the previous year
1939+
* for purposes of counting weeks
1940+
*/
1941+
if (dayn< (day4-day0))
1942+
{
1943+
day4=date2j((tm->tm_year-1),1,4);
1944+
/* day0 == offset to first day of week (Monday) */
1945+
day0= (j2day(day4-1) %7);
1946+
}
1947+
*result= (((dayn- (day4-day0)) /7)+1);
1948+
/* Sometimes the last few days in a year will fall into
1949+
* the first week of the next year, so check for this.
1950+
*/
1951+
if (*result >=53)
1952+
{
1953+
day4=date2j((tm->tm_year+1),1,4);
1954+
/* day0 == offset to first day of week (Monday) */
1955+
day0= (j2day(day4-1) %7);
1956+
if (dayn >= (day4-day0))
1957+
*result= (((dayn- (day4-day0)) /7)+1);
1958+
}
1959+
}
1960+
break;
1961+
19301962
caseDTK_YEAR:
19311963
*result=tm->tm_year;
19321964
break;
@@ -1939,7 +1971,7 @@ timestamp_part(text *units, Timestamp *timestamp)
19391971
*result= (tm->tm_year /100);
19401972
break;
19411973

1942-
caseDTK_MILLENIUM:
1974+
caseDTK_MILLENNIUM:
19431975
*result= (tm->tm_year /1000);
19441976
break;
19451977

@@ -2082,7 +2114,7 @@ interval_part(text *units, Interval *interval)
20822114
*result= (tm->tm_year /100);
20832115
break;
20842116

2085-
caseDTK_MILLENIUM:
2117+
caseDTK_MILLENNIUM:
20862118
*result= (tm->tm_year /1000);
20872119
break;
20882120

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp