Skip to content

Commit a536b2d

Browse files
committed
Add time/date macros for code clarity:
#define DAYS_PER_YEAR 365.25 #define MONTHS_PER_YEAR 12 #define DAYS_PER_MONTH 30 #define HOURS_PER_DAY 24
1 parent dc73819 commit a536b2d

File tree

17 files changed

+248
-229
lines changed

17 files changed

+248
-229
lines changed

src/backend/commands/variable.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.110 2005/07/20 16:42:30 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.111 2005/07/21 03:56:10 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -325,7 +325,7 @@ assign_timezone(const char *value, bool doit, GucSource source)
325325
if (doit)
326326
{
327327
/* Here we change from SQL to Unix sign convention */
328-
CTimeZone = -hours * 3600;
328+
CTimeZone = -hours * SECS_PER_HOUR;
329329
HasCTZSet = true;
330330
}
331331
}
@@ -402,7 +402,7 @@ assign_timezone(const char *value, bool doit, GucSource source)
402402
if (!result)
403403
return NULL;
404404
snprintf(result, 64, "%.5f",
405-
(double) (-CTimeZone) / 3600.0);
405+
(double) (-CTimeZone) / (double)SECS_PER_HOUR);
406406
}
407407
else
408408
result = strdup(value);

src/backend/postmaster/postmaster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.459 2005/07/14 05:13:40 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.460 2005/07/21 03:56:11 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -1284,7 +1284,7 @@ ServerLoop(void)
12841284
* less than an hour ...
12851285
*/
12861286
now = time(NULL);
1287-
if (now - last_touch_time >= 58 * 60)
1287+
if (now - last_touch_time >= 58 * SECS_PER_MINUTE)
12881288
{
12891289
TouchSocketFile();
12901290
TouchSocketLockFile();

src/backend/postmaster/syslogger.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.16 2005/07/04 04:51:47 tgl Exp $
21+
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.17 2005/07/21 03:56:11 momjian Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -41,7 +41,7 @@
4141
#include "storage/pg_shmem.h"
4242
#include "utils/guc.h"
4343
#include "utils/ps_status.h"
44-
44+
#include "utils/timestamp.h"
4545

4646
/*
4747
* We really want line-buffered mode for logfile output, but Windows does
@@ -60,7 +60,7 @@
6060
* start, but the rest can change at SIGHUP.
6161
*/
6262
bool Redirect_stderr = false;
63-
int Log_RotationAge = 24 * 60;
63+
int Log_RotationAge = HOURS_PER_DAY * SECS_PER_MINUTE;
6464
int Log_RotationSize = 10 * 1024;
6565
char *Log_directory = NULL;
6666
char *Log_filename = NULL;
@@ -855,7 +855,7 @@ set_next_rotation_time(void)
855855
* fairly loosely. In this version we align to local time rather than
856856
* GMT.
857857
*/
858-
rotinterval = Log_RotationAge * 60; /* convert to seconds */
858+
rotinterval = Log_RotationAge * SECS_PER_MINUTE; /* convert to seconds */
859859
now = time(NULL);
860860
tm = pg_localtime(&now, global_timezone);
861861
now += tm->tm_gmtoff;

src/backend/tcop/postgres.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.454 2005/07/14 05:13:41 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.455 2005/07/21 03:56:11 momjian Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -3536,10 +3536,10 @@ log_disconnections(int code, Datum arg)
35363536
end.tv_sec -= port->session_start.tv_sec;
35373537
end.tv_usec -= port->session_start.tv_usec;
35383538

3539-
hours = end.tv_sec / 3600;
3540-
end.tv_sec %= 3600;
3541-
minutes = end.tv_sec / 60;
3542-
seconds = end.tv_sec % 60;
3539+
hours = end.tv_sec / SECS_PER_HOUR;
3540+
end.tv_sec %= SECS_PER_HOUR;
3541+
minutes = end.tv_sec / SECS_PER_MINUTE;
3542+
seconds = end.tv_sec % SECS_PER_MINUTE;
35433543

35443544
/* if time has gone backwards for some reason say so, or print time */
35453545

src/backend/utils/adt/date.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.113 2005/07/20 16:42:30 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.114 2005/07/21 03:56:13 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -31,7 +31,7 @@
3131

3232
/*
3333
* gcc's -ffast-math switch breaks routines that expect exact results from
34-
* expressions like timeval / 3600, where timeval is double.
34+
* expressions like timeval / SECS_PER_HOUR, where timeval is double.
3535
*/
3636
#ifdef __FAST_MATH__
3737
#error -ffast-math is known to break this code
@@ -918,10 +918,10 @@ static int
918918
tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result)
919919
{
920920
#ifdef HAVE_INT64_TIMESTAMP
921-
*result = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec)
921+
*result = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec)
922922
* USECS_PER_SEC) + fsec;
923923
#else
924-
*result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec;
924+
*result = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec;
925925
#endif
926926
return 0;
927927
}
@@ -946,8 +946,8 @@ time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec)
946946
double trem;
947947

