* 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
This commit is contained in:
Adrien Destugues 2010-07-18 19:24:15 +00:00
parent 4366ca40fe
commit cc5a68f1c1
2 changed files with 19 additions and 15 deletions

View File

@ -30,7 +30,7 @@ TTimeEdit::TTimeEdit(BRect frame, const char* name, uint32 sections)
fLastKeyDownTime(0) fLastKeyDownTime(0)
{ {
InitView(); InitView();
fTime = BTime::CurrentTime(B_LOCAL_TIME); fTime = BDateTime::CurrentDateTime(B_LOCAL_TIME);
} }
@ -94,7 +94,7 @@ TTimeEdit::DrawSection(uint32 index, bool hasFocus)
return; return;
BRect bounds = section->Frame(); BRect bounds = section->Frame();
time_t time = fTime.Hour() * 3600 + fTime.Minute() * 60 + fTime.Second(); time_t time = fTime.Time_t();
SetLowColor(ViewColor()); SetLowColor(ViewColor());
BString field; BString field;
@ -150,7 +150,7 @@ TTimeEdit::DrawSeparator(uint32 index)
BCountry* country; BCountry* country;
be_locale_roster->GetDefaultCountry(&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); country->FormatTime(&text, fieldPositions, fieldCount, time, true);
// TODO : this should be cached somehow to not redo it for each field // TODO : this should be cached somehow to not redo it for each field
@ -215,11 +215,11 @@ TTimeEdit::SectionFocus(uint32 index)
void void
TTimeEdit::SetTime(int32 hour, int32 minute, int32 second) TTimeEdit::SetTime(int32 hour, int32 minute, int32 second)
{ {
if (fTime.Hour() == hour && fTime.Minute() == minute if (fTime.Time().Hour() == hour && fTime.Time().Minute() == minute
&& fTime.Second() == second) && fTime.Time().Second() == second)
return; return;
fTime.SetTime(hour, minute, second); fTime.SetTime(BTime(hour, minute, second));
Invalidate(Bounds()); Invalidate(Bounds());
} }
@ -317,7 +317,8 @@ TTimeEdit::_CheckRange()
else if (value < 0) else if (value < 0)
value = 23; value = 23;
fTime.SetTime(value, fTime.Minute(), fTime.Second()); fTime.SetTime(BTime(value, fTime.Time().Minute(),
fTime.Time().Second()));
break; break;
case B_DATE_ELEMENT_MINUTE: case B_DATE_ELEMENT_MINUTE:
@ -326,7 +327,8 @@ TTimeEdit::_CheckRange()
else if (value < 0) else if (value < 0)
value = 59; value = 59;
fTime.SetTime(fTime.Hour(), value, fTime.Second()); fTime.SetTime(BTime(fTime.Time().Hour(), value,
fTime.Time().Second()));
break; break;
case B_DATE_ELEMENT_SECOND: case B_DATE_ELEMENT_SECOND:
@ -335,11 +337,12 @@ TTimeEdit::_CheckRange()
else if (value < 0) else if (value < 0)
value = 59; value = 59;
fTime.SetTime(fTime.Hour(), fTime.Minute(), value); fTime.SetTime(BTime(fTime.Time().Hour(), fTime.Time().Minute(),
value));
break; break;
case B_DATE_ELEMENT_AM_PM: case B_DATE_ELEMENT_AM_PM:
value = fTime.Hour(); value = fTime.Time().Hour();
if (value < 13) if (value < 13)
value += 12; value += 12;
else else
@ -348,7 +351,8 @@ TTimeEdit::_CheckRange()
value = 0; value = 0;
// modify hour value to reflect change in am/ pm // 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; break;
default: default:
@ -417,15 +421,15 @@ TTimeEdit::_SectionValue(int32 index) const
} }
switch (fields[index]) { switch (fields[index]) {
case B_DATE_ELEMENT_HOUR: case B_DATE_ELEMENT_HOUR:
value = fTime.Hour(); value = fTime.Time().Hour();
break; break;
case B_DATE_ELEMENT_MINUTE: case B_DATE_ELEMENT_MINUTE:
value = fTime.Minute(); value = fTime.Time().Minute();
break; break;
case B_DATE_ELEMENT_SECOND: case B_DATE_ELEMENT_SECOND:
value = fTime.Second(); value = fTime.Time().Second();
break; break;
default: default:

View File

@ -46,7 +46,7 @@ class TTimeEdit : public TSectionEdit {
int32 _SectionValue(int32 index) const; int32 _SectionValue(int32 index) const;
private: private:
BTime fTime; BDateTime fTime;
bigtime_t fLastKeyDownTime; bigtime_t fLastKeyDownTime;
int32 fLastKeyDownInt; int32 fLastKeyDownInt;
}; };