Update Deskbar Clock to use predefined time formats
... with day of week tacked on at the beginning. This fixes #9143 by better allowing the Locale Kit to format the time. It was localized before but now also uses localized time separators. There might be still a bug with day of week though, depending on if day of week should go before or after the time in your locale (It is hard coded to before).
This commit is contained in:
@@ -88,7 +88,6 @@ TTimeView::TTimeView(float maxWidth, float height, bool use24HourClock,
|
||||
fLastTimeStr[0] = 0;
|
||||
fLastDateStr[0] = 0;
|
||||
fNeedToUpdate = true;
|
||||
UpdateTimeFormat();
|
||||
|
||||
fLocale = *BLocale::Default();
|
||||
}
|
||||
@@ -385,7 +384,24 @@ TTimeView::ShowCalendar(BPoint where)
|
||||
void
|
||||
TTimeView::GetCurrentTime()
|
||||
{
|
||||
fLocale.FormatTime(fCurrentTimeStr, 64, fCurrentTime, fTimeFormat);
|
||||
char tmp[sizeof(fCurrentTimeStr)];
|
||||
ssize_t offset = 0;
|
||||
|
||||
if (fShowSeconds) {
|
||||
fLocale.FormatTime(tmp, sizeof(fCurrentTimeStr), fCurrentTime,
|
||||
B_MEDIUM_TIME_FORMAT);
|
||||
} else {
|
||||
fLocale.FormatTime(tmp, sizeof(fCurrentTimeStr), fCurrentTime,
|
||||
B_SHORT_TIME_FORMAT);
|
||||
}
|
||||
|
||||
if (fShowDayOfWeek) {
|
||||
BString timeFormat("eee ");
|
||||
offset = fLocale.FormatTime(fCurrentTimeStr, sizeof(fCurrentTimeStr),
|
||||
fCurrentTime, timeFormat);
|
||||
}
|
||||
|
||||
strlcpy(fCurrentTimeStr + offset, tmp, sizeof(fCurrentTimeStr) - offset);
|
||||
}
|
||||
|
||||
|
||||
@@ -394,7 +410,8 @@ TTimeView::GetCurrentDate()
|
||||
{
|
||||
char tmp[64];
|
||||
|
||||
fLocale.FormatDate(tmp, 64, fCurrentTime, B_FULL_DATE_FORMAT);
|
||||
fLocale.FormatDate(tmp, sizeof(fCurrentDateStr), fCurrentTime,
|
||||
B_FULL_DATE_FORMAT);
|
||||
|
||||
// remove leading 0 from date when month is less than 10 (MM/DD/YY)
|
||||
// or remove leading 0 from date when day is less than 10 (DD/MM/YY)
|
||||
@@ -460,7 +477,6 @@ void
|
||||
TTimeView::Update()
|
||||
{
|
||||
fLocale = *BLocale::Default();
|
||||
UpdateTimeFormat();
|
||||
|
||||
GetCurrentTime();
|
||||
GetCurrentDate();
|
||||
@@ -472,26 +488,3 @@ TTimeView::Update()
|
||||
if (fParent != NULL)
|
||||
fParent->Invalidate();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTimeView::UpdateTimeFormat()
|
||||
{
|
||||
BString timeFormat;
|
||||
|
||||
if (fShowDayOfWeek)
|
||||
timeFormat.Append("eee ");
|
||||
|
||||
if (fUse24HourClock)
|
||||
timeFormat.Append("H:mm");
|
||||
else
|
||||
timeFormat.Append("h:mm");
|
||||
|
||||
if (fShowSeconds)
|
||||
timeFormat.Append(":ss");
|
||||
|
||||
if (!fUse24HourClock)
|
||||
timeFormat.Append(" a");
|
||||
|
||||
fTimeFormat = timeFormat;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,6 @@ private:
|
||||
void CalculateTextPlacement();
|
||||
void ShowTimeOptions(BPoint);
|
||||
void Update();
|
||||
void UpdateTimeFormat();
|
||||
|
||||
BView* fParent;
|
||||
bool fNeedToUpdate;
|
||||
|
||||
Reference in New Issue
Block a user