use of com.ibm.icu.text.DateFormat in project es6draft by anba.
the class DateTimeFormatConstructor method CreateDateTimeParts.
/**
* CreateDateTimeParts(dateTimeFormat, x)
*
* @param dateTimeFormat
* the date format object
* @param date
* the date object
* @return the formatted date-time object
*/
private static List<Map.Entry<String, String>> CreateDateTimeParts(DateTimeFormatObject dateTimeFormat, Date date) {
ArrayList<Map.Entry<String, String>> parts = new ArrayList<>();
DateFormat dateFormat = dateTimeFormat.getDateFormat();
AttributedCharacterIterator iterator = dateFormat.formatToCharacterIterator(date);
StringBuilder sb = new StringBuilder();
for (char ch = iterator.first(); ch != CharacterIterator.DONE; ch = iterator.next()) {
sb.append(ch);
if (iterator.getIndex() + 1 == iterator.getRunLimit()) {
Iterator<Attribute> keyIterator = iterator.getAttributes().keySet().iterator();
String key;
if (keyIterator.hasNext()) {
key = fieldToString((DateFormat.Field) keyIterator.next());
} else {
key = "separator";
}
String value = sb.toString();
sb.setLength(0);
parts.add(new AbstractMap.SimpleImmutableEntry<>(key, value));
}
}
return parts;
}
Aggregations