From cc5a68f1c17a9c3e8da7fb7695190eb858e7dc5d Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sun, 18 Jul 2010 19:24:15 +0000 Subject: [PATCH] * Use a BDateTime instead of a BTime to hold the time value forthe TimeEdit. This allow proper handling of conversion to time_t, taking timezones into account. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37568 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/time/DateTimeEdit.cpp | 32 +++++++++++++++------------ src/preferences/time/DateTimeEdit.h | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/preferences/time/DateTimeEdit.cpp b/src/preferences/time/DateTimeEdit.cpp index bdad0e9c00..f0961773fa 100644 --- a/src/preferences/time/DateTimeEdit.cpp +++ b/src/preferences/time/DateTimeEdit.cpp @@ -30,7 +30,7 @@ TTimeEdit::TTimeEdit(BRect frame, const char* name, uint32 sections) fLastKeyDownTime(0) { InitView(); - fTime = BTime::CurrentTime(B_LOCAL_TIME); + fTime = BDateTime::CurrentDateTime(B_LOCAL_TIME); } @@ -94,7 +94,7 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus) return; BRect bounds = section->Frame(); - time_t time = fTime.Hour() * 3600 + fTime.Minute() * 60 + fTime.Second(); + time_t time = fTime.Time_t(); SetLowColor(ViewColor()); BString field; @@ -150,7 +150,7 @@ TTimeEdit::DrawSeparator(uint32 index) BCountry* country; be_locale_roster->GetDefaultCountry(&country); - time_t time = fTime.Hour() * 3600 + fTime.Minute() * 60 + fTime.Second(); + time_t time = fTime.Time_t(); country->FormatTime(&text, fieldPositions, fieldCount, time, true); // TODO : this should be cached somehow to not redo it for each field @@ -215,11 +215,11 @@ TTimeEdit::SectionFocus(uint32 index) void TTimeEdit::SetTime(int32 hour, int32 minute, int32 second) { - if (fTime.Hour() == hour && fTime.Minute() == minute - && fTime.Second() == second) + if (fTime.Time().Hour() == hour && fTime.Time().Minute() == minute + && fTime.Time().Second() == second) return; - fTime.SetTime(hour, minute, second); + fTime.SetTime(BTime(hour, minute, second)); Invalidate(Bounds()); } @@ -317,7 +317,8 @@ TTimeEdit::_CheckRange() else if (value < 0) value = 23; - fTime.SetTime(value, fTime.Minute(), fTime.Second()); + fTime.SetTime(BTime(value, fTime.Time().Minute(), + fTime.Time().Second())); break; case B_DATE_ELEMENT_MINUTE: @@ -326,7 +327,8 @@ TTimeEdit::_CheckRange() else if (value < 0) value = 59; - fTime.SetTime(fTime.Hour(), value, fTime.Second()); + fTime.SetTime(BTime(fTime.Time().Hour(), value, + fTime.Time().Second())); break; case B_DATE_ELEMENT_SECOND: @@ -335,11 +337,12 @@ TTimeEdit::_CheckRange() else if (value < 0) value = 59; - fTime.SetTime(fTime.Hour(), fTime.Minute(), value); + fTime.SetTime(BTime(fTime.Time().Hour(), fTime.Time().Minute(), + value)); break; case B_DATE_ELEMENT_AM_PM: - value = fTime.Hour(); + value = fTime.Time().Hour(); if (value < 13) value += 12; else @@ -348,7 +351,8 @@ TTimeEdit::_CheckRange() value = 0; // modify hour value to reflect change in am/ pm - fTime.SetTime(value, fTime.Minute(), fTime.Second()); + fTime.SetTime(BTime(value, fTime.Time().Minute(), + fTime.Time().Second())); break; default: @@ -417,15 +421,15 @@ TTimeEdit::_SectionValue(int32 index) const } switch (fields[index]) { case B_DATE_ELEMENT_HOUR: - value = fTime.Hour(); + value = fTime.Time().Hour(); break; case B_DATE_ELEMENT_MINUTE: - value = fTime.Minute(); + value = fTime.Time().Minute(); break; case B_DATE_ELEMENT_SECOND: - value = fTime.Second(); + value = fTime.Time().Second(); break; default: diff --git a/src/preferences/time/DateTimeEdit.h b/src/preferences/time/DateTimeEdit.h index 0b7da5d386..3d3b77236c 100644 --- a/src/preferences/time/DateTimeEdit.h +++ b/src/preferences/time/DateTimeEdit.h @@ -46,7 +46,7 @@ class TTimeEdit : public TSectionEdit { int32 _SectionValue(int32 index) const; private: - BTime fTime; + BDateTime fTime; bigtime_t fLastKeyDownTime; int32 fLastKeyDownInt; };