diff options
author | Artur Signell <artur@vaadin.com> | 2013-06-03 12:18:57 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2013-06-04 16:52:03 +0300 |
commit | 93751c13557a5dc7cbf853327b73d5b272f1f0d5 (patch) | |
tree | a0d64245b3fc82e2fbbb4f5a27e7569982f9e476 /client | |
parent | 666dbb5f6b80a83c01140159901754fa317a977e (diff) | |
download | vaadin-framework-93751c13557a5dc7cbf853327b73d5b272f1f0d5.tar.gz vaadin-framework-93751c13557a5dc7cbf853327b73d5b272f1f0d5.zip |
Use correct day names when formatting dates (#6207)
Change-Id: I2010f87ef4f9359cdc95104cc02c83355a8630ed
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/DateTimeService.java | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/client/src/com/vaadin/client/DateTimeService.java b/client/src/com/vaadin/client/DateTimeService.java index 53e8f81a38..5fd0574d3e 100644 --- a/client/src/com/vaadin/client/DateTimeService.java +++ b/client/src/com/vaadin/client/DateTimeService.java @@ -308,10 +308,11 @@ public class DateTimeService { */ public String formatDate(Date date, String formatStr) { /* - * Format month names separately when locale for the DateTimeService is - * not the same as the browser locale + * Format month and day names separately when locale for the + * DateTimeService is not the same as the browser locale */ formatStr = formatMonthNames(date, formatStr); + formatStr = formatDayNames(date, formatStr); // Format uses the browser locale DateTimeFormat format = DateTimeFormat.getFormat(formatStr); @@ -321,6 +322,49 @@ public class DateTimeService { return result; } + private String formatDayNames(Date date, String formatStr) { + if (formatStr.contains("EEEE")) { + String dayName = getDay(date.getDay()); + + if (dayName != null) { + /* + * Replace 4 or more E:s with the quoted day name. Also + * concatenate generated string with any other string prepending + * or following the EEEE pattern, i.e. 'EEEE'ta ' becomes 'DAYta + * ' and not 'DAY''ta ', 'ab'EEEE becomes 'abDAY', 'x'EEEE'y' + * becomes 'xDAYy'. + */ + formatStr = formatStr.replaceAll("'([E]{4,})'", dayName); + formatStr = formatStr.replaceAll("([E]{4,})'", "'" + dayName); + formatStr = formatStr.replaceAll("'([E]{4,})", dayName + "'"); + formatStr = formatStr + .replaceAll("[E]{4,}", "'" + dayName + "'"); + } + } + + if (formatStr.contains("EEE")) { + + String dayName = getShortDay(date.getMonth()); + + if (dayName != null) { + /* + * Replace 3 or more E:s with the quoted month name. Also + * concatenate generated string with any other string prepending + * or following the EEE pattern, i.e. 'EEE'ta ' becomes 'DAYta ' + * and not 'DAY''ta ', 'ab'EEE becomes 'abDAY', 'x'EEE'y' + * becomes 'xDAYy'. + */ + formatStr = formatStr.replaceAll("'([E]{3,})'", dayName); + formatStr = formatStr.replaceAll("([E]{3,})'", "'" + dayName); + formatStr = formatStr.replaceAll("'([E]{3,})", dayName + "'"); + formatStr = formatStr + .replaceAll("[E]{3,}", "'" + dayName + "'"); + } + } + + return formatStr; + } + private String formatMonthNames(Date date, String formatStr) { if (formatStr.contains("MMMM")) { String monthName = getMonth(date.getMonth()); |