Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
1f4f4534
Commit
1f4f4534
authored
28 years ago
by
Thomas G. Lockhart
Browse files
Options
Downloads
Patches
Plain Diff
Use the standard date/time encoder rather than strftime() for output.
This allows use of the DateStyle session variable.
parent
01264e84
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/backend/utils/adt/nabstime.c
+63
-122
63 additions, 122 deletions
src/backend/utils/adt/nabstime.c
with
63 additions
and
122 deletions
src/backend/utils/adt/nabstime.c
+
63
−
122
View file @
1f4f4534
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.2
6
1997/0
5/11 15:11:4
5 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.2
7
1997/0
6/23 14:56:1
5 thomas Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -97,35 +97,67 @@ GetCurrentTime(struct tm *tm)
{
int
tz
;
abstime2tm
(
GetCurrentTransactionStartTime
(),
&
tz
,
tm
);
abstime2tm
(
GetCurrentTransactionStartTime
(),
&
tz
,
tm
,
NULL
);
return
;
}
/* GetCurrentTime() */
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
if
(
tzp
!=
NULL
)
time
-=
*
tzp
;
tt
=
gmtime
((
time_t
*
)
&
time
);
(
void
)
ftime
(
&
tb
);
#endif
/* XXX HACK to get time behavior compatible with Postgres v6.0 - tgl 97/04/07 */
#ifdef USE_POSIX_TIME
if
(
tzp
!=
NULL
)
{
t
t
=
localtime
((
time_t
*
)
&
time
);
t
x
=
localtime
((
time_t
*
)
&
time
);
}
else
{
t
t
=
gmtime
((
time_t
*
)
&
time
);
t
x
=
gmtime
((
time_t
*
)
&
time
);
};
#else
#endif
#ifdef DATEDEBUG
#ifdef HAVE_INT_TIMEZONE
printf
(
"datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02d %s %s dst=%d
\n
"
,
tx
->
tm_year
,
tx
->
tm_mon
,
tx
->
tm_mday
,
tx
->
tm_hour
,
tx
->
tm_min
,
tx
->
tm_sec
,
tzname
[
0
],
tzname
[
1
],
tx
->
tm_isdst
);
#else
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
;
tm
->
tm_year
=
tt
->
tm_year
+
1900
;
tm
->
tm_mon
=
tt
->
tm_mon
+
1
;
tm
->
tm_mday
=
tt
->
tm_mday
;
tm
->
tm_hour
=
tt
->
tm_hour
;
tm
->
tm_min
=
tt
->
tm_min
;
tm
->
tm_sec
=
tt
->
tm_sec
;
tm
->
tm_isdst
=
tt
->
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
;
}
/* abstime2tm() */
...
...
@@ -163,15 +195,6 @@ tm2abstime( struct tm *tm, int tz)
(
day
==
MIN_DAYNUM
&&
sec
>
0
))
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 */
if
(
!
AbsoluteTimeIsReal
(
sec
))
return
(
INVALID_ABSTIME
);
...
...
@@ -246,22 +269,18 @@ printf( "nabstimein- %d fields are type %d (DTK_DATE=%d)\n", nf, dtype, DTK_DATE
}
/* nabstimein() */
/*
/*
nabstimeout()
* Given an AbsoluteTime return the English text version of the date
*/
char
*
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
;
int
tz
;
double
fsec
=
0
;
struct
tm
tt
,
*
tm
=
&
tt
;
char
buf
[
MAXDATELEN
+
1
];
char
zone
[
MAXDATELEN
+
1
],
*
tzn
=
zone
;
switch
(
time
)
{
case
EPOCH_ABSTIME
:
(
void
)
strcpy
(
buf
,
EPOCH
);
break
;
...
...
@@ -270,96 +289,18 @@ nabstimeout(AbsoluteTime time)
case
NOEND_ABSTIME
:
(
void
)
strcpy
(
buf
,
LATE
);
break
;
case
NOSTART_ABSTIME
:
(
void
)
strcpy
(
buf
,
EARLY
);
break
;
default:
/* hack -- localtime happens to work for negative times */
(
void
)
strftime
(
buf
,
sizeof
(
buf
),
"%a %b %d %H:%M:%S %Y %Z"
,
localtime
((
time_t
*
)
&
time
));
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
if
(
tm
->
tm_year
<
70
)
{
tm
->
tm_year
+=
2000
;
}
else
if
(
tm
->
tm_year
<
1000
)
{
tm
->
tm_year
+=
1900
;
};
abstime2tm
(
time
,
&
tz
,
tm
,
tzn
);
#if DATEDEBUG
#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
);
EncodeDateTime
(
tm
,
fsec
,
&
tz
,
&
tzn
,
DateStyle
,
buf
);
break
;
}
result
=
PALLOC
(
strlen
(
buf
)
+
1
);
strcpy
(
result
,
buf
);
/*
* 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
;
}
/* qmktime() */
return
(
result
);
}
/* nabstimeout() */
/*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment