Use BDateTimeFormat for deskbar clock
* don't try to cook a custom format by appending strings, and instead let BDateTimeFormat decide on the appropriate format to use.
This commit is contained in:
@@ -383,36 +383,20 @@ TTimeView::ShowCalendar(BPoint where)
|
|||||||
void
|
void
|
||||||
TTimeView::GetCurrentTime()
|
TTimeView::GetCurrentTime()
|
||||||
{
|
{
|
||||||
ssize_t offset_dow = 0;
|
int32 fields = B_DATE_ELEMENT_HOUR | B_DATE_ELEMENT_MINUTE;
|
||||||
ssize_t offset_time = 0;
|
if (fShowSeconds)
|
||||||
|
fields |= B_DATE_ELEMENT_SECOND;
|
||||||
|
if (fShowDayOfWeek)
|
||||||
|
fields |= B_DATE_ELEMENT_WEEKDAY;
|
||||||
|
if (fShowTimeZone)
|
||||||
|
fields |= B_DATE_ELEMENT_TIMEZONE;
|
||||||
|
|
||||||
// ToDo: Check to see if we should write day of week after time for locale
|
fTimeFormat.SetDateTimeFormat(B_SHORT_DATE_FORMAT, B_SHORT_TIME_FORMAT,
|
||||||
|
fields);
|
||||||
|
|
||||||
if (fShowDayOfWeek) {
|
fTimeFormat.Format(fCurrentTimeStr,
|
||||||
BString timeFormat("eee ");
|
sizeof(fCurrentTimeStr), fCurrentTime,
|
||||||
offset_dow = fTimeFormat.Format(fCurrentTimeStr,
|
B_SHORT_DATE_FORMAT, B_SHORT_TIME_FORMAT);
|
||||||
sizeof(fCurrentTimeStr), fCurrentTime, timeFormat);
|
|
||||||
|
|
||||||
if (offset_dow < 0) {
|
|
||||||
// error occured, attempt to overwrite with current time
|
|
||||||
// (this should not ever happen)
|
|
||||||
fTimeFormat.Format(fCurrentTimeStr, sizeof(fCurrentTimeStr),
|
|
||||||
fCurrentTime,
|
|
||||||
fShowSeconds ? B_MEDIUM_TIME_FORMAT : B_SHORT_TIME_FORMAT);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
offset_time = fTimeFormat.Format(fCurrentTimeStr + offset_dow,
|
|
||||||
sizeof(fCurrentTimeStr) - offset_dow, fCurrentTime,
|
|
||||||
fShowSeconds ? B_MEDIUM_TIME_FORMAT : B_SHORT_TIME_FORMAT);
|
|
||||||
|
|
||||||
if (fShowTimeZone) {
|
|
||||||
BString timeFormat(" V");
|
|
||||||
ssize_t offset = offset_dow + offset_time;
|
|
||||||
fTimeFormat.Format(fCurrentTimeStr + offset,
|
|
||||||
sizeof(fCurrentTimeStr) - offset, fCurrentTime, timeFormat);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ All rights reserved.
|
|||||||
|
|
||||||
|
|
||||||
#include <DateFormat.h>
|
#include <DateFormat.h>
|
||||||
|
#include <DateTimeFormat.h>
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <TimeFormat.h>
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ private:
|
|||||||
// For date and time localization purposes
|
// For date and time localization purposes
|
||||||
BLocale fLocale;
|
BLocale fLocale;
|
||||||
BDateFormat fDateFormat;
|
BDateFormat fDateFormat;
|
||||||
BTimeFormat fTimeFormat;
|
BDateTimeFormat fTimeFormat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user