< prev index next >
src/java.base/share/classes/sun/util/locale/provider/DateFormatProviderImpl.java
Print this page
rev 47480 : [mq]: 8176841
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -30,10 +30,11 @@
import java.text.spi.DateFormatProvider;
import java.util.Calendar;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Set;
+import java.util.TimeZone;
/**
* Concrete implementation of the {@link java.text.spi.DateFormatProvider
* DateFormatProvider} class for the JRE LocaleProviderAdapter.
*
@@ -145,22 +146,34 @@
private DateFormat getInstance(int dateStyle, int timeStyle, Locale locale) {
if (locale == null) {
throw new NullPointerException();
}
- SimpleDateFormat sdf = new SimpleDateFormat("", locale);
+ // Check for region override
+ Locale rg = CalendarDataUtility.findRegionOverride(locale).orElse(locale);
+
+ SimpleDateFormat sdf = new SimpleDateFormat("", rg);
Calendar cal = sdf.getCalendar();
try {
String pattern = LocaleProviderAdapter.forType(type)
- .getLocaleResources(locale).getDateTimePattern(timeStyle, dateStyle,
+ .getLocaleResources(rg).getDateTimePattern(timeStyle, dateStyle,
cal);
sdf.applyPattern(pattern);
} catch (MissingResourceException mre) {
// Specify the fallback pattern
sdf.applyPattern("M/d/yy h:mm a");
}
+ // Check for timezone override
+ String tz = locale.getUnicodeLocaleType("tz");
+ if (tz != null) {
+ sdf.setTimeZone(
+ TimeZoneNameUtility.convertLDMLShortID(tz)
+ .map(TimeZone::getTimeZone)
+ .orElseGet(sdf::getTimeZone));
+ }
+
return sdf;
}
@Override
public Set<String> getAvailableLanguageTags() {
< prev index next >