< prev index next >

src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.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) 2012, 2016, 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) 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 118,127 **** --- 118,128 ---- import java.util.TimeZone; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import sun.text.spi.JavaTimeDateTimePatternProvider; + import sun.util.locale.provider.CalendarDataUtility; import sun.util.locale.provider.LocaleProviderAdapter; import sun.util.locale.provider.LocaleResources; import sun.util.locale.provider.TimeZoneNameUtility; /**
*** 214,224 **** throw new IllegalArgumentException("Either dateStyle or timeStyle must be non-null"); } LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(JavaTimeDateTimePatternProvider.class, locale); JavaTimeDateTimePatternProvider provider = adapter.getJavaTimeDateTimePatternProvider(); String pattern = provider.getJavaTimeDateTimePattern(convertStyle(timeStyle), ! convertStyle(dateStyle), chrono.getCalendarType(), locale); return pattern; } /** * Converts the given FormatStyle to the java.text.DateFormat style. --- 215,226 ---- throw new IllegalArgumentException("Either dateStyle or timeStyle must be non-null"); } LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(JavaTimeDateTimePatternProvider.class, locale); JavaTimeDateTimePatternProvider provider = adapter.getJavaTimeDateTimePatternProvider(); String pattern = provider.getJavaTimeDateTimePattern(convertStyle(timeStyle), ! convertStyle(dateStyle), chrono.getCalendarType(), ! CalendarDataUtility.findRegionOverride(locale).orElse(locale)); return pattern; } /** * Converts the given FormatStyle to the java.text.DateFormat style.
*** 2158,2167 **** --- 2160,2175 ---- * using the default locale. * <p> * This will create a formatter with the {@linkplain Locale#getDefault(Locale.Category) default FORMAT locale}. * Numbers will be printed and parsed using the standard DecimalStyle. * The resolver style will be {@link ResolverStyle#SMART SMART}. + * If the default locale contains "ca" (calendar), "rg" (region override) + * and/or "tz" (timezone) + * <a href="../../util/Locale.html#def_locale_extension">Unicode extensions</a>, + * the chronology and/or the zone are overriden. If both "ca" and "rg" are + * specified, the chronology from "ca" extension supersedes the implicit one + * from "rg" extension. * <p> * Calling this method will end any open optional sections by repeatedly * calling {@link #optionalEnd()} before creating the formatter. * <p> * This builder can still be used after creating the formatter if desired,
*** 2178,2187 **** --- 2186,2201 ---- * using the specified locale. * <p> * This will create a formatter with the specified locale. * Numbers will be printed and parsed using the standard DecimalStyle. * The resolver style will be {@link ResolverStyle#SMART SMART}. + * If the specified locale contains "ca" (calendar), "rg" (region override) + * and/or "tz" (timezone) + * <a href="../../util/Locale.html#def_locale_extension">Unicode extensions</a>, + * the chronology and/or the zone are overriden. If both "ca" and "rg" are + * specified, the chronology from "ca" extension supersedes the implicit one + * from "rg" extension. * <p> * Calling this method will end any open optional sections by repeatedly * calling {@link #optionalEnd()} before creating the formatter. * <p> * This builder can still be used after creating the formatter if desired,
*** 2216,2227 **** Objects.requireNonNull(locale, "locale"); while (active.parent != null) { optionalEnd(); } CompositePrinterParser pp = new CompositePrinterParser(printerParsers, false); return new DateTimeFormatter(pp, locale, DecimalStyle.STANDARD, ! resolverStyle, null, chrono, null); } //----------------------------------------------------------------------- /** * Strategy for formatting/parsing date-time information. --- 2230,2251 ---- Objects.requireNonNull(locale, "locale"); while (active.parent != null) { optionalEnd(); } CompositePrinterParser pp = new CompositePrinterParser(printerParsers, false); + + // Check for chronology/timezone in locale object + Chronology c = locale.getUnicodeLocaleType("ca") != null ? + Chronology.ofLocale(locale) : chrono; + String tzType = locale.getUnicodeLocaleType("tz"); + ZoneId z = tzType != null ? + TimeZoneNameUtility.convertLDMLShortID(tzType) + .map(ZoneId::of) + .orElse(null) : + null; return new DateTimeFormatter(pp, locale, DecimalStyle.STANDARD, ! resolverStyle, null, c, z); } //----------------------------------------------------------------------- /** * Strategy for formatting/parsing date-time information.
< prev index next >