mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8176841: Additional Unicode Language-Tag Extensions
8189134: New system properties for the default Locale extensions 8190918: Retrieve the region specific data regardless of language in locale 8191349: Add a new method in j.t.f.DateTimeFormatter to reflect Unicode extensions Reviewed-by: scolebourne, lancea, rriggs, rgoel, nishjain
This commit is contained in:
parent
3246c46f41
commit
f065141ddc
55 changed files with 3631 additions and 890 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -47,10 +47,34 @@ public class CalendarDataUtility {
|
|||
}
|
||||
|
||||
public static int retrieveFirstDayOfWeek(Locale locale) {
|
||||
// Look for the Unicode Extension in the locale parameter
|
||||
if (locale.hasExtensions()) {
|
||||
String fw = locale.getUnicodeLocaleType("fw");
|
||||
if (fw != null) {
|
||||
switch (fw.toLowerCase(Locale.ROOT)) {
|
||||
case "mon":
|
||||
return MONDAY;
|
||||
case "tue":
|
||||
return TUESDAY;
|
||||
case "wed":
|
||||
return WEDNESDAY;
|
||||
case "thu":
|
||||
return THURSDAY;
|
||||
case "fri":
|
||||
return FRIDAY;
|
||||
case "sat":
|
||||
return SATURDAY;
|
||||
case "sun":
|
||||
return SUNDAY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LocaleServiceProviderPool pool =
|
||||
LocaleServiceProviderPool.getPool(CalendarDataProvider.class);
|
||||
Integer value = pool.getLocalizedObject(CalendarWeekParameterGetter.INSTANCE,
|
||||
locale, true, FIRST_DAY_OF_WEEK);
|
||||
findRegionOverride(locale),
|
||||
true, FIRST_DAY_OF_WEEK);
|
||||
return (value != null && (value >= SUNDAY && value <= SATURDAY)) ? value : SUNDAY;
|
||||
}
|
||||
|
||||
|
@ -58,7 +82,8 @@ public class CalendarDataUtility {
|
|||
LocaleServiceProviderPool pool =
|
||||
LocaleServiceProviderPool.getPool(CalendarDataProvider.class);
|
||||
Integer value = pool.getLocalizedObject(CalendarWeekParameterGetter.INSTANCE,
|
||||
locale, true, MINIMAL_DAYS_IN_FIRST_WEEK);
|
||||
findRegionOverride(locale),
|
||||
true, MINIMAL_DAYS_IN_FIRST_WEEK);
|
||||
return (value != null && (value >= 1 && value <= 7)) ? value : 1;
|
||||
}
|
||||
|
||||
|
@ -102,6 +127,32 @@ public class CalendarDataUtility {
|
|||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to look for a region override extension.
|
||||
* If no region override is found, returns the original locale.
|
||||
*/
|
||||
public static Locale findRegionOverride(Locale l) {
|
||||
String rg = l.getUnicodeLocaleType("rg");
|
||||
Locale override = l;
|
||||
|
||||
if (rg != null && rg.length() == 6) {
|
||||
// UN M.49 code should not be allowed here
|
||||
// cannot use regex here, as it could be a recursive call
|
||||
rg = rg.toUpperCase(Locale.ROOT);
|
||||
if (rg.charAt(0) >= 0x0041 &&
|
||||
rg.charAt(0) <= 0x005A &&
|
||||
rg.charAt(1) >= 0x0041 &&
|
||||
rg.charAt(1) <= 0x005A &&
|
||||
rg.substring(2).equals("ZZZZ")) {
|
||||
override = new Locale.Builder().setLocale(l)
|
||||
.setRegion(rg.substring(0, 2))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
return override;
|
||||
}
|
||||
|
||||
static String normalizeCalendarType(String requestID) {
|
||||
String type;
|
||||
if (requestID.equals("gregorian") || requestID.equals("iso8601")) {
|
||||
|
@ -179,7 +230,7 @@ public class CalendarDataUtility {
|
|||
}
|
||||
}
|
||||
|
||||
private static class CalendarWeekParameterGetter
|
||||
private static class CalendarWeekParameterGetter
|
||||
implements LocaleServiceProviderPool.LocalizedObjectGetter<CalendarDataProvider,
|
||||
Integer> {
|
||||
private static final CalendarWeekParameterGetter INSTANCE =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue