Cookies: avoid timezone confusion

Cookies date are always in GMT time. Using mktime wrongly converts them
as local time instead. This would lead to cookies expiring too early or
too late.
This commit is contained in:
Adrien Destugues 2014-01-19 12:01:36 +01:00
parent 8540ec2446
commit 32da3d9dae

View File

@ -107,7 +107,11 @@ BHttpTime::Parse()
// TODO: The above was used initially. See http://en.wikipedia.org/wiki/Time.h
// stippi: I don't know how Christophe had this code compiling initially,
// since Haiku does not appear to implement timegm().
return mktime(&expireTime);
// Using mktime() doesn't cut it, as cookies set with a date shortly in the
// future (eg. 1 hour) would expire immediately.
time_t t = mktime(&expireTime);
t -= mktime(gmtime(&t)) - (int)mktime(localtime(&t));
return t;
}