patch: change magic constants to DEFINE value for readability.

Started by CharSyamover 10 years ago2 messages
#1CharSyam
charsyam@gmail.com
1 attachment(s)

in src/backend/utils/misc/tzparser.c

It uses 60 * 60 to represent SECS_PER_HOUR.

and It is already define in other files.

so I think using SECS_PER_HOUR is more clear for readability.

and I attached patch.(it just change 60 * 60 to SECS_PER_HOUR)

What do you think?

Attachments:

magic.patchapplication/octet-stream; name=magic.patchDownload
diff --git src/backend/utils/misc/tzparser.c src/backend/utils/misc/tzparser.c
index ce738b8..2efa271 100644
--- src/backend/utils/misc/tzparser.c
+++ src/backend/utils/misc/tzparser.c
@@ -29,6 +29,7 @@
 #include "utils/guc.h"
 #include "utils/memutils.h"
 #include "utils/tzparser.h"
+#include "utils/datetime.h"
 
 
 #define WHITESPACE " \t\n\r"
@@ -67,8 +68,8 @@ validateTzEntry(tzEntry *tzentry)
 	/*
 	 * Sanity-check the offset: shouldn't exceed 14 hours
 	 */
-	if (tzentry->offset > 14 * 60 * 60 ||
-		tzentry->offset < -14 * 60 * 60)
+	if (tzentry->offset > 14 * SECS_PER_HOUR ||
+		tzentry->offset < -14 * SECS_PER_HOUR)
 	{
 		GUC_check_errmsg("time zone offset %d is out of range in time zone file \"%s\", line %d",
 						 tzentry->offset,
@@ -156,7 +157,7 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
 		 * zones that probably will never be used in the current session.
 		 */
 		tzentry->zone = pstrdup(offset);
-		tzentry->offset = 0;
+		tzentry->offset = 0 * SECS_PER_HOUR;
 		tzentry->is_dst = false;
 		remain = strtok(NULL, WHITESPACE);
 	}
#2Bruce Momjian
bruce@momjian.us
In reply to: CharSyam (#1)
Re: [HACKERS] patch: change magic constants to DEFINE value for readability.

On Sat, May 23, 2015 at 11:40:36AM +0900, CharSyam wrote:

in src/backend/utils/misc/tzparser.c

It uses 60 * 60 to represent SECS_PER_HOUR.

and It is already define in other files.

so I think using SECS_PER_HOUR is more clear for readability.

and I attached patch.(it just change 60 * 60 to SECS_PER_HOUR)

What do you think?

Yes, this patch is nine years old, but macros are better, as you
suggested, so patch applied to master.

--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com

Only you can decide what is important to you.