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>
This commit is contained in:

committed by
Junio C Hamano

parent
e6e87516f5
commit
e1033da6af
10
date.c
10
date.c
@ -694,8 +694,14 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
|
|||||||
|
|
||||||
/* mktime uses local timezone */
|
/* mktime uses local timezone */
|
||||||
*timestamp = tm_to_time_t(&tm);
|
*timestamp = tm_to_time_t(&tm);
|
||||||
if (*offset == -1)
|
if (*offset == -1) {
|
||||||
*offset = ((time_t)*timestamp - mktime(&tm)) / 60;
|
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)
|
if (*timestamp == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
Reference in New Issue
Block a user