Fix time offset calculation in case of unsigned time_t

Fix time offset calculation expression in case if time_t is unsigned. This code works fine for signed and unsigned time_t. Signed-off-by: Mike Gorchak <mike.gorchak.qnx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mike Gorchak committed Feb 25, 2013 at 23:53 UTC e1033da6af80b77d720ba7df9b8d3439666582e4
1 file changed +8 -2
date.c
+8 -2
@@ -694,8 +694,14 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
694
695 /* mktime uses local timezone */
696 *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 + }
705
706 if (*timestamp == -1)
707 return -1;