@@ -342,7 +342,7 @@ j2date(int jd, int *year, int *month, int *day)
342
342
* year = y - 4800 ;
343
343
quad = julian * 2141 / 65536 ;
344
344
* day = julian - 7834 * quad / 256 ;
345
- * month = (quad + 10 ) % 12 + 1 ;
345
+ * month = (quad + 10 ) % MONTHS_PER_YEAR + 1 ;
346
346
347
347
return ;
348
348
} /* j2date() */
@@ -952,8 +952,8 @@ DecodeDateTime(char **field, int *ftype, int nf,
952
952
* DecodeTime()
953
953
*/
954
954
/* test for > 24:00:00 */
955
- if (tm -> tm_hour > 24 ||
956
- (tm -> tm_hour == 24 &&
955
+ if (tm -> tm_hour > HOURS_PER_DAY ||
956
+ (tm -> tm_hour == HOURS_PER_DAY &&
957
957
(tm -> tm_min > 0 || tm -> tm_sec > 0 || * fsec > 0 )))
958
958
return DTERR_FIELD_OVERFLOW ;
959
959
break ;
@@ -1371,12 +1371,12 @@ DecodeDateTime(char **field, int *ftype, int nf,
1371
1371
return dterr ;
1372
1372
1373
1373
/* handle AM/PM */
1374
- if (mer != HR24 && tm -> tm_hour > 12 )
1374
+ if (mer != HR24 && tm -> tm_hour > HOURS_PER_DAY / 2 )
1375
1375
return DTERR_FIELD_OVERFLOW ;
1376
- if (mer == AM && tm -> tm_hour == 12 )
1376
+ if (mer == AM && tm -> tm_hour == HOURS_PER_DAY / 2 )
1377
1377
tm -> tm_hour = 0 ;
1378
- else if (mer == PM && tm -> tm_hour != 12 )
1379
- tm -> tm_hour += 12 ;
1378
+ else if (mer == PM && tm -> tm_hour != HOURS_PER_DAY / 2 )
1379
+ tm -> tm_hour += HOURS_PER_DAY / 2 ;
1380
1380
1381
1381
/* do additional checking for full date specs... */
1382
1382
if (* dtype == DTK_DATE )
@@ -2058,17 +2058,18 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
2058
2058
return dterr ;
2059
2059
2060
2060
/* handle AM/PM */
2061
- if (mer != HR24 && tm -> tm_hour > 12 )
2061
+ if (mer != HR24 && tm -> tm_hour > HOURS_PER_DAY / 2 )
2062
2062
return DTERR_FIELD_OVERFLOW ;
2063
- if (mer == AM && tm -> tm_hour == 12 )
2063
+ if (mer == AM && tm -> tm_hour == HOURS_PER_DAY / 2 )
2064
2064
tm -> tm_hour = 0 ;
2065
- else if (mer == PM && tm -> tm_hour != 12 )
2066
- tm -> tm_hour += 12 ;
2065
+ else if (mer == PM && tm -> tm_hour != HOURS_PER_DAY / 2 )
2066
+ tm -> tm_hour += HOURS_PER_DAY / 2 ;
2067
2067
2068
- if (tm -> tm_hour < 0 || tm -> tm_min < 0 || tm -> tm_min > 59 ||
2069
- tm -> tm_sec < 0 || tm -> tm_sec > 60 || tm -> tm_hour > 24 ||
2068
+ if (tm -> tm_hour < 0 || tm -> tm_min < 0 || tm -> tm_min > MINS_PER_HOUR - 1 ||
2069
+ tm -> tm_sec < 0 || tm -> tm_sec > SECS_PER_MINUTE ||
2070
+ tm -> tm_hour > HOURS_PER_DAY ||
2070
2071
/* test for > 24:00:00 */
2071
- (tm -> tm_hour == 24 &&
2072
+ (tm -> tm_hour == HOURS_PER_DAY &&
2072
2073
(tm -> tm_min > 0 || tm -> tm_sec > 0 || * fsec > 0 )) ||
2073
2074
#ifdef HAVE_INT64_TIMESTAMP
2074
2075
* fsec < INT64CONST (0 ) || * fsec > USECS_PER_SEC
@@ -2396,13 +2397,15 @@ DecodeTime(char *str, int fmask, int range,
2396
2397
2397
2398
/* do a sanity check */
2398
2399
#ifdef HAVE_INT64_TIMESTAMP
2399
- if (tm -> tm_hour < 0 || tm -> tm_min < 0 || tm -> tm_min > 59 ||
2400
- tm -> tm_sec < 0 || tm -> tm_sec > 60 || * fsec < INT64CONST (0 ) ||
2400
+ if (tm -> tm_hour < 0 || tm -> tm_min < 0 || tm -> tm_min > MINS_PER_HOUR - 1 ||
2401
+ tm -> tm_sec < 0 || tm -> tm_sec > SECS_PER_MINUTE ||
2402
+ * fsec < INT64CONST (0 ) ||
2401
2403
* fsec > USECS_PER_SEC )
2402
2404
return DTERR_FIELD_OVERFLOW ;
2403
2405
#else
2404
- if (tm -> tm_hour < 0 || tm -> tm_min < 0 || tm -> tm_min > 59 ||
2405
- tm -> tm_sec < 0 || tm -> tm_sec > 60 || * fsec < 0 || * fsec > 1 )
2406
+ if (tm -> tm_hour < 0 || tm -> tm_min < 0 || tm -> tm_min > MINS_PER_HOUR - 1 ||
2407
+ tm -> tm_sec < 0 || tm -> tm_sec > SECS_PER_MINUTE ||
2408
+ * fsec < 0 || * fsec > 1 )
2406
2409
return DTERR_FIELD_OVERFLOW ;
2407
2410
#endif
2408
2411
@@ -2748,9 +2751,9 @@ DecodeTimezone(char *str, int *tzp)
2748
2751
2749
2752
if (hr < 0 || hr > 14 )
2750
2753
return DTERR_TZDISP_OVERFLOW ;
2751
- if (min < 0 || min >= 60 )
2754
+ if (min < 0 || min >= MINS_PER_HOUR )
2752
2755
return DTERR_TZDISP_OVERFLOW ;
2753
- if (sec < 0 || sec >= 60 )
2756
+ if (sec < 0 || sec >= SECS_PER_MINUTE )
2754
2757
return DTERR_TZDISP_OVERFLOW ;
2755
2758
2756
2759
tz = (hr * MINS_PER_HOUR + min ) * SECS_PER_MINUTE + sec ;
@@ -3324,7 +3327,7 @@ DecodeISO8601Interval(char *str,
3324
3327
{
3325
3328
case 'Y' :
3326
3329
tm -> tm_year += val ;
3327
- tm -> tm_mon += (fval * 12 );
3330
+ tm -> tm_mon += (fval * MONTHS_PER_YEAR );
3328
3331
break ;
3329
3332
case 'M' :
3330
3333
tm -> tm_mon += val ;
@@ -3359,7 +3362,7 @@ DecodeISO8601Interval(char *str,
3359
3362
return DTERR_BAD_FORMAT ;
3360
3363
3361
3364
tm -> tm_year += val ;
3362
- tm -> tm_mon += (fval * 12 );
3365
+ tm -> tm_mon += (fval * MONTHS_PER_YEAR );
3363
3366
if (unit == '\0' )
3364
3367
return 0 ;
3365
3368
if (unit == 'T' )
@@ -4155,7 +4158,7 @@ InstallTimeZoneAbbrevs(tzEntry *abbrevs, int n)
4155
4158
{
4156
4159
strncpy (newtbl [i ].token , abbrevs [i ].abbrev , TOKMAXLEN );
4157
4160
newtbl [i ].type = abbrevs [i ].is_dst ? DTZ : TZ ;
4158
- TOVAL (& newtbl [i ], abbrevs [i ].offset / 60 );
4161
+ TOVAL (& newtbl [i ], abbrevs [i ].offset / MINS_PER_HOUR );
4159
4162
}
4160
4163
4161
4164
/* Check the ordering, if testing */
0 commit comments