Commit 86d00978 authored by tkent@chromium.org's avatar tkent@chromium.org
Browse files

Introduce Localizer::dateTimeFormatWithSecond and dateTimeFormatWithoutSecond

https://bugs.webkit.org/show_bug.cgi?id=98229

Reviewed by Kentaro Hara.

Unify identical code in DateTimeInputType and DateTimeLocalInputType as
Localizer member functions.
They still have some common code. We'll address it later.

No new tests. This doesn't change any behavior.

* platform/text/Localizer.h:
(Localizer): Add dateTimeFormatWithSecond and dateTimeFormatWithoutSecond.
* platform/text/Localizer.cpp:
(WebCore::Localizer::dateTimeFormatWithSecond):
Implemented. Just concatenating dateFormat, a space, and timeFormat.
(WebCore::Localizer::dateTimeFormatWithoutSecond):
Implemented. Just concatenating dateFormat, a space, and shortTimeFormat.

* html/DateTimeInputType.cpp:
(WebCore::DateTimeInputType::setupLayoutParameters):
Use dateTimeFormatWithSecond and dateTimeFormatWithoutSecond.
* html/DateTimeLocalInputType.cpp:
(WebCore::DateTimeLocalInputType::setupLayoutParameters): ditto.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@130247 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ba29d01e
2012-10-02 Kent Tamura <tkent@chromium.org>
Introduce Localizer::dateTimeFormatWithSecond and dateTimeFormatWithoutSecond
https://bugs.webkit.org/show_bug.cgi?id=98229
Reviewed by Kentaro Hara.
Unify identical code in DateTimeInputType and DateTimeLocalInputType as
Localizer member functions.
They still have some common code. We'll address it later.
No new tests. This doesn't change any behavior.
* platform/text/Localizer.h:
(Localizer): Add dateTimeFormatWithSecond and dateTimeFormatWithoutSecond.
* platform/text/Localizer.cpp:
(WebCore::Localizer::dateTimeFormatWithSecond):
Implemented. Just concatenating dateFormat, a space, and timeFormat.
(WebCore::Localizer::dateTimeFormatWithoutSecond):
Implemented. Just concatenating dateFormat, a space, and shortTimeFormat.
* html/DateTimeInputType.cpp:
(WebCore::DateTimeInputType::setupLayoutParameters):
Use dateTimeFormatWithSecond and dateTimeFormatWithoutSecond.
* html/DateTimeLocalInputType.cpp:
(WebCore::DateTimeLocalInputType::setupLayoutParameters): ditto.
2012-10-03 Kent Tamura <tkent@chromium.org>
Refactoring: DateTimeEditBuilder had better hold LayoutParameters
......
......@@ -145,20 +145,13 @@ String DateTimeInputType::formatDateTimeFieldsState(const DateTimeFieldsState& d
void DateTimeInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters& layoutParameters, const DateComponents& date) const
{
// FIXME: It is better to have Localizer::dateTimeFormat() and use it
// here rather than constructing from dateFormat() and timeFormat().
StringBuilder builder;
builder.append(layoutParameters.localizer.dateFormat());
builder.append(' ');
if (date.second() || layoutParameters.shouldHaveSecondField()) {
builder.append(layoutParameters.localizer.timeFormat());
layoutParameters.dateTimeFormat = layoutParameters.localizer.dateTimeFormatWithSecond();
layoutParameters.fallbackDateTimeFormat = "dd/MM/yyyy HH:mm:ss";
} else {
builder.append(layoutParameters.localizer.shortTimeFormat());
layoutParameters.dateTimeFormat = layoutParameters.localizer.dateTimeFormatWithoutSecond();
layoutParameters.fallbackDateTimeFormat = "dd/MM/yyyy HH:mm";
}
layoutParameters.dateTimeFormat = builder.toString();
layoutParameters.placeholderForDay = placeholderForDayOfMonthField();
layoutParameters.placeholderForMonth = placeholderForMonthField();
layoutParameters.placeholderForYear = placeholderForYearField();
......
......@@ -151,20 +151,13 @@ String DateTimeLocalInputType::formatDateTimeFieldsState(const DateTimeFieldsSta
void DateTimeLocalInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters& layoutParameters, const DateComponents& date) const
{
// FIXME: It is better to have Localizer::dateTimeFormat() and use it
// here rather than constructing from dateFormat() and timeFormat().
StringBuilder builder;
builder.append(layoutParameters.localizer.dateFormat());
builder.append(' ');
if (date.second() || layoutParameters.shouldHaveSecondField()) {
builder.append(layoutParameters.localizer.timeFormat());
layoutParameters.dateTimeFormat = layoutParameters.localizer.dateTimeFormatWithSecond();
layoutParameters.fallbackDateTimeFormat = "dd/MM/yyyy HH:mm:ss";
} else {
builder.append(layoutParameters.localizer.shortTimeFormat());
layoutParameters.dateTimeFormat = layoutParameters.localizer.dateTimeFormatWithoutSecond();
layoutParameters.fallbackDateTimeFormat = "dd/MM/yyyy HH:mm";
}
layoutParameters.dateTimeFormat = builder.toString();
layoutParameters.placeholderForDay = placeholderForDayOfMonthField();
layoutParameters.placeholderForMonth = placeholderForMonthField();
layoutParameters.placeholderForYear = placeholderForYearField();
......
......@@ -207,6 +207,26 @@ String Localizer::shortTimeFormat()
return m_localizedShortTimeFormatText;
}
String Localizer::dateTimeFormatWithSecond()
{
// FIXME: We should retreive the separator and the order from the system.
StringBuilder builder;
builder.append(dateFormat());
builder.append(' ');
builder.append(timeFormat());
return builder.toString();
}
String Localizer::dateTimeFormatWithoutSecond()
{
// FIXME: We should retreive the separator and the order from the system.
StringBuilder builder;
builder.append(dateFormat());
builder.append(' ');
builder.append(shortTimeFormat());
return builder.toString();
}
const Vector<String>& Localizer::timeAMPMLabels()
{
if (!m_timeAMPMLabels.isEmpty())
......
......@@ -72,6 +72,14 @@ public:
// Note: Some platforms return same value as timeFormat().
virtual String shortTimeFormat();
// Returns a date-time format in Unicode TR35 LDML. It should have a second
// field.
String dateTimeFormatWithSecond();
// Returns a date-time format in Unicode TR35 LDML. It should have no second
// field.
String dateTimeFormatWithoutSecond();
// Returns localized period field(AM/PM) strings.
virtual const Vector<String>& timeAMPMLabels();
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment