mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Add datetime macros for constants, for clarity:
#define SECS_PER_DAY 86400 #define USECS_PER_DAY INT64CONST(86400000000) #define USECS_PER_HOUR INT64CONST(3600000000) #define USECS_PER_MINUTE INT64CONST(60000000) #define USECS_PER_SEC INT64CONST(1000000)
This commit is contained in:
@@ -2255,7 +2255,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
|
||||
|
||||
tmask |= DTK_TIME_M;
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
dt2time((time * INT64CONST(86400000000)), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
|
||||
dt2time((time * USECS_PER_DAY), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
|
||||
#else
|
||||
dt2time((time * 86400), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
|
||||
#endif
|
||||
|
@@ -700,8 +700,8 @@ interval2tm(interval span, struct tm * tm, fsec_t *fsec)
|
||||
time = span.time;
|
||||
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
tm->tm_mday = (time / INT64CONST(86400000000));
|
||||
time -= (tm->tm_mday * INT64CONST(86400000000));
|
||||
tm->tm_mday = (time / USECS_PER_DAY);
|
||||
time -= (tm->tm_mday * USECS_PER_DAY);
|
||||
tm->tm_hour = (time / INT64CONST(3600000000));
|
||||
time -= (tm->tm_hour * INT64CONST(3600000000));
|
||||
tm->tm_min = (time / INT64CONST(60000000));
|
||||
|
@@ -69,9 +69,9 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp *result)
|
||||
dDate = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
|
||||
time = time2t(tm->tm_hour, tm->tm_min, tm->tm_sec, fsec);
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
*result = (dDate * INT64CONST(86400000000)) + time;
|
||||
*result = (dDate * USECS_PER_DAY) + time;
|
||||
/* check for major overflow */
|
||||
if ((*result - time) / INT64CONST(86400000000) != dDate)
|
||||
if ((*result - time) / USECS_PER_DAY != dDate)
|
||||
return -1;
|
||||
/* check for just-barely overflow (okay except time-of-day wraps) */
|
||||
if ((*result < 0) ? (dDate >= 0) : (dDate < 0))
|
||||
@@ -163,11 +163,11 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
|
||||
|
||||
time = dt;
|
||||
#ifdef HAVE_INT64_TIMESTAMP
|
||||
TMODULO(time, dDate, INT64CONST(86400000000));
|
||||
TMODULO(time, dDate, USECS_PER_DAY);
|
||||
|
||||
if (time < INT64CONST(0))
|
||||
{
|
||||
time += INT64CONST(86400000000);
|
||||
time += USECS_PER_DAY;
|
||||
dDate -= 1;
|
||||
}
|
||||
#else
|
||||
|
Reference in New Issue
Block a user