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
1f4f4534
Commit
1f4f4534
authored
Jun 23, 1997
by
Thomas G. Lockhart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the standard date/time encoder rather than strftime() for output.
This allows use of the DateStyle session variable.
parent
01264e84
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
122 deletions
+63
-122
src/backend/utils/adt/nabstime.c
src/backend/utils/adt/nabstime.c
+63
-122
No files found.
src/backend/utils/adt/nabstime.c
View file @
1f4f4534
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.2
6 1997/05/11 15:11:4
5 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.2
7 1997/06/23 14:56:1
5 thomas Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -97,35 +97,67 @@ GetCurrentTime(struct tm *tm)
...
@@ -97,35 +97,67 @@ GetCurrentTime(struct tm *tm)
{
{
int
tz
;
int
tz
;
abstime2tm
(
GetCurrentTransactionStartTime
(),
&
tz
,
tm
);
abstime2tm
(
GetCurrentTransactionStartTime
(),
&
tz
,
tm
,
NULL
);
return
;
return
;
}
/* GetCurrentTime() */
}
/* GetCurrentTime() */
void
void
abstime2tm
(
AbsoluteTime
time
,
int
*
tzp
,
struct
tm
*
tm
)
abstime2tm
(
AbsoluteTime
time
,
int
*
tzp
,
struct
tm
*
tm
,
char
*
tzn
)
{
{
struct
tm
*
tt
;
#ifdef USE_POSIX_TIME
struct
tm
*
tx
;
#else
/* ! USE_POSIX_TIME */
struct
timeb
tb
;
/* the old V7-ism */
#if FALSE
(
void
)
ftime
(
&
tb
);
if
(
tzp
!=
NULL
)
time
-=
*
tzp
;
tt
=
gmtime
((
time_t
*
)
&
time
);
#endif
#endif
/* XXX HACK to get time behavior compatible with Postgres v6.0 - tgl 97/04/07 */
#ifdef USE_POSIX_TIME
if
(
tzp
!=
NULL
)
{
if
(
tzp
!=
NULL
)
{
t
t
=
localtime
((
time_t
*
)
&
time
);
t
x
=
localtime
((
time_t
*
)
&
time
);
}
else
{
}
else
{
t
t
=
gmtime
((
time_t
*
)
&
time
);
t
x
=
gmtime
((
time_t
*
)
&
time
);
};
};
#else
#endif
tm
->
tm_year
=
tt
->
tm_year
+
1900
;
#ifdef DATEDEBUG
tm
->
tm_mon
=
tt
->
tm_mon
+
1
;
#ifdef HAVE_INT_TIMEZONE
tm
->
tm_mday
=
tt
->
tm_mday
;
printf
(
"datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02d %s %s dst=%d
\n
"
,
tm
->
tm_hour
=
tt
->
tm_hour
;
tx
->
tm_year
,
tx
->
tm_mon
,
tx
->
tm_mday
,
tx
->
tm_hour
,
tx
->
tm_min
,
tx
->
tm_sec
,
tm
->
tm_min
=
tt
->
tm_min
;
tzname
[
0
],
tzname
[
1
],
tx
->
tm_isdst
);
tm
->
tm_sec
=
tt
->
tm_sec
;
#else
tm
->
tm_isdst
=
tt
->
tm_isdst
;
printf
(
"datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02d %s dst=%d
\n
"
,
tx
->
tm_year
,
tx
->
tm_mon
,
tx
->
tm_mday
,
tx
->
tm_hour
,
tx
->
tm_min
,
tx
->
tm_sec
,
tx
->
tm_zone
,
tx
->
tm_isdst
);
#endif
#else
#endif
tm
->
tm_year
=
tx
->
tm_year
+
1900
;
tm
->
tm_mon
=
tx
->
tm_mon
+
1
;
tm
->
tm_mday
=
tx
->
tm_mday
;
tm
->
tm_hour
=
tx
->
tm_hour
;
tm
->
tm_min
=
tx
->
tm_min
;
tm
->
tm_sec
=
tx
->
tm_sec
;
tm
->
tm_isdst
=
tx
->
tm_isdst
;
#ifdef USE_POSIX_TIME
#ifdef HAVE_INT_TIMEZONE
if
(
tzp
!=
NULL
)
*
tzp
=
(
tm
->
tm_isdst
?
(
timezone
-
3600
)
:
timezone
);
if
(
tzn
!=
NULL
)
strcpy
(
tzn
,
tzname
[
tm
->
tm_isdst
]);
#else
/* !HAVE_INT_TIMEZONE */
if
(
tzp
!=
NULL
)
*
tzp
=
-
tm
->
tm_gmtoff
;
/* tm_gmtoff is Sun/DEC-ism */
/* XXX FreeBSD man pages indicate that this should work - tgl 97/04/23 */
if
(
tzn
!=
NULL
)
strcpy
(
tzn
,
tm
->
tm_zone
);
#endif
#else
/* ! USE_POSIX_TIME */
if
(
tzp
!=
NULL
)
*
tzp
=
tb
.
timezone
*
60
;
/* XXX does this work to get the local timezone string in V7? - tgl 97/03/18 */
if
(
tzn
!=
NULL
)
strftime
(
tzn
,
MAXTZLEN
,
"%Z"
,
localtime
(
&
now
));
#endif
return
;
return
;
}
/* abstime2tm() */
}
/* abstime2tm() */
...
@@ -163,15 +195,6 @@ tm2abstime( struct tm *tm, int tz)
...
@@ -163,15 +195,6 @@ tm2abstime( struct tm *tm, int tz)
(
day
==
MIN_DAYNUM
&&
sec
>
0
))
(
day
==
MIN_DAYNUM
&&
sec
>
0
))
return
(
INVALID_ABSTIME
);
return
(
INVALID_ABSTIME
);
#if FALSE
/* daylight correction */
if
(
tm
->
tm_isdst
<
0
)
{
/* unknown; find out */
tm
->
tm_isdst
=
(
CDayLight
>
0
);
};
if
(
tm
->
tm_isdst
>
0
)
sec
-=
60
*
60
;
#endif
/* check for reserved values (e.g. "current" on edge of usual range */
/* check for reserved values (e.g. "current" on edge of usual range */
if
(
!
AbsoluteTimeIsReal
(
sec
))
if
(
!
AbsoluteTimeIsReal
(
sec
))
return
(
INVALID_ABSTIME
);
return
(
INVALID_ABSTIME
);
...
@@ -246,22 +269,18 @@ printf( "nabstimein- %d fields are type %d (DTK_DATE=%d)\n", nf, dtype, DTK_DATE
...
@@ -246,22 +269,18 @@ printf( "nabstimein- %d fields are type %d (DTK_DATE=%d)\n", nf, dtype, DTK_DATE
}
/* nabstimein() */
}
/* nabstimein() */
/*
/*
nabstimeout()
* Given an AbsoluteTime return the English text version of the date
* Given an AbsoluteTime return the English text version of the date
*/
*/
char
*
char
*
nabstimeout
(
AbsoluteTime
time
)
nabstimeout
(
AbsoluteTime
time
)
{
{
/*
* Fri Jan 28 23:05:29 1994 PST
* 0 1 2
* 12345678901234567890123456789
*
* we allocate some extra -- timezones are usually 3 characters but
* this is not in the POSIX standard...
*/
char
buf
[
40
];
char
*
result
;
char
*
result
;
int
tz
;
double
fsec
=
0
;
struct
tm
tt
,
*
tm
=
&
tt
;
char
buf
[
MAXDATELEN
+
1
];
char
zone
[
MAXDATELEN
+
1
],
*
tzn
=
zone
;
switch
(
time
)
{
switch
(
time
)
{
case
EPOCH_ABSTIME
:
(
void
)
strcpy
(
buf
,
EPOCH
);
break
;
case
EPOCH_ABSTIME
:
(
void
)
strcpy
(
buf
,
EPOCH
);
break
;
...
@@ -270,96 +289,18 @@ nabstimeout(AbsoluteTime time)
...
@@ -270,96 +289,18 @@ nabstimeout(AbsoluteTime time)
case
NOEND_ABSTIME
:
(
void
)
strcpy
(
buf
,
LATE
);
break
;
case
NOEND_ABSTIME
:
(
void
)
strcpy
(
buf
,
LATE
);
break
;
case
NOSTART_ABSTIME
:
(
void
)
strcpy
(
buf
,
EARLY
);
break
;
case
NOSTART_ABSTIME
:
(
void
)
strcpy
(
buf
,
EARLY
);
break
;
default:
default:
/* hack -- localtime happens to work for negative times */
abstime2tm
(
time
,
&
tz
,
tm
,
tzn
);
(
void
)
strftime
(
buf
,
sizeof
(
buf
),
"%a %b %d %H:%M:%S %Y %Z"
,
#if DATEDEBUG
localtime
((
time_t
*
)
&
time
));
#endif
EncodeDateTime
(
tm
,
fsec
,
&
tz
,
&
tzn
,
DateStyle
,
buf
);
break
;
break
;
}
}
result
=
(
char
*
)
palloc
(
strlen
(
buf
)
+
1
);
strcpy
(
result
,
buf
);
return
result
;
}
/* turn a (struct tm) and a few variables into a time_t, with range checking */
AbsoluteTime
dateconv
(
register
struct
tm
*
tm
,
int
zone
)
{
tm
->
tm_wday
=
tm
->
tm_yday
=
0
;
#if FALSE
result
=
PALLOC
(
strlen
(
buf
)
+
1
);
if
(
tm
->
tm_year
<
70
)
{
strcpy
(
result
,
buf
);
tm
->
tm_year
+=
2000
;
}
else
if
(
tm
->
tm_year
<
1000
)
{
tm
->
tm_year
+=
1900
;
};
#endif
/* validate, before going out of range on some members */
if
(
tm
->
tm_year
<
1901
||
tm
->
tm_year
>
2038
||
tm
->
tm_mon
<
1
||
tm
->
tm_mon
>
12
||
tm
->
tm_mday
<
1
||
tm
->
tm_mday
>
31
||
tm
->
tm_hour
<
0
||
tm
->
tm_hour
>=
24
||
tm
->
tm_min
<
0
||
tm
->
tm_min
>
59
||
tm
->
tm_sec
<
0
||
tm
->
tm_sec
>
59
)
return
INVALID_ABSTIME
;
/*
* zone should really be -zone, and tz should be set to tp->value, not
* -tp->value. Or the table could be fixed.
*/
tm
->
tm_sec
+=
zone
;
/* mktime lets it be out of range */
/* convert to seconds */
return
qmktime
(
tm
);
}
/*
* near-ANSI qmktime suitable for use by dateconv; not necessarily as paranoid
* as ANSI requires, and it may not canonicalise the struct tm. Ignores tm_wday
* and tm_yday.
*/
time_t
qmktime
(
struct
tm
*
tm
)
{
time_t
sec
;
int
day
;
#if FALSE
/* If it was a 2 digit year */
if
(
tm
->
tm_year
<
100
)
tm
->
tm_year
+=
1900
;
#endif
day
=
(
date2j
(
tm
->
tm_year
,
tm
->
tm_mon
,
tm
->
tm_mday
)
-
date2j
(
1970
,
1
,
1
));
/* check for time out of range */
if
((
day
<
MIN_DAYNUM
)
||
(
day
>
MAX_DAYNUM
))
return
INVALID_ABSTIME
;
/* convert to seconds */
sec
=
tm
->
tm_sec
+
(
tm
->
tm_min
+
(
day
*
24
+
tm
->
tm_hour
)
*
60
)
*
60
;
/* check for overflow */
if
((
day
==
MAX_DAYNUM
&&
sec
<
0
)
||
(
day
==
MIN_DAYNUM
&&
sec
>
0
))
return
INVALID_ABSTIME
;
/* check for reserved values (e.g. "current" on edge of usual range */
if
(
!
AbsoluteTimeIsReal
(
sec
))
return
INVALID_ABSTIME
;
/* daylight correction */
if
(
tm
->
tm_isdst
<
0
)
{
/* unknown; find out */
tm
->
tm_isdst
=
(
CDayLight
>
0
);
};
if
(
tm
->
tm_isdst
>
0
)
sec
-=
60
*
60
;
return
sec
;
return
(
result
)
;
}
/*
qmktime
() */
}
/*
nabstimeout
() */
/*
/*
...
...
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