mirror of
https://github.com/postgres/postgres.git
synced 2025-07-12 21:01:52 +03:00
Enable timespan_finite() and text_timespan() routines (was commented out).
Define an "ISO-style" timespan output format with "hh:mm:ss" fields. Enabled by DateStyle = USE_ISO_DATES.
This commit is contained in:
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.45 1997/12/04 23:30:52 thomas Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.46 1997/12/17 23:22:17 thomas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -49,8 +49,6 @@ static datetkn *datebsearch(char *key, datetkn *base, unsigned int nel);
|
|||||||
static DateTime dt2local(DateTime dt, int timezone);
|
static DateTime dt2local(DateTime dt, int timezone);
|
||||||
static void dt2time(DateTime dt, int *hour, int *min, double *sec);
|
static void dt2time(DateTime dt, int *hour, int *min, double *sec);
|
||||||
static int j2day(int jd);
|
static int j2day(int jd);
|
||||||
static int timespan2tm(TimeSpan span, struct tm * tm, float8 *fsec);
|
|
||||||
static int tm2timespan(struct tm * tm, double fsec, TimeSpan *span);
|
|
||||||
|
|
||||||
#define USE_DATE_CACHE 1
|
#define USE_DATE_CACHE 1
|
||||||
#define ROUND_ALL 0
|
#define ROUND_ALL 0
|
||||||
@ -297,8 +295,6 @@ datetime_finite(DateTime *datetime)
|
|||||||
return (!DATETIME_NOT_FINITE(*datetime));
|
return (!DATETIME_NOT_FINITE(*datetime));
|
||||||
} /* datetime_finite() */
|
} /* datetime_finite() */
|
||||||
|
|
||||||
|
|
||||||
#ifdef NOT_USED
|
|
||||||
bool
|
bool
|
||||||
timespan_finite(TimeSpan *timespan)
|
timespan_finite(TimeSpan *timespan)
|
||||||
{
|
{
|
||||||
@ -308,7 +304,6 @@ timespan_finite(TimeSpan *timespan)
|
|||||||
return (!TIMESPAN_NOT_FINITE(*timespan));
|
return (!TIMESPAN_NOT_FINITE(*timespan));
|
||||||
} /* timespan_finite() */
|
} /* timespan_finite() */
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*----------------------------------------------------------
|
/*----------------------------------------------------------
|
||||||
* Relational operators for datetime.
|
* Relational operators for datetime.
|
||||||
@ -1368,7 +1363,6 @@ timespan_text(TimeSpan *timespan)
|
|||||||
* Text type may not be null terminated, so copy to temporary string
|
* Text type may not be null terminated, so copy to temporary string
|
||||||
* then call the standard input routine.
|
* then call the standard input routine.
|
||||||
*/
|
*/
|
||||||
#ifdef NOT_USED
|
|
||||||
TimeSpan *
|
TimeSpan *
|
||||||
text_timespan(text *str)
|
text_timespan(text *str)
|
||||||
{
|
{
|
||||||
@ -1392,8 +1386,6 @@ text_timespan(text *str)
|
|||||||
return (result);
|
return (result);
|
||||||
} /* text_timespan() */
|
} /* text_timespan() */
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* datetime_trunc()
|
/* datetime_trunc()
|
||||||
* Extract specified field from datetime.
|
* Extract specified field from datetime.
|
||||||
*/
|
*/
|
||||||
@ -2573,7 +2565,7 @@ tm2datetime(struct tm * tm, double fsec, int *tzp, DateTime *result)
|
|||||||
/* timespan2tm()
|
/* timespan2tm()
|
||||||
* Convert a timespan data type to a tm structure.
|
* Convert a timespan data type to a tm structure.
|
||||||
*/
|
*/
|
||||||
static int
|
int
|
||||||
timespan2tm(TimeSpan span, struct tm * tm, float8 *fsec)
|
timespan2tm(TimeSpan span, struct tm * tm, float8 *fsec)
|
||||||
{
|
{
|
||||||
double time;
|
double time;
|
||||||
@ -2610,7 +2602,7 @@ timespan2tm(TimeSpan span, struct tm * tm, float8 *fsec)
|
|||||||
return 0;
|
return 0;
|
||||||
} /* timespan2tm() */
|
} /* timespan2tm() */
|
||||||
|
|
||||||
static int
|
int
|
||||||
tm2timespan(struct tm * tm, double fsec, TimeSpan *span)
|
tm2timespan(struct tm * tm, double fsec, TimeSpan *span)
|
||||||
{
|
{
|
||||||
span->month = ((tm->tm_year * 12) + tm->tm_mon);
|
span->month = ((tm->tm_year * 12) + tm->tm_mon);
|
||||||
@ -4369,10 +4361,19 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
|
|||||||
{
|
{
|
||||||
int is_before = FALSE;
|
int is_before = FALSE;
|
||||||
int is_nonzero = FALSE;
|
int is_nonzero = FALSE;
|
||||||
char *cp;
|
char *cp = str;
|
||||||
|
|
||||||
strcpy(str, "@");
|
switch (style)
|
||||||
cp = str + strlen(str);
|
{
|
||||||
|
/* compatible with ISO date formats */
|
||||||
|
case USE_ISO_DATES:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
strcpy(cp, "@");
|
||||||
|
cp += strlen(cp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (tm->tm_year != 0)
|
if (tm->tm_year != 0)
|
||||||
{
|
{
|
||||||
@ -4398,6 +4399,38 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
|
|||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (style)
|
||||||
|
{
|
||||||
|
/* compatible with ISO date formats */
|
||||||
|
case USE_ISO_DATES:
|
||||||
|
if ((tm->tm_hour != 0) || (tm->tm_min != 0))
|
||||||
|
is_nonzero = TRUE;
|
||||||
|
is_before |= ((tm->tm_hour < 0) || (tm->tm_min < 0));
|
||||||
|
sprintf(cp, " %02d:%02d", abs(tm->tm_hour), abs(tm->tm_min));
|
||||||
|
cp += strlen(cp);
|
||||||
|
|
||||||
|
/* fractional seconds? */
|
||||||
|
if (fsec != 0)
|
||||||
|
{
|
||||||
|
is_nonzero = TRUE;
|
||||||
|
fsec += tm->tm_sec;
|
||||||
|
is_before |= (fsec < 0);
|
||||||
|
sprintf(cp, ":%05.2f", fabs(fsec));
|
||||||
|
cp += strlen(cp);
|
||||||
|
|
||||||
|
/* otherwise, integer seconds only? */
|
||||||
|
}
|
||||||
|
else if (tm->tm_sec != 0)
|
||||||
|
{
|
||||||
|
is_nonzero = TRUE;
|
||||||
|
is_before |= (tm->tm_sec < 0);
|
||||||
|
sprintf(cp, ":%02d", abs(tm->tm_sec));
|
||||||
|
cp += strlen(cp);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case USE_POSTGRES_DATES:
|
||||||
|
default:
|
||||||
if (tm->tm_hour != 0)
|
if (tm->tm_hour != 0)
|
||||||
{
|
{
|
||||||
is_nonzero = TRUE;
|
is_nonzero = TRUE;
|
||||||
@ -4432,6 +4465,8 @@ EncodeTimeSpan(struct tm * tm, double fsec, int style, char *str)
|
|||||||
sprintf(cp, " %d sec%s", abs(tm->tm_sec), ((abs(tm->tm_sec) != 1) ? "s" : ""));
|
sprintf(cp, " %d sec%s", abs(tm->tm_sec), ((abs(tm->tm_sec) != 1) ? "s" : ""));
|
||||||
cp += strlen(cp);
|
cp += strlen(cp);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* identically zero? then put in a unitless zero... */
|
/* identically zero? then put in a unitless zero... */
|
||||||
if (!is_nonzero)
|
if (!is_nonzero)
|
||||||
|
Reference in New Issue
Block a user