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
09ff9dbe
Commit
09ff9dbe
authored
May 24, 2005
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove more extraneous parentheses in date/time functions.
parent
a99b2852
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
391 additions
and
414 deletions
+391
-414
src/backend/utils/adt/date.c
src/backend/utils/adt/date.c
+53
-56
src/backend/utils/adt/datetime.c
src/backend/utils/adt/datetime.c
+29
-29
src/backend/utils/adt/nabstime.c
src/backend/utils/adt/nabstime.c
+32
-32
src/backend/utils/adt/timestamp.c
src/backend/utils/adt/timestamp.c
+40
-41
src/interfaces/ecpg/pgtypeslib/datetime.c
src/interfaces/ecpg/pgtypeslib/datetime.c
+4
-4
src/interfaces/ecpg/pgtypeslib/dt_common.c
src/interfaces/ecpg/pgtypeslib/dt_common.c
+129
-143
src/interfaces/ecpg/pgtypeslib/interval.c
src/interfaces/ecpg/pgtypeslib/interval.c
+74
-80
src/interfaces/ecpg/pgtypeslib/numeric.c
src/interfaces/ecpg/pgtypeslib/numeric.c
+2
-2
src/interfaces/ecpg/pgtypeslib/timestamp.c
src/interfaces/ecpg/pgtypeslib/timestamp.c
+28
-27
No files found.
src/backend/utils/adt/date.c
View file @
09ff9dbe
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.10
7 2005/05/23 21:54:01
momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.10
8 2005/05/24 02:09:45
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -921,10 +921,10 @@ static int
...
@@ -921,10 +921,10 @@ static int
tm2time
(
struct
pg_tm
*
tm
,
fsec_t
fsec
,
TimeADT
*
result
)
tm2time
(
struct
pg_tm
*
tm
,
fsec_t
fsec
,
TimeADT
*
result
)
{
{
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
*
result
=
((((
((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
)
*
result
=
((((
tm
->
tm_hour
*
60
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
)
*
USECS_PER_SEC
)
+
fsec
)
;
*
USECS_PER_SEC
)
+
fsec
;
#else
#else
*
result
=
((
((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
)
;
*
result
=
((
tm
->
tm_hour
*
60
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
;
#endif
#endif
return
0
;
return
0
;
}
}
...
@@ -938,12 +938,12 @@ static int
...
@@ -938,12 +938,12 @@ static int
time2tm
(
TimeADT
time
,
struct
pg_tm
*
tm
,
fsec_t
*
fsec
)
time2tm
(
TimeADT
time
,
struct
pg_tm
*
tm
,
fsec_t
*
fsec
)
{
{
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
tm
->
tm_hour
=
(
time
/
USECS_PER_HOUR
)
;
tm
->
tm_hour
=
time
/
USECS_PER_HOUR
;
time
-=
(
tm
->
tm_hour
*
USECS_PER_HOUR
)
;
time
-=
tm
->
tm_hour
*
USECS_PER_HOUR
;
tm
->
tm_min
=
(
time
/
USECS_PER_MINUTE
)
;
tm
->
tm_min
=
time
/
USECS_PER_MINUTE
;
time
-=
(
tm
->
tm_min
*
USECS_PER_MINUTE
)
;
time
-=
tm
->
tm_min
*
USECS_PER_MINUTE
;
tm
->
tm_sec
=
(
time
/
USECS_PER_SEC
)
;
tm
->
tm_sec
=
time
/
USECS_PER_SEC
;
time
-=
(
tm
->
tm_sec
*
USECS_PER_SEC
)
;
time
-=
tm
->
tm_sec
*
USECS_PER_SEC
;
*
fsec
=
time
;
*
fsec
=
time
;
#else
#else
double
trem
;
double
trem
;
...
@@ -1077,7 +1077,7 @@ AdjustTimeForTypmod(TimeADT *time, int32 typmod)
...
@@ -1077,7 +1077,7 @@ AdjustTimeForTypmod(TimeADT *time, int32 typmod)
};
};
#endif
#endif
if
(
(
typmod
>=
0
)
&&
(
typmod
<=
MAX_TIME_PRECISION
)
)
if
(
typmod
>=
0
&&
typmod
<=
MAX_TIME_PRECISION
)
{
{
/*
/*
* Note: this round-to-nearest code is not completely consistent
* Note: this round-to-nearest code is not completely consistent
...
@@ -1089,17 +1089,17 @@ AdjustTimeForTypmod(TimeADT *time, int32 typmod)
...
@@ -1089,17 +1089,17 @@ AdjustTimeForTypmod(TimeADT *time, int32 typmod)
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
if
(
*
time
>=
INT64CONST
(
0
))
if
(
*
time
>=
INT64CONST
(
0
))
{
{
*
time
=
((
(
*
time
+
TimeOffsets
[
typmod
])
/
TimeScales
[
typmod
])
*
time
=
((
*
time
+
TimeOffsets
[
typmod
])
/
TimeScales
[
typmod
])
*
*
TimeScales
[
typmod
])
;
TimeScales
[
typmod
]
;
}
}
else
else
{
{
*
time
=
-
((((
-*
time
)
+
TimeOffsets
[
typmod
])
/
TimeScales
[
typmod
])
*
time
=
-
((((
-*
time
)
+
TimeOffsets
[
typmod
])
/
TimeScales
[
typmod
])
*
*
TimeScales
[
typmod
]);
TimeScales
[
typmod
]);
}
}
#else
#else
*
time
=
(
rint
(((
double
)
*
time
)
*
TimeScales
[
typmod
])
*
time
=
rint
((
double
)
*
time
*
TimeScales
[
typmod
])
/
TimeScales
[
typmod
]
)
;
/
TimeScales
[
typmod
];
#endif
#endif
}
}
}
}
...
@@ -1342,10 +1342,10 @@ timestamp_time(PG_FUNCTION_ARGS)
...
@@ -1342,10 +1342,10 @@ timestamp_time(PG_FUNCTION_ARGS)
* Could also do this with time = (timestamp / USECS_PER_DAY *
* Could also do this with time = (timestamp / USECS_PER_DAY *
* USECS_PER_DAY) - timestamp;
* USECS_PER_DAY) - timestamp;
*/
*/
result
=
((((
((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
)
result
=
((((
tm
->
tm_hour
*
60
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
)
*
*
USECS_PER_SEC
)
+
fsec
)
;
USECS_PER_SEC
)
+
fsec
;
#else
#else
result
=
((
((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
)
;
result
=
((
tm
->
tm_hour
*
60
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
;
#endif
#endif
PG_RETURN_TIMEADT
(
result
);
PG_RETURN_TIMEADT
(
result
);
...
@@ -1379,10 +1379,10 @@ timestamptz_time(PG_FUNCTION_ARGS)
...
@@ -1379,10 +1379,10 @@ timestamptz_time(PG_FUNCTION_ARGS)
* Could also do this with time = (timestamp / USECS_PER_DAY *
* Could also do this with time = (timestamp / USECS_PER_DAY *
* USECS_PER_DAY) - timestamp;
* USECS_PER_DAY) - timestamp;
*/
*/
result
=
((((
((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
)
result
=
((((
tm
->
tm_hour
*
60
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
)
*
*
USECS_PER_SEC
)
+
fsec
)
;
USECS_PER_SEC
)
+
fsec
;
#else
#else
result
=
((
((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
)
;
result
=
((
tm
->
tm_hour
*
60
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
;
#endif
#endif
PG_RETURN_TIMEADT
(
result
);
PG_RETURN_TIMEADT
(
result
);
...
@@ -1624,26 +1624,25 @@ time_part(PG_FUNCTION_ARGS)
...
@@ -1624,26 +1624,25 @@ time_part(PG_FUNCTION_ARGS)
{
{
case
DTK_MICROSEC
:
case
DTK_MICROSEC
:
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
=
((
tm
->
tm_sec
*
USECS_PER_SEC
)
+
fsec
)
;
result
=
tm
->
tm_sec
*
USECS_PER_SEC
+
fsec
;
#else
#else
result
=
(
(
tm
->
tm_sec
+
fsec
)
*
1000000
)
;
result
=
(
tm
->
tm_sec
+
fsec
)
*
1000000
;
#endif
#endif
break
;
break
;
case
DTK_MILLISEC
:
case
DTK_MILLISEC
:
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
=
((
tm
->
tm_sec
*
INT64CONST
(
1000
))
result
=
tm
->
tm_sec
*
INT64CONST
(
1000
)
+
fsec
/
INT64CONST
(
1000
);
+
(
fsec
/
INT64CONST
(
1000
)));
#else
#else
result
=
(
(
tm
->
tm_sec
+
fsec
)
*
1000
)
;
result
=
(
tm
->
tm_sec
+
fsec
)
*
1000
;
#endif
#endif
break
;
break
;
case
DTK_SECOND
:
case
DTK_SECOND
:
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
=
(
tm
->
tm_sec
+
(
fsec
/
USECS_PER_SEC
))
;
result
=
tm
->
tm_sec
+
fsec
/
USECS_PER_SEC
;
#else
#else
result
=
(
tm
->
tm_sec
+
fsec
)
;
result
=
tm
->
tm_sec
+
fsec
;
#endif
#endif
break
;
break
;
...
@@ -1675,7 +1674,7 @@ time_part(PG_FUNCTION_ARGS)
...
@@ -1675,7 +1674,7 @@ time_part(PG_FUNCTION_ARGS)
result
=
0
;
result
=
0
;
}
}
}
}
else
if
(
(
type
==
RESERV
)
&&
(
val
==
DTK_EPOCH
)
)
else
if
(
type
==
RESERV
&&
val
==
DTK_EPOCH
)
{
{
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
=
(
time
/
1000000e0
);
result
=
(
time
/
1000000e0
);
...
@@ -1708,10 +1707,10 @@ static int
...
@@ -1708,10 +1707,10 @@ static int
tm2timetz
(
struct
pg_tm
*
tm
,
fsec_t
fsec
,
int
tz
,
TimeTzADT
*
result
)
tm2timetz
(
struct
pg_tm
*
tm
,
fsec_t
fsec
,
int
tz
,
TimeTzADT
*
result
)
{
{
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
->
time
=
((((
((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
)
result
->
time
=
((((
tm
->
tm_hour
*
60
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
)
*
*
USECS_PER_SEC
)
+
fsec
)
;
USECS_PER_SEC
)
+
fsec
;
#else
#else
result
->
time
=
((
((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
)
;
result
->
time
=
((
tm
->
tm_hour
*
60
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
+
fsec
;
#endif
#endif
result
->
zone
=
tz
;
result
->
zone
=
tz
;
...
@@ -1823,12 +1822,12 @@ timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp)
...
@@ -1823,12 +1822,12 @@ timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp)
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
int64
trem
=
time
->
time
;
int64
trem
=
time
->
time
;
tm
->
tm_hour
=
(
trem
/
USECS_PER_HOUR
)
;
tm
->
tm_hour
=
trem
/
USECS_PER_HOUR
;
trem
-=
(
tm
->
tm_hour
*
USECS_PER_HOUR
)
;
trem
-=
tm
->
tm_hour
*
USECS_PER_HOUR
;
tm
->
tm_min
=
(
trem
/
USECS_PER_MINUTE
)
;
tm
->
tm_min
=
trem
/
USECS_PER_MINUTE
;
trem
-=
(
tm
->
tm_min
*
USECS_PER_MINUTE
)
;
trem
-=
tm
->
tm_min
*
USECS_PER_MINUTE
;
tm
->
tm_sec
=
(
trem
/
USECS_PER_SEC
)
;
tm
->
tm_sec
=
trem
/
USECS_PER_SEC
;
*
fsec
=
(
trem
-
(
tm
->
tm_sec
*
USECS_PER_SEC
))
;
*
fsec
=
trem
-
tm
->
tm_sec
*
USECS_PER_SEC
;
#else
#else
double
trem
=
time
->
time
;
double
trem
=
time
->
time
;
...
@@ -2281,10 +2280,9 @@ datetimetz_timestamptz(PG_FUNCTION_ARGS)
...
@@ -2281,10 +2280,9 @@ datetimetz_timestamptz(PG_FUNCTION_ARGS)
TimestampTz
result
;
TimestampTz
result
;
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
=
(((
date
*
USECS_PER_DAY
)
+
time
->
time
)
result
=
(
date
*
USECS_PER_DAY
+
time
->
time
)
+
time
->
zone
*
USECS_PER_SEC
;
+
(
time
->
zone
*
USECS_PER_SEC
));
#else
#else
result
=
(((
date
*
(
double
)
SECS_PER_DAY
)
+
time
->
time
)
+
time
->
zone
)
;
result
=
date
*
(
double
)
SECS_PER_DAY
+
time
->
time
+
time
->
zone
;
#endif
#endif
PG_RETURN_TIMESTAMP
(
result
);
PG_RETURN_TIMESTAMP
(
result
);
...
@@ -2400,26 +2398,25 @@ timetz_part(PG_FUNCTION_ARGS)
...
@@ -2400,26 +2398,25 @@ timetz_part(PG_FUNCTION_ARGS)
case
DTK_MICROSEC
:
case
DTK_MICROSEC
:
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
=
((
tm
->
tm_sec
*
USECS_PER_SEC
)
+
fsec
)
;
result
=
tm
->
tm_sec
*
USECS_PER_SEC
+
fsec
;
#else
#else
result
=
(
(
tm
->
tm_sec
+
fsec
)
*
1000000
)
;
result
=
(
tm
->
tm_sec
+
fsec
)
*
1000000
;
#endif
#endif
break
;
break
;
case
DTK_MILLISEC
:
case
DTK_MILLISEC
:
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
=
((
tm
->
tm_sec
*
INT64CONST
(
1000
))
result
=
tm
->
tm_sec
*
INT64CONST
(
1000
)
+
fsec
/
INT64CONST
(
1000
);
+
(
fsec
/
INT64CONST
(
1000
)));
#else
#else
result
=
(
(
tm
->
tm_sec
+
fsec
)
*
1000
)
;
result
=
(
tm
->
tm_sec
+
fsec
)
*
1000
;
#endif
#endif
break
;
break
;
case
DTK_SECOND
:
case
DTK_SECOND
:
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
=
(
tm
->
tm_sec
+
(
fsec
/
USECS_PER_SEC
))
;
result
=
tm
->
tm_sec
+
fsec
/
USECS_PER_SEC
;
#else
#else
result
=
(
tm
->
tm_sec
+
fsec
)
;
result
=
tm
->
tm_sec
+
fsec
;
#endif
#endif
break
;
break
;
...
@@ -2448,12 +2445,12 @@ timetz_part(PG_FUNCTION_ARGS)
...
@@ -2448,12 +2445,12 @@ timetz_part(PG_FUNCTION_ARGS)
result
=
0
;
result
=
0
;
}
}
}
}
else
if
(
(
type
==
RESERV
)
&&
(
val
==
DTK_EPOCH
)
)
else
if
(
type
==
RESERV
&&
val
==
DTK_EPOCH
)
{
{
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
=
((
time
->
time
/
1000000e0
)
+
time
->
zone
)
;
result
=
time
->
time
/
1000000e0
+
time
->
zone
;
#else
#else
result
=
(
time
->
time
+
time
->
zone
)
;
result
=
time
->
time
+
time
->
zone
;
#endif
#endif
}
}
else
else
...
@@ -2492,11 +2489,11 @@ timetz_zone(PG_FUNCTION_ARGS)
...
@@ -2492,11 +2489,11 @@ timetz_zone(PG_FUNCTION_ARGS)
result
=
(
TimeTzADT
*
)
palloc
(
sizeof
(
TimeTzADT
));
result
=
(
TimeTzADT
*
)
palloc
(
sizeof
(
TimeTzADT
));
if
(
(
type
==
TZ
)
||
(
type
==
DTZ
)
)
if
(
type
==
TZ
||
type
==
DTZ
)
{
{
tz
=
val
*
60
;
tz
=
val
*
60
;
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
->
time
=
time
->
time
+
(
(
time
->
zone
-
tz
)
*
USECS_PER_SEC
)
;
result
->
time
=
time
->
time
+
(
time
->
zone
-
tz
)
*
USECS_PER_SEC
;
while
(
result
->
time
<
INT64CONST
(
0
))
while
(
result
->
time
<
INT64CONST
(
0
))
result
->
time
+=
USECS_PER_DAY
;
result
->
time
+=
USECS_PER_DAY
;
while
(
result
->
time
>=
USECS_PER_DAY
)
while
(
result
->
time
>=
USECS_PER_DAY
)
...
@@ -2550,7 +2547,7 @@ timetz_izone(PG_FUNCTION_ARGS)
...
@@ -2550,7 +2547,7 @@ timetz_izone(PG_FUNCTION_ARGS)
result
=
(
TimeTzADT
*
)
palloc
(
sizeof
(
TimeTzADT
));
result
=
(
TimeTzADT
*
)
palloc
(
sizeof
(
TimeTzADT
));
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
->
time
=
time
->
time
+
(
(
time
->
zone
-
tz
)
*
USECS_PER_SEC
)
;
result
->
time
=
time
->
time
+
(
time
->
zone
-
tz
)
*
USECS_PER_SEC
;
while
(
result
->
time
<
INT64CONST
(
0
))
while
(
result
->
time
<
INT64CONST
(
0
))
result
->
time
+=
USECS_PER_DAY
;
result
->
time
+=
USECS_PER_DAY
;
while
(
result
->
time
>=
USECS_PER_DAY
)
while
(
result
->
time
>=
USECS_PER_DAY
)
...
...
src/backend/utils/adt/datetime.c
View file @
09ff9dbe
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.14
3 2005/05/23 21:54:01
momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.14
4 2005/05/24 02:09:45
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -3020,7 +3020,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
...
@@ -3020,7 +3020,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
return
DTERR_BAD_FORMAT
;
return
DTERR_BAD_FORMAT
;
if
(
*
field
[
i
]
==
'-'
)
if
(
*
field
[
i
]
==
'-'
)
fval
=
-
(
fval
)
;
fval
=
-
fval
;
}
}
else
if
(
*
cp
==
'\0'
)
else
if
(
*
cp
==
'\0'
)
fval
=
0
;
fval
=
0
;
...
@@ -3033,24 +3033,24 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
...
@@ -3033,24 +3033,24 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
{
{
case
DTK_MICROSEC
:
case
DTK_MICROSEC
:
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
*
fsec
+=
(
val
+
fval
)
;
*
fsec
+=
val
+
fval
;
#else
#else
*
fsec
+=
(
(
val
+
fval
)
*
1e-6
)
;
*
fsec
+=
(
val
+
fval
)
*
1e-6
;
#endif
#endif
break
;
break
;
case
DTK_MILLISEC
:
case
DTK_MILLISEC
:
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
*
fsec
+=
(
(
val
+
fval
)
*
1000
)
;
*
fsec
+=
(
val
+
fval
)
*
1000
;
#else
#else
*
fsec
+=
(
(
val
+
fval
)
*
1e-3
)
;
*
fsec
+=
(
val
+
fval
)
*
1e-3
;
#endif
#endif
break
;
break
;
case
DTK_SECOND
:
case
DTK_SECOND
:
tm
->
tm_sec
+=
val
;
tm
->
tm_sec
+=
val
;
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
*
fsec
+=
(
fval
*
1000000
)
;
*
fsec
+=
fval
*
1000000
;
#else
#else
*
fsec
+=
fval
;
*
fsec
+=
fval
;
#endif
#endif
...
@@ -3067,9 +3067,9 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
...
@@ -3067,9 +3067,9 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
sec
=
fval
;
sec
=
fval
;
tm
->
tm_sec
+=
sec
;
tm
->
tm_sec
+=
sec
;
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
*
fsec
+=
(
(
fval
-
sec
)
*
1000000
)
;
*
fsec
+=
(
fval
-
sec
)
*
1000000
;
#else
#else
*
fsec
+=
(
fval
-
sec
)
;
*
fsec
+=
fval
-
sec
;
#endif
#endif
}
}
tmask
=
DTK_M
(
MINUTE
);
tmask
=
DTK_M
(
MINUTE
);
...
@@ -3085,9 +3085,9 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
...
@@ -3085,9 +3085,9 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
sec
=
fval
;
sec
=
fval
;
tm
->
tm_sec
+=
sec
;
tm
->
tm_sec
+=
sec
;
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
*
fsec
+=
(
(
fval
-
sec
)
*
1000000
)
;
*
fsec
+=
(
fval
-
sec
)
*
1000000
;
#else
#else
*
fsec
+=
(
fval
-
sec
)
;
*
fsec
+=
fval
-
sec
;
#endif
#endif
}
}
tmask
=
DTK_M
(
HOUR
);
tmask
=
DTK_M
(
HOUR
);
...
@@ -3103,9 +3103,9 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
...
@@ -3103,9 +3103,9 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
sec
=
fval
;
sec
=
fval
;
tm
->
tm_sec
+=
sec
;
tm
->
tm_sec
+=
sec
;
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
*
fsec
+=
(
(
fval
-
sec
)
*
1000000
)
;
*
fsec
+=
(
fval
-
sec
)
*
1000000
;
#else
#else
*
fsec
+=
(
fval
-
sec
)
;
*
fsec
+=
fval
-
sec
;
#endif
#endif
}
}
tmask
=
(
fmask
&
DTK_M
(
DAY
))
?
0
:
DTK_M
(
DAY
);
tmask
=
(
fmask
&
DTK_M
(
DAY
))
?
0
:
DTK_M
(
DAY
);
...
@@ -3117,13 +3117,13 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
...
@@ -3117,13 +3117,13 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
{
{
int
sec
;
int
sec
;
fval
*=
(
7
*
SECS_PER_DAY
)
;
fval
*=
7
*
SECS_PER_DAY
;
sec
=
fval
;
sec
=
fval
;
tm
->
tm_sec
+=
sec
;
tm
->
tm_sec
+=
sec
;
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
*
fsec
+=
(
(
fval
-
sec
)
*
1000000
)
;
*
fsec
+=
(
fval
-
sec
)
*
1000000
;
#else
#else
*
fsec
+=
(
fval
-
sec
)
;
*
fsec
+=
fval
-
sec
;
#endif
#endif
}
}
tmask
=
(
fmask
&
DTK_M
(
DAY
))
?
0
:
DTK_M
(
DAY
);
tmask
=
(
fmask
&
DTK_M
(
DAY
))
?
0
:
DTK_M
(
DAY
);
...
@@ -3135,13 +3135,13 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
...
@@ -3135,13 +3135,13 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
{
{
int
sec
;
int
sec
;
fval
*=
(
30
*
SECS_PER_DAY
)
;
fval
*=
30
*
SECS_PER_DAY
;
sec
=
fval
;
sec
=
fval
;
tm
->
tm_sec
+=
sec
;
tm
->
tm_sec
+=
sec
;
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
*
fsec
+=
(
(
fval
-
sec
)
*
1000000
)
;
*
fsec
+=
(
fval
-
sec
)
*
1000000
;
#else
#else
*
fsec
+=
(
fval
-
sec
)
;
*
fsec
+=
fval
-
sec
;
#endif
#endif
}
}
tmask
=
DTK_M
(
MONTH
);
tmask
=
DTK_M
(
MONTH
);
...
@@ -3150,28 +3150,28 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
...
@@ -3150,28 +3150,28 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
case
DTK_YEAR
:
case
DTK_YEAR
:
tm
->
tm_year
+=
val
;
tm
->
tm_year
+=
val
;
if
(
fval
!=
0
)
if
(
fval
!=
0
)
tm
->
tm_mon
+=
(
fval
*
12
)
;
tm
->
tm_mon
+=
fval
*
12
;
tmask
=
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
);
tmask
=
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
);
break
;
break
;
case
DTK_DECADE
:
case
DTK_DECADE
:
tm
->
tm_year
+=
val
*
10
;
tm
->
tm_year
+=
val
*
10
;
if
(
fval
!=
0
)
if
(
fval
!=
0
)
tm
->
tm_mon
+=
(
fval
*
120
)
;
tm
->
tm_mon
+=
fval
*
120
;
tmask
=
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
);
tmask
=
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
);
break
;
break
;
case
DTK_CENTURY
:
case
DTK_CENTURY
:
tm
->
tm_year
+=
val
*
100
;
tm
->
tm_year
+=
val
*
100
;
if
(
fval
!=
0
)
if
(
fval
!=
0
)
tm
->
tm_mon
+=
(
fval
*
1200
)
;
tm
->
tm_mon
+=
fval
*
1200
;
tmask
=
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
);
tmask
=
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
);
break
;
break
;
case
DTK_MILLENNIUM
:
case
DTK_MILLENNIUM
:
tm
->
tm_year
+=
val
*
1000
;
tm
->
tm_year
+=
val
*
1000
;
if
(
fval
!=
0
)
if
(
fval
!=
0
)
tm
->
tm_mon
+=
(
fval
*
12000
)
;
tm
->
tm_mon
+=
fval
*
12000
;
tmask
=
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
);
tmask
=
(
fmask
&
DTK_M
(
YEAR
))
?
0
:
DTK_M
(
YEAR
);
break
;
break
;
...
@@ -3233,12 +3233,12 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
...
@@ -3233,12 +3233,12 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct pg_tm * tm,
if
(
is_before
)
if
(
is_before
)
{
{
*
fsec
=
-
(
*
fsec
);
*
fsec
=
-
(
*
fsec
);
tm
->
tm_sec
=
-
(
tm
->
tm_sec
)
;
tm
->
tm_sec
=
-
tm
->
tm_sec
;
tm
->
tm_min
=
-
(
tm
->
tm_min
)
;
tm
->
tm_min
=
-
tm
->
tm_min
;
tm
->
tm_hour
=
-
(
tm
->
tm_hour
)
;
tm
->
tm_hour
=
-
tm
->
tm_hour
;
tm
->
tm_mday
=
-
(
tm
->
tm_mday
)
;
tm
->
tm_mday
=
-
tm
->
tm_mday
;
tm
->
tm_mon
=
-
(
tm
->
tm_mon
)
;
tm
->
tm_mon
=
-
tm
->
tm_mon
;
tm
->
tm_year
=
-
(
tm
->
tm_year
)
;
tm
->
tm_year
=
-
tm
->
tm_year
;
}
}
/* ensure that at least one time field has been found */
/* ensure that at least one time field has been found */
...
...
src/backend/utils/adt/nabstime.c
View file @
09ff9dbe
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.13
0 2005/05/23 21:54:02
momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.13
1 2005/05/24 02:09:45
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
#include "miscadmin.h"
#include "miscadmin.h"
#include "pgtime.h"
#include "pgtime.h"
#include "utils/builtins.h"
#include "utils/builtins.h"
#include "utils/timestamp.h"
#define MIN_DAYNUM -24856
/* December 13, 1901 */
#define MIN_DAYNUM -24856
/* December 13, 1901 */
#define MAX_DAYNUM 24854
/* January 18, 2038 */
#define MAX_DAYNUM 24854
/* January 18, 2038 */
...
@@ -191,7 +191,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
...
@@ -191,7 +191,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
if
(
HasCTZSet
&&
(
tzp
!=
NULL
))
if
(
HasCTZSet
&&
(
tzp
!=
NULL
))
time
-=
CTimeZone
;
time
-=
CTimeZone
;
if
(
(
!
HasCTZSet
)
&&
(
tzp
!=
NULL
)
)
if
(
!
HasCTZSet
&&
tzp
!=
NULL
)
tx
=
pg_localtime
(
&
time
,
global_timezone
);
tx
=
pg_localtime
(
&
time
,
global_timezone
);
else
else
tx
=
pg_gmtime
(
&
time
);
tx
=
pg_gmtime
(
&
time
);
...
@@ -273,7 +273,7 @@ tm2abstime(struct pg_tm * tm, int tz)
...
@@ -273,7 +273,7 @@ tm2abstime(struct pg_tm * tm, int tz)
day
=
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
-
UNIX_EPOCH_JDATE
;
day
=
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
-
UNIX_EPOCH_JDATE
;
/* check for time out of range */
/* check for time out of range */
if
(
(
day
<
MIN_DAYNUM
)
||
(
day
>
MAX_DAYNUM
)
)
if
(
day
<
MIN_DAYNUM
||
day
>
MAX_DAYNUM
)
return
INVALID_ABSTIME
;
return
INVALID_ABSTIME
;
/* convert to seconds */
/* convert to seconds */
...
@@ -432,9 +432,9 @@ abstime_finite(PG_FUNCTION_ARGS)
...
@@ -432,9 +432,9 @@ abstime_finite(PG_FUNCTION_ARGS)
{
{
AbsoluteTime
abstime
=
PG_GETARG_ABSOLUTETIME
(
0
);
AbsoluteTime
abstime
=
PG_GETARG_ABSOLUTETIME
(
0
);
PG_RETURN_BOOL
(
(
abstime
!=
INVALID_ABSTIME
)
&&
PG_RETURN_BOOL
(
abstime
!=
INVALID_ABSTIME
&&
(
abstime
!=
NOSTART_ABSTIME
)
&&
abstime
!=
NOSTART_ABSTIME
&&
(
abstime
!=
NOEND_ABSTIME
)
);
abstime
!=
NOEND_ABSTIME
);
}
}
...
@@ -729,8 +729,8 @@ reltimein(PG_FUNCTION_ARGS)
...
@@ -729,8 +729,8 @@ reltimein(PG_FUNCTION_ARGS)
switch
(
dtype
)
switch
(
dtype
)
{
{
case
DTK_DELTA
:
case
DTK_DELTA
:
result
=
((
((
tm
->
tm_hour
*
60
)
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
)
;
result
=
((
tm
->
tm_hour
*
60
+
tm
->
tm_min
)
*
60
)
+
tm
->
tm_sec
;
result
+=
((
tm
->
tm_year
*
36525
*
864
)
+
(((
tm
->
tm_mon
*
30
)
+
tm
->
tm_mday
)
*
SECS_PER_DAY
))
;
result
+=
tm
->
tm_year
*
36525
*
864
+
((
tm
->
tm_mon
*
30
)
+
tm
->
tm_mday
)
*
SECS_PER_DAY
;
break
;
break
;
default:
default:
...
@@ -946,14 +946,14 @@ interval_reltime(PG_FUNCTION_ARGS)
...
@@ -946,14 +946,14 @@ interval_reltime(PG_FUNCTION_ARGS)
}
}
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
span
=
((
((
INT64CONST
(
365250000
)
*
year
)
+
(
INT64CONST
(
30000000
)
*
month
))
span
=
((
INT64CONST
(
365250000
)
*
year
+
INT64CONST
(
30000000
)
*
month
)
*
*
INT64CONST
(
SECS_PER_DAY
))
+
interval
->
time
)
;
INT64CONST
(
86400
))
+
interval
->
time
;
span
/=
USECS_PER_SEC
;
span
/=
USECS_PER_SEC
;
#else
#else
span
=
(
((((
double
)
365
.
25
*
year
)
+
((
double
)
30
*
month
))
*
SECS_PER_DAY
)
+
interval
->
time
)
;
span
=
(
365
.
25
*
year
+
30
.
0
*
month
)
*
SECS_PER_DAY
+
interval
->
time
;
#endif
#endif
if
(
(
span
<
INT_MIN
)
||
(
span
>
INT_MAX
)
)
if
(
span
<
INT_MIN
||
span
>
INT_MAX
)
time
=
INVALID_RELTIME
;
time
=
INVALID_RELTIME
;
else
else
time
=
span
;
time
=
span
;
...
@@ -991,12 +991,12 @@ reltime_interval(PG_FUNCTION_ARGS)
...
@@ -991,12 +991,12 @@ reltime_interval(PG_FUNCTION_ARGS)
result
->
time
=
(
reltime
*
USECS_PER_SEC
);
result
->
time
=
(
reltime
*
USECS_PER_SEC
);
#else
#else
TMODULO
(
reltime
,
year
,
(
36525
*
864
)
);
TMODULO
(
reltime
,
year
,
36525
*
864
);
TMODULO
(
reltime
,
month
,
(
30
*
SECS_PER_DAY
)
);
TMODULO
(
reltime
,
month
,
30
*
SECS_PER_DAY
);
result
->
time
=
reltime
;
result
->
time
=
reltime
;
#endif
#endif
result
->
month
=
((
12
*
year
)
+
month
)
;
result
->
month
=
12
*
year
+
month
;
break
;
break
;
}
}
...
@@ -1049,8 +1049,8 @@ timepl(PG_FUNCTION_ARGS)
...
@@ -1049,8 +1049,8 @@ timepl(PG_FUNCTION_ARGS)
if
(
AbsoluteTimeIsReal
(
t1
)
&&
if
(
AbsoluteTimeIsReal
(
t1
)
&&
RelativeTimeIsValid
(
t2
)
&&
RelativeTimeIsValid
(
t2
)
&&
((
t2
>
0
)
?
(
t1
<
NOEND_ABSTIME
-
t2
)
((
t2
>
0
&&
t1
<
NOEND_ABSTIME
-
t2
)
||
:
(
t1
>
NOSTART_ABSTIME
-
t2
)))
/* prevent overflow */
(
t2
<=
0
&&
t1
>
NOSTART_ABSTIME
-
t2
)))
/* prevent overflow */
PG_RETURN_ABSOLUTETIME
(
t1
+
t2
);
PG_RETURN_ABSOLUTETIME
(
t1
+
t2
);
PG_RETURN_ABSOLUTETIME
(
INVALID_ABSTIME
);
PG_RETURN_ABSOLUTETIME
(
INVALID_ABSTIME
);
...
@@ -1068,8 +1068,8 @@ timemi(PG_FUNCTION_ARGS)
...
@@ -1068,8 +1068,8 @@ timemi(PG_FUNCTION_ARGS)
if
(
AbsoluteTimeIsReal
(
t1
)
&&
if
(
AbsoluteTimeIsReal
(
t1
)
&&
RelativeTimeIsValid
(
t2
)
&&
RelativeTimeIsValid
(
t2
)
&&
((
t2
>
0
)
?
(
t1
>
NOSTART_ABSTIME
+
t2
)
((
t2
>
0
&&
t1
>
NOSTART_ABSTIME
+
t2
)
||
:
(
t1
<
NOEND_ABSTIME
+
t2
)))
/* prevent overflow */
(
t2
<=
0
&&
t1
<
NOEND_ABSTIME
+
t2
)))
/* prevent overflow */
PG_RETURN_ABSOLUTETIME
(
t1
-
t2
);
PG_RETURN_ABSOLUTETIME
(
t1
-
t2
);
PG_RETURN_ABSOLUTETIME
(
INVALID_ABSTIME
);
PG_RETURN_ABSOLUTETIME
(
INVALID_ABSTIME
);
...
@@ -1272,12 +1272,12 @@ tinterval_cmp_internal(TimeInterval a, TimeInterval b)
...
@@ -1272,12 +1272,12 @@ tinterval_cmp_internal(TimeInterval a, TimeInterval b)
* non-INVALID. This is somewhat arbitrary; the important thing is to
* non-INVALID. This is somewhat arbitrary; the important thing is to
* have a consistent sort order.
* have a consistent sort order.
*/
*/
a_invalid
=
((
a
->
status
==
T_INTERVAL_INVAL
)
||
a_invalid
=
a
->
status
==
T_INTERVAL_INVAL
||
(
a
->
data
[
0
]
==
INVALID_ABSTIME
)
||
a
->
data
[
0
]
==
INVALID_ABSTIME
||
(
a
->
data
[
1
]
==
INVALID_ABSTIME
))
;
a
->
data
[
1
]
==
INVALID_ABSTIME
;
b_invalid
=
((
b
->
status
==
T_INTERVAL_INVAL
)
||
b_invalid
=
b
->
status
==
T_INTERVAL_INVAL
||
(
b
->
data
[
0
]
==
INVALID_ABSTIME
)
||
b
->
data
[
0
]
==
INVALID_ABSTIME
||
(
b
->
data
[
1
]
==
INVALID_ABSTIME
))
;
b
->
data
[
1
]
==
INVALID_ABSTIME
;
if
(
a_invalid
)
if
(
a_invalid
)
{
{
...
@@ -1390,7 +1390,7 @@ tintervalleneq(PG_FUNCTION_ARGS)
...
@@ -1390,7 +1390,7 @@ tintervalleneq(PG_FUNCTION_ARGS)
PG_RETURN_BOOL
(
false
);
PG_RETURN_BOOL
(
false
);
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
TimeIntervalGetDatum
(
i
)));
TimeIntervalGetDatum
(
i
)));
PG_RETURN_BOOL
(
(
rt
!=
INVALID_RELTIME
)
&&
(
rt
==
t
)
);
PG_RETURN_BOOL
(
rt
!=
INVALID_RELTIME
&&
rt
==
t
);
}
}
Datum
Datum
...
@@ -1404,7 +1404,7 @@ tintervallenne(PG_FUNCTION_ARGS)
...
@@ -1404,7 +1404,7 @@ tintervallenne(PG_FUNCTION_ARGS)
PG_RETURN_BOOL
(
false
);
PG_RETURN_BOOL
(
false
);
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
TimeIntervalGetDatum
(
i
)));
TimeIntervalGetDatum
(
i
)));
PG_RETURN_BOOL
(
(
rt
!=
INVALID_RELTIME
)
&&
(
rt
!=
t
)
);
PG_RETURN_BOOL
(
rt
!=
INVALID_RELTIME
&&
rt
!=
t
);
}
}
Datum
Datum
...
@@ -1418,7 +1418,7 @@ tintervallenlt(PG_FUNCTION_ARGS)
...
@@ -1418,7 +1418,7 @@ tintervallenlt(PG_FUNCTION_ARGS)
PG_RETURN_BOOL
(
false
);
PG_RETURN_BOOL
(
false
);
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
TimeIntervalGetDatum
(
i
)));
TimeIntervalGetDatum
(
i
)));
PG_RETURN_BOOL
(
(
rt
!=
INVALID_RELTIME
)
&&
(
rt
<
t
)
);
PG_RETURN_BOOL
(
rt
!=
INVALID_RELTIME
&&
rt
<
t
);
}
}
Datum
Datum
...
@@ -1432,7 +1432,7 @@ tintervallengt(PG_FUNCTION_ARGS)
...
@@ -1432,7 +1432,7 @@ tintervallengt(PG_FUNCTION_ARGS)
PG_RETURN_BOOL
(
false
);
PG_RETURN_BOOL
(
false
);
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
TimeIntervalGetDatum
(
i
)));
TimeIntervalGetDatum
(
i
)));
PG_RETURN_BOOL
(
(
rt
!=
INVALID_RELTIME
)
&&
(
rt
>
t
)
);
PG_RETURN_BOOL
(
rt
!=
INVALID_RELTIME
&&
rt
>
t
);
}
}
Datum
Datum
...
@@ -1446,7 +1446,7 @@ tintervallenle(PG_FUNCTION_ARGS)
...
@@ -1446,7 +1446,7 @@ tintervallenle(PG_FUNCTION_ARGS)
PG_RETURN_BOOL
(
false
);
PG_RETURN_BOOL
(
false
);
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
TimeIntervalGetDatum
(
i
)));
TimeIntervalGetDatum
(
i
)));
PG_RETURN_BOOL
(
(
rt
!=
INVALID_RELTIME
)
&&
(
rt
<=
t
)
);
PG_RETURN_BOOL
(
rt
!=
INVALID_RELTIME
&&
rt
<=
t
);
}
}
Datum
Datum
...
@@ -1460,7 +1460,7 @@ tintervallenge(PG_FUNCTION_ARGS)
...
@@ -1460,7 +1460,7 @@ tintervallenge(PG_FUNCTION_ARGS)
PG_RETURN_BOOL
(
false
);
PG_RETURN_BOOL
(
false
);
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
rt
=
DatumGetRelativeTime
(
DirectFunctionCall1
(
tintervalrel
,
TimeIntervalGetDatum
(
i
)));
TimeIntervalGetDatum
(
i
)));
PG_RETURN_BOOL
(
(
rt
!=
INVALID_RELTIME
)
&&
(
rt
>=
t
)
);
PG_RETURN_BOOL
(
rt
!=
INVALID_RELTIME
&&
rt
>=
t
);
}
}
/*
/*
...
...
src/backend/utils/adt/timestamp.c
View file @
09ff9dbe
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.12
2 2005/05/23 21:54:02
momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.12
3 2005/05/24 02:09:45
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -280,8 +280,8 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
...
@@ -280,8 +280,8 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
if
(
*
time
>=
INT64CONST
(
0
))
if
(
*
time
>=
INT64CONST
(
0
))
{
{
*
time
=
((
(
*
time
+
TimestampOffsets
[
typmod
])
/
TimestampScales
[
typmod
])
*
time
=
((
*
time
+
TimestampOffsets
[
typmod
])
/
TimestampScales
[
typmod
])
*
*
TimestampScales
[
typmod
])
;
TimestampScales
[
typmod
]
;
}
}
else
else
{
{
...
@@ -289,8 +289,7 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
...
@@ -289,8 +289,7 @@ AdjustTimestampForTypmod(Timestamp *time, int32 typmod)
*
TimestampScales
[
typmod
]);
*
TimestampScales
[
typmod
]);
}
}
#else
#else
*
time
=
(
rint
(((
double
)
*
time
)
*
TimestampScales
[
typmod
])
*
time
=
rint
((
double
)
*
time
*
TimestampScales
[
typmod
])
/
TimestampScales
[
typmod
];
/
TimestampScales
[
typmod
]);
#endif
#endif
}
}
}
}
...
@@ -891,7 +890,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
...
@@ -891,7 +890,7 @@ AdjustIntervalForTypmod(Interval *interval, int32 typmod)
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
if
(
interval
->
time
>=
INT64CONST
(
0
))
if
(
interval
->
time
>=
INT64CONST
(
0
))
{
{
interval
->
time
=
((
(
interval
->
time
+
interval
->
time
=
((
interval
->
time
+
IntervalOffsets
[
precision
])
/
IntervalOffsets
[
precision
])
/
IntervalScales
[
precision
])
*
IntervalScales
[
precision
])
*
IntervalScales
[
precision
];
IntervalScales
[
precision
];
...
@@ -1212,15 +1211,15 @@ tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)
...
@@ -1212,15 +1211,15 @@ 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
#ifdef HAVE_INT64_TIMESTAMP
span
->
time
=
(((((((
(
tm
->
tm_mday
*
INT64CONST
(
24
))
span
->
time
=
(((((((
tm
->
tm_mday
*
INT64CONST
(
24
))
+
+
tm
->
tm_hour
)
*
INT64CONST
(
60
))
tm
->
tm_hour
)
*
INT64CONST
(
60
))
+
+
tm
->
tm_min
)
*
INT64CONST
(
60
))
tm
->
tm_min
)
*
INT64CONST
(
60
))
+
+
tm
->
tm_sec
)
*
USECS_PER_SEC
)
+
fsec
)
;
tm
->
tm_sec
)
*
USECS_PER_SEC
)
+
fsec
;
#else
#else
span
->
time
=
(((((
(
tm
->
tm_mday
*
24
.
0
)
span
->
time
=
(((((
tm
->
tm_mday
*
24
.
0
)
+
+
tm
->
tm_hour
)
*
60
.
0
)
tm
->
tm_hour
)
*
60
.
0
)
+
+
tm
->
tm_min
)
*
60
.
0
)
tm
->
tm_min
)
*
60
.
0
)
+
+
tm
->
tm_sec
)
;
tm
->
tm_sec
;
span
->
time
=
JROUND
(
span
->
time
+
fsec
);
span
->
time
=
JROUND
(
span
->
time
+
fsec
);
#endif
#endif
...
@@ -1231,14 +1230,14 @@ tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)
...
@@ -1231,14 +1230,14 @@ tm2interval(struct pg_tm * tm, fsec_t fsec, Interval *span)
static
int64
static
int64
time2t
(
const
int
hour
,
const
int
min
,
const
int
sec
,
const
fsec_t
fsec
)
time2t
(
const
int
hour
,
const
int
min
,
const
int
sec
,
const
fsec_t
fsec
)
{
{
return
(((((
(
hour
*
60
)
+
min
)
*
60
)
+
sec
)
*
USECS_PER_SEC
)
+
fsec
)
;
return
(((((
hour
*
60
)
+
min
)
*
60
)
+
sec
)
*
USECS_PER_SEC
)
+
fsec
;
}
/* time2t() */
}
/* time2t() */
#else
#else
static
double
static
double
time2t
(
const
int
hour
,
const
int
min
,
const
int
sec
,
const
fsec_t
fsec
)
time2t
(
const
int
hour
,
const
int
min
,
const
int
sec
,
const
fsec_t
fsec
)
{
{
return
(((
(
hour
*
60
)
+
min
)
*
60
)
+
sec
+
fsec
)
;
return
(((
hour
*
60
)
+
min
)
*
60
)
+
sec
+
fsec
;
}
/* time2t() */
}
/* time2t() */
#endif
#endif
...
@@ -1324,7 +1323,7 @@ int
...
@@ -1324,7 +1323,7 @@ int
timestamp_cmp_internal
(
Timestamp
dt1
,
Timestamp
dt2
)
timestamp_cmp_internal
(
Timestamp
dt1
,
Timestamp
dt2
)
{
{
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
return
(
(
dt1
<
dt2
)
?
-
1
:
((
dt1
>
dt2
)
?
1
:
0
)
);
return
(
dt1
<
dt2
)
?
-
1
:
((
dt1
>
dt2
)
?
1
:
0
);
#else
#else
/*
/*
...
@@ -1935,13 +1934,13 @@ timestamp_pl_interval(PG_FUNCTION_ARGS)
...
@@ -1935,13 +1934,13 @@ timestamp_pl_interval(PG_FUNCTION_ARGS)
tm
->
tm_mon
+=
span
->
month
;
tm
->
tm_mon
+=
span
->
month
;
if
(
tm
->
tm_mon
>
12
)
if
(
tm
->
tm_mon
>
12
)
{
{
tm
->
tm_year
+=
(
(
tm
->
tm_mon
-
1
)
/
12
)
;
tm
->
tm_year
+=
(
tm
->
tm_mon
-
1
)
/
12
;
tm
->
tm_mon
=
((
(
tm
->
tm_mon
-
1
)
%
12
)
+
1
)
;
tm
->
tm_mon
=
((
tm
->
tm_mon
-
1
)
%
12
)
+
1
;
}
}
else
if
(
tm
->
tm_mon
<
1
)
else
if
(
tm
->
tm_mon
<
1
)
{
{
tm
->
tm_year
+=
((
tm
->
tm_mon
/
12
)
-
1
)
;
tm
->
tm_year
+=
tm
->
tm_mon
/
12
-
1
;
tm
->
tm_mon
=
((
tm
->
tm_mon
%
12
)
+
12
)
;
tm
->
tm_mon
=
tm
->
tm_mon
%
12
+
12
;
}
}
/* adjust for end of month boundary problems... */
/* adjust for end of month boundary problems... */
...
@@ -2014,13 +2013,13 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS)
...
@@ -2014,13 +2013,13 @@ timestamptz_pl_interval(PG_FUNCTION_ARGS)
tm
->
tm_mon
+=
span
->
month
;
tm
->
tm_mon
+=
span
->
month
;
if
(
tm
->
tm_mon
>
12
)
if
(
tm
->
tm_mon
>
12
)
{
{
tm
->
tm_year
+=
(
(
tm
->
tm_mon
-
1
)
/
12
)
;
tm
->
tm_year
+=
(
tm
->
tm_mon
-
1
)
/
12
;
tm
->
tm_mon
=
((
(
tm
->
tm_mon
-
1
)
%
12
)
+
1
)
;
tm
->
tm_mon
=
((
tm
->
tm_mon
-
1
)
%
12
)
+
1
;
}
}
else
if
(
tm
->
tm_mon
<
1
)
else
if
(
tm
->
tm_mon
<
1
)
{
{
tm
->
tm_year
+=
((
tm
->
tm_mon
/
12
)
-
1
)
;
tm
->
tm_year
+=
tm
->
tm_mon
/
12
-
1
;
tm
->
tm_mon
=
((
tm
->
tm_mon
%
12
)
+
12
)
;
tm
->
tm_mon
=
tm
->
tm_mon
%
12
+
12
;
}
}
/* adjust for end of month boundary problems... */
/* adjust for end of month boundary problems... */
...
@@ -2337,12 +2336,12 @@ timestamp_age(PG_FUNCTION_ARGS)
...
@@ -2337,12 +2336,12 @@ timestamp_age(PG_FUNCTION_ARGS)
timestamp2tm
(
dt2
,
NULL
,
tm2
,
&
fsec2
,
NULL
)
==
0
)
timestamp2tm
(
dt2
,
NULL
,
tm2
,
&
fsec2
,
NULL
)
==
0
)
{
{
fsec
=
(
fsec1
-
fsec2
);
fsec
=
(
fsec1
-
fsec2
);
tm
->
tm_sec
=
(
tm1
->
tm_sec
-
tm2
->
tm_sec
)
;
tm
->
tm_sec
=
tm1
->
tm_sec
-
tm2
->
tm_sec
;
tm
->
tm_min
=
(
tm1
->
tm_min
-
tm2
->
tm_min
)
;
tm
->
tm_min
=
tm1
->
tm_min
-
tm2
->
tm_min
;
tm
->
tm_hour
=
(
tm1
->
tm_hour
-
tm2
->
tm_hour
)
;
tm
->
tm_hour
=
tm1
->
tm_hour
-
tm2
->
tm_hour
;
tm
->
tm_mday
=
(
tm1
->
tm_mday
-
tm2
->
tm_mday
)
;
tm
->
tm_mday
=
tm1
->
tm_mday
-
tm2
->
tm_mday
;
tm
->
tm_mon
=
(
tm1
->
tm_mon
-
tm2
->
tm_mon
)
;
tm
->
tm_mon
=
tm1
->
tm_mon
-
tm2
->
tm_mon
;
tm
->
tm_year
=
(
tm1
->
tm_year
-
tm2
->
tm_year
)
;
tm
->
tm_year
=
tm1
->
tm_year
-
tm2
->
tm_year
;
/* flip sign if necessary... */
/* flip sign if necessary... */
if
(
dt1
<
dt2
)
if
(
dt1
<
dt2
)
...
@@ -2450,13 +2449,13 @@ timestamptz_age(PG_FUNCTION_ARGS)
...
@@ -2450,13 +2449,13 @@ timestamptz_age(PG_FUNCTION_ARGS)
if
(
timestamp2tm
(
dt1
,
&
tz1
,
tm1
,
&
fsec1
,
&
tzn
)
==
0
&&
if
(
timestamp2tm
(
dt1
,
&
tz1
,
tm1
,
&
fsec1
,
&
tzn
)
==
0
&&
timestamp2tm
(
dt2
,
&
tz2
,
tm2
,
&
fsec2
,
&
tzn
)
==
0
)
timestamp2tm
(
dt2
,
&
tz2
,
tm2
,
&
fsec2
,
&
tzn
)
==
0
)
{
{
fsec
=
(
fsec1
-
fsec2
)
;
fsec
=
fsec1
-
fsec2
;
tm
->
tm_sec
=
(
tm1
->
tm_sec
-
tm2
->
tm_sec
)
;
tm
->
tm_sec
=
tm1
->
tm_sec
-
tm2
->
tm_sec
;
tm
->
tm_min
=
(
tm1
->
tm_min
-
tm2
->
tm_min
)
;
tm
->
tm_min
=
tm1
->
tm_min
-
tm2
->
tm_min
;
tm
->
tm_hour
=
(
tm1
->
tm_hour
-
tm2
->
tm_hour
)
;
tm
->
tm_hour
=
tm1
->
tm_hour
-
tm2
->
tm_hour
;
tm
->
tm_mday
=
(
tm1
->
tm_mday
-
tm2
->
tm_mday
)
;
tm
->
tm_mday
=
tm1
->
tm_mday
-
tm2
->
tm_mday
;
tm
->
tm_mon
=
(
tm1
->
tm_mon
-
tm2
->
tm_mon
)
;
tm
->
tm_mon
=
tm1
->
tm_mon
-
tm2
->
tm_mon
;
tm
->
tm_year
=
(
tm1
->
tm_year
-
tm2
->
tm_year
)
;
tm
->
tm_year
=
tm1
->
tm_year
-
tm2
->
tm_year
;
/* flip sign if necessary... */
/* flip sign if necessary... */
if
(
dt1
<
dt2
)
if
(
dt1
<
dt2
)
...
@@ -3048,7 +3047,7 @@ interval_trunc(PG_FUNCTION_ARGS)
...
@@ -3048,7 +3047,7 @@ interval_trunc(PG_FUNCTION_ARGS)
case
DTK_YEAR
:
case
DTK_YEAR
:
tm
->
tm_mon
=
0
;
tm
->
tm_mon
=
0
;
case
DTK_QUARTER
:
case
DTK_QUARTER
:
tm
->
tm_mon
=
(
3
*
(
tm
->
tm_mon
/
3
)
);
tm
->
tm_mon
=
3
*
(
tm
->
tm_mon
/
3
);
case
DTK_MONTH
:
case
DTK_MONTH
:
tm
->
tm_mday
=
0
;
tm
->
tm_mday
=
0
;
case
DTK_DAY
:
case
DTK_DAY
:
...
@@ -3357,7 +3356,7 @@ timestamp_part(PG_FUNCTION_ARGS)
...
@@ -3357,7 +3356,7 @@ timestamp_part(PG_FUNCTION_ARGS)
* ----
* ----
*/
*/
if
(
tm
->
tm_year
>
0
)
if
(
tm
->
tm_year
>
0
)
result
=
(
(
tm
->
tm_year
+
99
)
/
100
)
;
result
=
(
tm
->
tm_year
+
99
)
/
100
;
else
else
/* caution: C division may have negative remainder */
/* caution: C division may have negative remainder */
result
=
-
((
99
-
(
tm
->
tm_year
-
1
))
/
100
);
result
=
-
((
99
-
(
tm
->
tm_year
-
1
))
/
100
);
...
@@ -3419,7 +3418,7 @@ timestamp_part(PG_FUNCTION_ARGS)
...
@@ -3419,7 +3418,7 @@ timestamp_part(PG_FUNCTION_ARGS)
errmsg
(
"timestamp out of range"
)));
errmsg
(
"timestamp out of range"
)));
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
result
=
(
(
timestamptz
-
SetEpochTimestamp
())
/
1000000e0
)
;
result
=
(
timestamptz
-
SetEpochTimestamp
())
/
1000000e0
;
#else
#else
result
=
timestamptz
-
SetEpochTimestamp
();
result
=
timestamptz
-
SetEpochTimestamp
();
#endif
#endif
...
...
src/interfaces/ecpg/pgtypeslib/datetime.c
View file @
09ff9dbe
...
@@ -57,8 +57,8 @@ PGTYPESdate_from_asc(char *str, char **endptr)
...
@@ -57,8 +57,8 @@ PGTYPESdate_from_asc(char *str, char **endptr)
return
INT_MIN
;
return
INT_MIN
;
}
}
if
(
(
ParseDateTime
(
str
,
lowstr
,
field
,
ftype
,
MAXDATEFIELDS
,
&
nf
,
ptr
)
!=
0
)
if
(
ParseDateTime
(
str
,
lowstr
,
field
,
ftype
,
MAXDATEFIELDS
,
&
nf
,
ptr
)
!=
0
||
||
(
DecodeDateTime
(
field
,
ftype
,
nf
,
&
dtype
,
tm
,
&
fsec
,
&
tzp
,
EuroDates
)
!=
0
)
)
DecodeDateTime
(
field
,
ftype
,
nf
,
&
dtype
,
tm
,
&
fsec
,
&
tzp
,
EuroDates
)
!=
0
)
{
{
errno
=
PGTYPES_DATE_BAD_DATE
;
errno
=
PGTYPES_DATE_BAD_DATE
;
return
INT_MIN
;
return
INT_MIN
;
...
@@ -92,7 +92,7 @@ PGTYPESdate_to_asc(date dDate)
...
@@ -92,7 +92,7 @@ PGTYPESdate_to_asc(date dDate)
int
DateStyle
=
1
;
int
DateStyle
=
1
;
bool
EuroDates
=
FALSE
;
bool
EuroDates
=
FALSE
;
j2date
(
(
dDate
+
date2j
(
2000
,
1
,
1
)
),
&
(
tm
->
tm_year
),
&
(
tm
->
tm_mon
),
&
(
tm
->
tm_mday
));
j2date
(
dDate
+
date2j
(
2000
,
1
,
1
),
&
(
tm
->
tm_year
),
&
(
tm
->
tm_mon
),
&
(
tm
->
tm_mday
));
EncodeDateOnly
(
tm
,
DateStyle
,
buf
,
EuroDates
);
EncodeDateOnly
(
tm
,
DateStyle
,
buf
,
EuroDates
);
return
pgtypes_strdup
(
buf
);
return
pgtypes_strdup
(
buf
);
}
}
...
@@ -200,7 +200,7 @@ PGTYPESdate_fmt_asc(date dDate, char *fmtstring, char *outbuf)
...
@@ -200,7 +200,7 @@ PGTYPESdate_fmt_asc(date dDate, char *fmtstring, char *outbuf)
strcpy
(
outbuf
,
fmtstring
);
strcpy
(
outbuf
,
fmtstring
);
/* get the date */
/* get the date */
j2date
(
(
dDate
+
date2j
(
2000
,
1
,
1
)
),
&
(
tm
.
tm_year
),
&
(
tm
.
tm_mon
),
&
(
tm
.
tm_mday
));
j2date
(
dDate
+
date2j
(
2000
,
1
,
1
),
&
(
tm
.
tm_year
),
&
(
tm
.
tm_mon
),
&
(
tm
.
tm_mday
));
dow
=
PGTYPESdate_dayofweek
(
dDate
);
dow
=
PGTYPESdate_dayofweek
(
dDate
);
for
(
i
=
0
;
mapping
[
i
].
format
!=
NULL
;
i
++
)
for
(
i
=
0
;
mapping
[
i
].
format
!=
NULL
;
i
++
)
...
...
src/interfaces/ecpg/pgtypeslib/dt_common.c
View file @
09ff9dbe
This diff is collapsed.
Click to expand it.
src/interfaces/ecpg/pgtypeslib/interval.c
View file @
09ff9dbe
This diff is collapsed.
Click to expand it.
src/interfaces/ecpg/pgtypeslib/numeric.c
View file @
09ff9dbe
...
@@ -218,7 +218,7 @@ set_var_from_str(char *str, char **ptr, numeric *dest)
...
@@ -218,7 +218,7 @@ set_var_from_str(char *str, char **ptr, numeric *dest)
char
*
endptr
;
char
*
endptr
;
(
*
ptr
)
++
;
(
*
ptr
)
++
;
exponent
=
strtol
(
(
*
ptr
)
,
&
endptr
,
10
);
exponent
=
strtol
(
*
ptr
,
&
endptr
,
10
);
if
(
endptr
==
(
*
ptr
))
if
(
endptr
==
(
*
ptr
))
{
{
errno
=
PGTYPES_NUM_BAD_NUMERIC
;
errno
=
PGTYPES_NUM_BAD_NUMERIC
;
...
@@ -1351,7 +1351,7 @@ PGTYPESnumeric_from_long(signed long int long_val, numeric *var)
...
@@ -1351,7 +1351,7 @@ PGTYPESnumeric_from_long(signed long int long_val, numeric *var)
{
{
size
++
;
size
++
;
reach_limit
*=
10
;
reach_limit
*=
10
;
}
while
(
(
reach_limit
-
1
)
<
abs_long_val
&&
reach_limit
<=
LONG_MAX
/
10
);
}
while
(
reach_limit
-
1
<
abs_long_val
&&
reach_limit
<=
LONG_MAX
/
10
);
if
(
reach_limit
>
LONG_MAX
/
10
)
if
(
reach_limit
>
LONG_MAX
/
10
)
{
{
...
...
src/interfaces/ecpg/pgtypeslib/timestamp.c
View file @
09ff9dbe
...
@@ -20,14 +20,14 @@ int PGTYPEStimestamp_defmt_scan(char **, char *, timestamp *, int *, int *, int
...
@@ -20,14 +20,14 @@ int PGTYPEStimestamp_defmt_scan(char **, char *, timestamp *, int *, int *, int
static
int64
static
int64
time2t
(
const
int
hour
,
const
int
min
,
const
int
sec
,
const
fsec_t
fsec
)
time2t
(
const
int
hour
,
const
int
min
,
const
int
sec
,
const
fsec_t
fsec
)
{
{
return
(((((
(
hour
*
60
)
+
min
)
*
60
)
+
sec
)
*
USECS_PER_SEC
)
+
fsec
)
;
return
(((((
hour
*
60
)
+
min
)
*
60
)
+
sec
)
*
USECS_PER_SEC
)
+
fsec
;
}
/* time2t() */
}
/* time2t() */
#else
#else
static
double
static
double
time2t
(
const
int
hour
,
const
int
min
,
const
int
sec
,
const
fsec_t
fsec
)
time2t
(
const
int
hour
,
const
int
min
,
const
int
sec
,
const
fsec_t
fsec
)
{
{
return
(((
(
hour
*
60
)
+
min
)
*
60
)
+
sec
+
fsec
)
;
return
(((
hour
*
60
)
+
min
)
*
60
)
+
sec
+
fsec
;
}
/* time2t() */
}
/* time2t() */
#endif
#endif
...
@@ -74,10 +74,11 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp *result)
...
@@ -74,10 +74,11 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp *result)
if
((
*
result
-
time
)
/
USECS_PER_DAY
!=
dDate
)
if
((
*
result
-
time
)
/
USECS_PER_DAY
!=
dDate
)
return
-
1
;
return
-
1
;
/* check for just-barely overflow (okay except time-of-day wraps) */
/* check for just-barely overflow (okay except time-of-day wraps) */
if
((
*
result
<
0
)
?
(
dDate
>=
0
)
:
(
dDate
<
0
))
if
((
*
result
<
0
&&
dDate
>=
0
)
||
(
*
result
>=
0
&&
dDate
<
0
))
return
-
1
;
return
-
1
;
#else
#else
*
result
=
((
dDate
*
SECS_PER_DAY
)
+
time
)
;
*
result
=
dDate
*
SECS_PER_DAY
+
time
;
#endif
#endif
if
(
tzp
!=
NULL
)
if
(
tzp
!=
NULL
)
*
result
=
dt2local
(
*
result
,
-
(
*
tzp
));
*
result
=
dt2local
(
*
result
,
-
(
*
tzp
));
...
@@ -110,19 +111,19 @@ dt2time(timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
...
@@ -110,19 +111,19 @@ dt2time(timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
time
=
jd
;
time
=
jd
;
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
*
hour
=
(
time
/
USECS_PER_HOUR
)
;
*
hour
=
time
/
USECS_PER_HOUR
;
time
-=
(
(
*
hour
)
*
USECS_PER_HOUR
)
;
time
-=
(
*
hour
)
*
USECS_PER_HOUR
;
*
min
=
(
time
/
USECS_PER_MINUTE
)
;
*
min
=
time
/
USECS_PER_MINUTE
;
time
-=
(
(
*
min
)
*
USECS_PER_MINUTE
)
;
time
-=
(
*
min
)
*
USECS_PER_MINUTE
;
*
sec
=
(
time
/
USECS_PER_SEC
)
;
*
sec
=
time
/
USECS_PER_SEC
;
*
fsec
=
(
time
-
(
*
sec
*
USECS_PER_SEC
))
;
*
fsec
=
time
-
*
sec
*
USECS_PER_SEC
;
*
sec
=
(
time
/
USECS_PER_SEC
)
;
*
sec
=
time
/
USECS_PER_SEC
;
*
fsec
=
(
time
-
(
*
sec
*
USECS_PER_SEC
))
;
*
fsec
=
time
-
*
sec
*
USECS_PER_SEC
;
#else
#else
*
hour
=
(
time
/
3600
)
;
*
hour
=
time
/
3600
;
time
-=
(
(
*
hour
)
*
3600
)
;
time
-=
(
*
hour
)
*
3600
;
*
min
=
(
time
/
60
)
;
*
min
=
time
/
60
;
time
-=
(
(
*
min
)
*
60
)
;
time
-=
(
*
min
)
*
60
;
*
sec
=
time
;
*
sec
=
time
;
*
fsec
=
JROUND
(
time
-
*
sec
);
*
fsec
=
JROUND
(
time
-
*
sec
);
#endif
#endif
...
@@ -199,10 +200,10 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
...
@@ -199,10 +200,10 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
if
(
IS_VALID_UTIME
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
))
if
(
IS_VALID_UTIME
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
))
{
{
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
utime
=
((
dt
/
USECS_PER_SEC
)
utime
=
dt
/
USECS_PER_SEC
+
+
((
date0
-
date2j
(
1970
,
1
,
1
))
*
INT64CONST
(
SECS_PER_DAY
)
));
((
date0
-
date2j
(
1970
,
1
,
1
))
*
INT64CONST
(
86400
));
#else
#else
utime
=
(
dt
+
((
date0
-
date2j
(
1970
,
1
,
1
))
*
SECS_PER_DAY
))
;
utime
=
dt
+
(
date0
-
date2j
(
1970
,
1
,
1
))
*
SECS_PER_DAY
;
#endif
#endif
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)
...
@@ -222,7 +223,7 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
...
@@ -222,7 +223,7 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
if
(
tzn
!=
NULL
)
if
(
tzn
!=
NULL
)
*
tzn
=
(
char
*
)
tm
->
tm_zone
;
*
tzn
=
(
char
*
)
tm
->
tm_zone
;
#elif defined(HAVE_INT_TIMEZONE)
#elif defined(HAVE_INT_TIMEZONE)
*
tzp
=
(
(
tm
->
tm_isdst
>
0
)
?
(
TIMEZONE_GLOBAL
-
3600
)
:
TIMEZONE_GLOBAL
)
;
*
tzp
=
(
tm
->
tm_isdst
>
0
)
?
TIMEZONE_GLOBAL
-
3600
:
TIMEZONE_GLOBAL
;
if
(
tzn
!=
NULL
)
if
(
tzn
!=
NULL
)
*
tzn
=
TZNAME_GLOBAL
[(
tm
->
tm_isdst
>
0
)];
*
tzn
=
TZNAME_GLOBAL
[(
tm
->
tm_isdst
>
0
)];
#endif
#endif
...
@@ -301,8 +302,8 @@ PGTYPEStimestamp_from_asc(char *str, char **endptr)
...
@@ -301,8 +302,8 @@ PGTYPEStimestamp_from_asc(char *str, char **endptr)
return
(
noresult
);
return
(
noresult
);
}
}
if
(
(
ParseDateTime
(
str
,
lowstr
,
field
,
ftype
,
MAXDATEFIELDS
,
&
nf
,
ptr
)
!=
0
)
if
(
ParseDateTime
(
str
,
lowstr
,
field
,
ftype
,
MAXDATEFIELDS
,
&
nf
,
ptr
)
!=
0
||
||
(
DecodeDateTime
(
field
,
ftype
,
nf
,
&
dtype
,
tm
,
&
fsec
,
&
tz
,
0
)
!=
0
)
)
DecodeDateTime
(
field
,
ftype
,
nf
,
&
dtype
,
tm
,
&
fsec
,
&
tz
,
0
)
!=
0
)
{
{
errno
=
PGTYPES_TS_BAD_TIMESTAMP
;
errno
=
PGTYPES_TS_BAD_TIMESTAMP
;
return
(
noresult
);
return
(
noresult
);
...
@@ -571,7 +572,7 @@ dttofmtasc_replace(timestamp *ts, date dDate, int dow, struct tm * tm,
...
@@ -571,7 +572,7 @@ dttofmtasc_replace(timestamp *ts, date dDate, int dow, struct tm * tm,
break
;
break
;
case
's'
:
case
's'
:
#ifdef HAVE_INT64_TIMESTAMP
#ifdef HAVE_INT64_TIMESTAMP
replace_val
.
int64_val
=
(
(
*
ts
-
SetEpochTimestamp
())
/
1000000e0
)
;
replace_val
.
int64_val
=
(
*
ts
-
SetEpochTimestamp
())
/
1000000e0
;
replace_type
=
PGTYPES_TYPE_INT64
;
replace_type
=
PGTYPES_TYPE_INT64
;
#else
#else
replace_val
.
double_val
=
*
ts
-
SetEpochTimestamp
();
replace_val
.
double_val
=
*
ts
-
SetEpochTimestamp
();
...
@@ -879,13 +880,13 @@ PGTYPEStimestamp_add_interval(timestamp *tin, interval *span, timestamp *tout)
...
@@ -879,13 +880,13 @@ PGTYPEStimestamp_add_interval(timestamp *tin, interval *span, timestamp *tout)
tm
->
tm_mon
+=
span
->
month
;
tm
->
tm_mon
+=
span
->
month
;
if
(
tm
->
tm_mon
>
12
)
if
(
tm
->
tm_mon
>
12
)
{
{
tm
->
tm_year
+=
(
(
tm
->
tm_mon
-
1
)
/
12
)
;
tm
->
tm_year
+=
(
tm
->
tm_mon
-
1
)
/
12
;
tm
->
tm_mon
=
(
((
tm
->
tm_mon
-
1
)
%
12
)
+
1
)
;
tm
->
tm_mon
=
(
tm
->
tm_mon
-
1
)
%
12
+
1
;
}
}
else
if
(
tm
->
tm_mon
<
1
)
else
if
(
tm
->
tm_mon
<
1
)
{
{
tm
->
tm_year
+=
((
tm
->
tm_mon
/
12
)
-
1
)
;
tm
->
tm_year
+=
tm
->
tm_mon
/
12
-
1
;
tm
->
tm_mon
=
((
tm
->
tm_mon
%
12
)
+
12
)
;
tm
->
tm_mon
=
tm
->
tm_mon
%
12
+
12
;
}
}
...
...
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