948948
trem = time;
949-
TMODULO(trem, tm->tm_hour, 3600.0);
950-
TMODULO(trem, tm->tm_min, 60.0);
949+
TMODULO(trem, tm->tm_hour, (double)SECS_PER_HOUR);
950+
TMODULO(trem, tm->tm_min, (double)SECS_PER_MINUTE);
951951
TMODULO(trem, tm->tm_sec, 1.0);
952952
*fsec = trem;
953953
#endif
@@ -1348,10 +1348,10 @@ timestamp_time(PG_FUNCTION_ARGS)
13481348
* Could also do this with time = (timestamp / USECS_PER_DAY *
13491349
* USECS_PER_DAY) - timestamp;
13501350
*/
1351-
result = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec) *
1351+
result = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
13521352
USECS_PER_SEC) + fsec;
13531353
#else
1354-
result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec;
1354+
result = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec;
13551355
#endif
13561356

13571357
PG_RETURN_TIMEADT(result);
@@ -1385,10 +1385,10 @@ timestamptz_time(PG_FUNCTION_ARGS)
13851385
* Could also do this with time = (timestamp / USECS_PER_DAY *
13861386
* USECS_PER_DAY) - timestamp;
13871387
*/
1388-
result = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec) *
1388+
result = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
13891389
USECS_PER_SEC) + fsec;
13901390
#else
1391-
result = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec;
1391+
result = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec;
13921392
#endif
13931393

13941394
PG_RETURN_TIMEADT(result);
@@ -1715,10 +1715,10 @@ static int
17151715
tm2timetz(struct pg_tm * tm, fsec_t fsec, int tz, TimeTzADT *result)
17161716
{
17171717
#ifdef HAVE_INT64_TIMESTAMP
1718-
result->time = ((((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec) *
1718+
result->time = ((((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
17191719
USECS_PER_SEC) + fsec;
17201720
#else
1721-
result->time = ((tm->tm_hour * 60 + tm->tm_min) * 60) + tm->tm_sec + fsec;
1721+
result->time = ((tm->tm_hour * SECS_PER_MINUTE + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec + fsec;
17221722
#endif
17231723
result->zone = tz;
17241724

@@ -1843,8 +1843,8 @@ timetz2tm(TimeTzADT *time, struct pg_tm * tm, fsec_t *fsec, int *tzp)
18431843
#else
18441844
double trem = time->time;
18451845

1846-
TMODULO(trem, tm->tm_hour, 3600.0);
1847-
TMODULO(trem, tm->tm_min, 60.0);
1846+
TMODULO(trem, tm->tm_hour, (double)SECS_PER_HOUR);
1847+
TMODULO(trem, tm->tm_min, (double)SECS_PER_MINUTE);
18481848
TMODULO(trem, tm->tm_sec, 1.0);
18491849
*fsec = trem;
18501850
#endif
@@ -2399,13 +2399,13 @@ timetz_part(PG_FUNCTION_ARGS)
23992399

24002400
case DTK_TZ_MINUTE:
24012401
result = -tz;
2402-
result /= 60;
2403-
FMODULO(result, dummy, 60.0);
2402+
result /= SECS_PER_MINUTE;
2403+
FMODULO(result, dummy, (double)SECS_PER_MINUTE);
24042404
break;
24052405

24062406
case DTK_TZ_HOUR:
24072407
dummy = -tz;
2408-
FMODULO(dummy, result, 3600.0);
2408+
FMODULO(dummy, result, (double)SECS_PER_HOUR);
24092409
break;
24102410

24112411
case DTK_MICROSEC:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy