summaryrefslogtreecommitdiff
path: root/date.c
diff options
context:
space:
mode:
authorMike Gorchak <mike.gorchak.qnx@gmail.com>2013-02-25 23:53:40 +0200
committerJunio C Hamano <gitster@pobox.com>2013-02-25 14:29:12 -0800
commite1033da6af80b77d720ba7df9b8d3439666582e4 (patch)
treee14f11d40ac27dd6dedf267062a657b94946967f /date.c
parente6e87516f569c2344f760287aec66f70da856c6d (diff)
downloadgit-e1033da6af80b77d720ba7df9b8d3439666582e4.tar.gz
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>
Diffstat (limited to 'date.c')
-rw-r--r--date.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/date.c b/date.c
index 1ac28e5e7b..df20d0ba1d 100644
--- a/date.c
+++ b/date.c
@@ -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;