< prev index next >

src/java.base/share/classes/sun/util/locale/provider/DateFormatProviderImpl.java

Print this page
rev 47733 : 8176841: Additional Unicode Language-Tag Extensions
8189134: New system properties for the default Locale extensions
Reviewed-by:

*** 1,7 **** /* ! * Copyright (c) 1999, 2012, 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 --- 1,7 ---- /* ! * 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,39 **** --- 30,40 ---- 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,166 **** private DateFormat getInstance(int dateStyle, int timeStyle, Locale locale) { if (locale == null) { throw new NullPointerException(); } ! SimpleDateFormat sdf = new SimpleDateFormat("", locale); Calendar cal = sdf.getCalendar(); try { String pattern = LocaleProviderAdapter.forType(type) ! .getLocaleResources(locale).getDateTimePattern(timeStyle, dateStyle, cal); sdf.applyPattern(pattern); } catch (MissingResourceException mre) { // Specify the fallback pattern sdf.applyPattern("M/d/yy h:mm a"); } return sdf; } @Override public Set<String> getAvailableLanguageTags() { --- 146,179 ---- private DateFormat getInstance(int dateStyle, int timeStyle, Locale locale) { if (locale == null) { throw new NullPointerException(); } ! // 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(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 >