Skip to content

Commit

Permalink
Fix time offset calculation in case of unsigned time_t
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Mike Gorchak authored and Junio C Hamano committed Feb 25, 2013
1 parent e6e8751 commit e1033da
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions date.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,14 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)

/* mktime uses local timezone */
*timestamp = tm_to_time_t(&tm);
if (*offset == -1)
*offset = ((time_t)*timestamp - mktime(&tm)) / 60;
if (*offset == -1) {
time_t temp_time = mktime(&tm);
if ((time_t)*timestamp > temp_time) {
*offset = ((time_t)*timestamp - temp_time) / 60;
} else {
*offset = -(int)((temp_time - (time_t)*timestamp) / 60);
}
}

if (*timestamp == -1)
return -1;
Expand Down

0 comments on commit e1033da

Please sign in to comment.