8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.105 2005/04 /23 22:53:05 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.106 2005/05 /23 18:56:55 momjian Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -281,11 +281,11 @@ date_mii(PG_FUNCTION_ARGS)
281
281
#ifdef HAVE_INT64_TIMESTAMP
282
282
/* date is days since 2000, timestamp is microseconds since same... */
283
283
#define date2timestamp (dateVal ) \
284
- ((Timestamp) ((dateVal) * INT64CONST(86400000000) ))
284
+ ((Timestamp) ((dateVal) * USECS_PER_DAY ))
285
285
#else
286
286
/* date is days since 2000, timestamp is seconds since same... */
287
287
#define date2timestamp (dateVal ) \
288
- ((Timestamp) ((dateVal) * 86400.0 ))
288
+ ((Timestamp) ((dateVal) * (double)SECS_PER_DAY ))
289
289
#endif
290
290
291
291
static TimestampTz
@@ -305,10 +305,10 @@ date2timestamptz(DateADT dateVal)
305
305
tz = DetermineLocalTimeZone (tm );
306
306
307
307
#ifdef HAVE_INT64_TIMESTAMP
308
- result = (dateVal * INT64CONST ( 86400000000 ) )
309
- + (tz * INT64CONST ( 1000000 ) );
308
+ result = (dateVal * USECS_PER_DAY )
309
+ + (tz * USECS_PER_SEC );
310
310
#else
311
- result = dateVal * 86400.0 + tz ;
311
+ result = dateVal * ( double ) SECS_PER_DAY + tz ;
312
312
#endif
313
313
314
314
return result ;
@@ -922,7 +922,7 @@ tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result)
922
922
{
923
923
#ifdef HAVE_INT64_TIMESTAMP
924
924
* result = ((((((tm -> tm_hour * 60 ) + tm -> tm_min ) * 60 ) + tm -> tm_sec )
925
- * INT64CONST ( 1000000 ) ) + fsec );
925
+ * USECS_PER_SEC ) + fsec );
926
926
#else
927
927
* result = ((((tm -> tm_hour * 60 ) + tm -> tm_min ) * 60 ) + tm -> tm_sec + fsec );
928
928
#endif
@@ -938,12 +938,12 @@ static int
938
938
time2tm (TimeADT time , struct pg_tm * tm , fsec_t * fsec )
939
939
{
940
940
#ifdef HAVE_INT64_TIMESTAMP
941
- tm -> tm_hour = (time / INT64CONST ( 3600000000 ) );
942
- time -= (tm -> tm_hour * INT64CONST ( 3600000000 ) );
943
- tm -> tm_min = (time / INT64CONST ( 60000000 ) );
944
- time -= (tm -> tm_min * INT64CONST ( 60000000 ) );
945
- tm -> tm_sec = (time / INT64CONST ( 1000000 ) );
946
- time -= (tm -> tm_sec * INT64CONST ( 1000000 ) );
941
+ tm -> tm_hour = (time / USECS_PER_HOUR );
942
+ time -= (tm -> tm_hour * USECS_PER_HOUR );
943
+ tm -> tm_min = (time / USECS_PER_MINUTE );
944
+ time -= (tm -> tm_min * USECS_PER_MINUTE );
945
+ tm -> tm_sec = (time / USECS_PER_SEC );
946
+ time -= (tm -> tm_sec * USECS_PER_SEC );
947
947
* fsec = time ;
948
948
#else
949
949
double trem ;
@@ -1343,7 +1343,7 @@ timestamp_time(PG_FUNCTION_ARGS)
1343
1343
* 86400000000) - timestamp;
1344
1344
*/
1345
1345
result = ((((((tm -> tm_hour * 60 ) + tm -> tm_min ) * 60 ) + tm -> tm_sec )
1346
- * INT64CONST ( 1000000 ) ) + fsec );
1346
+ * USECS_PER_SEC ) + fsec );
1347
1347
#else
1348
1348
result = ((((tm -> tm_hour * 60 ) + tm -> tm_min ) * 60 ) + tm -> tm_sec + fsec );
1349
1349
#endif
@@ -1380,7 +1380,7 @@ timestamptz_time(PG_FUNCTION_ARGS)
1380
1380
* 86400000000) - timestamp;
1381
1381
*/
1382
1382
result = ((((((tm -> tm_hour * 60 ) + tm -> tm_min ) * 60 ) + tm -> tm_sec )
1383
- * INT64CONST ( 1000000 ) ) + fsec );
1383
+ * USECS_PER_SEC ) + fsec );
1384
1384
#else
1385
1385
result = ((((tm -> tm_hour * 60 ) + tm -> tm_min ) * 60 ) + tm -> tm_sec + fsec );
1386
1386
#endif
@@ -1440,20 +1440,20 @@ interval_time(PG_FUNCTION_ARGS)
1440
1440
int64 days ;
1441
1441
1442
1442
result = span -> time ;
1443
- if (result >= INT64CONST ( 86400000000 ) )
1443
+ if (result >= USECS_PER_DAY )
1444
1444
{
1445
- days = result / INT64CONST ( 86400000000 ) ;
1446
- result -= days * INT64CONST ( 86400000000 ) ;
1445
+ days = result / USECS_PER_DAY ;
1446
+ result -= days * USECS_PER_DAY ;
1447
1447
}
1448
1448
else if (result < 0 )
1449
1449
{
1450
- days = (- result + INT64CONST ( 86400000000 ) - 1 ) / INT64CONST ( 86400000000 ) ;
1451
- result += days * INT64CONST ( 86400000000 ) ;
1450
+ days = (- result + USECS_PER_DAY - 1 ) / USECS_PER_DAY ;
1451
+ result += days * USECS_PER_DAY ;
1452
1452
}
1453
1453
#else
1454
1454
result = span -> time ;
1455
- if (result >= 86400e0 || result < 0 )
1456
- result -= floor (result / 86400e0 ) * 86400e0 ;
1455
+ if (result >= ( double ) SECS_PER_DAY || result < 0 )
1456
+ result -= floor (result / ( double ) SECS_PER_DAY ) * ( double ) SECS_PER_DAY ;
1457
1457
#endif
1458
1458
1459
1459
PG_RETURN_TIMEADT (result );
@@ -1489,14 +1489,14 @@ time_pl_interval(PG_FUNCTION_ARGS)
1489
1489
1490
1490
#ifdef HAVE_INT64_TIMESTAMP
1491
1491
result = (time + span -> time );
1492
- result -= (result / INT64CONST ( 86400000000 ) * INT64CONST ( 86400000000 ) );
1492
+ result -= (result / USECS_PER_DAY * USECS_PER_DAY );
1493
1493
if (result < INT64CONST (0 ))
1494
- result += INT64CONST ( 86400000000 ) ;
1494
+ result += USECS_PER_DAY ;
1495
1495
#else
1496
1496
TimeADT time1 ;
1497
1497
1498
1498
result = (time + span -> time );
1499
- TMODULO (result , time1 , 86400e0 );
1499
+ TMODULO (result , time1 , ( double ) SECS_PER_DAY );
1500
1500
if (result < 0 )
1501
1501
result += 86400 ;
1502
1502
#endif
@@ -1516,14 +1516,14 @@ time_mi_interval(PG_FUNCTION_ARGS)
1516
1516
1517
1517
#ifdef HAVE_INT64_TIMESTAMP
1518
1518
result = (time - span -> time );
1519
- result -= (result / INT64CONST ( 86400000000 ) * INT64CONST ( 86400000000 ) );
1519
+ result -= (result / USECS_PER_DAY * USECS_PER_DAY );
1520
1520
if (result < INT64CONST (0 ))
1521
- result += INT64CONST ( 86400000000 ) ;
1521
+ result += USECS_PER_DAY ;
1522
1522
#else
1523
1523
TimeADT time1 ;
1524
1524
1525
1525
result = (time - span -> time );
1526
- TMODULO (result , time1 , 86400e0 );
1526
+ TMODULO (result , time1 , ( double ) SECS_PER_DAY );
1527
1527
if (result < 0 )
1528
1528
result += 86400 ;
1529
1529
#endif
@@ -1624,7 +1624,7 @@ time_part(PG_FUNCTION_ARGS)
1624
1624
{
1625
1625
case DTK_MICROSEC :
1626
1626
#ifdef HAVE_INT64_TIMESTAMP
1627
- result = ((tm -> tm_sec * INT64CONST ( 1000000 ) ) + fsec );
1627
+ result = ((tm -> tm_sec * USECS_PER_SEC ) + fsec );
1628
1628
#else
1629
1629
result = ((tm -> tm_sec + fsec ) * 1000000 );
1630
1630
#endif
@@ -1641,7 +1641,7 @@ time_part(PG_FUNCTION_ARGS)
1641
1641
1642
1642
case DTK_SECOND :
1643
1643
#ifdef HAVE_INT64_TIMESTAMP
1644
- result = (tm -> tm_sec + (fsec / INT64CONST ( 1000000 ) ));
1644
+ result = (tm -> tm_sec + (fsec / USECS_PER_SEC ));
1645
1645
#else
1646
1646
result = (tm -> tm_sec + fsec );
1647
1647
#endif
@@ -1709,7 +1709,7 @@ tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result)
1709
1709
{
1710
1710
#ifdef HAVE_INT64_TIMESTAMP
1711
1711
result -> time = ((((((tm -> tm_hour * 60 ) + tm -> tm_min ) * 60 ) + tm -> tm_sec )
1712
- * INT64CONST ( 1000000 ) ) + fsec );
1712
+ * USECS_PER_SEC ) + fsec );
1713
1713
#else
1714
1714
result -> time = ((((tm -> tm_hour * 60 ) + tm -> tm_min ) * 60 ) + tm -> tm_sec + fsec );
1715
1715
#endif
@@ -1823,12 +1823,12 @@ timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp)
1823
1823
#ifdef HAVE_INT64_TIMESTAMP
1824
1824
int64 trem = time -> time ;
1825
1825
1826
- tm -> tm_hour = (trem / INT64CONST ( 3600000000 ) );
1827
- trem -= (tm -> tm_hour * INT64CONST ( 3600000000 ) );
1828
- tm -> tm_min = (trem / INT64CONST ( 60000000 ) );
1829
- trem -= (tm -> tm_min * INT64CONST ( 60000000 ) );
1830
- tm -> tm_sec = (trem / INT64CONST ( 1000000 ) );
1831
- * fsec = (trem - (tm -> tm_sec * INT64CONST ( 1000000 ) ));
1826
+ tm -> tm_hour = (trem / USECS_PER_HOUR );
1827
+ trem -= (tm -> tm_hour * USECS_PER_HOUR );
1828
+ tm -> tm_min = (trem / USECS_PER_MINUTE );
1829
+ trem -= (tm -> tm_min * USECS_PER_MINUTE );
1830
+ tm -> tm_sec = (trem / USECS_PER_SEC );
1831
+ * fsec = (trem - (tm -> tm_sec * USECS_PER_SEC ));
1832
1832
#else
1833
1833
double trem = time -> time ;
1834
1834
@@ -1874,8 +1874,8 @@ timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
1874
1874
int64 t1 ,
1875
1875
t2 ;
1876
1876
1877
- t1 = time1 -> time + (time1 -> zone * INT64CONST ( 1000000 ) );
1878
- t2 = time2 -> time + (time2 -> zone * INT64CONST ( 1000000 ) );
1877
+ t1 = time1 -> time + (time1 -> zone * USECS_PER_SEC );
1878
+ t2 = time2 -> time + (time2 -> zone * USECS_PER_SEC );
1879
1879
#else
1880
1880
double t1 ,
1881
1881
t2 ;
@@ -2026,12 +2026,12 @@ timetz_pl_interval(PG_FUNCTION_ARGS)
2026
2026
2027
2027
#ifdef HAVE_INT64_TIMESTAMP
2028
2028
result -> time = (time -> time + span -> time );
2029
- result -> time -= (result -> time / INT64CONST ( 86400000000 ) * INT64CONST ( 86400000000 ) );
2029
+ result -> time -= (result -> time / USECS_PER_DAY * USECS_PER_DAY );
2030
2030
if (result -> time < INT64CONST (0 ))
2031
- result -> time += INT64CONST ( 86400000000 ) ;
2031
+ result -> time += USECS_PER_DAY ;
2032
2032
#else
2033
2033
result -> time = (time -> time + span -> time );
2034
- TMODULO (result -> time , time1 .time , 86400e0 );
2034
+ TMODULO (result -> time , time1 .time , ( double ) SECS_PER_DAY );
2035
2035
if (result -> time < 0 )
2036
2036
result -> time += 86400 ;
2037
2037
#endif
@@ -2059,12 +2059,12 @@ timetz_mi_interval(PG_FUNCTION_ARGS)
2059
2059
2060
2060
#ifdef HAVE_INT64_TIMESTAMP
2061
2061
result -> time = (time -> time - span -> time );
2062
- result -> time -= (result -> time / INT64CONST ( 86400000000 ) * INT64CONST ( 86400000000 ) );
2062
+ result -> time -= (result -> time / USECS_PER_DAY * USECS_PER_DAY );
2063
2063
if (result -> time < INT64CONST (0 ))
2064
- result -> time += INT64CONST ( 86400000000 ) ;
2064
+ result -> time += USECS_PER_DAY ;
2065
2065
#else
2066
2066
result -> time = (time -> time - span -> time );
2067
- TMODULO (result -> time , time1 .time , 86400e0 );
2067
+ TMODULO (result -> time , time1 .time , ( double ) SECS_PER_DAY );
2068
2068
if (result -> time < 0 )
2069
2069
result -> time += 86400 ;
2070
2070
#endif
@@ -2281,10 +2281,10 @@ datetimetz_timestamptz(PG_FUNCTION_ARGS)
2281
2281
TimestampTz result ;
2282
2282
2283
2283
#ifdef HAVE_INT64_TIMESTAMP
2284
- result = (((date * INT64CONST ( 86400000000 ) ) + time -> time )
2285
- + (time -> zone * INT64CONST ( 1000000 ) ));
2284
+ result = (((date * USECS_PER_DAY ) + time -> time )
2285
+ + (time -> zone * USECS_PER_SEC ));
2286
2286
#else
2287
- result = (((date * 86400.0 ) + time -> time ) + time -> zone );
2287
+ result = (((date * ( double ) SECS_PER_DAY ) + time -> time ) + time -> zone );
2288
2288
#endif
2289
2289
2290
2290
PG_RETURN_TIMESTAMP (result );
@@ -2400,7 +2400,7 @@ timetz_part(PG_FUNCTION_ARGS)
2400
2400
2401
2401
case DTK_MICROSEC :
2402
2402
#ifdef HAVE_INT64_TIMESTAMP
2403
- result = ((tm -> tm_sec * INT64CONST ( 1000000 ) ) + fsec );
2403
+ result = ((tm -> tm_sec * USECS_PER_SEC ) + fsec );
2404
2404
#else
2405
2405
result = ((tm -> tm_sec + fsec ) * 1000000 );
2406
2406
#endif
@@ -2417,7 +2417,7 @@ timetz_part(PG_FUNCTION_ARGS)
2417
2417
2418
2418
case DTK_SECOND :
2419
2419
#ifdef HAVE_INT64_TIMESTAMP
2420
- result = (tm -> tm_sec + (fsec / INT64CONST ( 1000000 ) ));
2420
+ result = (tm -> tm_sec + (fsec / USECS_PER_SEC ));
2421
2421
#else
2422
2422
result = (tm -> tm_sec + fsec );
2423
2423
#endif
@@ -2496,11 +2496,11 @@ timetz_zone(PG_FUNCTION_ARGS)
2496
2496
{
2497
2497
tz = val * 60 ;
2498
2498
#ifdef HAVE_INT64_TIMESTAMP
2499
- result -> time = time -> time + ((time -> zone - tz ) * INT64CONST ( 1000000 ) );
2499
+ result -> time = time -> time + ((time -> zone - tz ) * USECS_PER_SEC );
2500
2500
while (result -> time < INT64CONST (0 ))
2501
- result -> time += INT64CONST ( 86400000000 ) ;
2502
- while (result -> time >= INT64CONST ( 86400000000 ) )
2503
- result -> time -= INT64CONST ( 86400000000 ) ;
2501
+ result -> time += USECS_PER_DAY ;
2502
+ while (result -> time >= USECS_PER_DAY )
2503
+ result -> time -= USECS_PER_DAY ;
2504
2504
#else
2505
2505
result -> time = time -> time + (time -> zone - tz );
2506
2506
while (result -> time < 0 )
@@ -2542,19 +2542,19 @@ timetz_izone(PG_FUNCTION_ARGS)
2542
2542
PointerGetDatum (zone ))))));
2543
2543
2544
2544
#ifdef HAVE_INT64_TIMESTAMP
2545
- tz = - (zone -> time / INT64CONST ( 1000000 ) );
2545
+ tz = - (zone -> time / USECS_PER_SEC );
2546
2546
#else
2547
2547
tz = - (zone -> time );
2548
2548
#endif
2549
2549
2550
2550
result = (TimeTzADT * ) palloc (sizeof (TimeTzADT ));
2551
2551
2552
2552
#ifdef HAVE_INT64_TIMESTAMP
2553
- result -> time = time -> time + ((time -> zone - tz ) * INT64CONST ( 1000000 ) );
2553
+ result -> time = time -> time + ((time -> zone - tz ) * USECS_PER_SEC );
2554
2554
while (result -> time < INT64CONST (0 ))
2555
- result -> time += INT64CONST ( 86400000000 ) ;
2556
- while (result -> time >= INT64CONST ( 86400000000 ) )
2557
- result -> time -= INT64CONST ( 86400000000 ) ;
2555
+ result -> time += USECS_PER_DAY ;
2556
+ while (result -> time >= USECS_PER_DAY )
2557
+ result -> time -= USECS_PER_DAY ;
2558
2558
#else
2559
2559
result -> time = time -> time + (time -> zone - tz );
2560
2560
while (result -> time < 0 )
0 commit comments