aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/formatting.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2011-03-12 09:31:18 -0500
committerBruce Momjian <bruce@momjian.us>2011-03-12 09:35:56 -0500
commit3a3f39fdc00c6caa41d795475189ac844403b770 (patch)
tree2cee74a6ad8f09bec94434ce24ff0c30d154b662 /src/backend/utils/adt/formatting.c
parent3d9f7ec1ffde399accda096da4df46b178e8b960 (diff)
downloadpostgresql-3a3f39fdc00c6caa41d795475189ac844403b770.tar.gz
postgresql-3a3f39fdc00c6caa41d795475189ac844403b770.zip
Use macros for time-based constants, rather than constants.
Diffstat (limited to 'src/backend/utils/adt/formatting.c')
-rw-r--r--src/backend/utils/adt/formatting.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index f90d36d24cc..aba11459bb1 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -2129,7 +2129,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
* intervals
*/
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : 2,
- tm->tm_hour % (HOURS_PER_DAY / 2) == 0 ? 12 :
+ tm->tm_hour % (HOURS_PER_DAY / 2) == 0 ? HOURS_PER_DAY / 2 :
tm->tm_hour % (HOURS_PER_DAY / 2));
if (S_THth(n->suffix))
str_numth(s, s, S_TH_TYPE(n->suffix));
@@ -2486,14 +2486,14 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
if (!tm->tm_mon)
break;
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -4,
- rm_months_upper[12 - tm->tm_mon]);
+ rm_months_upper[MONTHS_PER_YEAR - tm->tm_mon]);
s += strlen(s);
break;
case DCH_rm:
if (!tm->tm_mon)
break;
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -4,
- rm_months_lower[12 - tm->tm_mon]);
+ rm_months_lower[MONTHS_PER_YEAR - tm->tm_mon]);
s += strlen(s);
break;
case DCH_W:
@@ -2779,12 +2779,12 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_RM:
from_char_seq_search(&value, &s, rm_months_upper,
ALL_UPPER, MAX_RM_LEN, n);
- from_char_set_int(&out->mm, 12 - value, n);
+ from_char_set_int(&out->mm, MONTHS_PER_YEAR - value, n);
break;
case DCH_rm:
from_char_seq_search(&value, &s, rm_months_lower,
ALL_LOWER, MAX_RM_LEN, n);
- from_char_set_int(&out->mm, 12 - value, n);
+ from_char_set_int(&out->mm, MONTHS_PER_YEAR - value, n);
break;
case DCH_W:
from_char_parse_int(&out->w, &s, n);
@@ -3236,16 +3236,16 @@ do_to_timestamp(text *date_txt, text *fmt,
if (tmfc.clock == CLOCK_12_HOUR)
{
- if (tm->tm_hour < 1 || tm->tm_hour > 12)
+ if (tm->tm_hour < 1 || tm->tm_hour > HOURS_PER_DAY / 2)
ereport(ERROR,
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
errmsg("hour \"%d\" is invalid for the 12-hour clock",
tm->tm_hour),
errhint("Use the 24-hour clock, or give an hour between 1 and 12.")));
- if (tmfc.pm && tm->tm_hour < 12)
- tm->tm_hour += 12;
- else if (!tmfc.pm && tm->tm_hour == 12)
+ if (tmfc.pm && tm->tm_hour < HOURS_PER_DAY / 2)
+ tm->tm_hour += HOURS_PER_DAY / 2;
+ else if (!tmfc.pm && tm->tm_hour == HOURS_PER_DAY / 2)
tm->tm_hour = 0;
}
@@ -3347,7 +3347,7 @@ do_to_timestamp(text *date_txt, text *fmt,
y = ysum[isleap(tm->tm_year)];
- for (i = 1; i <= 12; i++)
+ for (i = 1; i <= MONTHS_PER_YEAR; i++)
{
if (tmfc.ddd < y[i])
break;