Search in sources :

Example 1 with DateFormat

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;
}
Also used : Attribute(java.text.AttributedCharacterIterator.Attribute) ArrayList(java.util.ArrayList) AttributedCharacterIterator(java.text.AttributedCharacterIterator) AbstractMap(java.util.AbstractMap) DateField(com.github.anba.es6draft.runtime.objects.intl.DateFieldSymbolTable.DateField) DateFormat(com.ibm.icu.text.DateFormat) SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat)

Aggregations

DateField (com.github.anba.es6draft.runtime.objects.intl.DateFieldSymbolTable.DateField)1 DateFormat (com.ibm.icu.text.DateFormat)1 SimpleDateFormat (com.ibm.icu.text.SimpleDateFormat)1 AttributedCharacterIterator (java.text.AttributedCharacterIterator)1 Attribute (java.text.AttributedCharacterIterator.Attribute)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1