* fixed broken Time_t since i changed BDate to be able to go back before 1970

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29708 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Karsten Heimrich
2009-03-25 20:49:46 +00:00
parent 934e233b60
commit 6d585c1cb0
2 changed files with 24 additions and 12 deletions
+3 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2007-2008, Haiku, Inc. All Rights Reserved. * Copyright 2007-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _DATE_TIME_H_ #ifndef _DATE_TIME_H_
@@ -147,6 +147,7 @@ class BDate {
class BDateTime { class BDateTime {
public: public:
BDateTime();
BDateTime(const BDate &date, const BTime &time); BDateTime(const BDate &date, const BTime &time);
~BDateTime(); ~BDateTime();
@@ -161,7 +162,7 @@ class BDateTime {
BTime Time() const; BTime Time() const;
void SetTime(const BTime &time); void SetTime(const BTime &time);
uint32 Time_t() const; static uint32 Time_t(time_type type);
private: private:
BDate fDate; BDate fDate;
+21 -10
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2008, Haiku, Inc. All Rights Reserved. * Copyright 2004-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -536,10 +536,11 @@ bool
BDate::IsLeapYear(int32 year) const BDate::IsLeapYear(int32 year) const
{ {
if (year < 1582) { if (year < 1582) {
if (year < 0) year++; if (year < 0)
year++;
return (year % 4) == 0; return (year % 4) == 0;
} }
return year % 400 == 0 || year % 4 == 0 && year % 100 != 0; return (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0));
} }
@@ -777,6 +778,13 @@ BDate::_DateToJulianDay(int32 _year, int32 month, int32 day) const
// #pragma mark - BDateTime // #pragma mark - BDateTime
BDateTime::BDateTime()
: fDate(BDate()),
fTime(BTime())
{
}
BDateTime::BDateTime(const BDate &date, const BTime &time) BDateTime::BDateTime(const BDate &date, const BTime &time)
: fDate(date), : fDate(date),
fTime(time) fTime(time)
@@ -843,17 +851,20 @@ BDateTime::SetTime(const BTime &time)
uint32 uint32
BDateTime::Time_t() const BDateTime::Time_t(time_type type)
{ {
BTime time = BTime::CurrentTime(type);
BDate date = BDate::CurrentDate(type);
tm tm_struct; tm tm_struct;
tm_struct.tm_hour = fTime.Hour(); tm_struct.tm_hour = time.Hour();
tm_struct.tm_min = fTime.Minute(); tm_struct.tm_min = time.Minute();
tm_struct.tm_sec = fTime.Second(); tm_struct.tm_sec = time.Second();
tm_struct.tm_year = fDate.Year() - 1900; tm_struct.tm_year = date.Year() - 1900;
tm_struct.tm_mon = fDate.Month() - 1; tm_struct.tm_mon = date.Month() - 1;
tm_struct.tm_mday = fDate.Day(); tm_struct.tm_mday = date.Day();
// set less 0 as we wan't use it // set less 0 as we wan't use it
tm_struct.tm_isdst = -1; tm_struct.tm_isdst = -1;