{"thread":{"id":"33013","subject":"[PATCH 1/1] Fix time offset calculation in case of unsigned time_t","startedAt":"2013-02-25T21:53:40Z","lastAt":"2013-02-25T21:53:40Z","messageCount":1,"participants":["Mike Gorchak"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"210298","messageId":"CAHXAxrO3nSVmALnefXWbvjR-=dOgVHDDVhyhJCeu9fsco=vjOw@mail.gmail.com","threadId":"33013","inReplyTo":null,"subject":"[PATCH 1/1] Fix time offset calculation in case of unsigned time_t","fromName":"Mike Gorchak","fromEmail":"mike.gorchak.qnx@gmail.com","sentAt":"2013-02-25T21:53:40Z","receivedAt":"2013-02-25T21:53:40Z","isPatch":true,"sender":{"key":"mike.gorchak.qnx@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1337711?v=4"},"body":"Fix time offset calculation expression in case if time_t\nis unsigned. This code works fine for signed and\nunsigned time_t.\n\nSigned-off-by: Mike Gorchak <mike.gorchak.qnx@gmail.com>\n---\n date.c | 11 +++++++++--\n 1 file changed, 9 insertions(+), 2 deletions(-)\n\ndiff --git a/date.c b/date.c\nindex 1ac28e5..11ee7b4 100644\n--- a/date.c\n+++ b/date.c\n@@ -648,6 +648,7 @@ int parse_date_basic(const char *date, unsigned\nlong *timestamp, int *offset)\n \tstruct tm tm;\n \tint tm_gmt;\n \tunsigned long dummy_timestamp;\n+\ttime_t temp_time;\n \tint dummy_offset;\n\n \tif (!timestamp)\n@@ -694,8 +695,14 @@ int parse_date_basic(const char *date, unsigned\nlong *timestamp, int *offset)\n\n \t/* mktime uses local timezone */\n \t*timestamp = tm_to_time_t(&tm);\n-\tif (*offset == -1)\n-\t\t*offset = ((time_t)*timestamp - mktime(&tm)) / 60;\n+\tif (*offset == -1) {\n+\t\ttemp_time = mktime(&tm);\n+\t\tif ((time_t)*timestamp > temp_time) {\n+\t\t\t*offset = ((time_t)*timestamp - temp_time) / 60;\n+\t\t} else {\n+\t\t\t*offset = -(int)((temp_time - (time_t)*timestamp) / 60);\n+\t\t}\n+\t}\n\n \tif (*timestamp == -1)\n \t\treturn -1;\n-- \n1.8.2-rc0\n"}]}