|
@@ -2770,7 +2770,9 @@ correct_tm(int islocal, const time_t *timep, struct tm *resultbuf,
|
|
|
const char *outcome;
|
|
|
|
|
|
if (PREDICT_LIKELY(r)) {
|
|
|
- if (r->tm_year > 8099) { /* We can't strftime dates after 9999 CE. */
|
|
|
+ /* We can't strftime dates after 9999 CE, and we want to avoid dates
|
|
|
+ * before 1 CE (avoiding the year 0 issue and negative years). */
|
|
|
+ if (r->tm_year > 8099) {
|
|
|
r->tm_year = 8099;
|
|
|
r->tm_mon = 11;
|
|
|
r->tm_mday = 31;
|
|
@@ -2778,6 +2780,14 @@ correct_tm(int islocal, const time_t *timep, struct tm *resultbuf,
|
|
|
r->tm_hour = 23;
|
|
|
r->tm_min = 59;
|
|
|
r->tm_sec = 59;
|
|
|
+ } else if (r->tm_year < (1-1900)) {
|
|
|
+ r->tm_year = (1-1900);
|
|
|
+ r->tm_mon = 0;
|
|
|
+ r->tm_mday = 1;
|
|
|
+ r->tm_yday = 0;
|
|
|
+ r->tm_hour = 0;
|
|
|
+ r->tm_min = 0;
|
|
|
+ r->tm_sec = 0;
|
|
|
}
|
|
|
return r;
|
|
|
}
|