Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
33d0d4ce
Commit
33d0d4ce
authored
May 23, 2005
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unnecessary parentheses in datetime/timestamp code.
parent
c1393173
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
330 additions
and
327 deletions
+330
-327
src/backend/utils/adt/datetime.c
src/backend/utils/adt/datetime.c
+192
-195
src/backend/utils/adt/timestamp.c
src/backend/utils/adt/timestamp.c
+138
-132
No files found.
src/backend/utils/adt/datetime.c
View file @
33d0d4ce
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.14
0 2005/05/21 03:38:05
momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.14
1 2005/05/23 17:13:14
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -684,7 +684,7 @@ TrimTrailingZeros(char *str)
#if 0
/* chop off trailing one to cope with interval rounding */
if (strcmp(
(str + len - 4)
, "0001") == 0)
if (strcmp(
str + len - 4
, "0001") == 0)
{
len -= 4;
*(str + len) = '\0';
...
...
@@ -692,8 +692,7 @@ TrimTrailingZeros(char *str)
#endif
/* chop off trailing zeros... but leave at least 2 fractional digits */
while
((
*
(
str
+
len
-
1
)
==
'0'
)
&&
(
*
(
str
+
len
-
3
)
!=
'.'
))
while
(
*
(
str
+
len
-
1
)
==
'0'
&&
*
(
str
+
len
-
3
)
!=
'.'
)
{
len
--
;
*
(
str
+
len
)
=
'\0'
;
...
...
@@ -769,7 +768,7 @@ ParseDateTime(const char *timestr, char *lowstr,
*
lp
++
=
*
cp
++
;
}
/* date field? allow embedded text month */
else
if
(
(
*
cp
==
'-'
)
||
(
*
cp
==
'/'
)
||
(
*
cp
==
'.'
)
)
else
if
(
*
cp
==
'-'
||
*
cp
==
'/'
||
*
cp
==
'.'
)
{
/* save delimiting character to use later */
char
delim
=
*
cp
;
...
...
@@ -790,14 +789,14 @@ ParseDateTime(const char *timestr, char *lowstr,
{
ftype
[
nf
]
=
DTK_DATE
;
*
lp
++
=
*
cp
++
;
while
(
isdigit
((
unsigned
char
)
*
cp
)
||
(
*
cp
==
delim
)
)
while
(
isdigit
((
unsigned
char
)
*
cp
)
||
*
cp
==
delim
)
*
lp
++
=
*
cp
++
;
}
}
else
{
ftype
[
nf
]
=
DTK_DATE
;
while
(
isalnum
((
unsigned
char
)
*
cp
)
||
(
*
cp
==
delim
)
)
while
(
isalnum
((
unsigned
char
)
*
cp
)
||
*
cp
==
delim
)
*
lp
++
=
pg_tolower
((
unsigned
char
)
*
cp
++
);
}
}
...
...
@@ -834,18 +833,18 @@ ParseDateTime(const char *timestr, char *lowstr,
* Full date string with leading text month? Could also be a
* POSIX time zone...
*/
if
(
(
*
cp
==
'-'
)
||
(
*
cp
==
'/'
)
||
(
*
cp
==
'.'
)
)
if
(
*
cp
==
'-'
||
*
cp
==
'/'
||
*
cp
==
'.'
)
{
char
delim
=
*
cp
;
ftype
[
nf
]
=
DTK_DATE
;
*
lp
++
=
*
cp
++
;
while
(
isdigit
((
unsigned
char
)
*
cp
)
||
(
*
cp
==
delim
)
)
while
(
isdigit
((
unsigned
char
)
*
cp
)
||
*
cp
==
delim
)
*
lp
++
=
*
cp
++
;
}
}
/* sign? then special or numeric timezone */
else
if
(
(
*
cp
==
'+'
)
||
(
*
cp
==
'-'
)
)
else
if
(
*
cp
==
'+'
||
*
cp
==
'-'
)
{
*
lp
++
=
*
cp
++
;
/* soak up leading whitespace */
...
...
@@ -857,7 +856,7 @@ ParseDateTime(const char *timestr, char *lowstr,
ftype
[
nf
]
=
DTK_TZ
;
*
lp
++
=
*
cp
++
;
while
(
isdigit
((
unsigned
char
)
*
cp
)
||
(
*
cp
==
':'
)
||
(
*
cp
==
'.'
)
)
*
cp
==
':'
||
*
cp
==
'.'
)
*
lp
++
=
*
cp
++
;
}
/* special? */
...
...
@@ -982,8 +981,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
* a run-together time with trailing time zone (e.g. hhmmss-zz).
* - thomas 2001-12-25
***/
else
if
(((
fmask
&
DTK_DATE_M
)
==
DTK_DATE_M
)
||
(
ptype
!=
0
))
else
if
((
fmask
&
DTK_DATE_M
)
==
DTK_DATE_M
||
ptype
!=
0
)
{
/* No time zone accepted? Then quit... */
if
(
tzp
==
NULL
)
...
...
@@ -1083,9 +1081,9 @@ DecodeDateTime(char **field, int *ftype, int nf,
* second field of a POSIX time: EST+3 (equivalent to
* PST)
*/
if
(
(
i
>
0
)
&&
((
fmask
&
DTK_M
(
TZ
))
!=
0
)
&&
(
ftype
[
i
-
1
]
==
DTK_TZ
)
&&
(
isalpha
((
unsigned
char
)
*
field
[
i
-
1
])
))
if
(
i
>
0
&&
(
fmask
&
DTK_M
(
TZ
))
!=
0
&&
ftype
[
i
-
1
]
==
DTK_TZ
&&
isalpha
((
unsigned
char
)
*
field
[
i
-
1
]
))
{
*
tzp
-=
tz
;
tmask
=
0
;
...
...
@@ -1142,8 +1140,8 @@ DecodeDateTime(char **field, int *ftype, int nf,
* already have a month and hour? then assume
* minutes
*/
if
((
(
fmask
&
DTK_M
(
MONTH
))
!=
0
)
&&
((
fmask
&
DTK_M
(
HOUR
))
!=
0
)
)
if
((
fmask
&
DTK_M
(
MONTH
))
!=
0
&&
(
fmask
&
DTK_M
(
HOUR
))
!=
0
)
{
tm
->
tm_min
=
val
;
tmask
=
DTK_M
(
MINUTE
);
...
...
@@ -1212,11 +1210,12 @@ DecodeDateTime(char **field, int *ftype, int nf,
tmask
|=
DTK_TIME_M
;
#ifdef HAVE_INT64_TIMESTAMP
dt2time
((
time
*
INT64CONST
(
86400000000
)),
&
tm
->
tm_hour
,
&
tm
->
tm_min
,
&
tm
->
tm_sec
,
fsec
);
dt2time
(
time
*
INT64CONST
(
86400000000
),
&
tm
->
tm_hour
,
&
tm
->
tm_min
,
&
tm
->
tm_sec
,
fsec
);
#else
dt2time
(
(
time
*
86400
)
,
&
tm
->
tm_
hour
,
&
tm
->
tm_
min
,
&
tm
->
tm_sec
,
fsec
);
dt2time
(
time
*
86400
,
&
tm
->
tm_hour
,
&
tm
->
tm_min
,
&
tm
->
tm_sec
,
fsec
);
#endif
}
break
;
...
...
@@ -1252,14 +1251,14 @@ DecodeDateTime(char **field, int *ftype, int nf,
cp
=
strchr
(
field
[
i
],
'.'
);
/* Embedded decimal and no date yet? */
if
(
(
cp
!=
NULL
)
&&
!
(
fmask
&
DTK_DATE_M
))
if
(
cp
!=
NULL
&&
!
(
fmask
&
DTK_DATE_M
))
{
dterr
=
DecodeDate
(
field
[
i
],
fmask
,
&
tmask
,
tm
);
if
(
dterr
)
return
dterr
;
}
/* embedded decimal and several digits before? */
else
if
(
(
cp
!=
NULL
)
&&
((
flen
-
strlen
(
cp
))
>
2
)
)
else
if
(
cp
!=
NULL
&&
flen
-
strlen
(
cp
)
>
2
)
{
/*
* Interpret as a concatenated date or time Set
...
...
@@ -1325,8 +1324,8 @@ DecodeDateTime(char **field, int *ftype, int nf,
tmask
=
DTK_DATE_M
;
*
dtype
=
DTK_DATE
;
GetCurrentDateTime
(
tm
);
j2date
(
(
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
-
1
)
,
&
tm
->
tm_year
,
&
tm
->
tm_mon
,
&
tm
->
tm_mday
);
j2date
(
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
-
1
,
&
tm
->
tm_year
,
&
tm
->
tm_mon
,
&
tm
->
tm_mday
);
tm
->
tm_hour
=
0
;
tm
->
tm_min
=
0
;
tm
->
tm_sec
=
0
;
...
...
@@ -1345,8 +1344,8 @@ DecodeDateTime(char **field, int *ftype, int nf,
tmask
=
DTK_DATE_M
;
*
dtype
=
DTK_DATE
;
GetCurrentDateTime
(
tm
);
j2date
(
(
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
+
1
)
,
&
tm
->
tm_year
,
&
tm
->
tm_mon
,
&
tm
->
tm_mday
);
j2date
(
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
+
1
,
&
tm
->
tm_year
,
&
tm
->
tm_mon
,
&
tm
->
tm_mday
);
tm
->
tm_hour
=
0
;
tm
->
tm_min
=
0
;
tm
->
tm_sec
=
0
;
...
...
@@ -1374,9 +1373,9 @@ DecodeDateTime(char **field, int *ftype, int nf,
* already have a (numeric) month? then see if we
* can substitute...
*/
if
((
fmask
&
DTK_M
(
MONTH
))
&&
(
!
haveTextMonth
)
&&
(
!
(
fmask
&
DTK_M
(
DAY
)))
&&
((
tm
->
tm_mon
>=
1
)
&&
(
tm
->
tm_mon
<=
31
))
)
if
((
fmask
&
DTK_M
(
MONTH
))
&&
!
haveTextMonth
&&
!
(
fmask
&
DTK_M
(
DAY
))
&&
tm
->
tm_mon
>=
1
&&
tm
->
tm_mon
<=
31
)
{
tm
->
tm_mday
=
tm
->
tm_mon
;
tmask
=
DTK_M
(
DAY
);
...
...
@@ -1459,10 +1458,10 @@ DecodeDateTime(char **field, int *ftype, int nf,
* DTK_TIME should be hh:mm:ss.fff
* DTK_DATE should be hhmmss-zz
***/
if
(
(
i
>=
(
nf
-
1
))
||
((
ftype
[
i
+
1
]
!=
DTK_NUMBER
)
&&
(
ftype
[
i
+
1
]
!=
DTK_TIME
)
&&
(
ftype
[
i
+
1
]
!=
DTK_DATE
)
))
if
(
i
>=
nf
-
1
||
(
ftype
[
i
+
1
]
!=
DTK_NUMBER
&&
ftype
[
i
+
1
]
!=
DTK_TIME
&&
ftype
[
i
+
1
]
!=
DTK_DATE
))
return
DTERR_BAD_FORMAT
;
ptype
=
val
;
...
...
@@ -1525,11 +1524,11 @@ DecodeDateTime(char **field, int *ftype, int nf,
return
DTERR_MD_FIELD_OVERFLOW
;
}
if
(
(
mer
!=
HR24
)
&&
(
tm
->
tm_hour
>
12
)
)
if
(
mer
!=
HR24
&&
tm
->
tm_hour
>
12
)
return
DTERR_FIELD_OVERFLOW
;
if
(
(
mer
==
AM
)
&&
(
tm
->
tm_hour
==
12
)
)
if
(
mer
==
AM
&&
tm
->
tm_hour
==
12
)
tm
->
tm_hour
=
0
;
else
if
(
(
mer
==
PM
)
&&
(
tm
->
tm_hour
!=
12
)
)
else
if
(
mer
==
PM
&&
tm
->
tm_hour
!=
12
)
tm
->
tm_hour
+=
12
;
/* do additional checking for full date specs... */
...
...
@@ -1650,12 +1649,16 @@ DetermineLocalTimeZone(struct pg_tm * tm)
* Form the candidate pg_time_t values with local-time adjustment
*/
beforetime
=
mytime
-
before_gmtoff
;
if
((
before_gmtoff
>
0
)
?
(
mytime
<
0
&&
beforetime
>
0
)
:
(
mytime
>
0
&&
beforetime
<
0
))
if
((
before_gmtoff
>
0
&&
mytime
<
0
&&
beforetime
>
0
)
||
(
before_gmtoff
<=
0
&&
mytime
>
0
&&
beforetime
<
0
))
goto
overflow
;
aftertime
=
mytime
-
after_gmtoff
;
if
((
after_gmtoff
>
0
)
?
(
mytime
<
0
&&
aftertime
>
0
)
:
(
mytime
>
0
&&
aftertime
<
0
))
if
((
after_gmtoff
>
0
&&
mytime
<
0
&&
aftertime
>
0
)
||
(
after_gmtoff
<=
0
&&
mytime
>
0
&&
aftertime
<
0
))
goto
overflow
;
/*
...
...
@@ -1741,9 +1744,8 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
return
DTERR_BAD_FORMAT
;
/* Under limited circumstances, we will accept a date... */
if
((
i
==
0
)
&&
(
nf
>=
2
)
&&
((
ftype
[
nf
-
1
]
==
DTK_DATE
)
||
(
ftype
[
1
]
==
DTK_TIME
)))
if
(
i
==
0
&&
nf
>=
2
&&
(
ftype
[
nf
-
1
]
==
DTK_DATE
||
ftype
[
1
]
==
DTK_TIME
))
{
dterr
=
DecodeDate
(
field
[
i
],
fmask
,
&
tmask
,
tm
);
if
(
dterr
)
...
...
@@ -1826,8 +1828,9 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
* second field of a POSIX time: EST+3 (equivalent to
* PST)
*/
if
((
i
>
0
)
&&
((
fmask
&
DTK_M
(
TZ
))
!=
0
)
&&
(
ftype
[
i
-
1
]
==
DTK_TZ
)
&&
(
isalpha
((
unsigned
char
)
*
field
[
i
-
1
])))
if
(
i
>
0
&&
(
fmask
&
DTK_M
(
TZ
))
!=
0
&&
ftype
[
i
-
1
]
==
DTK_TZ
&&
isalpha
((
unsigned
char
)
*
field
[
i
-
1
]))
{
*
tzp
-=
tz
;
tmask
=
0
;
...
...
@@ -1897,8 +1900,8 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
* already have a month and hour? then assume
* minutes
*/
if
((
(
fmask
&
DTK_M
(
MONTH
))
!=
0
)
&&
((
fmask
&
DTK_M
(
HOUR
))
!=
0
)
)
if
((
fmask
&
DTK_M
(
MONTH
))
!=
0
&&
(
fmask
&
DTK_M
(
HOUR
))
!=
0
)
{
tm
->
tm_min
=
val
;
tmask
=
DTK_M
(
MINUTE
);
...
...
@@ -1966,10 +1969,10 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
tmask
|=
DTK_TIME_M
;
#ifdef HAVE_INT64_TIMESTAMP
dt2time
(
(
time
*
INT64CONST
(
86400000000
)
),
dt2time
(
time
*
INT64CONST
(
86400000000
),
&
tm
->
tm_hour
,
&
tm
->
tm_min
,
&
tm
->
tm_sec
,
fsec
);
#else
dt2time
(
(
time
*
86400
)
,
dt2time
(
time
*
86400
,
&
tm
->
tm_hour
,
&
tm
->
tm_min
,
&
tm
->
tm_sec
,
fsec
);
#endif
}
...
...
@@ -2012,14 +2015,14 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
* Under limited circumstances, we will accept a
* date...
*/
if
(
(
i
==
0
)
&&
((
nf
>=
2
)
&&
(
ftype
[
nf
-
1
]
==
DTK_DATE
))
)
if
(
i
==
0
&&
nf
>=
2
&&
ftype
[
nf
-
1
]
==
DTK_DATE
)
{
dterr
=
DecodeDate
(
field
[
i
],
fmask
,
&
tmask
,
tm
);
if
(
dterr
)
return
dterr
;
}
/* embedded decimal and several digits before? */
else
if
(
(
flen
-
strlen
(
cp
)
)
>
2
)
else
if
(
flen
-
strlen
(
cp
)
>
2
)
{
/*
* Interpret as a concatenated date or time
...
...
@@ -2157,10 +2160,10 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
* DTK_TIME should be hh:mm:ss.fff
* DTK_DATE should be hhmmss-zz
***/
if
(
(
i
>=
(
nf
-
1
))
||
((
ftype
[
i
+
1
]
!=
DTK_NUMBER
)
&&
(
ftype
[
i
+
1
]
!=
DTK_TIME
)
&&
(
ftype
[
i
+
1
]
!=
DTK_DATE
)
))
if
(
i
>=
nf
-
1
||
(
ftype
[
i
+
1
]
!=
DTK_NUMBER
&&
ftype
[
i
+
1
]
!=
DTK_TIME
&&
ftype
[
i
+
1
]
!=
DTK_DATE
))
return
DTERR_BAD_FORMAT
;
ptype
=
val
;
...
...
@@ -2180,24 +2183,22 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
fmask
|=
tmask
;
}
if
(
(
mer
!=
HR24
)
&&
(
tm
->
tm_hour
>
12
)
)
if
(
mer
!=
HR24
&&
tm
->
tm_hour
>
12
)
return
DTERR_FIELD_OVERFLOW
;
if
(
(
mer
==
AM
)
&&
(
tm
->
tm_hour
==
12
)
)
if
(
mer
==
AM
&&
tm
->
tm_hour
==
12
)
tm
->
tm_hour
=
0
;
else
if
(
(
mer
==
PM
)
&&
(
tm
->
tm_hour
!=
12
)
)
else
if
(
mer
==
PM
&&
tm
->
tm_hour
!=
12
)
tm
->
tm_hour
+=
12
;
#ifdef HAVE_INT64_TIMESTAMP
if
((
tm
->
tm_hour
<
0
)
||
(
tm
->
tm_hour
>
23
)
||
(
tm
->
tm_min
<
0
)
||
(
tm
->
tm_min
>
59
)
||
(
tm
->
tm_sec
<
0
)
||
(
tm
->
tm_sec
>
60
)
||
(
*
fsec
<
INT64CONST
(
0
))
||
(
*
fsec
>=
INT64CONST
(
1000000
)))
if
(
tm
->
tm_hour
<
0
||
tm
->
tm_hour
>
23
||
tm
->
tm_min
<
0
||
tm
->
tm_min
>
59
||
tm
->
tm_sec
<
0
||
tm
->
tm_sec
>
60
||
*
fsec
<
INT64CONST
(
0
)
||
*
fsec
>=
INT64CONST
(
1000000
))
return
DTERR_FIELD_OVERFLOW
;
#else
if
((
tm
->
tm_hour
<
0
)
||
(
tm
->
tm_hour
>
23
)
||
(
tm
->
tm_min
<
0
)
||
(
tm
->
tm_min
>
59
)
||
(
tm
->
tm_sec
<
0
)
||
(
tm
->
tm_sec
>
60
)
||
(
*
fsec
<
0
)
||
(
*
fsec
>=
1
))
if
(
tm
->
tm_hour
<
0
||
tm
->
tm_hour
>
23
||
tm
->
tm_min
<
0
||
tm
->
tm_min
>
59
||
tm
->
tm_sec
<
0
||
tm
->
tm_sec
>
60
||
*
fsec
<
0
||
*
fsec
>=
1
)
return
DTERR_FIELD_OVERFLOW
;
#endif
...
...
@@ -2258,7 +2259,7 @@ DecodeDate(char *str, int fmask, int *tmask, struct pg_tm * tm)
char
*
field
[
MAXDATEFIELDS
];
/* parse this string... */
while
(
(
*
str
!=
'\0'
)
&&
(
nf
<
MAXDATEFIELDS
)
)
while
(
*
str
!=
'\0'
&&
nf
<
MAXDATEFIELDS
)
{
/* skip field separators */
while
(
!
isalnum
((
unsigned
char
)
*
str
))
...
...
@@ -2444,16 +2445,13 @@ DecodeTime(char *str, int fmask, int *tmask, struct pg_tm * tm, fsec_t *fsec)
/* do a sanity check */
#ifdef HAVE_INT64_TIMESTAMP
if
((
tm
->
tm_hour
<
0
)
||
(
tm
->
tm_min
<
0
)
||
(
tm
->
tm_min
>
59
)
||
(
tm
->
tm_sec
<
0
)
||
(
tm
->
tm_sec
>
60
)
||
(
*
fsec
<
INT64CONST
(
0
))
||
(
*
fsec
>=
INT64CONST
(
1000000
)))
if
(
tm
->
tm_hour
<
0
||
tm
->
tm_min
<
0
||
tm
->
tm_min
>
59
||
tm
->
tm_sec
<
0
||
tm
->
tm_sec
>
60
||
*
fsec
<
INT64CONST
(
0
)
||
*
fsec
>=
INT64CONST
(
1000000
))
return
DTERR_FIELD_OVERFLOW
;
#else
if
((
tm
->
tm_hour
<
0
)
||
(
tm
->
tm_min
<
0
)
||
(
tm
->
tm_min
>
59
)
||
(
tm
->
tm_sec
<
0
)
||
(
tm
->
tm_sec
>
60
)
||
(
*
fsec
<
0
)
||
(
*
fsec
>=
1
))
if
(
tm
->
tm_hour
<
0
||
tm
->
tm_min
<
0
||
tm
->
tm_min
>
59
||
tm
->
tm_sec
<
0
||
tm
->
tm_sec
>
60
||
*
fsec
<
0
||
*
fsec
>=
1
)
return
DTERR_FIELD_OVERFLOW
;
#endif
...
...
@@ -2487,7 +2485,7 @@ DecodeNumber(int flen, char *str, bool haveTextMonth, int fmask,
* More than two digits before decimal point? Then could be a date
* or a run-together time: 2001.360 20011225 040506.789
*/
if
(
(
cp
-
str
)
>
2
)
if
(
cp
-
str
>
2
)
{
dterr
=
DecodeNumberField
(
flen
,
str
,
(
fmask
|
DTK_DATE_M
),
...
...
@@ -2511,9 +2509,8 @@ DecodeNumber(int flen, char *str, bool haveTextMonth, int fmask,
return
DTERR_BAD_FORMAT
;
/* Special case for day of year */
if
((
flen
==
3
)
&&
((
fmask
&
DTK_DATE_M
)
==
DTK_M
(
YEAR
))
&&
((
val
>=
1
)
&&
(
val
<=
366
)))
if
(
flen
==
3
&&
(
fmask
&
DTK_DATE_M
)
==
DTK_M
(
YEAR
)
&&
val
>=
1
&&
val
<=
366
)
{
*
tmask
=
(
DTK_M
(
DOY
)
|
DTK_M
(
MONTH
)
|
DTK_M
(
DAY
));
tm
->
tm_yday
=
val
;
...
...
@@ -2764,13 +2761,13 @@ DecodeTimezone(char *str, int *tzp)
if
(
*
str
!=
'+'
&&
*
str
!=
'-'
)
return
DTERR_BAD_FORMAT
;
hr
=
strtol
(
(
str
+
1
)
,
&
cp
,
10
);
hr
=
strtol
(
str
+
1
,
&
cp
,
10
);
/* explicit delimiter? */
if
(
*
cp
==
':'
)
min
=
strtol
(
(
cp
+
1
)
,
&
cp
,
10
);
min
=
strtol
(
cp
+
1
,
&
cp
,
10
);
/* otherwise, might have run things together... */
else
if
(
(
*
cp
==
'\0'
)
&&
(
strlen
(
str
)
>
3
)
)
else
if
(
*
cp
==
'\0'
&&
strlen
(
str
)
>
3
)
{
min
=
hr
%
100
;
hr
=
hr
/
100
;
...
...
@@ -2778,9 +2775,9 @@ DecodeTimezone(char *str, int *tzp)
else
min
=
0
;
if
(
(
hr
<
0
)
||
(
hr
>
13
)
)
if
(
hr
<
0
||
hr
>
13
)
return
DTERR_TZDISP_OVERFLOW
;
if
(
(
min
<
0
)
||
(
min
>=
60
)
)
if
(
min
<
0
||
min
>=
60
)
return
DTERR_TZDISP_OVERFLOW
;
tz
=
(
hr
*
60
+
min
)
*
60
;
...
...
@@ -2866,8 +2863,8 @@ DecodeSpecial(int field, char *lowtoken, int *val)
int
type
;
datetkn
*
tp
;
if
(
(
datecache
[
field
]
!=
NULL
)
&&
(
strncmp
(
lowtoken
,
datecache
[
field
]
->
token
,
TOKMAXLEN
)
==
0
)
)
if
(
datecache
[
field
]
!=
NULL
&&
strncmp
(
lowtoken
,
datecache
[
field
]
->
token
,
TOKMAXLEN
)
==
0
)
tp
=
datecache
[
field
];
else
{
...
...
@@ -2957,7 +2954,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
* Timezone is a token with a leading sign character and
* otherwise the same as a non-signed time field
*/
Assert
(
(
*
field
[
i
]
==
'-'
)
||
(
*
field
[
i
]
==
'+'
)
);
Assert
(
*
field
[
i
]
==
'-'
||
*
field
[
i
]
==
'+'
);
/*
* A single signed number ends up here, but will be
...
...
@@ -2965,10 +2962,10 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
* through to DTK_NUMBER, which *can* tolerate this.
*/
cp
=
field
[
i
]
+
1
;
while
(
(
*
cp
!=
'\0'
)
&&
(
*
cp
!=
':'
)
&&
(
*
cp
!=
'.'
)
)
while
(
*
cp
!=
'\0'
&&
*
cp
!=
':'
&&
*
cp
!=
'.'
)
cp
++
;
if
(
(
*
cp
==
':'
)
&&
(
DecodeTime
(
field
[
i
]
+
1
,
fmask
,
&
tmask
,
tm
,
fsec
)
==
0
)
)
if
(
*
cp
==
':'
&&
DecodeTime
(
field
[
i
]
+
1
,
fmask
,
&
tmask
,
tm
,
fsec
)
==
0
)
{
if
(
*
field
[
i
]
==
'-'
)
{
...
...
@@ -3111,7 +3108,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
*
fsec
+=
(
fval
-
sec
);
#endif
}
tmask
=
(
(
fmask
&
DTK_M
(
DAY
))
?
0
:
DTK_M
(
DAY
)
);
tmask
=
(
fmask
&
DTK_M
(
DAY
))
?
0
:
DTK_M
(
DAY
);
break
;
case
DTK_WEEK
:
...
...
@@ -3129,7 +3126,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
*
fsec
+=
(
fval
-
sec
);
#endif
}
tmask
=
(
(
fmask
&
DTK_M
(
DAY
))
?
0
:
DTK_M
(
DAY
)
);
tmask
=
(
fmask
&
DTK_M
(
DAY
))
?
0
:
DTK_M
(
DAY
);
break
;
case
DTK_MONTH
:
...
...
@@ -3154,28 +3151,28 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
tm
->
tm_year
+=
val
;
if
(
fval
!=
0
)
tm
->
tm_mon
+=
(
fval
*
12
);
tmask
=
(
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
)
);
tmask
=
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
);
break
;
case
DTK_DECADE
:
tm
->
tm_year
+=
val
*
10
;
if
(
fval
!=
0
)
tm
->
tm_mon
+=
(
fval
*
120
);
tmask
=
(
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
)
);
tmask
=
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
);
break
;
case
DTK_CENTURY
:
tm
->
tm_year
+=
val
*
100
;
if
(
fval
!=
0
)
tm
->
tm_mon
+=
(
fval
*
1200
);
tmask
=
(
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
)
);
tmask
=
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
);
break
;
case
DTK_MILLENNIUM
:
tm
->
tm_year
+=
val
*
1000
;
if
(
fval
!=
0
)
tm
->
tm_mon
+=
(
fval
*
12000
);
tmask
=
(
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
)
);
tmask
=
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
);
break
;
default:
...
...
@@ -3262,8 +3259,8 @@ DecodeUnits(int field, char *lowtoken, int *val)
int
type
;
datetkn
*
tp
;
if
(
(
deltacache
[
field
]
!=
NULL
)
&&
(
strncmp
(
lowtoken
,
deltacache
[
field
]
->
token
,
TOKMAXLEN
)
==
0
)
)
if
(
deltacache
[
field
]
!=
NULL
&&
strncmp
(
lowtoken
,
deltacache
[
field
]
->
token
,
TOKMAXLEN
)
==
0
)
tp
=
deltacache
[
field
];
else
tp
=
datebsearch
(
lowtoken
,
deltatktbl
,
szdeltatktbl
);
...
...
@@ -3276,7 +3273,7 @@ DecodeUnits(int field, char *lowtoken, int *val)
else
{
type
=
tp
->
type
;
if
(
(
type
==
TZ
)
||
(
type
==
DTZ
)
)
if
(
type
==
TZ
||
type
==
DTZ
)
*
val
=
FROMVAL
(
tp
);
else
*
val
=
tp
->
value
;
...
...
@@ -3372,7 +3369,7 @@ datebsearch(char *key, datetkn *base, unsigned int nel)
int
EncodeDateOnly
(
struct
pg_tm
*
tm
,
int
style
,
char
*
str
)
{
if
(
(
tm
->
tm_mon
<
1
)
||
(
tm
->
tm_mon
>
12
)
)
if
(
tm
->
tm_mon
<
1
||
tm
->
tm_mon
>
12
)
return
-
1
;
switch
(
style
)
...
...
@@ -3394,18 +3391,18 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str)
else
sprintf
(
str
,
"%02d/%02d"
,
tm
->
tm_mon
,
tm
->
tm_mday
);
if
(
tm
->
tm_year
>
0
)
sprintf
(
(
str
+
5
)
,
"/%04d"
,
tm
->
tm_year
);
sprintf
(
str
+
5
,
"/%04d"
,
tm
->
tm_year
);
else
sprintf
(
(
str
+
5
)
,
"/%04d %s"
,
-
(
tm
->
tm_year
-
1
),
"BC"
);
sprintf
(
str
+
5
,
"/%04d %s"
,
-
(
tm
->
tm_year
-
1
),
"BC"
);
break
;
case
USE_GERMAN_DATES
:
/* German-style date format */
sprintf
(
str
,
"%02d.%02d"
,
tm
->
tm_mday
,
tm
->
tm_mon
);
if
(
tm
->
tm_year
>
0
)
sprintf
(
(
str
+
5
)
,
".%04d"
,
tm
->
tm_year
);
sprintf
(
str
+
5
,
".%04d"
,
tm
->
tm_year
);
else
sprintf
(
(
str
+
5
)
,
".%04d %s"
,
-
(
tm
->
tm_year
-
1
),
"BC"
);
sprintf
(
str
+
5
,
".%04d %s"
,
-
(
tm
->
tm_year
-
1
),
"BC"
);
break
;
case
USE_POSTGRES_DATES
:
...
...
@@ -3416,9 +3413,9 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str)
else
sprintf
(
str
,
"%02d-%02d"
,
tm
->
tm_mon
,
tm
->
tm_mday
);
if
(
tm
->
tm_year
>
0
)
sprintf
(
(
str
+
5
)
,
"-%04d"
,
tm
->
tm_year
);
sprintf
(
str
+
5
,
"-%04d"
,
tm
->
tm_year
);
else
sprintf
(
(
str
+
5
)
,
"-%04d %s"
,
-
(
tm
->
tm_year
-
1
),
"BC"
);
sprintf
(
str
+
5
,
"-%04d %s"
,
-
(
tm
->
tm_year
-
1
),
"BC"
);
break
;
}
...
...
@@ -3432,7 +3429,7 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str)
int
EncodeTimeOnly
(
struct
pg_tm
*
tm
,
fsec_t
fsec
,
int
*
tzp
,
int
style
,
char
*
str
)
{
if
(
(
tm
->
tm_hour
<
0
)
||
(
tm
->
tm_hour
>
24
)
)
if
(
tm
->
tm_hour
<
0
||
tm
->
tm_hour
>
24
)
return
-
1
;
sprintf
(
str
,
"%02d:%02d"
,
tm
->
tm_hour
,
tm
->
tm_min
);
...
...
@@ -3445,17 +3442,17 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
if
(
fsec
!=
0
)
{
#ifdef HAVE_INT64_TIMESTAMP
sprintf
(
(
str
+
strlen
(
str
)
),
":%02d.%06d"
,
tm
->
tm_sec
,
fsec
);
sprintf
(
str
+
strlen
(
str
),
":%02d.%06d"
,
tm
->
tm_sec
,
fsec
);
#else
sprintf
(
(
str
+
strlen
(
str
)
),
":%013.10f"
,
tm
->
tm_sec
+
fsec
);
sprintf
(
str
+
strlen
(
str
),
":%013.10f"
,
tm
->
tm_sec
+
fsec
);
#endif
/* chop off trailing pairs of zeros... */
while
(
(
strcmp
((
str
+
strlen
(
str
)
-
2
),
"00"
)
==
0
)
&&
(
*
(
str
+
strlen
(
str
)
-
3
)
!=
'.'
)
)
while
(
strcmp
((
str
+
strlen
(
str
)
-
2
),
"00"
)
==
0
&&
*
(
str
+
strlen
(
str
)
-
3
)
!=
'.'
)
*
(
str
+
strlen
(
str
)
-
2
)
=
'\0'
;
}
else
sprintf
(
(
str
+
strlen
(
str
)
),
":%02d"
,
tm
->
tm_sec
);
sprintf
(
str
+
strlen
(
str
),
":%02d"
,
tm
->
tm_sec
);
if
(
tzp
!=
NULL
)
{
...
...
@@ -3463,8 +3460,8 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
min
;
hour
=
-
(
*
tzp
/
3600
);
min
=
(
(
abs
(
*
tzp
)
/
60
)
%
60
)
;
sprintf
(
(
str
+
strlen
(
str
)),
((
min
!=
0
)
?
"%+03d:%02d"
:
"%+03d"
)
,
hour
,
min
);
min
=
(
abs
(
*
tzp
)
/
60
)
%
60
;
sprintf
(
str
+
strlen
(
str
),
(
min
!=
0
)
?
"%+03d:%02d"
:
"%+03d"
,
hour
,
min
);
}
return
TRUE
;
...
...
@@ -3491,9 +3488,9 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
/*
* Why are we checking only the month field? Change this to an
* assert... if (
(tm->tm_mon < 1) || (tm->tm_mon > 12)
) return -1;
* assert... if (
tm->tm_mon < 1 || tm->tm_mon > 12
) return -1;
*/
Assert
(
(
tm
->
tm_mon
>=
1
)
&&
(
tm
->
tm_mon
<=
12
)
);
Assert
(
tm
->
tm_mon
>=
1
&&
tm
->
tm_mon
<=
12
);
switch
(
style
)
{
...
...
@@ -3501,7 +3498,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
/* Compatible with ISO-8601 date formats */
sprintf
(
str
,
"%04d-%02d-%02d %02d:%02d"
,
((
tm
->
tm_year
>
0
)
?
tm
->
tm_year
:
-
(
tm
->
tm_year
-
1
)
),
(
tm
->
tm_year
>
0
)
?
tm
->
tm_year
:
-
(
tm
->
tm_year
-
1
),
tm
->
tm_mon
,
tm
->
tm_mday
,
tm
->
tm_hour
,
tm
->
tm_min
);
/*
...
...
@@ -3514,18 +3511,18 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
#ifdef HAVE_INT64_TIMESTAMP
if
(
fsec
!=
0
)
{
sprintf
(
(
str
+
strlen
(
str
)
),
":%02d.%06d"
,
tm
->
tm_sec
,
fsec
);
sprintf
(
str
+
strlen
(
str
),
":%02d.%06d"
,
tm
->
tm_sec
,
fsec
);
TrimTrailingZeros
(
str
);
}
#else
if
(
(
fsec
!=
0
)
&&
(
tm
->
tm_year
>
0
)
)
if
(
fsec
!=
0
&&
tm
->
tm_year
>
0
)
{
sprintf
(
(
str
+
strlen
(
str
)
),
":%09.6f"
,
tm
->
tm_sec
+
fsec
);
sprintf
(
str
+
strlen
(
str
),
":%09.6f"
,
tm
->
tm_sec
+
fsec
);
TrimTrailingZeros
(
str
);
}
#endif
else
sprintf
(
(
str
+
strlen
(
str
)
),
":%02d"
,
tm
->
tm_sec
);
sprintf
(
str
+
strlen
(
str
),
":%02d"
,
tm
->
tm_sec
);
/*
* tzp == NULL indicates that we don't want *any* time zone
...
...
@@ -3536,12 +3533,12 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
if
(
tzp
!=
NULL
&&
tm
->
tm_isdst
>=
0
)
{
hour
=
-
(
*
tzp
/
3600
);
min
=
(
(
abs
(
*
tzp
)
/
60
)
%
60
)
;
sprintf
(
(
str
+
strlen
(
str
)),
((
min
!=
0
)
?
"%+03d:%02d"
:
"%+03d"
)
,
hour
,
min
);
min
=
(
abs
(
*
tzp
)
/
60
)
%
60
;
sprintf
(
str
+
strlen
(
str
),
(
min
!=
0
)
?
"%+03d:%02d"
:
"%+03d"
,
hour
,
min
);
}
if
(
tm
->
tm_year
<=
0
)
sprintf
(
(
str
+
strlen
(
str
)
),
" BC"
);
sprintf
(
str
+
strlen
(
str
),
" BC"
);
break
;
case
USE_SQL_DATES
:
...
...
@@ -3552,8 +3549,8 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
else
sprintf
(
str
,
"%02d/%02d"
,
tm
->
tm_mon
,
tm
->
tm_mday
);
sprintf
(
(
str
+
5
)
,
"/%04d %02d:%02d"
,
((
tm
->
tm_year
>
0
)
?
tm
->
tm_year
:
-
(
tm
->
tm_year
-
1
)
),
sprintf
(
str
+
5
,
"/%04d %02d:%02d"
,
(
tm
->
tm_year
>
0
)
?
tm
->
tm_year
:
-
(
tm
->
tm_year
-
1
),
tm
->
tm_hour
,
tm
->
tm_min
);
/*
...
...
@@ -3566,33 +3563,33 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
#ifdef HAVE_INT64_TIMESTAMP
if
(
fsec
!=
0
)
{
sprintf
(
(
str
+
strlen
(
str
)
),
":%02d.%06d"
,
tm
->
tm_sec
,
fsec
);
sprintf
(
str
+
strlen
(
str
),
":%02d.%06d"
,
tm
->
tm_sec
,
fsec
);
TrimTrailingZeros
(
str
);
}
#else
if
(
(
fsec
!=
0
)
&&
(
tm
->
tm_year
>
0
)
)
if
(
fsec
!=
0
&&
tm
->
tm_year
>
0
)
{
sprintf
(
(
str
+
strlen
(
str
)
),
":%09.6f"
,
tm
->
tm_sec
+
fsec
);
sprintf
(
str
+
strlen
(
str
),
":%09.6f"
,
tm
->
tm_sec
+
fsec
);
TrimTrailingZeros
(
str
);
}
#endif
else
sprintf
(
(
str
+
strlen
(
str
)
),
":%02d"
,
tm
->
tm_sec
);
sprintf
(
str
+
strlen
(
str
),
":%02d"
,
tm
->
tm_sec
);
if
(
tzp
!=
NULL
&&
tm
->
tm_isdst
>=
0
)
{
if
(
*
tzn
!=
NULL
)
sprintf
(
(
str
+
strlen
(
str
)
),
" %.*s"
,
MAXTZLEN
,
*
tzn
);
sprintf
(
str
+
strlen
(
str
),
" %.*s"
,
MAXTZLEN
,
*
tzn
);
else
{
hour
=
-
(
*
tzp
/
3600
);
min
=
(
(
abs
(
*
tzp
)
/
60
)
%
60
)
;
sprintf
(
(
str
+
strlen
(
str
)),
((
min
!=
0
)
?
"%+03d:%02d"
:
"%+03d"
)
,
hour
,
min
);
min
=
(
abs
(
*
tzp
)
/
60
)
%
60
;
sprintf
(
str
+
strlen
(
str
),
(
min
!=
0
)
?
"%+03d:%02d"
:
"%+03d"
,
hour
,
min
);
}
}
if
(
tm
->
tm_year
<=
0
)
sprintf
(
(
str
+
strlen
(
str
)
),
" BC"
);
sprintf
(
str
+
strlen
(
str
),
" BC"
);
break
;
case
USE_GERMAN_DATES
:
...
...
@@ -3600,8 +3597,8 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
sprintf
(
str
,
"%02d.%02d"
,
tm
->
tm_mday
,
tm
->
tm_mon
);
sprintf
(
(
str
+
5
)
,
".%04d %02d:%02d"
,
((
tm
->
tm_year
>
0
)
?
tm
->
tm_year
:
-
(
tm
->
tm_year
-
1
)
),
sprintf
(
str
+
5
,
".%04d %02d:%02d"
,
(
tm
->
tm_year
>
0
)
?
tm
->
tm_year
:
-
(
tm
->
tm_year
-
1
),
tm
->
tm_hour
,
tm
->
tm_min
);
/*
...
...
@@ -3614,33 +3611,33 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
#ifdef HAVE_INT64_TIMESTAMP
if
(
fsec
!=
0
)
{
sprintf
(
(
str
+
strlen
(
str
)
),
":%02d.%06d"
,
tm
->
tm_sec
,
fsec
);
sprintf
(
str
+
strlen
(
str
),
":%02d.%06d"
,
tm
->
tm_sec
,
fsec
);
TrimTrailingZeros
(
str
);
}
#else
if
(
(
fsec
!=
0
)
&&
(
tm
->
tm_year
>
0
)
)
if
(
fsec
!=
0
&&
tm
->
tm_year
>
0
)
{
sprintf
(
(
str
+
strlen
(
str
)
),
":%09.6f"
,
tm
->
tm_sec
+
fsec
);
sprintf
(
str
+
strlen
(
str
),
":%09.6f"
,
tm
->
tm_sec
+
fsec
);
TrimTrailingZeros
(
str
);
}
#endif
else
sprintf
(
(
str
+
strlen
(
str
)
),
":%02d"
,
tm
->
tm_sec
);
sprintf
(
str
+
strlen
(
str
),
":%02d"
,
tm
->
tm_sec
);
if
(
tzp
!=
NULL
&&
tm
->
tm_isdst
>=
0
)
{
if
(
*
tzn
!=
NULL
)
sprintf
(
(
str
+
strlen
(
str
)
),
" %.*s"
,
MAXTZLEN
,
*
tzn
);
sprintf
(
str
+
strlen
(
str
),
" %.*s"
,
MAXTZLEN
,
*
tzn
);
else
{
hour
=
-
(
*
tzp
/
3600
);
min
=
(
(
abs
(
*
tzp
)
/
60
)
%
60
)
;
sprintf
(
(
str
+
strlen
(
str
)),
((
min
!=
0
)
?
"%+03d:%02d"
:
"%+03d"
)
,
hour
,
min
);
min
=
(
abs
(
*
tzp
)
/
60
)
%
60
;
sprintf
(
str
+
strlen
(
str
),
(
min
!=
0
)
?
"%+03d:%02d"
:
"%+03d"
,
hour
,
min
);
}
}
if
(
tm
->
tm_year
<=
0
)
sprintf
(
(
str
+
strlen
(
str
)
),
" BC"
);
sprintf
(
str
+
strlen
(
str
),
" BC"
);
break
;
case
USE_POSTGRES_DATES
:
...
...
@@ -3651,14 +3648,14 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
tm
->
tm_wday
=
j2day
(
day
);
strncpy
(
str
,
days
[
tm
->
tm_wday
],
3
);
strcpy
(
(
str
+
3
)
,
" "
);
strcpy
(
str
+
3
,
" "
);
if
(
DateOrder
==
DATEORDER_DMY
)
sprintf
(
(
str
+
4
)
,
"%02d %3s"
,
tm
->
tm_mday
,
months
[
tm
->
tm_mon
-
1
]);
sprintf
(
str
+
4
,
"%02d %3s"
,
tm
->
tm_mday
,
months
[
tm
->
tm_mon
-
1
]);
else
sprintf
(
(
str
+
4
)
,
"%3s %02d"
,
months
[
tm
->
tm_mon
-
1
],
tm
->
tm_mday
);
sprintf
(
str
+
4
,
"%3s %02d"
,
months
[
tm
->
tm_mon
-
1
],
tm
->
tm_mday
);
sprintf
(
(
str
+
10
)
,
" %02d:%02d"
,
tm
->
tm_hour
,
tm
->
tm_min
);
sprintf
(
str
+
10
,
" %02d:%02d"
,
tm
->
tm_hour
,
tm
->
tm_min
);
/*
* Print fractional seconds if any. The field widths here
...
...
@@ -3670,26 +3667,26 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
#ifdef HAVE_INT64_TIMESTAMP
if
(
fsec
!=
0
)
{
sprintf
(
(
str
+
strlen
(
str
)
),
":%02d.%06d"
,
tm
->
tm_sec
,
fsec
);
sprintf
(
str
+
strlen
(
str
),
":%02d.%06d"
,
tm
->
tm_sec
,
fsec
);
TrimTrailingZeros
(
str
);
}
#else
if
(
(
fsec
!=
0
)
&&
(
tm
->
tm_year
>
0
)
)
if
(
fsec
!=
0
&&
tm
->
tm_year
>
0
)
{
sprintf
(
(
str
+
strlen
(
str
)
),
":%09.6f"
,
tm
->
tm_sec
+
fsec
);
sprintf
(
str
+
strlen
(
str
),
":%09.6f"
,
tm
->
tm_sec
+
fsec
);
TrimTrailingZeros
(
str
);
}
#endif
else
sprintf
(
(
str
+
strlen
(
str
)
),
":%02d"
,
tm
->
tm_sec
);
sprintf
(
str
+
strlen
(
str
),
":%02d"
,
tm
->
tm_sec
);
sprintf
(
(
str
+
strlen
(
str
)
),
" %04d"
,
(
(
tm
->
tm_year
>
0
)
?
tm
->
tm_year
:
-
(
tm
->
tm_year
-
1
)
));
sprintf
(
str
+
strlen
(
str
),
" %04d"
,
(
tm
->
tm_year
>
0
)
?
tm
->
tm_year
:
-
(
tm
->
tm_year
-
1
));
if
(
tzp
!=
NULL
&&
tm
->
tm_isdst
>=
0
)
{
if
(
*
tzn
!=
NULL
)
sprintf
(
(
str
+
strlen
(
str
)
),
" %.*s"
,
MAXTZLEN
,
*
tzn
);
sprintf
(
str
+
strlen
(
str
),
" %.*s"
,
MAXTZLEN
,
*
tzn
);
else
{
/*
...
...
@@ -3700,13 +3697,13 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
* 2001-10-19
*/
hour
=
-
(
*
tzp
/
3600
);
min
=
(
(
abs
(
*
tzp
)
/
60
)
%
60
)
;
sprintf
(
(
str
+
strlen
(
str
)),
((
min
!=
0
)
?
" %+03d:%02d"
:
" %+03d"
)
,
hour
,
min
);
min
=
(
abs
(
*
tzp
)
/
60
)
%
60
;
sprintf
(
str
+
strlen
(
str
),
(
min
!=
0
)
?
" %+03d:%02d"
:
" %+03d"
,
hour
,
min
);
}
}
if
(
tm
->
tm_year
<=
0
)
sprintf
(
(
str
+
strlen
(
str
)
),
" BC"
);
sprintf
(
str
+
strlen
(
str
),
" BC"
);
break
;
}
...
...
@@ -3742,7 +3739,7 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
if
(
tm
->
tm_year
!=
0
)
{
sprintf
(
cp
,
"%d year%s"
,
tm
->
tm_year
,
(
(
tm
->
tm_year
!=
1
)
?
"s"
:
""
)
);
tm
->
tm_year
,
(
tm
->
tm_year
!=
1
)
?
"s"
:
""
);
cp
+=
strlen
(
cp
);
is_before
=
(
tm
->
tm_year
<
0
);
is_nonzero
=
TRUE
;
...
...
@@ -3750,9 +3747,9 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
if
(
tm
->
tm_mon
!=
0
)
{
sprintf
(
cp
,
"%s%s%d mon%s"
,
(
is_nonzero
?
" "
:
""
)
,
(
(
is_before
&&
(
tm
->
tm_mon
>
0
))
?
"+"
:
""
)
,
tm
->
tm_mon
,
(
(
tm
->
tm_mon
!=
1
)
?
"s"
:
""
)
);
sprintf
(
cp
,
"%s%s%d mon%s"
,
is_nonzero
?
" "
:
""
,
(
is_before
&&
tm
->
tm_mon
>
0
)
?
"+"
:
""
,
tm
->
tm_mon
,
(
tm
->
tm_mon
!=
1
)
?
"s"
:
""
);
cp
+=
strlen
(
cp
);
is_before
=
(
tm
->
tm_mon
<
0
);
is_nonzero
=
TRUE
;
...
...
@@ -3760,21 +3757,21 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
if
(
tm
->
tm_mday
!=
0
)
{
sprintf
(
cp
,
"%s%s%d day%s"
,
(
is_nonzero
?
" "
:
""
)
,
(
(
is_before
&&
(
tm
->
tm_mday
>
0
))
?
"+"
:
""
)
,
tm
->
tm_mday
,
(
(
tm
->
tm_mday
!=
1
)
?
"s"
:
""
)
);
sprintf
(
cp
,
"%s%s%d day%s"
,
is_nonzero
?
" "
:
""
,
(
is_before
&&
tm
->
tm_mday
>
0
)
?
"+"
:
""
,
tm
->
tm_mday
,
(
tm
->
tm_mday
!=
1
)
?
"s"
:
""
);
cp
+=
strlen
(
cp
);
is_before
=
(
tm
->
tm_mday
<
0
);
is_nonzero
=
TRUE
;
}
if
(
(
!
is_nonzero
)
||
(
tm
->
tm_hour
!=
0
)
||
(
tm
->
tm_min
!=
0
)
||
(
tm
->
tm_sec
!=
0
)
||
(
fsec
!=
0
)
)
if
(
!
is_nonzero
||
tm
->
tm_hour
!=
0
||
tm
->
tm_min
!=
0
||
tm
->
tm_sec
!=
0
||
fsec
!=
0
)
{
int
minus
=
(
(
tm
->
tm_hour
<
0
)
||
(
tm
->
tm_min
<
0
)
||
(
tm
->
tm_sec
<
0
)
||
(
fsec
<
0
)
);
int
minus
=
(
tm
->
tm_hour
<
0
||
tm
->
tm_min
<
0
||
tm
->
tm_sec
<
0
||
fsec
<
0
);
sprintf
(
cp
,
"%s%s%02d:%02d"
,
(
is_nonzero
?
" "
:
""
)
,
sprintf
(
cp
,
"%s%s%02d:%02d"
,
is_nonzero
?
" "
:
""
,
(
minus
?
"-"
:
(
is_before
?
"+"
:
""
)),
abs
(
tm
->
tm_hour
),
abs
(
tm
->
tm_min
));
cp
+=
strlen
(
cp
);
...
...
@@ -3816,7 +3813,7 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
year
=
-
year
;
sprintf
(
cp
,
"%d year%s"
,
year
,
(
(
year
!=
1
)
?
"s"
:
""
)
);
(
year
!=
1
)
?
"s"
:
""
);
cp
+=
strlen
(
cp
);
is_before
=
(
tm
->
tm_year
<
0
);
is_nonzero
=
TRUE
;
...
...
@@ -3826,11 +3823,11 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
{
int
mon
=
tm
->
tm_mon
;
if
(
is_before
||
(
(
!
is_nonzero
)
&&
(
tm
->
tm_mon
<
0
)
))
if
(
is_before
||
(
!
is_nonzero
&&
tm
->
tm_mon
<
0
))
mon
=
-
mon
;
sprintf
(
cp
,
"%s%d mon%s"
,
(
is_nonzero
?
" "
:
""
)
,
mon
,
(
(
mon
!=
1
)
?
"s"
:
""
)
);
sprintf
(
cp
,
"%s%d mon%s"
,
is_nonzero
?
" "
:
""
,
mon
,
(
mon
!=
1
)
?
"s"
:
""
);
cp
+=
strlen
(
cp
);
if
(
!
is_nonzero
)
is_before
=
(
tm
->
tm_mon
<
0
);
...
...
@@ -3841,11 +3838,11 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
{
int
day
=
tm
->
tm_mday
;
if
(
is_before
||
(
(
!
is_nonzero
)
&&
(
tm
->
tm_mday
<
0
)
))
if
(
is_before
||
(
!
is_nonzero
&&
tm
->
tm_mday
<
0
))
day
=
-
day
;
sprintf
(
cp
,
"%s%d day%s"
,
(
is_nonzero
?
" "
:
""
)
,
day
,
(
(
day
!=
1
)
?
"s"
:
""
)
);
sprintf
(
cp
,
"%s%d day%s"
,
is_nonzero
?
" "
:
""
,
day
,
(
day
!=
1
)
?
"s"
:
""
);
cp
+=
strlen
(
cp
);
if
(
!
is_nonzero
)
is_before
=
(
tm
->
tm_mday
<
0
);
...
...
@@ -3855,11 +3852,11 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
{
int
hour
=
tm
->
tm_hour
;
if
(
is_before
||
(
(
!
is_nonzero
)
&&
(
tm
->
tm_hour
<
0
)
))
if
(
is_before
||
(
!
is_nonzero
&&
tm
->
tm_hour
<
0
))
hour
=
-
hour
;
sprintf
(
cp
,
"%s%d hour%s"
,
(
is_nonzero
?
" "
:
""
)
,
hour
,
(
(
hour
!=
1
)
?
"s"
:
""
)
);
sprintf
(
cp
,
"%s%d hour%s"
,
is_nonzero
?
" "
:
""
,
hour
,
(
hour
!=
1
)
?
"s"
:
""
);
cp
+=
strlen
(
cp
);
if
(
!
is_nonzero
)
is_before
=
(
tm
->
tm_hour
<
0
);
...
...
@@ -3870,11 +3867,11 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
{
int
min
=
tm
->
tm_min
;
if
(
is_before
||
(
(
!
is_nonzero
)
&&
(
tm
->
tm_min
<
0
)
))
if
(
is_before
||
(
!
is_nonzero
&&
tm
->
tm_min
<
0
))
min
=
-
min
;
sprintf
(
cp
,
"%s%d min%s"
,
(
is_nonzero
?
" "
:
""
)
,
min
,
(
(
min
!=
1
)
?
"s"
:
""
)
);
sprintf
(
cp
,
"%s%d min%s"
,
is_nonzero
?
" "
:
""
,
min
,
(
min
!=
1
)
?
"s"
:
""
);
cp
+=
strlen
(
cp
);
if
(
!
is_nonzero
)
is_before
=
(
tm
->
tm_min
<
0
);
...
...
@@ -3888,27 +3885,27 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
#ifdef HAVE_INT64_TIMESTAMP
sec
=
fsec
;
if
(
is_before
||
(
(
!
is_nonzero
)
&&
(
tm
->
tm_sec
<
0
)
))
if
(
is_before
||
(
!
is_nonzero
&&
tm
->
tm_sec
<
0
))
{
tm
->
tm_sec
=
-
tm
->
tm_sec
;
sec
=
-
sec
;
is_before
=
TRUE
;
}
else
if
(
(
!
is_nonzero
)
&&
(
tm
->
tm_sec
==
0
)
&&
(
fsec
<
0
)
)
else
if
(
!
is_nonzero
&&
tm
->
tm_sec
==
0
&&
fsec
<
0
)
{
sec
=
-
sec
;
is_before
=
TRUE
;
}
sprintf
(
cp
,
"%s%d.%02d secs"
,
(
is_nonzero
?
" "
:
""
)
,
tm
->
tm_sec
,
((
(
int
)
sec
)
/
10000
)
);
sprintf
(
cp
,
"%s%d.%02d secs"
,
is_nonzero
?
" "
:
""
,
tm
->
tm_sec
,
((
int
)
sec
)
/
10000
);
cp
+=
strlen
(
cp
);
#else
fsec
+=
tm
->
tm_sec
;
sec
=
fsec
;
if
(
is_before
||
(
(
!
is_nonzero
)
&&
(
fsec
<
0
)
))
if
(
is_before
||
(
!
is_nonzero
&&
fsec
<
0
))
sec
=
-
sec
;
sprintf
(
cp
,
"%s%.2f secs"
,
(
is_nonzero
?
" "
:
""
)
,
sec
);
sprintf
(
cp
,
"%s%.2f secs"
,
is_nonzero
?
" "
:
""
,
sec
);
cp
+=
strlen
(
cp
);
if
(
!
is_nonzero
)
is_before
=
(
fsec
<
0
);
...
...
@@ -3920,11 +3917,11 @@ EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str)
{
int
sec
=
tm
->
tm_sec
;
if
(
is_before
||
(
(
!
is_nonzero
)
&&
(
tm
->
tm_sec
<
0
)
))
if
(
is_before
||
(
!
is_nonzero
&&
tm
->
tm_sec
<
0
))
sec
=
-
sec
;
sprintf
(
cp
,
"%s%d sec%s"
,
(
is_nonzero
?
" "
:
""
)
,
sec
,
(
(
sec
!=
1
)
?
"s"
:
""
)
);
sprintf
(
cp
,
"%s%d sec%s"
,
is_nonzero
?
" "
:
""
,
sec
,
(
sec
!=
1
)
?
"s"
:
""
);
cp
+=
strlen
(
cp
);
if
(
!
is_nonzero
)
is_before
=
(
tm
->
tm_sec
<
0
);
...
...
src/backend/utils/adt/timestamp.c
View file @
33d0d4ce
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.1
19 2005/04/19 03:13:59
momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.1
20 2005/05/23 17:13:14
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -264,7 +264,7 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
if
(
!
TIMESTAMP_NOT_FINITE
(
*
time
)
&&
(
typmod
!=
-
1
)
&&
(
typmod
!=
MAX_TIMESTAMP_PRECISION
))
{
if
(
(
typmod
<
0
)
||
(
typmod
>
MAX_TIMESTAMP_PRECISION
)
)
if
(
typmod
<
0
||
typmod
>
MAX_TIMESTAMP_PRECISION
)
ereport
(
ERROR
,
(
errcode
(
ERRCODE_INVALID_PARAMETER_VALUE
),
errmsg
(
"timestamp(%d) precision must be between %d and %d"
,
...
...
@@ -578,12 +578,12 @@ interval_recv(PG_FUNCTION_ARGS)
interval
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
#ifdef HAVE_INT64_TIMESTAMP
interval
->
time
=
pq_getmsgint64
(
buf
);
interval
->
time
=
pq_getmsgint64
(
buf
);
#else
interval
->
time
=
pq_getmsgfloat8
(
buf
);
interval
->
time
=
pq_getmsgfloat8
(
buf
);
#endif
interval
->
month
=
pq_getmsgint
(
buf
,
sizeof
(
interval
->
month
));
interval
->
month
=
pq_getmsgint
(
buf
,
sizeof
(
interval
->
month
));
PG_RETURN_INTERVAL_P
(
interval
);
}
...
...
@@ -678,28 +678,28 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
}
else
if
(
range
==
INTERVAL_MASK
(
YEAR
))
{
interval
->
month
=
((
interval
->
month
/
12
)
*
12
)
;
interval
->
time
=
0
;
interval
->
month
=
(
interval
->
month
/
12
)
*
12
;
interval
->
time
=
0
;
}
else
if
(
range
==
INTERVAL_MASK
(
MONTH
))
{
interval
->
month
%=
12
;
interval
->
time
=
0
;
interval
->
month
%=
12
;
interval
->
time
=
0
;
}
/* YEAR TO MONTH */
else
if
(
range
==
(
INTERVAL_MASK
(
YEAR
)
|
INTERVAL_MASK
(
MONTH
)))
interval
->
time
=
0
;
interval
->
time
=
0
;
else
if
(
range
==
INTERVAL_MASK
(
DAY
))
{
interval
->
month
=
0
;
interval
->
month
=
0
;
#ifdef HAVE_INT64_TIMESTAMP
interval
->
time
=
(((
int
)
(
interval
->
time
/
INT64CONST
(
86400000000
)))
*
INT64CONST
(
86400000000
)
);
interval
->
time
=
((
int
)
(
interval
->
time
/
INT64CONST
(
86400000000
)))
*
INT64CONST
(
86400000000
);
#else
interval
->
time
=
(((
int
)
(
interval
->
time
/
86400
))
*
86400
)
;
interval
->
time
=
((
int
)
(
interval
->
time
/
86400
))
*
86400
;
#endif
}
else
if
(
range
==
INTERVAL_MASK
(
HOUR
))
...
...
@@ -711,17 +711,17 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
double
day
;
#endif
interval
->
month
=
0
;
interval
->
month
=
0
;
#ifdef HAVE_INT64_TIMESTAMP
day
=
(
interval
->
time
/
INT64CONST
(
86400000000
)
);
interval
->
time
-=
(
day
*
INT64CONST
(
86400000000
)
);
interval
->
time
=
((
interval
->
time
/
INT64CONST
(
3600000000
))
*
INT64CONST
(
3600000000
)
);
day
=
interval
->
time
/
INT64CONST
(
86400000000
);
interval
->
time
-=
day
*
INT64CONST
(
86400000000
);
interval
->
time
=
(
interval
->
time
/
INT64CONST
(
3600000000
))
*
INT64CONST
(
3600000000
);
#else
TMODULO
(
interval
->
time
,
day
,
86400
.
0
);
interval
->
time
=
(((
int
)
(
interval
->
time
/
3600
))
*
3600
.
0
)
;
interval
->
time
=
((
int
)
(
interval
->
time
/
3600
))
*
3600
.
0
;
#endif
}
else
if
(
range
==
INTERVAL_MASK
(
MINUTE
))
...
...
@@ -733,17 +733,17 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
double
hour
;
#endif
interval
->
month
=
0
;
interval
->
month
=
0
;
#ifdef HAVE_INT64_TIMESTAMP
hour
=
(
interval
->
time
/
INT64CONST
(
3600000000
)
);
interval
->
time
-=
(
hour
*
INT64CONST
(
3600000000
)
);
interval
->
time
=
((
interval
->
time
/
INT64CONST
(
60000000
))
*
INT64CONST
(
60000000
)
);
hour
=
interval
->
time
/
INT64CONST
(
3600000000
);
interval
->
time
-=
hour
*
INT64CONST
(
3600000000
);
interval
->
time
=
(
interval
->
time
/
INT64CONST
(
60000000
))
*
INT64CONST
(
60000000
);
#else
TMODULO
(
interval
->
time
,
hour
,
3600
.
0
);
interval
->
time
=
(((
int
)
(
interval
->
time
/
60
))
*
60
)
;
interval
->
time
=
((
int
)
(
interval
->
time
/
60
))
*
60
;
#endif
}
else
if
(
range
==
INTERVAL_MASK
(
SECOND
))
...
...
@@ -755,11 +755,11 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
double
minute
;
#endif
interval
->
month
=
0
;
interval
->
month
=
0
;
#ifdef HAVE_INT64_TIMESTAMP
minute
=
(
interval
->
time
/
INT64CONST
(
60000000
)
);
interval
->
time
-=
(
minute
*
INT64CONST
(
60000000
)
);
minute
=
interval
->
time
/
INT64CONST
(
60000000
);
interval
->
time
-=
minute
*
INT64CONST
(
60000000
);
#else
TMODULO
(
interval
->
time
,
minute
,
60
.
0
);
...
...
@@ -770,14 +770,14 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
else
if
(
range
==
(
INTERVAL_MASK
(
DAY
)
|
INTERVAL_MASK
(
HOUR
)))
{
interval
->
month
=
0
;
interval
->
month
=
0
;
#ifdef HAVE_INT64_TIMESTAMP
interval
->
time
=
((
interval
->
time
/
INT64CONST
(
3600000000
))
*
INT64CONST
(
3600000000
)
);
interval
->
time
=
(
interval
->
time
/
INT64CONST
(
3600000000
))
*
INT64CONST
(
3600000000
);
#else
interval
->
time
=
(((
int
)
(
interval
->
time
/
3600
))
*
3600
)
;
interval
->
time
=
((
int
)
(
interval
->
time
/
3600
))
*
3600
;
#endif
}
/* DAY TO MINUTE */
...
...
@@ -785,14 +785,14 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
INTERVAL_MASK
(
HOUR
)
|
INTERVAL_MASK
(
MINUTE
)))
{
interval
->
month
=
0
;
interval
->
month
=
0
;
#ifdef HAVE_INT64_TIMESTAMP
interval
->
time
=
((
interval
->
time
/
INT64CONST
(
60000000
))
*
INT64CONST
(
60000000
)
);
interval
->
time
=
(
interval
->
time
/
INT64CONST
(
60000000
))
*
INT64CONST
(
60000000
);
#else
interval
->
time
=
(((
int
)
(
interval
->
time
/
60
))
*
60
)
;
interval
->
time
=
((
int
)
(
interval
->
time
/
60
))
*
60
;
#endif
}
/* DAY TO SECOND */
...
...
@@ -800,7 +800,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
INTERVAL_MASK
(
HOUR
)
|
INTERVAL_MASK
(
MINUTE
)
|
INTERVAL_MASK
(
SECOND
)))
interval
->
month
=
0
;
interval
->
month
=
0
;
/* HOUR TO MINUTE */
else
if
(
range
==
(
INTERVAL_MASK
(
HOUR
)
|
...
...
@@ -813,17 +813,17 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
double
day
;
#endif
interval
->
month
=
0
;
interval
->
month
=
0
;
#ifdef HAVE_INT64_TIMESTAMP
day
=
(
interval
->
time
/
INT64CONST
(
86400000000
));
interval
->
time
-=
(
day
*
INT64CONST
(
86400000000
)
);
interval
->
time
=
((
interval
->
time
/
INT64CONST
(
60000000
))
*
INT64CONST
(
60000000
)
);
interval
->
time
-=
day
*
INT64CONST
(
86400000000
);
interval
->
time
=
(
interval
->
time
/
INT64CONST
(
60000000
))
*
INT64CONST
(
60000000
);
#else
TMODULO
(
interval
->
time
,
day
,
86400
.
0
);
interval
->
time
=
(((
int
)
(
interval
->
time
/
60
))
*
60
)
;
interval
->
time
=
((
int
)
(
interval
->
time
/
60
))
*
60
;
#endif
}
/* HOUR TO SECOND */
...
...
@@ -838,11 +838,11 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
double
day
;
#endif
interval
->
month
=
0
;
interval
->
month
=
0
;
#ifdef HAVE_INT64_TIMESTAMP
day
=
(
interval
->
time
/
INT64CONST
(
86400000000
)
);
interval
->
time
-=
(
day
*
INT64CONST
(
86400000000
)
);
day
=
interval
->
time
/
INT64CONST
(
86400000000
);
interval
->
time
-=
day
*
INT64CONST
(
86400000000
);
#else
TMODULO
(
interval
->
time
,
day
,
86400
.
0
);
...
...
@@ -859,12 +859,11 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
double
hour
;
#endif
interval
->
month
=
0
;
interval
->
month
=
0
;
#ifdef HAVE_INT64_TIMESTAMP
hour
=
(
interval
->
time
/
INT64CONST
(
3600000000
));
interval
->
time
-=
(
hour
*
INT64CONST
(
3600000000
));
hour
=
interval
->
time
/
INT64CONST
(
3600000000
);
interval
->
time
-=
hour
*
INT64CONST
(
3600000000
);
#else
TMODULO
(
interval
->
time
,
hour
,
3600
.
0
);
#endif
...
...
@@ -875,7 +874,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
/* Need to adjust precision? If not, don't even try! */
if
(
precision
!=
INTERVAL_FULL_PRECISION
)
{
if
(
(
precision
<
0
)
||
(
precision
>
MAX_INTERVAL_PRECISION
)
)
if
(
precision
<
0
||
precision
>
MAX_INTERVAL_PRECISION
)
ereport
(
ERROR
,
(
errcode
(
ERRCODE_INVALID_PARAMETER_VALUE
),
errmsg
(
"interval(%d) precision must be between %d and %d"
,
...
...
@@ -892,17 +891,22 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
#ifdef HAVE_INT64_TIMESTAMP
if
(
interval
->
time
>=
INT64CONST
(
0
))
{
interval
->
time
=
(((
interval
->
time
+
IntervalOffsets
[
precision
])
/
IntervalScales
[
precision
])
*
IntervalScales
[
precision
]);
interval
->
time
=
(((
interval
->
time
+
IntervalOffsets
[
precision
])
/
IntervalScales
[
precision
])
*
IntervalScales
[
precision
];
}
else
{
interval
->
time
=
-
(((
-
interval
->
time
+
IntervalOffsets
[
precision
])
/
IntervalScales
[
precision
])
*
IntervalScales
[
precision
]);
interval
->
time
=
-
(((
-
interval
->
time
+
IntervalOffsets
[
precision
])
/
IntervalScales
[
precision
])
*
IntervalScales
[
precision
]);
}
#else
interval
->
time
=
(
rint
(((
double
)
interval
->
time
)
*
IntervalScales
[
precision
])
/
IntervalScales
[
precision
]);
interval
->
time
=
rint
(((
double
)
interval
->
time
)
*
IntervalScales
[
precision
])
/
IntervalScales
[
precision
];
#endif
}
}
...
...
@@ -954,17 +958,17 @@ dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
time
=
jd
;
#ifdef HAVE_INT64_TIMESTAMP
*
hour
=
(
time
/
INT64CONST
(
3600000000
)
);
time
-=
(
(
*
hour
)
*
INT64CONST
(
3600000000
)
);
*
min
=
(
time
/
INT64CONST
(
60000000
)
);
time
-=
(
(
*
min
)
*
INT64CONST
(
60000000
)
);
*
sec
=
(
time
/
INT64CONST
(
1000000
)
);
*
fsec
=
(
time
-
(
*
sec
*
INT64CONST
(
1000000
)
));
*
hour
=
time
/
INT64CONST
(
3600000000
);
time
-=
(
*
hour
)
*
INT64CONST
(
3600000000
);
*
min
=
time
/
INT64CONST
(
60000000
);
time
-=
(
*
min
)
*
INT64CONST
(
60000000
);
*
sec
=
time
/
INT64CONST
(
1000000
);
*
fsec
=
time
-
(
*
sec
*
INT64CONST
(
1000000
));
#else
*
hour
=
(
time
/
3600
)
;
time
-=
(
(
*
hour
)
*
3600
)
;
*
min
=
(
time
/
60
)
;
time
-=
(
(
*
min
)
*
60
)
;
*
hour
=
time
/
3600
;
time
-=
(
*
hour
)
*
3600
;
*
min
=
time
/
60
;
time
-=
(
*
min
)
*
60
;
*
sec
=
time
;
*
fsec
=
JROUND
(
time
-
*
sec
);
#endif
...
...
@@ -1010,7 +1014,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn
if
(
time
<
INT64CONST
(
0
))
{
time
+=
INT64CONST
(
86400000000
);
date
-=
1
;
date
-=
1
;
}
#else
TMODULO
(
time
,
date
,
86400e0
);
...
...
@@ -1018,7 +1022,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, char **tzn
if
(
time
<
0
)
{
time
+=
86400
;
date
-=
1
;
date
-=
1
;
}
#endif
...
...
@@ -1138,15 +1142,16 @@ tm2timestamp(struct pg_tm * tm, fsec_t fsec, int *tzp, Timestamp *result)
time
=
time2t
(
tm
->
tm_hour
,
tm
->
tm_min
,
tm
->
tm_sec
,
fsec
);
#ifdef HAVE_INT64_TIMESTAMP
*
result
=
(
date
*
INT64CONST
(
86400000000
))
+
time
;
*
result
=
date
*
INT64CONST
(
86400000000
)
+
time
;
/* check for major overflow */
if
((
*
result
-
time
)
/
INT64CONST
(
86400000000
)
!=
date
)
return
-
1
;
/* check for just-barely overflow (okay except time-of-day wraps) */
if
((
*
result
<
0
)
?
(
date
>=
0
)
:
(
date
<
0
))
if
((
*
result
<
0
&&
date
>=
0
)
||
(
*
result
>=
0
&&
date
<
0
))
return
-
1
;
#else
*
result
=
((
date
*
86400
)
+
time
)
;
*
result
=
date
*
86400
+
time
;
#endif
if
(
tzp
!=
NULL
)
*
result
=
dt2local
(
*
result
,
-
(
*
tzp
));
...
...
@@ -1205,7 +1210,7 @@ interval2tm(Interval span, struct pg_tm * tm, fsec_t *fsec)
int
tm2interval
(
struct
pg_tm
*
tm
,
fsec_t
fsec
,
Interval
*
span
)
{
span
->
month
=
((
tm
->
tm_year
*
12
)
+
tm
->
tm_mon
)
;
span
->
month
=
tm
->
tm_year
*
12
+
tm
->
tm_mon
;
#ifdef HAVE_INT64_TIMESTAMP
span
->
time
=
((((((((
tm
->
tm_mday
*
INT64CONST
(
24
))
+
tm
->
tm_hour
)
*
INT64CONST
(
60
))
...
...
@@ -1611,14 +1616,14 @@ interval_cmp_internal(Interval *interval1, Interval *interval2)
#ifdef HAVE_INT64_TIMESTAMP
if
(
interval1
->
month
!=
0
)
span1
+=
((
interval1
->
month
*
INT64CONST
(
30
)
*
INT64CONST
(
86400000000
))
);
span1
+=
interval1
->
month
*
INT64CONST
(
30
)
*
INT64CONST
(
86400000000
);
if
(
interval2
->
month
!=
0
)
span2
+=
((
interval2
->
month
*
INT64CONST
(
30
)
*
INT64CONST
(
86400000000
))
);
span2
+=
interval2
->
month
*
INT64CONST
(
30
)
*
INT64CONST
(
86400000000
);
#else
if
(
interval1
->
month
!=
0
)
span1
+=
(
interval1
->
month
*
(
30
.
0
*
86400
)
);
span1
+=
interval1
->
month
*
(
30
.
0
*
86400
);
if
(
interval2
->
month
!=
0
)
span2
+=
(
interval2
->
month
*
(
30
.
0
*
86400
)
);
span2
+=
interval2
->
month
*
(
30
.
0
*
86400
);
#endif
return
((
span1
<
span2
)
?
-
1
:
(
span1
>
span2
)
?
1
:
0
);
...
...
@@ -2155,8 +2160,8 @@ interval_mul(PG_FUNCTION_ARGS)
#ifdef HAVE_INT64_TIMESTAMP
result
->
month
=
months
;
result
->
time
=
(
span1
->
time
*
factor
);
result
->
time
+=
(
(
months
-
result
->
month
)
*
INT64CONST
(
30
)
*
INT64CONST
(
86400000000
)
);
result
->
time
+=
(
months
-
result
->
month
)
*
INT64CONST
(
30
)
*
INT64CONST
(
86400000000
);
#else
result
->
month
=
rint
(
months
);
result
->
time
=
JROUND
(
span1
->
time
*
factor
);
...
...
@@ -2199,10 +2204,10 @@ interval_div(PG_FUNCTION_ARGS)
result
->
month
=
(
span
->
month
/
factor
);
result
->
time
=
(
span
->
time
/
factor
);
/* evaluate fractional months as 30 days */
result
->
time
+=
((
(
span
->
month
-
(
result
->
month
*
factor
))
*
INT64CONST
(
30
)
*
INT64CONST
(
86400000000
))
/
factor
)
;
result
->
time
+=
((
span
->
month
-
(
result
->
month
*
factor
))
*
INT64CONST
(
30
)
*
INT64CONST
(
86400000000
))
/
factor
;
#else
months
=
(
span
->
month
/
factor
)
;
months
=
span
->
month
/
factor
;
result
->
month
=
rint
(
months
);
result
->
time
=
JROUND
(
span
->
time
/
factor
);
/* evaluate fractional months as 30 days */
...
...
@@ -2328,8 +2333,8 @@ timestamp_age(PG_FUNCTION_ARGS)
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
if
(
(
timestamp2tm
(
dt1
,
NULL
,
tm1
,
&
fsec1
,
NULL
)
==
0
)
&&
(
timestamp2tm
(
dt2
,
NULL
,
tm2
,
&
fsec2
,
NULL
)
==
0
)
)
if
(
timestamp2tm
(
dt1
,
NULL
,
tm1
,
&
fsec1
,
NULL
)
==
0
&&
timestamp2tm
(
dt2
,
NULL
,
tm2
,
&
fsec2
,
NULL
)
==
0
)
{
fsec
=
(
fsec1
-
fsec2
);
tm
->
tm_sec
=
(
tm1
->
tm_sec
-
tm2
->
tm_sec
);
...
...
@@ -2442,8 +2447,8 @@ timestamptz_age(PG_FUNCTION_ARGS)
result
=
(
Interval
*
)
palloc
(
sizeof
(
Interval
));
if
(
(
timestamp2tm
(
dt1
,
&
tz1
,
tm1
,
&
fsec1
,
&
tzn
)
==
0
)
&&
(
timestamp2tm
(
dt2
,
&
tz2
,
tm2
,
&
fsec2
,
&
tzn
)
==
0
)
)
if
(
timestamp2tm
(
dt1
,
&
tz1
,
tm1
,
&
fsec1
,
&
tzn
)
==
0
&&
timestamp2tm
(
dt2
,
&
tz2
,
tm2
,
&
fsec2
,
&
tzn
)
==
0
)
{
fsec
=
(
fsec1
-
fsec2
);
tm
->
tm_sec
=
(
tm1
->
tm_sec
-
tm2
->
tm_sec
);
...
...
@@ -2810,7 +2815,7 @@ timestamp_trunc(PG_FUNCTION_ARGS)
case
DTK_MILLISEC
:
#ifdef HAVE_INT64_TIMESTAMP
fsec
=
(
(
fsec
/
1000
)
*
1000
)
;
fsec
=
(
fsec
/
1000
)
*
1000
;
#else
fsec
=
rint
(
fsec
*
1000
)
/
1000
;
#endif
...
...
@@ -3150,7 +3155,7 @@ date2isoweek(int year, int mon, int mday)
* We need the first week containing a Thursday, otherwise this day
* falls into the previous year for purposes of counting weeks
*/
if
(
dayn
<
(
day4
-
day0
)
)
if
(
dayn
<
day4
-
day0
)
{
day4
=
date2j
(
year
-
1
,
1
,
4
);
...
...
@@ -3158,7 +3163,7 @@ date2isoweek(int year, int mon, int mday)
day0
=
j2day
(
day4
-
1
);
}
result
=
(
((
dayn
-
(
day4
-
day0
))
/
7
)
+
1
)
;
result
=
(
dayn
-
(
day4
-
day0
))
/
7
+
1
;
/*
* Sometimes the last few days in a year will fall into the first week
...
...
@@ -3171,8 +3176,8 @@ date2isoweek(int year, int mon, int mday)
/* day0 == offset to first day of week (Monday) */
day0
=
j2day
(
day4
-
1
);
if
(
dayn
>=
(
day4
-
day0
)
)
result
=
(
((
dayn
-
(
day4
-
day0
))
/
7
)
+
1
)
;
if
(
dayn
>=
day4
-
day0
)
result
=
(
dayn
-
(
day4
-
day0
))
/
7
+
1
;
}
return
(
int
)
result
;
...
...
@@ -3204,7 +3209,7 @@ date2isoyear(int year, int mon, int mday)
* We need the first week containing a Thursday, otherwise this day
* falls into the previous year for purposes of counting weeks
*/
if
(
dayn
<
(
day4
-
day0
)
)
if
(
dayn
<
day4
-
day0
)
{
day4
=
date2j
(
year
-
1
,
1
,
4
);
...
...
@@ -3214,7 +3219,7 @@ date2isoyear(int year, int mon, int mday)
year
--
;
}
result
=
(
((
dayn
-
(
day4
-
day0
))
/
7
)
+
1
)
;
result
=
(
dayn
-
(
day4
-
day0
))
/
7
+
1
;
/*
* Sometimes the last few days in a year will fall into the first week
...
...
@@ -3227,7 +3232,7 @@ date2isoyear(int year, int mon, int mday)
/* day0 == offset to first day of week (Monday) */
day0
=
j2day
(
day4
-
1
);
if
(
dayn
>=
(
day4
-
day0
)
)
if
(
dayn
>=
day4
-
day0
)
year
++
;
}
...
...
@@ -3276,7 +3281,7 @@ timestamp_part(PG_FUNCTION_ARGS)
{
case
DTK_MICROSEC
:
#ifdef HAVE_INT64_TIMESTAMP
result
=
((
tm
->
tm_sec
*
1000000e0
)
+
fsec
)
;
result
=
tm
->
tm_sec
*
1000000e0
+
fsec
;
#else
result
=
(
tm
->
tm_sec
+
fsec
)
*
1000000
;
#endif
...
...
@@ -3284,7 +3289,7 @@ timestamp_part(PG_FUNCTION_ARGS)
case
DTK_MILLISEC
:
#ifdef HAVE_INT64_TIMESTAMP
result
=
((
tm
->
tm_sec
*
1000e0
)
+
(
fsec
/
1000e0
))
;
result
=
tm
->
tm_sec
*
1000e0
+
fsec
/
1000e0
;
#else
result
=
(
tm
->
tm_sec
+
fsec
)
*
1000
;
#endif
...
...
@@ -3292,9 +3297,9 @@ timestamp_part(PG_FUNCTION_ARGS)
case
DTK_SECOND
:
#ifdef HAVE_INT64_TIMESTAMP
result
=
(
tm
->
tm_sec
+
(
fsec
/
1000000e0
))
;
result
=
tm
->
tm_sec
+
fsec
/
1000000e0
;
#else
result
=
(
tm
->
tm_sec
+
fsec
)
;
result
=
tm
->
tm_sec
+
fsec
;
#endif
break
;
...
...
@@ -3315,7 +3320,7 @@ timestamp_part(PG_FUNCTION_ARGS)
break
;
case
DTK_QUARTER
:
result
=
(
(
tm
->
tm_mon
-
1
)
/
3
)
+
1
;
result
=
(
tm
->
tm_mon
-
1
)
/
3
+
1
;
break
;
case
DTK_WEEK
:
...
...
@@ -3345,10 +3350,11 @@ timestamp_part(PG_FUNCTION_ARGS)
case
DTK_CENTURY
:
/*
* centuries AD, c>0: year in [ (c-1)*100+1 : c*100 ]
* centuries BC, c<0: year in [ c*100 : (c+1)*100-1
* ] there is no number 0 century.
/* ----
* centuries AD, c>0: year in [ (c-1)* 100 + 1 : c*100 ]
* centuries BC, c<0: year in [ c*100 : (c+1) * 100 - 1]
* there is no number 0 century.
* ----
*/
if
(
tm
->
tm_year
>
0
)
result
=
((
tm
->
tm_year
+
99
)
/
100
);
...
...
@@ -3368,11 +3374,11 @@ timestamp_part(PG_FUNCTION_ARGS)
case
DTK_JULIAN
:
result
=
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
);
#ifdef HAVE_INT64_TIMESTAMP
result
+=
((((
(
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
(
fsec
/
1000000e0
))
/
86400e0
)
;
result
+=
((((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
(
fsec
/
1000000e0
))
/
86400e0
;
#else
result
+=
((((
(
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
)
/
86400e0
)
;
result
+=
((((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
)
/
86400e0
;
#endif
break
;
...
...
@@ -3515,7 +3521,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
case
DTK_MICROSEC
:
#ifdef HAVE_INT64_TIMESTAMP
result
=
((
tm
->
tm_sec
*
1000000e0
)
+
fsec
)
;
result
=
tm
->
tm_sec
*
1000000e0
+
fsec
;
#else
result
=
(
tm
->
tm_sec
+
fsec
)
*
1000000
;
#endif
...
...
@@ -3523,7 +3529,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
case
DTK_MILLISEC
:
#ifdef HAVE_INT64_TIMESTAMP
result
=
((
tm
->
tm_sec
*
1000e0
)
+
(
fsec
/
1000e0
))
;
result
=
tm
->
tm_sec
*
1000e0
+
fsec
/
1000e0
;
#else
result
=
(
tm
->
tm_sec
+
fsec
)
*
1000
;
#endif
...
...
@@ -3531,9 +3537,9 @@ timestamptz_part(PG_FUNCTION_ARGS)
case
DTK_SECOND
:
#ifdef HAVE_INT64_TIMESTAMP
result
=
(
tm
->
tm_sec
+
(
fsec
/
1000000e0
))
;
result
=
tm
->
tm_sec
+
fsec
/
1000000e0
;
#else
result
=
(
tm
->
tm_sec
+
fsec
)
;
result
=
tm
->
tm_sec
+
fsec
;
#endif
break
;
...
...
@@ -3554,7 +3560,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
break
;
case
DTK_QUARTER
:
result
=
(
(
tm
->
tm_mon
-
1
)
/
3
)
+
1
;
result
=
(
tm
->
tm_mon
-
1
)
/
3
+
1
;
break
;
case
DTK_WEEK
:
...
...
@@ -3580,7 +3586,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
case
DTK_CENTURY
:
/* see comments in timestamp_part */
if
(
tm
->
tm_year
>
0
)
result
=
(
(
tm
->
tm_year
+
99
)
/
100
)
;
result
=
(
tm
->
tm_year
+
99
)
/
100
;
else
result
=
-
((
99
-
(
tm
->
tm_year
-
1
))
/
100
);
break
;
...
...
@@ -3588,7 +3594,7 @@ timestamptz_part(PG_FUNCTION_ARGS)
case
DTK_MILLENNIUM
:
/* see comments in timestamp_part */
if
(
tm
->
tm_year
>
0
)
result
=
(
(
tm
->
tm_year
+
999
)
/
1000
)
;
result
=
(
tm
->
tm_year
+
999
)
/
1000
;
else
result
=
-
((
999
-
(
tm
->
tm_year
-
1
))
/
1000
);
break
;
...
...
@@ -3596,11 +3602,11 @@ timestamptz_part(PG_FUNCTION_ARGS)
case
DTK_JULIAN
:
result
=
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
);
#ifdef HAVE_INT64_TIMESTAMP
result
+=
((((
(
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
(
fsec
/
1000000e0
))
/
86400e0
)
;
result
+=
((((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
(
fsec
/
1000000e0
))
/
86400e0
;
#else
result
+=
((((
(
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
)
/
86400e0
)
;
result
+=
((((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
)
/
86400e0
;
#endif
break
;
...
...
@@ -3619,9 +3625,9 @@ timestamptz_part(PG_FUNCTION_ARGS)
{
case
DTK_EPOCH
:
#ifdef HAVE_INT64_TIMESTAMP
result
=
(
(
timestamp
-
SetEpochTimestamp
())
/
1000000e0
)
;
result
=
(
timestamp
-
SetEpochTimestamp
())
/
1000000e0
;
#else
result
=
timestamp
-
SetEpochTimestamp
();
result
=
timestamp
-
SetEpochTimestamp
();
#endif
break
;
...
...
@@ -3696,7 +3702,7 @@ interval_part(PG_FUNCTION_ARGS)
{
case
DTK_MICROSEC
:
#ifdef HAVE_INT64_TIMESTAMP
result
=
((
tm
->
tm_sec
*
1000000e0
)
+
fsec
)
;
result
=
tm
->
tm_sec
*
1000000e0
+
fsec
;
#else
result
=
(
tm
->
tm_sec
+
fsec
)
*
1000000
;
#endif
...
...
@@ -3704,7 +3710,7 @@ interval_part(PG_FUNCTION_ARGS)
case
DTK_MILLISEC
:
#ifdef HAVE_INT64_TIMESTAMP
result
=
((
tm
->
tm_sec
*
1000e0
)
+
(
fsec
/
1000e0
))
;
result
=
tm
->
tm_sec
*
1000e0
+
fsec
/
1000e0
;
#else
result
=
(
tm
->
tm_sec
+
fsec
)
*
1000
;
#endif
...
...
@@ -3712,9 +3718,9 @@ interval_part(PG_FUNCTION_ARGS)
case
DTK_SECOND
:
#ifdef HAVE_INT64_TIMESTAMP
result
=
(
tm
->
tm_sec
+
(
fsec
/
1000000e0
))
;
result
=
tm
->
tm_sec
+
fsec
/
1000000e0
;
#else
result
=
(
tm
->
tm_sec
+
fsec
)
;
result
=
tm
->
tm_sec
+
fsec
;
#endif
break
;
...
...
@@ -3773,17 +3779,17 @@ interval_part(PG_FUNCTION_ARGS)
result
=
0
;
}
}
else
if
(
(
type
==
RESERV
)
&&
(
val
==
DTK_EPOCH
)
)
else
if
(
type
==
RESERV
&&
val
==
DTK_EPOCH
)
{
#ifdef HAVE_INT64_TIMESTAMP
result
=
(
interval
->
time
/
1000000e0
)
;
result
=
interval
->
time
/
1000000e0
;
#else
result
=
interval
->
time
;
#endif
if
(
interval
->
month
!=
0
)
{
result
+=
(
(
365
.
25
*
86400
)
*
(
interval
->
month
/
12
)
);
result
+=
(
(
30
.
0
*
86400
)
*
(
interval
->
month
%
12
)
);
result
+=
(
365
.
25
*
86400
)
*
(
interval
->
month
/
12
);
result
+=
(
30
.
0
*
86400
)
*
(
interval
->
month
%
12
);
}
}
else
...
...
@@ -3825,7 +3831,7 @@ timestamp_zone(PG_FUNCTION_ARGS)
type
=
DecodeSpecial
(
0
,
lowzone
,
&
val
);
if
(
(
type
==
TZ
)
||
(
type
==
DTZ
)
)
if
(
type
==
TZ
||
type
==
DTZ
)
{
tz
=
-
(
val
*
60
);
...
...
@@ -3866,9 +3872,9 @@ timestamp_izone(PG_FUNCTION_ARGS)
PointerGetDatum
(
zone
))))));
#ifdef HAVE_INT64_TIMESTAMP
tz
=
(
zone
->
time
/
INT64CONST
(
1000000
)
);
tz
=
zone
->
time
/
INT64CONST
(
1000000
);
#else
tz
=
(
zone
->
time
)
;
tz
=
zone
->
time
;
#endif
result
=
dt2local
(
timestamp
,
tz
);
...
...
@@ -3974,7 +3980,7 @@ timestamptz_zone(PG_FUNCTION_ARGS)
type
=
DecodeSpecial
(
0
,
lowzone
,
&
val
);
if
(
(
type
==
TZ
)
||
(
type
==
DTZ
)
)
if
(
type
==
TZ
||
type
==
DTZ
)
{
tz
=
val
*
60
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment