use of com.ibm.icu.util.ULocale in project es6draft by anba.
the class DateTimeFormatObject method createDateFormat.
private DateFormat createDateFormat() {
ULocale locale = ULocale.forLanguageTag(this.locale);
// calendar and numberingSystem are already handled in language-tag
// assert locale.getKeywordValue("calendar").equals(calendar);
// assert locale.getKeywordValue("numbers").equals(numberingSystem);
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern.get(), locale);
if (timeZone != null) {
dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
}
Calendar calendar = dateFormat.getCalendar();
if (calendar instanceof GregorianCalendar) {
// format uses a proleptic Gregorian calendar with no year 0
GregorianCalendar gregorian = (GregorianCalendar) calendar;
gregorian.setGregorianChange(new Date(Long.MIN_VALUE));
}
return dateFormat;
}
use of com.ibm.icu.util.ULocale in project es6draft by anba.
the class DateTimeFormatConstructor method BestFitFormatMatcher.
/**
* 12.1.4 BestFitFormatMatcher (options, formats)
*
* @param formatRecord
* the format matcher record
* @param dataLocale
* the locale
* @return the best applicable pattern
*/
public static String BestFitFormatMatcher(FormatMatcherRecord formatRecord, String dataLocale) {
// Let ICU4J compute the best applicable pattern for the requested input values
ULocale locale = ULocale.forLanguageTag(dataLocale);
DateTimePatternGenerator generator = DateTimePatternGenerator.getInstance(locale);
String pattern = generator.getBestPattern(formatRecord.toSkeleton());
// Fixup the hour representation to match the expected hour cycle.
if (formatRecord.isTime() && formatRecord.hasNonDefaultHourCycle(locale)) {
pattern = modifyHour(formatRecord, pattern);
}
return pattern;
}
use of com.ibm.icu.util.ULocale in project es6draft by anba.
the class IntlAbstractOperations method addLikelySubtagsWithDefaults.
private static ULocale addLikelySubtagsWithDefaults(ULocale locale) {
ULocale maximized = ULocale.addLikelySubtags(locale);
if (maximized == locale) {
// If already in maximal form or no data available for maximization, make sure
// language, script and region are not undefined (ICU4J expects all are defined).
String language = locale.getLanguage();
String script = locale.getScript();
String region = locale.getCountry();
if (language.isEmpty() || script.isEmpty() || region.isEmpty()) {
return new ULocale(toLocaleId(language, script, region));
}
}
return maximized;
}
use of com.ibm.icu.util.ULocale in project es6draft by anba.
the class NumberFormatObject method createNumberFormat.
private NumberFormat createNumberFormat() {
ULocale locale = ULocale.forLanguageTag(this.locale);
int choice;
if ("decimal".equals(style)) {
choice = NumberFormat.NUMBERSTYLE;
} else if ("percent".equals(style)) {
choice = NumberFormat.PERCENTSTYLE;
} else {
if ("code".equals(currencyDisplay)) {
choice = NumberFormat.ISOCURRENCYSTYLE;
} else if ("symbol".equals(currencyDisplay)) {
choice = NumberFormat.CURRENCYSTYLE;
} else {
choice = NumberFormat.PLURALCURRENCYSTYLE;
}
}
DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale, choice);
if ("currency".equals(style)) {
numberFormat.setCurrency(Currency.getInstance(currency));
}
// assert locale.getKeywordValue("numbers").equals(numberingSystem);
if (minimumSignificantDigits != 0 && maximumSignificantDigits != 0) {
numberFormat.setSignificantDigitsUsed(true);
numberFormat.setMinimumSignificantDigits(minimumSignificantDigits);
numberFormat.setMaximumSignificantDigits(maximumSignificantDigits);
} else {
numberFormat.setSignificantDigitsUsed(false);
numberFormat.setMinimumIntegerDigits(minimumIntegerDigits);
numberFormat.setMinimumFractionDigits(minimumFractionDigits);
numberFormat.setMaximumFractionDigits(maximumFractionDigits);
}
numberFormat.setGroupingUsed(useGrouping);
// as required by ToRawPrecision/ToRawFixed
// FIXME: ICU4J bug:
// new Intl.NumberFormat("en",{useGrouping:false}).format(111111111111111)
// returns "111111111111111.02"
numberFormat.setRoundingMode(BigDecimal.ROUND_HALF_UP);
return numberFormat;
}
use of com.ibm.icu.util.ULocale in project es6draft by anba.
the class SegmenterObject method createBreakIterator.
private BreakIterator createBreakIterator() {
ULocale locale = ULocale.forLanguageTag(this.locale);
if ("line".equals(granularity)) {
// "strictness" cannot be set through unicode extensions (u-lb-strict), handle here:
locale = locale.setKeywordValue("lb", strictness);
}
BreakIterator breakIterator;
switch(granularity) {
case "grapheme":
breakIterator = BreakIterator.getCharacterInstance(locale);
break;
case "word":
breakIterator = BreakIterator.getWordInstance(locale);
break;
case "sentence":
breakIterator = BreakIterator.getSentenceInstance(locale);
break;
case "line":
breakIterator = BreakIterator.getLineInstance(locale);
break;
default:
throw new AssertionError();
}
return breakIterator;
}
Aggregations