1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Massive commit to run PGINDENT on all *.c and *.h files.

This commit is contained in:
Bruce Momjian
1997-09-07 05:04:48 +00:00
parent 8fecd4febf
commit 1ccd423235
687 changed files with 150775 additions and 136888 deletions

View File

@ -1,17 +1,17 @@
/*-------------------------------------------------------------------------
*
* datetime.c--
* implements DATE and TIME data types specified in SQL-92 standard
* implements DATE and TIME data types specified in SQL-92 standard
*
* Copyright (c) 1994-5, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.13 1997/09/05 18:11:10 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.14 1997/09/07 04:50:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdio.h> /* for sprintf() */
#include <stdio.h> /* for sprintf() */
#include <string.h>
#include <limits.h>
@ -25,12 +25,12 @@
#include "utils/datetime.h"
#include "access/xact.h"
static int date2tm(DateADT dateVal, int *tzp, struct tm *tm, double *fsec, char **tzn);
static int date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn);
static int day_tab[2][12] = {
{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31} };
static int day_tab[2][12] = {
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
#define isleap(y) (((y % 4) == 0 && (y % 100) != 0) || (y % 400) == 0)
@ -49,7 +49,7 @@ static int day_tab[2][12] = {
|| ((m == UTIME_MAXMONTH) && (d <= UTIME_MAXDAY))))))
/*****************************************************************************
* Date ADT
* Date ADT
*****************************************************************************/
@ -59,234 +59,250 @@ static int day_tab[2][12] = {
DateADT
date_in(char *str)
{
DateADT date;
double fsec;
struct tm tt, *tm = &tt;
int tzp;
int dtype;
int nf;
char *field[MAXDATEFIELDS];
int ftype[MAXDATEFIELDS];
char lowstr[MAXDATELEN+1];
DateADT date;
double fsec;
struct tm tt,
*tm = &tt;
int tzp;
int dtype;
int nf;
char *field[MAXDATEFIELDS];
int ftype[MAXDATEFIELDS];
char lowstr[MAXDATELEN + 1];
if (!PointerIsValid(str))
elog(WARN,"Bad (null) date external representation",NULL);
if (!PointerIsValid(str))
elog(WARN, "Bad (null) date external representation", NULL);
#ifdef DATEDEBUG
printf( "date_in- input string is %s\n", str);
printf("date_in- input string is %s\n", str);
#endif
if ((ParseDateTime( str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime( field, ftype, nf, &dtype, tm, &fsec, &tzp) != 0))
elog(WARN,"Bad date external representation %s",str);
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp) != 0))
elog(WARN, "Bad date external representation %s", str);
switch (dtype) {
case DTK_DATE:
break;
switch (dtype)
{
case DTK_DATE:
break;
case DTK_CURRENT:
GetCurrentTime(tm);
break;
case DTK_CURRENT:
GetCurrentTime(tm);
break;
case DTK_EPOCH:
tm->tm_year = 1970;
tm->tm_mon = 1;
tm->tm_mday = 1;
break;
case DTK_EPOCH:
tm->tm_year = 1970;
tm->tm_mon = 1;
tm->tm_mday = 1;
break;
default:
elog(WARN,"Unrecognized date external representation %s",str);
}
default:
elog(WARN, "Unrecognized date external representation %s", str);
}
if (tm->tm_year < 0 || tm->tm_year > 32767)
elog(WARN, "date_in: year must be limited to values 0 through 32767 in '%s'", str);
if (tm->tm_mon < 1 || tm->tm_mon > 12)
elog(WARN, "date_in: month must be limited to values 1 through 12 in '%s'", str);
if (tm->tm_mday < 1 || tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon-1])
elog(WARN, "date_in: day must be limited to values 1 through %d in '%s'",
day_tab[isleap(tm->tm_year)][tm->tm_mon-1], str);
if (tm->tm_year < 0 || tm->tm_year > 32767)
elog(WARN, "date_in: year must be limited to values 0 through 32767 in '%s'", str);
if (tm->tm_mon < 1 || tm->tm_mon > 12)
elog(WARN, "date_in: month must be limited to values 1 through 12 in '%s'", str);
if (tm->tm_mday < 1 || tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1])
elog(WARN, "date_in: day must be limited to values 1 through %d in '%s'",
day_tab[isleap(tm->tm_year)][tm->tm_mon - 1], str);
date = (date2j( tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000,1,1));
date = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1));
return(date);
} /* date_in() */
return (date);
} /* date_in() */
/* date_out()
* Given internal format date, convert to text string.
*/
char *
char *
date_out(DateADT date)
{
char *result;
struct tm tt, *tm = &tt;
char buf[MAXDATELEN+1];
char *result;
struct tm tt,
*tm = &tt;
char buf[MAXDATELEN + 1];
#if FALSE
int year, month, day;
int year,
month,
day;
#endif
j2date( (date + date2j(2000,1,1)),
&(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
j2date((date + date2j(2000, 1, 1)),
&(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
EncodeDateOnly( tm, DateStyle, buf);
EncodeDateOnly(tm, DateStyle, buf);
#if FALSE
if (EuroDates == 1) /* Output European-format dates */
sprintf(buf, "%02d-%02d-%04d", day, month, year);
else
sprintf(buf, "%02d-%02d-%04d", month, day, year);
if (EuroDates == 1) /* Output European-format dates */
sprintf(buf, "%02d-%02d-%04d", day, month, year);
else
sprintf(buf, "%02d-%02d-%04d", month, day, year);
#endif
result = PALLOC(strlen(buf)+1);
result = PALLOC(strlen(buf) + 1);
strcpy( result, buf);
strcpy(result, buf);
return(result);
} /* date_out() */
return (result);
} /* date_out() */
bool
date_eq(DateADT dateVal1, DateADT dateVal2)
{
return(dateVal1 == dateVal2);
return (dateVal1 == dateVal2);
}
bool
date_ne(DateADT dateVal1, DateADT dateVal2)
{
return(dateVal1 != dateVal2);
return (dateVal1 != dateVal2);
}
bool
date_lt(DateADT dateVal1, DateADT dateVal2)
{
return(dateVal1 < dateVal2);
} /* date_lt() */
return (dateVal1 < dateVal2);
} /* date_lt() */
bool
date_le(DateADT dateVal1, DateADT dateVal2)
{
return(dateVal1 <= dateVal2);
} /* date_le() */
return (dateVal1 <= dateVal2);
} /* date_le() */
bool
date_gt(DateADT dateVal1, DateADT dateVal2)
{
return(dateVal1 > dateVal2);
} /* date_gt() */
return (dateVal1 > dateVal2);
} /* date_gt() */
bool
date_ge(DateADT dateVal1, DateADT dateVal2)
{
return(dateVal1 >= dateVal2);
} /* date_ge() */
return (dateVal1 >= dateVal2);
} /* date_ge() */
int
date_cmp(DateADT dateVal1, DateADT dateVal2)
{
if (dateVal1 < dateVal2) {
return -1;
} else if (dateVal1 > dateVal2) {
return 1;
}
return 0;
} /* date_cmp() */
if (dateVal1 < dateVal2)
{
return -1;
}
else if (dateVal1 > dateVal2)
{
return 1;
}
return 0;
} /* date_cmp() */
DateADT
date_larger(DateADT dateVal1, DateADT dateVal2)
{
return(date_gt(dateVal1, dateVal2) ? dateVal1 : dateVal2);
} /* date_larger() */
return (date_gt(dateVal1, dateVal2) ? dateVal1 : dateVal2);
} /* date_larger() */
DateADT
date_smaller(DateADT dateVal1, DateADT dateVal2)
{
return(date_lt(dateVal1, dateVal2) ? dateVal1 : dateVal2);
} /* date_smaller() */
return (date_lt(dateVal1, dateVal2) ? dateVal1 : dateVal2);
} /* date_smaller() */
/* Compute difference between two dates in days. */
int4
date_mi(DateADT dateVal1, DateADT dateVal2)
{
return(dateVal1-dateVal2);
} /* date_mi() */
return (dateVal1 - dateVal2);
} /* date_mi() */
/* Add a number of days to a date, giving a new date.
Must handle both positive and negative numbers of days. */
Must handle both positive and negative numbers of days. */
DateADT
date_pli(DateADT dateVal, int4 days)
{
return(dateVal+days);
} /* date_pli() */
return (dateVal + days);
} /* date_pli() */
/* Subtract a number of days from a date, giving a new date. */
DateADT
date_mii(DateADT dateVal, int4 days)
{
return(date_pli(dateVal, -days));
} /* date_mii() */
return (date_pli(dateVal, -days));
} /* date_mii() */
/* date_datetime()
* Convert date to datetime data type.
*/
DateTime *
DateTime *
date_datetime(DateADT dateVal)
{
DateTime *result;
struct tm tt, *tm = &tt;
int tz;
double fsec = 0;
char *tzn;
DateTime *result;
struct tm tt,
*tm = &tt;
int tz;
double fsec = 0;
char *tzn;
result = PALLOCTYPE(DateTime);
result = PALLOCTYPE(DateTime);
if (date2tm( dateVal, &tz, tm, &fsec, &tzn) != 0)
elog(WARN,"Unable to convert date to datetime",NULL);
if (date2tm(dateVal, &tz, tm, &fsec, &tzn) != 0)
elog(WARN, "Unable to convert date to datetime", NULL);
#ifdef DATEDEBUG
printf( "date_datetime- date is %d.%02d.%02d\n", tm->tm_year, tm->tm_mon, tm->tm_mday);
printf( "date_datetime- time is %02d:%02d:%02d %.7f\n", tm->tm_hour, tm->tm_min, tm->tm_sec, fsec);
printf("date_datetime- date is %d.%02d.%02d\n", tm->tm_year, tm->tm_mon, tm->tm_mday);
printf("date_datetime- time is %02d:%02d:%02d %.7f\n", tm->tm_hour, tm->tm_min, tm->tm_sec, fsec);
#endif
if (tm2datetime( tm, fsec, &tz, result) != 0)
elog(WARN,"Datetime out of range",NULL);
if (tm2datetime(tm, fsec, &tz, result) != 0)
elog(WARN, "Datetime out of range", NULL);
return(result);
} /* date_datetime() */
return (result);
} /* date_datetime() */
/* datetime_date()
* Convert datetime to date data type.
*/
DateADT
datetime_date(DateTime *datetime)
datetime_date(DateTime * datetime)
{
DateADT result;
struct tm tt, *tm = &tt;
int tz;
double fsec;
char *tzn;
DateADT result;
struct tm tt,
*tm = &tt;
int tz;
double fsec;
char *tzn;
if (!PointerIsValid(datetime))
elog(WARN,"Unable to convert null datetime to date",NULL);
if (!PointerIsValid(datetime))
elog(WARN, "Unable to convert null datetime to date", NULL);
if (DATETIME_NOT_FINITE(*datetime))
elog(WARN,"Unable to convert datetime to date",NULL);
if (DATETIME_NOT_FINITE(*datetime))
elog(WARN, "Unable to convert datetime to date", NULL);
if (DATETIME_IS_EPOCH(*datetime)) {
datetime2tm( SetDateTime(*datetime), NULL, tm, &fsec, NULL);
if (DATETIME_IS_EPOCH(*datetime))
{
datetime2tm(SetDateTime(*datetime), NULL, tm, &fsec, NULL);
} else if (DATETIME_IS_CURRENT(*datetime)) {
datetime2tm( SetDateTime(*datetime), &tz, tm, &fsec, &tzn);
}
else if (DATETIME_IS_CURRENT(*datetime))
{
datetime2tm(SetDateTime(*datetime), &tz, tm, &fsec, &tzn);
} else {
if (datetime2tm( *datetime, &tz, tm, &fsec, &tzn) != 0)
elog(WARN,"Unable to convert datetime to date",NULL);
}
}
else
{
if (datetime2tm(*datetime, &tz, tm, &fsec, &tzn) != 0)
elog(WARN, "Unable to convert datetime to date", NULL);
}
result = (date2j( tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j( 2000, 1, 1));
result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1));
return(result);
} /* datetime_date() */
return (result);
} /* datetime_date() */
/* abstime_date()
@ -295,289 +311,320 @@ datetime_date(DateTime *datetime)
DateADT
abstime_date(AbsoluteTime abstime)
{
DateADT result;
struct tm tt, *tm = &tt;
int tz;
DateADT result;
struct tm tt,
*tm = &tt;
int tz;
switch (abstime) {
case INVALID_ABSTIME:
case NOSTART_ABSTIME:
case NOEND_ABSTIME:
elog(WARN,"Unable to convert reserved abstime value to date",NULL);
/* pretend to drop through to make compiler think that result will be set */
switch (abstime)
{
case INVALID_ABSTIME:
case NOSTART_ABSTIME:
case NOEND_ABSTIME:
elog(WARN, "Unable to convert reserved abstime value to date", NULL);
case EPOCH_ABSTIME:
result = date2j(1970,1,1) - date2j(2000,1,1);
break;
/*
* pretend to drop through to make compiler think that result will
* be set
*/
case CURRENT_ABSTIME:
GetCurrentTime(tm);
result = date2j( tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000,1,1);
break;
case EPOCH_ABSTIME:
result = date2j(1970, 1, 1) - date2j(2000, 1, 1);
break;
default:
abstime2tm(abstime, &tz, tm, NULL);
result = date2j(tm->tm_year,tm->tm_mon,tm->tm_mday) - date2j(2000,1,1);
break;
}
case CURRENT_ABSTIME:
GetCurrentTime(tm);
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
break;
return(result);
} /* abstime_date() */
default:
abstime2tm(abstime, &tz, tm, NULL);
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
break;
}
return (result);
} /* abstime_date() */
/* date2tm()
* Convert date to time structure.
* Note that date is an implicit local time, but the system calls assume
* that everything is GMT. So, convert to GMT, rotate to local time,
* and then convert again to try to get the time zones correct.
* that everything is GMT. So, convert to GMT, rotate to local time,
* and then convert again to try to get the time zones correct.
*/
static int
date2tm(DateADT dateVal, int *tzp, struct tm *tm, double *fsec, char **tzn)
date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn)
{
struct tm *tx;
time_t utime;
*fsec = 0;
struct tm *tx;
time_t utime;
j2date( (dateVal + date2j( 2000, 1, 1)), &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
tm->tm_hour = 0;
tm->tm_min = 0;
tm->tm_sec = 0;
tm->tm_isdst = -1;
*fsec = 0;
if (IS_VALID_UTIME( tm->tm_year, tm->tm_mon, tm->tm_mday)) {
/* convert to system time */
utime = ((dateVal + (date2j(2000,1,1)-date2j(1970,1,1)))*86400);
utime += (12*60*60); /* rotate to noon to get the right day in time zone */
#ifdef USE_POSIX_TIME
tx = localtime(&utime);
#ifdef DATEDEBUG
#ifdef HAVE_INT_TIMEZONE
printf( "date2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s %s dst=%d\n",
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, (double) tm->tm_sec,
tzname[0], tzname[1], tx->tm_isdst);
#endif
#endif
tm->tm_year = tx->tm_year + 1900;
tm->tm_mon = tx->tm_mon + 1;
tm->tm_mday = tx->tm_mday;
#if FALSE
tm->tm_hour = tx->tm_hour;
tm->tm_min = tx->tm_min;
tm->tm_sec = tx->tm_sec;
#endif
tm->tm_isdst = tx->tm_isdst;
#ifdef HAVE_INT_TIMEZONE
*tzp = (tm->tm_isdst? (timezone - 3600): timezone);
if (tzn != NULL) *tzn = tzname[(tm->tm_isdst > 0)];
#else /* !HAVE_INT_TIMEZONE */
tm->tm_gmtoff = tx->tm_gmtoff;
tm->tm_zone = tx->tm_zone;
*tzp = (tm->tm_isdst? (tm->tm_gmtoff - 3600): tm->tm_gmtoff); /* tm_gmtoff is Sun/DEC-ism */
if (tzn != NULL) *tzn = tm->tm_zone;
#endif
#else /* !USE_POSIX_TIME */
*tzp = CTimeZone; /* V7 conventions; don't know timezone? */
if (tzn != NULL) *tzn = CTZName;
#endif
/* otherwise, outside of timezone range so convert to GMT... */
} else {
#if FALSE
j2date( (dateVal + date2j( 2000, 1, 1)), &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
j2date((dateVal + date2j(2000, 1, 1)), &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
tm->tm_hour = 0;
tm->tm_min = 0;
tm->tm_sec = 0;
tm->tm_isdst = -1;
if (IS_VALID_UTIME(tm->tm_year, tm->tm_mon, tm->tm_mday))
{
/* convert to system time */
utime = ((dateVal + (date2j(2000, 1, 1) - date2j(1970, 1, 1))) * 86400);
utime += (12 * 60 * 60);/* rotate to noon to get the right day in
* time zone */
#ifdef USE_POSIX_TIME
tx = localtime(&utime);
#ifdef DATEDEBUG
#ifdef HAVE_INT_TIMEZONE
printf("date2tm- (localtime) %d.%02d.%02d %02d:%02d:%02.0f %s %s dst=%d\n",
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, (double) tm->tm_sec,
tzname[0], tzname[1], tx->tm_isdst);
#endif
#endif
tm->tm_year = tx->tm_year + 1900;
tm->tm_mon = tx->tm_mon + 1;
tm->tm_mday = tx->tm_mday;
#if FALSE
tm->tm_hour = tx->tm_hour;
tm->tm_min = tx->tm_min;
tm->tm_sec = tx->tm_sec;
#endif
tm->tm_isdst = tx->tm_isdst;
#ifdef HAVE_INT_TIMEZONE
*tzp = (tm->tm_isdst ? (timezone - 3600) : timezone);
if (tzn != NULL)
*tzn = tzname[(tm->tm_isdst > 0)];
#else /* !HAVE_INT_TIMEZONE */
tm->tm_gmtoff = tx->tm_gmtoff;
tm->tm_zone = tx->tm_zone;
*tzp = (tm->tm_isdst ? (tm->tm_gmtoff - 3600) : tm->tm_gmtoff); /* tm_gmtoff is
* Sun/DEC-ism */
if (tzn != NULL)
*tzn = tm->tm_zone;
#endif
#else /* !USE_POSIX_TIME */
*tzp = CTimeZone; /* V7 conventions; don't know timezone? */
if (tzn != NULL)
*tzn = CTZName;
#endif
/* otherwise, outside of timezone range so convert to GMT... */
}
else
{
#if FALSE
j2date((dateVal + date2j(2000, 1, 1)), &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
tm->tm_hour = 0;
tm->tm_min = 0;
tm->tm_sec = 0;
#endif
#ifdef DATEDEBUG
printf( "date2tm- convert %d-%d-%d %d:%d%d to datetime\n",
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
printf("date2tm- convert %d-%d-%d %d:%d%d to datetime\n",
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
#endif
*tzp = 0;
tm->tm_isdst = 0;
if (tzn != NULL) *tzn = NULL;
}
*tzp = 0;
tm->tm_isdst = 0;
if (tzn != NULL)
*tzn = NULL;
}
return 0;
} /* date2tm() */
return 0;
} /* date2tm() */
/*****************************************************************************
* Time ADT
* Time ADT
*****************************************************************************/
TimeADT *
TimeADT *
time_in(char *str)
{
TimeADT *time;
TimeADT *time;
double fsec;
struct tm tt, *tm = &tt;
double fsec;
struct tm tt,
*tm = &tt;
int nf;
char lowstr[MAXDATELEN+1];
char *field[MAXDATEFIELDS];
int dtype;
int ftype[MAXDATEFIELDS];
int nf;
char lowstr[MAXDATELEN + 1];
char *field[MAXDATEFIELDS];
int dtype;
int ftype[MAXDATEFIELDS];
if (!PointerIsValid(str))
elog(WARN,"Bad (null) time external representation",NULL);
if (!PointerIsValid(str))
elog(WARN, "Bad (null) time external representation", NULL);
if ((ParseDateTime( str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeTimeOnly( field, ftype, nf, &dtype, tm, &fsec) != 0))
elog(WARN,"Bad time external representation '%s'",str);
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec) != 0))
elog(WARN, "Bad time external representation '%s'", str);
if ((tm->tm_hour < 0) || (tm->tm_hour > 23))
elog(WARN,"Hour must be limited to values 0 through 23 in '%s'",str);
if ((tm->tm_min < 0) || (tm->tm_min > 59))
elog(WARN,"Minute must be limited to values 0 through 59 in '%s'",str);
if ((tm->tm_sec < 0) || ((tm->tm_sec + fsec) >= 60))
elog(WARN,"Second must be limited to values 0 through < 60 in '%s'",str);
if ((tm->tm_hour < 0) || (tm->tm_hour > 23))
elog(WARN, "Hour must be limited to values 0 through 23 in '%s'", str);
if ((tm->tm_min < 0) || (tm->tm_min > 59))
elog(WARN, "Minute must be limited to values 0 through 59 in '%s'", str);
if ((tm->tm_sec < 0) || ((tm->tm_sec + fsec) >= 60))
elog(WARN, "Second must be limited to values 0 through < 60 in '%s'", str);
time = PALLOCTYPE(TimeADT);
time = PALLOCTYPE(TimeADT);
*time = ((((tm->tm_hour*60)+tm->tm_min)*60)+tm->tm_sec+fsec);
*time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
return(time);
} /* time_in() */
return (time);
} /* time_in() */
char *
time_out(TimeADT *time)
char *
time_out(TimeADT * time)
{
char *result;
struct tm tt, *tm = &tt;
char *result;
struct tm tt,
*tm = &tt;
#if FALSE
int hour, min, sec;
int hour,
min,
sec;
#endif
double fsec;
char buf[MAXDATELEN+1];
double fsec;
char buf[MAXDATELEN + 1];
if (!PointerIsValid(time))
return NULL;
if (!PointerIsValid(time))
return NULL;
tm->tm_hour = (*time / (60*60));
tm->tm_min = (((int) (*time / 60)) % 60);
tm->tm_sec = (((int) *time) % 60);
tm->tm_hour = (*time / (60 * 60));
tm->tm_min = (((int) (*time / 60)) % 60);
tm->tm_sec = (((int) *time) % 60);
fsec = 0;
fsec = 0;
EncodeTimeOnly( tm, fsec, DateStyle, buf);
EncodeTimeOnly(tm, fsec, DateStyle, buf);
#if FALSE
if (sec == 0.0) {
sprintf(buf, "%02d:%02d", hour, min);
if (sec == 0.0)
{
sprintf(buf, "%02d:%02d", hour, min);
} else {
if (fsec == 0) {
sprintf(buf, "%02d:%02d:%02d", hour, min, sec);
} else {
sprintf(buf, "%02d:%02d:%05.2f", hour, min, (sec+fsec));
}
}
else
{
if (fsec == 0)
{
sprintf(buf, "%02d:%02d:%02d", hour, min, sec);
}
else
{
sprintf(buf, "%02d:%02d:%05.2f", hour, min, (sec + fsec));
}
}
#endif
result = PALLOC(strlen(buf)+1);
result = PALLOC(strlen(buf) + 1);
strcpy( result, buf);
strcpy(result, buf);
return(result);
} /* time_out() */
return (result);
} /* time_out() */
bool
time_eq(TimeADT *time1, TimeADT *time2)
time_eq(TimeADT * time1, TimeADT * time2)
{
if (!PointerIsValid(time1) || !PointerIsValid(time2))
return(FALSE);
if (!PointerIsValid(time1) || !PointerIsValid(time2))
return (FALSE);
return(*time1 == *time2);
} /* time_eq() */
return (*time1 == *time2);
} /* time_eq() */
bool
time_ne(TimeADT *time1, TimeADT *time2)
time_ne(TimeADT * time1, TimeADT * time2)
{
if (!PointerIsValid(time1) || !PointerIsValid(time2))
return(FALSE);
if (!PointerIsValid(time1) || !PointerIsValid(time2))
return (FALSE);
return(*time1 != *time2);
} /* time_eq() */
return (*time1 != *time2);
} /* time_eq() */
bool
time_lt(TimeADT *time1, TimeADT *time2)
time_lt(TimeADT * time1, TimeADT * time2)
{
if (!PointerIsValid(time1) || !PointerIsValid(time2))
return(FALSE);
if (!PointerIsValid(time1) || !PointerIsValid(time2))
return (FALSE);
return(*time1 < *time2);
} /* time_eq() */
return (*time1 < *time2);
} /* time_eq() */
bool
time_le(TimeADT *time1, TimeADT *time2)
time_le(TimeADT * time1, TimeADT * time2)
{
if (!PointerIsValid(time1) || !PointerIsValid(time2))
return(FALSE);
if (!PointerIsValid(time1) || !PointerIsValid(time2))
return (FALSE);
return(*time1 <= *time2);
} /* time_eq() */
return (*time1 <= *time2);
} /* time_eq() */
bool
time_gt(TimeADT *time1, TimeADT *time2)
time_gt(TimeADT * time1, TimeADT * time2)
{
if (!PointerIsValid(time1) || !PointerIsValid(time2))
return(FALSE);
if (!PointerIsValid(time1) || !PointerIsValid(time2))
return (FALSE);
return(*time1 > *time2);
} /* time_eq() */
return (*time1 > *time2);
} /* time_eq() */
bool
time_ge(TimeADT *time1, TimeADT *time2)
time_ge(TimeADT * time1, TimeADT * time2)
{
if (!PointerIsValid(time1) || !PointerIsValid(time2))
return(FALSE);
if (!PointerIsValid(time1) || !PointerIsValid(time2))
return (FALSE);
return(*time1 >= *time2);
} /* time_eq() */
return (*time1 >= *time2);
} /* time_eq() */
int
time_cmp(TimeADT *time1, TimeADT *time2)
time_cmp(TimeADT * time1, TimeADT * time2)
{
return((*time1 < *time2)? -1: (((*time1 > *time2)? 1: 0)));
} /* time_cmp() */
return ((*time1 < *time2) ? -1 : (((*time1 > *time2) ? 1 : 0)));
} /* time_cmp() */
/* datetime_datetime()
* Convert date and time to datetime data type.
*/
DateTime *
datetime_datetime(DateADT date, TimeADT *time)
DateTime *
datetime_datetime(DateADT date, TimeADT * time)
{
DateTime *result;
DateTime *result;
if (!PointerIsValid(time)) {
result = PALLOCTYPE(DateTime);
DATETIME_INVALID(*result);
if (!PointerIsValid(time))
{
result = PALLOCTYPE(DateTime);
DATETIME_INVALID(*result);
} else {
result = date_datetime(date);
*result += *time;
}
}
else
{
result = date_datetime(date);
*result += *time;
}
return(result);
} /* datetime_datetime() */
return (result);
} /* datetime_datetime() */
int32 /* RelativeTime */
int32 /* RelativeTime */
int42reltime(int32 timevalue)
{
return(timevalue);
return (timevalue);
}