summaryrefslogtreecommitdiff
path: root/src/corefx
diff options
context:
space:
mode:
authorEric Erhardt <eerhardt@microsoft.com>2015-09-11 16:02:46 -0500
committerMatt Ellis <matell@microsoft.com>2015-09-22 11:50:39 -0700
commit9dc6f27b77af7bf4272f63d9af2ec5b5ca2ec43a (patch)
tree55f5a4a5654f09af6f753d4443acddf8485bb654 /src/corefx
parent87c7b73e23caa73394e29cab7399d18972328d2b (diff)
downloadcoreclr-9dc6f27b77af7bf4272f63d9af2ec5b5ca2ec43a.tar.gz
coreclr-9dc6f27b77af7bf4272f63d9af2ec5b5ca2ec43a.tar.bz2
coreclr-9dc6f27b77af7bf4272f63d9af2ec5b5ca2ec43a.zip
Fixing date patterns on Linux.
1. Getting more LongDatePatterns by getting both full and long ICU patterns. 2. Getting more ShortDatePatterns by getting both medium and short ICU patterns. Still keeping the "yMd" pattern, since this closely matches what is used on Windows. 3. Removing any duplicates in the date patterns. 4. "Normalizing" the date patterns from ICU format to .NET format. a. "EEEE", "eeee" and "cccc" is replaced with "dddd" b. "LLLL" is replaced with "MMMM" c. "G" is replaced with "g" d. A single 'y' is replaced with 'yyyy'
Diffstat (limited to 'src/corefx')
-rw-r--r--src/corefx/System.Globalization.Native/calendarData.cpp42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/corefx/System.Globalization.Native/calendarData.cpp b/src/corefx/System.Globalization.Native/calendarData.cpp
index 061fca9172..a9c356dbaf 100644
--- a/src/corefx/System.Globalization.Native/calendarData.cpp
+++ b/src/corefx/System.Globalization.Native/calendarData.cpp
@@ -9,6 +9,7 @@
#include "locale.hpp"
#include <unicode/dtfmtsym.h>
+#include <unicode/smpdtfmt.h>
#include <unicode/dtptngen.h>
#include <unicode/locdspnm.h>
@@ -245,7 +246,7 @@ CalendarDataResult GetMonthDayPattern(Locale& locale, UChar* sMonthDay, int32_t
if (U_FAILURE(err))
return GetCalendarDataResult(err);
- UnicodeString monthDayPattern = generator->getBestPattern(UnicodeString("MMMMd"), err);
+ UnicodeString monthDayPattern = generator->getBestPattern(UnicodeString(UDAT_MONTH_DAY), err);
if (U_FAILURE(err))
return GetCalendarDataResult(err);
@@ -299,6 +300,30 @@ extern "C" CalendarDataResult GetCalendarInfo(const UChar* localeName, CalendarI
/*
Function:
+InvokeCallbackForDatePattern
+
+Gets the ICU date pattern for the specified locale and EStyle and invokes the callback with the result.
+*/
+bool InvokeCallbackForDatePattern(Locale& locale, DateFormat::EStyle style, EnumCalendarInfoCallback callback, const void* context)
+{
+ LocalPointer<DateFormat> dateFormat(DateFormat::createDateInstance(style, locale));
+ if (dateFormat.isNull())
+ return false;
+
+ // cast to SimpleDateFormat so we can call toPattern()
+ SimpleDateFormat* sdf = dynamic_cast<SimpleDateFormat*>(dateFormat.getAlias());
+ if (sdf == NULL)
+ return false;
+
+ UnicodeString pattern;
+ sdf->toPattern(pattern);
+
+ callback(pattern.getTerminatedBuffer(), context);
+ return true;
+}
+
+/*
+Function:
InvokeCallbackForDateTimePattern
Gets the DateTime pattern for the specified skeleton and invokes the callback with the retrieved value.
@@ -451,14 +476,17 @@ extern "C" int32_t EnumCalendarInfo(
switch (dataType)
{
case ShortDates:
- return InvokeCallbackForDateTimePattern(locale, "Mdyyyy", callback, context);
+ // ShortDates to map kShort and kMedium in ICU, but also adding the "yMd" skeleton as well, as this
+ // closely matches what is used on Windows
+ return InvokeCallbackForDateTimePattern(locale, UDAT_YEAR_NUM_MONTH_DAY, callback, context) &&
+ InvokeCallbackForDatePattern(locale, DateFormat::kShort, callback, context) &&
+ InvokeCallbackForDatePattern(locale, DateFormat::kMedium, callback, context);
case LongDates:
- // TODO: need to replace the "EEEE"s with "dddd"s for .net
- // Also, "LLLL"s to "MMMM"s
- // Also, "G"s to "g"s
- return InvokeCallbackForDateTimePattern(locale, "eeeeMMMMddyyyy", callback, context);
+ // LongDates map to kFull and kLong in ICU.
+ return InvokeCallbackForDatePattern(locale, DateFormat::kFull, callback, context) &&
+ InvokeCallbackForDatePattern(locale, DateFormat::kLong, callback, context);
case YearMonths:
- return InvokeCallbackForDateTimePattern(locale, "yyyyMMMM", callback, context);
+ return InvokeCallbackForDateTimePattern(locale, UDAT_YEAR_MONTH, callback, context);
case DayNames:
return EnumWeekdays(locale, calendarId, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE, callback, context);
case AbbrevDayNames: