mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +03:00
Remove difftime() calls.
Still uses time_t declarations, but most code will be changed for next release.
This commit is contained in:
parent
43163cf5d6
commit
31174f11d0
@ -5,122 +5,13 @@
|
|||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
|
#include "access/xact.h"
|
||||||
|
|
||||||
/* sunos doesn't have this function */
|
|
||||||
#if defined(sunos4)
|
|
||||||
#define difftime(time1,time0) ((time1) - (time0))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if FALSE
|
|
||||||
/* copy the next part of the string into a buffer */
|
|
||||||
static const char *
|
|
||||||
cpstr(const char *s, char *buf)
|
|
||||||
{
|
|
||||||
char in = 0;
|
|
||||||
|
|
||||||
while (isspace(*s))
|
|
||||||
s++;
|
|
||||||
|
|
||||||
for (; *s && !isspace(*s); s++)
|
|
||||||
{
|
|
||||||
if (strchr("-,:/", *s))
|
|
||||||
{
|
|
||||||
buf[in] = 0;
|
|
||||||
return (s + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in < 16)
|
|
||||||
buf[in++] = tolower(*s);
|
|
||||||
}
|
|
||||||
|
|
||||||
buf[in] = 0;
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* assumes dd/mm/yyyy unless first item is month in word form */
|
|
||||||
time_t
|
time_t
|
||||||
timestamp_in(const char *timestamp_str)
|
timestamp_in(const char *timestamp_str)
|
||||||
{
|
{
|
||||||
int4 result;
|
int4 result;
|
||||||
|
|
||||||
#if FALSE
|
|
||||||
struct tm input_time;
|
|
||||||
char buf[18];
|
|
||||||
const char *p;
|
|
||||||
static const char *mstr[] = {
|
|
||||||
"january", "february", "march", "april", "may", "june",
|
|
||||||
"july", "august", "september", "october", "november", "december"
|
|
||||||
};
|
|
||||||
|
|
||||||
memset(&input_time, 0, sizeof(input_time));
|
|
||||||
p = cpstr(timestamp_str, buf);
|
|
||||||
if (isdigit(buf[0])) /* must be dd/mm/yyyy */
|
|
||||||
{
|
|
||||||
input_time.tm_mday = atoi(buf);
|
|
||||||
p = cpstr(p, buf);
|
|
||||||
if (!buf[0])
|
|
||||||
elog(WARN, "timestamp_in: timestamp \"%s\" not a proper date",
|
|
||||||
timestamp_str);
|
|
||||||
if (isdigit(buf[0]))
|
|
||||||
{
|
|
||||||
input_time.tm_mon = atoi(buf) - 1;
|
|
||||||
if (input_time.tm_mon < 0 || input_time.tm_mon > 11)
|
|
||||||
elog(WARN, "timestamp_in: timestamp \"%s\" invalid month",
|
|
||||||
timestamp_str);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < 12; i++)
|
|
||||||
if (strncmp(mstr[i], buf, strlen(buf)) == 0)
|
|
||||||
break;
|
|
||||||
if (1 > 11)
|
|
||||||
elog(WARN, "timestamp_in: timestamp \"%s\" invalid month",
|
|
||||||
timestamp_str);
|
|
||||||
input_time.tm_mon = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
/* must be month/dd/yyyy */
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < 12; i++)
|
|
||||||
if (strncmp(mstr[i], buf, strlen(buf)) == 0)
|
|
||||||
break;
|
|
||||||
if (1 > 11)
|
|
||||||
elog(WARN, "timestamp_in: timestamp \"%s\" invalid month",
|
|
||||||
timestamp_str);
|
|
||||||
input_time.tm_mon = i;
|
|
||||||
p = cpstr(p, buf);
|
|
||||||
input_time.tm_mday = atoi(buf);
|
|
||||||
if (!input_time.tm_mday || input_time.tm_mday > 31)
|
|
||||||
elog(WARN, "timestamp_in: timestamp \"%s\" not a proper date",
|
|
||||||
timestamp_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
p = cpstr(p, buf);
|
|
||||||
if (!buf[0] || !isdigit(buf[0]))
|
|
||||||
elog(WARN, "timestamp_in: timestamp \"%s\" not a proper date",
|
|
||||||
timestamp_str);
|
|
||||||
if ((input_time.tm_year = atoi(buf)) < 1900)
|
|
||||||
input_time.tm_year += 1900;
|
|
||||||
|
|
||||||
/* now get the time */
|
|
||||||
p = cpstr(p, buf);
|
|
||||||
input_time.tm_hour = atoi(buf);
|
|
||||||
p = cpstr(p, buf);
|
|
||||||
input_time.tm_min = atoi(buf);
|
|
||||||
p = cpstr(p, buf);
|
|
||||||
input_time.tm_sec = atoi(buf);
|
|
||||||
|
|
||||||
/* use mktime(), but make this GMT, not local time */
|
|
||||||
result = mktime(&input_time);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
result = nabstimein((char *) timestamp_str);
|
result = nabstimein((char *) timestamp_str);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -138,13 +29,6 @@ timestamp_out(time_t timestamp)
|
|||||||
char zone[MAXDATELEN + 1],
|
char zone[MAXDATELEN + 1],
|
||||||
*tzn = zone;
|
*tzn = zone;
|
||||||
|
|
||||||
#if FALSE
|
|
||||||
time = localtime(×tamp);
|
|
||||||
|
|
||||||
sprintf(result, "%04d-%02d-%02d %02d:%02d:%02d",
|
|
||||||
time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
|
|
||||||
time->tm_hour, time->tm_min, time->tm_sec);
|
|
||||||
#endif
|
|
||||||
abstime2tm(timestamp, &tz, tm, tzn);
|
abstime2tm(timestamp, &tz, tm, tzn);
|
||||||
EncodeDateTime(tm, fsec, &tz, &tzn, USE_ISO_DATES, buf);
|
EncodeDateTime(tm, fsec, &tz, &tzn, USE_ISO_DATES, buf);
|
||||||
|
|
||||||
@ -158,44 +42,62 @@ now(void)
|
|||||||
{
|
{
|
||||||
time_t sec;
|
time_t sec;
|
||||||
|
|
||||||
time(&sec);
|
sec = GetCurrentTransactionStartTime();
|
||||||
return (sec);
|
return (sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
timestampeq(time_t t1, time_t t2)
|
timestampeq(time_t t1, time_t t2)
|
||||||
{
|
{
|
||||||
return difftime(t1, t2) == 0;
|
#if FALSE
|
||||||
|
return(t1 == t2);
|
||||||
|
#endif
|
||||||
|
return(abstimeeq(t1,t2));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
timestampne(time_t t1, time_t t2)
|
timestampne(time_t t1, time_t t2)
|
||||||
{
|
{
|
||||||
return difftime(t1, t2) != 0;
|
#if FALSE
|
||||||
|
return(t1 != t2);
|
||||||
|
#endif
|
||||||
|
return(abstimene(t1,t2));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
timestamplt(time_t t1, time_t t2)
|
timestamplt(time_t t1, time_t t2)
|
||||||
{
|
{
|
||||||
return difftime(t1, t2) > 0;
|
#if FALSE
|
||||||
|
return(t1 > t2);
|
||||||
|
#endif
|
||||||
|
return(abstimelt(t1,t2));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
timestampgt(time_t t1, time_t t2)
|
timestampgt(time_t t1, time_t t2)
|
||||||
{
|
{
|
||||||
return difftime(t1, t2) < 0;
|
#if FALSE
|
||||||
|
return(t1 < t2);
|
||||||
|
#endif
|
||||||
|
return(abstimegt(t1,t2));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
timestample(time_t t1, time_t t2)
|
timestample(time_t t1, time_t t2)
|
||||||
{
|
{
|
||||||
return difftime(t1, t2) >= 0;
|
#if FALSE
|
||||||
|
return(t1 >= t2);
|
||||||
|
#endif
|
||||||
|
return(abstimele(t1,t2));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
timestampge(time_t t1, time_t t2)
|
timestampge(time_t t1, time_t t2)
|
||||||
{
|
{
|
||||||
return difftime(t1, t2) <= 0;
|
#if FALSE
|
||||||
|
return(t1 <= t2);
|
||||||
|
#endif
|
||||||
|
return(abstimege(t1,t2));
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime *
|
DateTime *
|
||||||
|
Loading…
x
Reference in New Issue
Block a user