From 6d585c1cb009e272236b0861545dc7176923a145 Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Wed, 25 Mar 2009 20:49:46 +0000 Subject: [PATCH] * 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 --- headers/private/shared/DateTime.h | 5 +++-- src/kits/shared/DateTime.cpp | 31 +++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/headers/private/shared/DateTime.h b/headers/private/shared/DateTime.h index d5f4c75bed..53e354e4ed 100755 --- a/headers/private/shared/DateTime.h +++ b/headers/private/shared/DateTime.h @@ -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. */ #ifndef _DATE_TIME_H_ @@ -147,6 +147,7 @@ class BDate { class BDateTime { public: + BDateTime(); BDateTime(const BDate &date, const BTime &time); ~BDateTime(); @@ -161,7 +162,7 @@ class BDateTime { BTime Time() const; void SetTime(const BTime &time); - uint32 Time_t() const; + static uint32 Time_t(time_type type); private: BDate fDate; diff --git a/src/kits/shared/DateTime.cpp b/src/kits/shared/DateTime.cpp index 2fdd0a5719..b859682392 100644 --- a/src/kits/shared/DateTime.cpp +++ b/src/kits/shared/DateTime.cpp @@ -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. * * Authors: @@ -536,10 +536,11 @@ bool BDate::IsLeapYear(int32 year) const { if (year < 1582) { - if (year < 0) year++; + if (year < 0) + year++; 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 +BDateTime::BDateTime() + : fDate(BDate()), + fTime(BTime()) +{ +} + + BDateTime::BDateTime(const BDate &date, const BTime &time) : fDate(date), fTime(time) @@ -843,17 +851,20 @@ BDateTime::SetTime(const BTime &time) 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_struct.tm_hour = fTime.Hour(); - tm_struct.tm_min = fTime.Minute(); - tm_struct.tm_sec = fTime.Second(); + tm_struct.tm_hour = time.Hour(); + tm_struct.tm_min = time.Minute(); + tm_struct.tm_sec = time.Second(); - tm_struct.tm_year = fDate.Year() - 1900; - tm_struct.tm_mon = fDate.Month() - 1; - tm_struct.tm_mday = fDate.Day(); + tm_struct.tm_year = date.Year() - 1900; + tm_struct.tm_mon = date.Month() - 1; + tm_struct.tm_mday = date.Day(); // set less 0 as we wan't use it tm_struct.tm_isdst = -1;