BDateTime: Time_T functions return or take a time_t
* They used an unsigned int, which led to overflows when trying to set them to a time before January 1st, 1970 (local time) * Some things use January 1st, 1970, GMT (or UTC) as a reference point. In my timezone this leads to such a negative date. An example is cookie expiration dates which are set to this date to expire them immediately. Spotted by Opera testsuite. * This makes the method unuseable for dates after 2036 (signed 32-bit time_t will overflow then. This gives us just 33 years to switch to a 64-bit time_t. In te meantime, please try using other methods to set the date and time for BDateTime objects if you need to go this far.
This commit is contained in:
@@ -189,8 +189,8 @@ public:
|
|||||||
const BTime& Time() const;
|
const BTime& Time() const;
|
||||||
void SetTime(const BTime &time);
|
void SetTime(const BTime &time);
|
||||||
|
|
||||||
int32 Time_t() const;
|
time_t Time_t() const;
|
||||||
void SetTime_t(uint32 seconds);
|
void SetTime_t(time_t seconds);
|
||||||
|
|
||||||
bool operator!=(const BDateTime& dateTime) const;
|
bool operator!=(const BDateTime& dateTime) const;
|
||||||
bool operator==(const BDateTime& dateTime) const;
|
bool operator==(const BDateTime& dateTime) const;
|
||||||
|
|||||||
@@ -1371,7 +1371,7 @@ BDateTime::SetTime(const BTime& time)
|
|||||||
1.1.1970 - 00:00:00. If the current date is before 1.1.1970 the function
|
1.1.1970 - 00:00:00. If the current date is before 1.1.1970 the function
|
||||||
returns -1;
|
returns -1;
|
||||||
*/
|
*/
|
||||||
int32
|
time_t
|
||||||
BDateTime::Time_t() const
|
BDateTime::Time_t() const
|
||||||
{
|
{
|
||||||
BDate date(1970, 1, 1);
|
BDate date(1970, 1, 1);
|
||||||
@@ -1392,7 +1392,7 @@ BDateTime::Time_t() const
|
|||||||
tm_struct.tm_isdst = -1;
|
tm_struct.tm_isdst = -1;
|
||||||
|
|
||||||
// return secs_since_jan1_1970 or -1 on error
|
// return secs_since_jan1_1970 or -1 on error
|
||||||
return int32(mktime(&tm_struct));
|
return mktime(&tm_struct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1401,8 +1401,14 @@ BDateTime::Time_t() const
|
|||||||
1.1.1970 - 00:00:00.
|
1.1.1970 - 00:00:00.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
BDateTime::SetTime_t(uint32 seconds)
|
BDateTime::SetTime_t(time_t seconds)
|
||||||
{
|
{
|
||||||
|
time_t timePart = seconds % kSecondsPerDay;
|
||||||
|
if (timePart < 0) {
|
||||||
|
timePart += kSecondsPerDay;
|
||||||
|
seconds -= kSecondsPerDay;
|
||||||
|
}
|
||||||
|
|
||||||
BTime time;
|
BTime time;
|
||||||
time.AddSeconds(seconds % kSecondsPerDay);
|
time.AddSeconds(seconds % kSecondsPerDay);
|
||||||
fTime.SetTime(time);
|
fTime.SetTime(time);
|
||||||
|
|||||||
Reference in New Issue
Block a user