summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg
diff options
context:
space:
mode:
authorBruce Momjian2005-05-23 21:54:02 +0000
committerBruce Momjian2005-05-23 21:54:02 +0000
commit4550c1e519ee1bdd33897def9cbe47516fcbc757 (patch)
treed963bdd1440476f246fdda92f0809e58eddc5f2f /src/interfaces/ecpg
parent5ebaae801c278b1801f54fcce5a651b3a7ce9af1 (diff)
More macro cleanups for date/time.
Diffstat (limited to 'src/interfaces/ecpg')
-rw-r--r--src/interfaces/ecpg/pgtypeslib/datetime.c4
-rw-r--r--src/interfaces/ecpg/pgtypeslib/dt.h8
-rw-r--r--src/interfaces/ecpg/pgtypeslib/dt_common.c16
-rw-r--r--src/interfaces/ecpg/pgtypeslib/interval.c28
-rw-r--r--src/interfaces/ecpg/pgtypeslib/timestamp.c32
5 files changed, 48 insertions, 40 deletions
diff --git a/src/interfaces/ecpg/pgtypeslib/datetime.c b/src/interfaces/ecpg/pgtypeslib/datetime.c
index 30781d734f5..cda4e5aab8e 100644
--- a/src/interfaces/ecpg/pgtypeslib/datetime.c
+++ b/src/interfaces/ecpg/pgtypeslib/datetime.c
@@ -22,10 +22,10 @@ PGTYPESdate_from_timestamp(timestamp dt)
#ifdef HAVE_INT64_TIMESTAMP
/* Microseconds to days */
- dDate = (dt / INT64CONST(86400000000));
+ dDate = (dt / USECS_PER_DAY);
#else
/* Seconds to days */
- dDate = (dt / 86400.0);
+ dDate = (dt / (double)SECS_PER_DAY);
#endif
return dDate;
diff --git a/src/interfaces/ecpg/pgtypeslib/dt.h b/src/interfaces/ecpg/pgtypeslib/dt.h
index e000ec4411c..53108a85bf4 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt.h
+++ b/src/interfaces/ecpg/pgtypeslib/dt.h
@@ -216,6 +216,14 @@ do { \
} while(0)
#endif
+#define SECS_PER_DAY 86400
+#ifdef HAVE_INT64_TIMESTAMP
+#define USECS_PER_DAY INT64CONST(86400000000)
+#define USECS_PER_HOUR INT64CONST(3600000000)
+#define USECS_PER_MINUTE INT64CONST(60000000)
+#define USECS_PER_SEC INT64CONST(1000000)
+#endif
+
/*
* Date/time validation
* Include check for leap year.
diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c
index 91a8d611b39..f516d281d45 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt_common.c
+++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c
@@ -1246,12 +1246,12 @@ dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec)
time = jd;
#ifdef HAVE_INT64_TIMESTAMP
- *hour = (time / INT64CONST(3600000000));
- time -= ((*hour) * INT64CONST(3600000000));
- *min = (time / INT64CONST(60000000));
- time -= ((*min) * INT64CONST(60000000));
- *sec = (time / INT64CONST(1000000));
- *fsec = (time - (*sec * INT64CONST(1000000)));
+ *hour = (time / USECS_PER_HOUR);
+ time -= ((*hour) * USECS_PER_HOUR);
+ *min = (time / USECS_PER_MINUTE);
+ time -= ((*min) * USECS_PER_MINUTE);
+ *sec = (time / USECS_PER_SEC);
+ *fsec = (time - (*sec * USECS_PER_SEC));
#else
*hour = (time / 3600);
time -= ((*hour) * 3600);
@@ -1675,7 +1675,7 @@ DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec)
if ((tm->tm_hour < 0)
|| (tm->tm_min < 0) || (tm->tm_min > 59)
|| (tm->tm_sec < 0) || (tm->tm_sec > 59)
- || (*fsec >= INT64CONST(1000000)))
+ || (*fsec >= USECS_PER_SEC))
return -1;
#else
if ((tm->tm_hour < 0)
@@ -2257,7 +2257,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
#ifdef HAVE_INT64_TIMESTAMP
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);
+ dt2time((time * SECS_PER_DAY), &tm->tm_hour, &tm->tm_min, &tm->tm_sec, fsec);
#endif
}
break;
diff --git a/src/interfaces/ecpg/pgtypeslib/interval.c b/src/interfaces/ecpg/pgtypeslib/interval.c
index eb18e6ce912..3c09071ce79 100644
--- a/src/interfaces/ecpg/pgtypeslib/interval.c
+++ b/src/interfaces/ecpg/pgtypeslib/interval.c
@@ -88,7 +88,7 @@ DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec)
if ((tm->tm_hour < 0)
|| (tm->tm_min < 0) || (tm->tm_min > 59)
|| (tm->tm_sec < 0) || (tm->tm_sec > 59)
- || (*fsec >= INT64CONST(1000000)))
+ || (*fsec >= USECS_PER_SEC))
return -1;
#else
if ((tm->tm_hour < 0)
@@ -296,7 +296,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm * tm, fse
{
int sec;
- fval *= 86400;
+ fval *= SECS_PER_DAY;
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
@@ -314,7 +314,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm * tm, fse
{
int sec;
- fval *= (7 * 86400);
+ fval *= (7 * SECS_PER_DAY);
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
@@ -332,7 +332,7 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm * tm, fse
{
int sec;
- fval *= (30 * 86400);
+ fval *= (30 * SECS_PER_DAY);
sec = fval;
tm->tm_sec += sec;
#ifdef HAVE_INT64_TIMESTAMP
@@ -419,8 +419,8 @@ DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm * tm, fse
int sec;
#ifdef HAVE_INT64_TIMESTAMP
- sec = (*fsec / INT64CONST(1000000));
- *fsec -= (sec * INT64CONST(1000000));
+ sec = (*fsec / USECS_PER_SEC);
+ *fsec -= (sec * USECS_PER_SEC);
#else
TMODULO(*fsec, sec, 1e0);
#endif
@@ -702,14 +702,14 @@ interval2tm(interval span, struct tm * tm, fsec_t *fsec)
#ifdef HAVE_INT64_TIMESTAMP
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));
- time -= (tm->tm_min * INT64CONST(60000000));
- tm->tm_sec = (time / INT64CONST(1000000));
- *fsec = (time - (tm->tm_sec * INT64CONST(1000000)));
+ tm->tm_hour = (time / USECS_PER_HOUR);
+ time -= (tm->tm_hour * USECS_PER_HOUR);
+ tm->tm_min = (time / USECS_PER_MINUTE);
+ time -= (tm->tm_min * USECS_PER_MINUTE);
+ tm->tm_sec = (time / USECS_PER_SEC);
+ *fsec = (time - (tm->tm_sec * USECS_PER_SEC));
#else
- TMODULO(time, tm->tm_mday, 86400e0);
+ TMODULO(time, tm->tm_mday, (double)SECS_PER_DAY);
TMODULO(time, tm->tm_hour, 3600e0);
TMODULO(time, tm->tm_min, 60e0);
TMODULO(time, tm->tm_sec, 1e0);
@@ -727,7 +727,7 @@ tm2interval(struct tm * tm, fsec_t fsec, interval *span)
span->time = ((((((((tm->tm_mday * INT64CONST(24))
+ tm->tm_hour) * INT64CONST(60))
+ tm->tm_min) * INT64CONST(60))
- + tm->tm_sec) * INT64CONST(1000000)) + fsec);
+ + tm->tm_sec) * USECS_PER_SEC) + fsec);
#else
span->time = ((((((tm->tm_mday * 24.0)
+ tm->tm_hour) * 60.0)
diff --git a/src/interfaces/ecpg/pgtypeslib/timestamp.c b/src/interfaces/ecpg/pgtypeslib/timestamp.c
index 971a4175174..836ae62e904 100644
--- a/src/interfaces/ecpg/pgtypeslib/timestamp.c
+++ b/src/interfaces/ecpg/pgtypeslib/timestamp.c
@@ -20,7 +20,7 @@ int PGTYPEStimestamp_defmt_scan(char **, char *, timestamp *, int *, int *, int
static int64
time2t(const int hour, const int min, const int sec, const fsec_t fsec)
{
- return ((((((hour * 60) + min) * 60) + sec) * INT64CONST(1000000)) + fsec);
+ return ((((((hour * 60) + min) * 60) + sec) * USECS_PER_SEC) + fsec);
} /* time2t() */
#else
@@ -35,7 +35,7 @@ static timestamp
dt2local(timestamp dt, int tz)
{
#ifdef HAVE_INT64_TIMESTAMP
- dt -= (tz * INT64CONST(1000000));
+ dt -= (tz * USECS_PER_SEC);
#else
dt -= tz;
dt = JROUND(dt);
@@ -77,7 +77,7 @@ tm2timestamp(struct tm * tm, fsec_t fsec, int *tzp, timestamp *result)
if ((*result < 0) ? (dDate >= 0) : (dDate < 0))
return -1;
#else
- *result = ((dDate * 86400) + time);
+ *result = ((dDate * SECS_PER_DAY) + time);
#endif
if (tzp != NULL)
*result = dt2local(*result, -(*tzp));
@@ -110,14 +110,14 @@ dt2time(timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
time = jd;
#ifdef HAVE_INT64_TIMESTAMP
- *hour = (time / INT64CONST(3600000000));
- time -= ((*hour) * INT64CONST(3600000000));
- *min = (time / INT64CONST(60000000));
- time -= ((*min) * INT64CONST(60000000));
- *sec = (time / INT64CONST(1000000));
- *fsec = (time - (*sec * INT64CONST(1000000)));
- *sec = (time / INT64CONST(1000000));
- *fsec = (time - (*sec * INT64CONST(1000000)));
+ *hour = (time / USECS_PER_HOUR);
+ time -= ((*hour) * USECS_PER_HOUR);
+ *min = (time / USECS_PER_MINUTE);
+ time -= ((*min) * USECS_PER_MINUTE);
+ *sec = (time / USECS_PER_SEC);
+ *fsec = (time - (*sec * USECS_PER_SEC));
+ *sec = (time / USECS_PER_SEC);
+ *fsec = (time - (*sec * USECS_PER_SEC));
#else
*hour = (time / 3600);
time -= ((*hour) * 3600);
@@ -171,11 +171,11 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
dDate -= 1;
}
#else
- TMODULO(time, dDate, 86400e0);
+ TMODULO(time, dDate, (double)SECS_PER_DAY);
if (time < 0)
{
- time += 86400;
+ time += SECS_PER_DAY;
dDate -= 1;
}
#endif
@@ -199,10 +199,10 @@ timestamp2tm(timestamp dt, int *tzp, struct tm * tm, fsec_t *fsec, char **tzn)
if (IS_VALID_UTIME(tm->tm_year, tm->tm_mon, tm->tm_mday))
{
#ifdef HAVE_INT64_TIMESTAMP
- utime = ((dt / INT64CONST(1000000))
- + ((date0 - date2j(1970, 1, 1)) * INT64CONST(86400)));
+ utime = ((dt / USECS_PER_SEC)
+ + ((date0 - date2j(1970, 1, 1)) * INT64CONST(SECS_PER_DAY)));
#else
- utime = (dt + ((date0 - date2j(1970, 1, 1)) * 86400));
+ utime = (dt + ((date0 - date2j(1970, 1, 1)) * SECS_PER_DAY));
#endif
#if defined(HAVE_TM_ZONE) || defined(HAVE_INT_TIMEZONE)