Skip to content

Commit f10a012

Browse files
committed
Merge branch 'mg/unsigned-time-t'
A few workarounds for systems with unsigned time_t. * mg/unsigned-time-t: Fix time offset calculation in case of unsigned time_t date.c: fix unsigned time_t comparison
2 parents edb99f9 + e1033da commit f10a012

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

date.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
383383
* sense to specify timestamp way into the future. Make
384384
* sure it is not later than ten days from now...
385385
*/
386-
if (now + 10*24*3600 < specified)
386+
if ((specified != -1) && (now + 10*24*3600 < specified))
387387
return 0;
388388
tm->tm_mon = r->tm_mon;
389389
tm->tm_mday = r->tm_mday;
@@ -694,8 +694,14 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
694694

695695
/* mktime uses local timezone */
696696
*timestamp = tm_to_time_t(&tm);
697-
if (*offset == -1)
698-
*offset = ((time_t)*timestamp - mktime(&tm)) / 60;
697+
if (*offset == -1) {
698+
time_t temp_time = mktime(&tm);
699+
if ((time_t)*timestamp > temp_time) {
700+
*offset = ((time_t)*timestamp - temp_time) / 60;
701+
} else {
702+
*offset = -(int)((temp_time - (time_t)*timestamp) / 60);
703+
}
704+
}
699705

700706
if (*timestamp == -1)
701707
return -1;

0 commit comments

Comments
 (0)