Example usage for java.util TimeZone LONG

List of usage examples for java.util TimeZone LONG

Introduction

In this page you can find the example usage for java.util TimeZone LONG.

Prototype

int LONG

To view the source code for java.util TimeZone LONG.

Click Source Link

Document

A style specifier for getDisplayName() indicating a long name, such as "Pacific Standard Time."

Usage

From source file:Main.java

public static void main(String args[]) {

    // create default time zone object
    TimeZone timezonedefault = TimeZone.getDefault();

    // get display name
    String disname = timezonedefault.getDisplayName(true, TimeZone.LONG);

    // checking display name         
    System.out.println("Display name is :" + disname);
}

From source file:Main.java

/**
 * Produce a string describing the offset of the given time zone from
 * UTC, including the DST offset if there is one.
 * /*from   w w w. j a v a2  s.c o  m*/
 * @param   zone         TimeZone whose offset we want.
 * @return               Formatted offset.
 */
public static String formatOffsetFull(TimeZone zone) {
    String fmt = zone.getID() + ": ";

    int base = zone.getRawOffset();
    fmt += zone.getDisplayName(false, TimeZone.LONG) + "=UTC" + intervalMsToHmsShort(base);

    int dst = zone.getDSTSavings();
    if (dst != 0)
        fmt += " (" + zone.getDisplayName(true, TimeZone.LONG) + "=UTC" + intervalMsToHmsShort(base + dst)
                + ")";

    return fmt;
}

From source file:com.lm.lic.manager.util.GenUtil.java

public static Date resetClientTimezone(HttpServletRequest request, Date date) {
    final TimeZone timeZone = TimeZone.getDefault();
    final boolean daylight = timeZone.inDaylightTime(date);
    final Locale locale = request.getLocale();
    String tzName = timeZone.getDisplayName(daylight, TimeZone.LONG, locale);
    // String countryCode = locale.getCountry();
    // TimeZone ltz = TimeZone.getTimeZone(countryCode);
    // TimeZoneNameUtility.getZoneStrings(locale);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from   ww  w .ja  v a 2s  . c o  m*/
    cal.setTimeZone(TimeZone.getTimeZone(tzName));
    return cal.getTime();
}

From source file:org.dpadgett.timer.WorldClockFragment.java

private void newClockDialog(final int position) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(context.getString(R.string.world_clock_select_timezone));
    final Map<String, String> timezoneNameToId = new HashMap<String, String>();
    final Set<Integer> timezones = new TreeSet<Integer>();
    final Map<Integer, List<String>> offsetToName = new HashMap<Integer, List<String>>();
    final long currentTime = System.currentTimeMillis();

    for (final String timezone : TimeZone.getAvailableIDs()) {
        final TimeZone tz = TimeZone.getTimeZone(timezone);
        final boolean isDaylight = tz.useDaylightTime();
        final String timezoneName = tz.getDisplayName(isDaylight, TimeZone.LONG, Locale.getDefault());
        if (timezoneNameToId.containsKey(timezoneName)) {
            continue;
        }/*from  w w w.jav a  2s. c o m*/
        final int millisOffset = tz.getOffset(currentTime);
        timezones.add(millisOffset);
        if (!offsetToName.containsKey(millisOffset)) {
            offsetToName.put(millisOffset, new ArrayList<String>());
        }
        offsetToName.get(millisOffset).add(timezoneName);
        timezoneNameToId.put(timezoneName, timezone);
    }
    for (final List<String> names : offsetToName.values()) {
        Collections.sort(names);
    }
    if (position > -1) {
        builder.setPositiveButton(context.getString(R.string.world_clock_button_remove),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        clockList.remove(position);
                        clocksListAdapter.notifyDataSetChanged();

                        final SharedPreferences.Editor prefs = context
                                .getSharedPreferences("WorldClocks", Context.MODE_PRIVATE).edit();
                        prefs.putInt("numClocks", clockList.size());
                        int idx;
                        for (idx = position; idx < clockList.size(); idx++) {
                            prefs.putString("clock" + idx, clockList.get(idx));
                        }
                        prefs.remove("clock" + idx);
                        prefs.commit();
                    }
                });
    }
    final LinearLayout tzView = (LinearLayout) LayoutInflater.from(context)
            .inflate(R.layout.timezone_picker_dialog, (ViewGroup) finder.findViewById(R.id.layout_root));

    final List<String> initialItems = new ArrayList<String>();
    initialItems.add(context.getString(R.string.world_clock_timezone_gmt));
    initialItems.add(context.getString(R.string.world_clock_timezone_utc));
    final ArrayAdapter<String> adapter = ArrayAdapter.newArrayAdapter(context,
            R.layout.timezone_dialog_list_item, initialItems);
    final ListView timezoneList = (ListView) tzView.findViewById(R.id.timezoneList);
    timezoneList.setAdapter(adapter);

    final TextView sliderView = (TextView) tzView.findViewById(R.id.timezoneLabel);

    final SeekBar timezoneSeeker = (SeekBar) tzView.findViewById(R.id.timezoneSeeker);
    final List<Integer> timezonesList = new ArrayList<Integer>(timezones);
    timezoneSeeker.setMax(timezonesList.size() - 1);
    if (position > -1) {
        final int offset = TimeZone.getTimeZone(clockList.get(position)).getOffset(currentTime);
        timezoneSeeker.setProgress(timezonesList.indexOf(offset));
    } else {
        timezoneSeeker.setProgress(timezonesList.indexOf(0));
    }
    timezoneSeeker.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        // initialize the timezoneSeeker
        {
            onProgressChanged(timezoneSeeker, timezoneSeeker.getProgress(), false);
        }

        @Override
        public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
            adapter.clear();
            adapter.addAll(offsetToName.get(timezonesList.get(progress)));
            final int millisOffset = timezonesList.get(progress);
            String offset = String.format("%02d:%02d", Math.abs(millisOffset / 1000 / 60 / 60),
                    Math.abs(millisOffset / 1000 / 60) % 60);
            if (millisOffset / 1000 / 60 / 60 < 0) {
                offset = "-" + offset;
            } else {
                offset = "+" + offset;
            }
            sliderView.setText(context.getString(R.string.world_clock_timezone_label) + offset);
        }

        @Override
        public void onStartTrackingTouch(final SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(final SeekBar seekBar) {
        }
    });
    builder.setView(tzView);
    final AlertDialog alert = builder.create();

    timezoneList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, final int selectedPosition,
                final long id) {
            final String timezoneName = adapter.getItem(selectedPosition);
            final String timezone = timezoneNameToId.get(timezoneName);
            addNewClock(timezone, position);
            alert.dismiss();
        }
    });

    alert.show();
}

From source file:org.pentaho.platform.web.http.api.resources.SystemResource.java

/**
 * Returns a list of TimeZones ensuring that the server (default) timezone is at the top of the list (0th element)
 * /*from w ww  .ja  v a  2 s.c  om*/
 * @return a list of TimeZones ensuring that the server (default) timezone is at the top of the list (0th element)
 */
@GET
@Path("/timezones")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@Facet(name = "Unsupported")
public TimeZoneWrapper getTimeZones() {
    Map<String, String> timeZones = new HashMap<String, String>();
    for (String tzId : TimeZone.getAvailableIDs()) {
        if (!tzId.toLowerCase().contains("gmt")) {
            int offset = TimeZone.getTimeZone(tzId).getOffset(System.currentTimeMillis());
            String text = String.format("%s%02d%02d", offset >= 0 ? "+" : "", offset / 3600000,
                    (offset / 60000) % 60);
            timeZones.put(tzId,
                    TimeZone.getTimeZone(tzId).getDisplayName(true, TimeZone.LONG) + " (UTC" + text + ")");
        }
    }
    return new TimeZoneWrapper(timeZones, TimeZone.getDefault().getID());
}

From source file:com.appsimobile.appsii.timezonepicker.TimeZoneData.java

void loadTzs(Context context) {
    mTimeZones = new ArrayList<>();
    HashSet<String> processedTimeZones = loadTzsInZoneTab(context);
    String[] tzIds = TimeZone.getAvailableIDs();

    if (DEBUG) {//from  w w w  .  j  av a 2  s.com
        Log.e(TAG, "Available time zones: " + tzIds.length);
    }

    for (String tzId : tzIds) {
        if (processedTimeZones.contains(tzId)) {
            continue;
        }

        /*
         * Dropping non-GMT tzs without a country code. They are not really
         * needed and they are dups but missing proper country codes. e.g.
         * WET CET MST7MDT PST8PDT Asia/Khandyga Asia/Ust-Nera EST
         */
        if (!tzId.startsWith("Etc/GMT")) {
            continue;
        }

        final TimeZone tz = TimeZone.getTimeZone(tzId);
        if (tz == null) {
            Log.e(TAG, "Timezone not found: " + tzId);
            continue;
        }

        TimeZoneInfo tzInfo = new TimeZoneInfo(tz, null);

        if (getIdenticalTimeZoneInTheCountry(tzInfo) == -1) {
            if (DEBUG) {
                Log.e(TAG, "# Adding time zone from getAvailId: " + tzInfo.toString());
            }
            mTimeZones.add(tzInfo);
        } else {
            if (DEBUG) {
                Log.e(TAG, "# Dropping identical time zone from getAvailId: " + tzInfo.toString());
            }
            continue;
        }
        //
        // TODO check for dups
        // checkForNameDups(tz, tzInfo.mCountry, false /* dls */,
        // TimeZone.SHORT, groupIdx, !found);
        // checkForNameDups(tz, tzInfo.mCountry, false /* dls */,
        // TimeZone.LONG, groupIdx, !found);
        // if (tz.useDaylightTime()) {
        // checkForNameDups(tz, tzInfo.mCountry, true /* dls */,
        // TimeZone.SHORT, groupIdx,
        // !found);
        // checkForNameDups(tz, tzInfo.mCountry, true /* dls */,
        // TimeZone.LONG, groupIdx,
        // !found);
        // }
    }

    // Don't change the order of mTimeZones after this sort
    Collections.sort(mTimeZones);

    mTimeZonesByCountry = new LinkedHashMap<>();
    mTimeZonesByOffsets = new SparseArray<>(mHasTimeZonesInHrOffset.length);
    int N = mTimeZones.size();
    mTimeZonesById = new SimpleArrayMap<>(N);
    for (int i = 0; i < N; i++) {
        TimeZoneInfo tz = mTimeZones.get(i);
        // /////////////////////
        // Lookup map for id -> tz
        mTimeZonesById.put(tz.mTzId, tz);
    }
    populateDisplayNameOverrides(mTimeZonesById, mContext.getResources());

    Date date = new Date(mTimeMillis);
    Locale defaultLocal = Locale.getDefault();

    int idx = 0;
    for (int i = 0; i < N; i++) {
        TimeZoneInfo tz = mTimeZones.get(i);
        // /////////////////////
        // Populate display name
        if (tz.mDisplayName == null) {
            tz.mDisplayName = tz.mTz.getDisplayName(tz.mTz.inDaylightTime(date), TimeZone.LONG, defaultLocal);
        }

        // /////////////////////
        // Grouping tz's by country for search by country
        IntList group = mTimeZonesByCountry.get(tz.mCountry);
        if (group == null) {
            group = new IntList();
            mTimeZonesByCountry.put(tz.mCountry, group);
        }

        group.add(idx);

        // /////////////////////
        // Grouping tz's by GMT offsets
        indexByOffsets(idx, tz);

        // Skip all the GMT+xx:xx style display names from search
        if (!tz.mDisplayName.endsWith(":00")) {
            mTimeZoneNames.add(tz.mDisplayName);
        } else if (DEBUG) {
            Log.e(TAG, "# Hiding from pretty name search: " + tz.mDisplayName);
        }

        idx++;
    }

    // printTimeZones();
}

From source file:com.application.utils.FastDatePrinter.java

/**
 * <p>Returns a list of Rules given a pattern.</p>
 *
 * @return a {@code List} of Rule objects
 * @throws IllegalArgumentException if pattern is invalid
 *///ww  w.j  a  v  a 2  s .c o m
protected List<Rule> parsePattern() {
    final DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
    final List<Rule> rules = new ArrayList<Rule>();

    final String[] ERAs = symbols.getEras();
    final String[] months = symbols.getMonths();
    final String[] shortMonths = symbols.getShortMonths();
    final String[] weekdays = symbols.getWeekdays();
    final String[] shortWeekdays = symbols.getShortWeekdays();
    final String[] AmPmStrings = symbols.getAmPmStrings();

    final int length = mPattern.length();
    final int[] indexRef = new int[1];

    for (int i = 0; i < length; i++) {
        indexRef[0] = i;
        final String token = parseToken(mPattern, indexRef);
        i = indexRef[0];

        final int tokenLen = token.length();
        if (tokenLen == 0) {
            break;
        }

        Rule rule;
        final char c = token.charAt(0);

        switch (c) {
        case 'G': // era designator (text)
            rule = new TextField(Calendar.ERA, ERAs);
            break;
        case 'y': // year (number)
            if (tokenLen == 2) {
                rule = TwoDigitYearField.INSTANCE;
            } else {
                rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen);
            }
            break;
        case 'M': // month in year (text and number)
            if (tokenLen >= 4) {
                rule = new TextField(Calendar.MONTH, months);
            } else if (tokenLen == 3) {
                rule = new TextField(Calendar.MONTH, shortMonths);
            } else if (tokenLen == 2) {
                rule = TwoDigitMonthField.INSTANCE;
            } else {
                rule = UnpaddedMonthField.INSTANCE;
            }
            break;
        case 'd': // day in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
            break;
        case 'h': // hour in am/pm (number, 1..12)
            rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
            break;
        case 'H': // hour in day (number, 0..23)
            rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
            break;
        case 'm': // minute in hour (number)
            rule = selectNumberRule(Calendar.MINUTE, tokenLen);
            break;
        case 's': // second in minute (number)
            rule = selectNumberRule(Calendar.SECOND, tokenLen);
            break;
        case 'S': // millisecond (number)
            rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
            break;
        case 'E': // day in week (text)
            rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
            break;
        case 'D': // day in year (number)
            rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
            break;
        case 'F': // day of week in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
            break;
        case 'w': // week in year (number)
            rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
            break;
        case 'W': // week in month (number)
            rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
            break;
        case 'a': // am/pm marker (text)
            rule = new TextField(Calendar.AM_PM, AmPmStrings);
            break;
        case 'k': // hour in day (1..24)
            rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
            break;
        case 'K': // hour in am/pm (0..11)
            rule = selectNumberRule(Calendar.HOUR, tokenLen);
            break;
        case 'z': // time zone (text)
            if (tokenLen >= 4) {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG);
            } else {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT);
            }
            break;
        case 'Z': // time zone (value)
            if (tokenLen == 1) {
                rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
            } else {
                rule = TimeZoneNumberRule.INSTANCE_COLON;
            }
            break;
        case '\'': // literal text
            final String sub = token.substring(1);
            if (sub.length() == 1) {
                rule = new CharacterLiteral(sub.charAt(0));
            } else {
                rule = new StringLiteral(sub);
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal pattern component: " + token);
        }

        rules.add(rule);
    }

    return rules;
}

From source file:org.eclipse.gyrex.jobs.internal.commands.LsCmd.java

private void printSchedule(final ISchedule schedule) {
    final StrBuilder info = new StrBuilder();
    info.append(schedule.getId());/*  w w w.j a v a  2 s.  co  m*/
    if (!schedule.isEnabled()) {
        info.appendln(" DISABLED");
    }

    final TimeZone timeZone = schedule.getTimeZone();
    info.append("  time zone: ").append(timeZone.getDisplayName(false, TimeZone.LONG, Locale.US))
            .appendln(timeZone.useDaylightTime() ? " (will adjust to daylight changes)"
                    : " (independent of daylight changes)");
    info.append("      queue: ").appendln(null != schedule.getQueueId() ? schedule.getQueueId() : "(default)");
    String prefix = "    entries: ";

    final List<IScheduleEntry> entries = schedule.getEntries();
    if (!entries.isEmpty()) {
        for (final IScheduleEntry entry : entries) {
            info.append(prefix).append(entry.getId()).append(' ').append(entry.getCronExpression()).append(' ')
                    .append(entry.getJobTypeId()).appendNewLine();
            prefix = "             ";
            final Map<String, String> parameter = entry.getJobParameter();
            if (!parameter.isEmpty()) {
                final Set<Entry<String, String>> entrySet = parameter.entrySet();
                for (final Entry<String, String> param : entrySet) {
                    info.append(prefix).append("    ").append(param.getKey()).append('=')
                            .appendln(param.getValue());
                }
            }
        }
    } else {
        info.append(prefix).appendln("(none)");
    }
    printf("%s", info.toString());
    return;
}

From source file:org.sqlite.date.FastDatePrinter.java

/**
 * <p>Returns a list of Rules given a pattern.</p>
 *
 * @return a {@code List} of Rule objects
 * @throws IllegalArgumentException if pattern is invalid
 *//*www  .jav  a  2 s .co m*/
protected List<Rule> parsePattern() {
    final DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
    final List<Rule> rules = new ArrayList<Rule>();

    final String[] ERAs = symbols.getEras();
    final String[] months = symbols.getMonths();
    final String[] shortMonths = symbols.getShortMonths();
    final String[] weekdays = symbols.getWeekdays();
    final String[] shortWeekdays = symbols.getShortWeekdays();
    final String[] AmPmStrings = symbols.getAmPmStrings();

    final int length = mPattern.length();
    final int[] indexRef = new int[1];

    for (int i = 0; i < length; i++) {
        indexRef[0] = i;
        final String token = parseToken(mPattern, indexRef);
        i = indexRef[0];

        final int tokenLen = token.length();
        if (tokenLen == 0) {
            break;
        }

        Rule rule;
        final char c = token.charAt(0);

        switch (c) {
        case 'G': // era designator (text)
            rule = new TextField(Calendar.ERA, ERAs);
            break;
        case 'y': // year (number)
            if (tokenLen == 2) {
                rule = TwoDigitYearField.INSTANCE;
            } else {
                rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen);
            }
            break;
        case 'M': // month in year (text and number)
            if (tokenLen >= 4) {
                rule = new TextField(Calendar.MONTH, months);
            } else if (tokenLen == 3) {
                rule = new TextField(Calendar.MONTH, shortMonths);
            } else if (tokenLen == 2) {
                rule = TwoDigitMonthField.INSTANCE;
            } else {
                rule = UnpaddedMonthField.INSTANCE;
            }
            break;
        case 'd': // day in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
            break;
        case 'h': // hour in am/pm (number, 1..12)
            rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
            break;
        case 'H': // hour in day (number, 0..23)
            rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
            break;
        case 'm': // minute in hour (number)
            rule = selectNumberRule(Calendar.MINUTE, tokenLen);
            break;
        case 's': // second in minute (number)
            rule = selectNumberRule(Calendar.SECOND, tokenLen);
            break;
        case 'S': // millisecond (number)
            rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
            break;
        case 'E': // day in week (text)
            rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
            break;
        case 'D': // day in year (number)
            rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
            break;
        case 'F': // day of week in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
            break;
        case 'w': // week in year (number)
            rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
            break;
        case 'W': // week in month (number)
            rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
            break;
        case 'a': // am/pm marker (text)
            rule = new TextField(Calendar.AM_PM, AmPmStrings);
            break;
        case 'k': // hour in day (1..24)
            rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
            break;
        case 'K': // hour in am/pm (0..11)
            rule = selectNumberRule(Calendar.HOUR, tokenLen);
            break;
        case 'X': // ISO 8601 
            rule = Iso8601_Rule.getRule(tokenLen);
            break;
        case 'z': // time zone (text)
            if (tokenLen >= 4) {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG);
            } else {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT);
            }
            break;
        case 'Z': // time zone (value)
            if (tokenLen == 1) {
                rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
            } else if (tokenLen == 2) {
                rule = TimeZoneNumberRule.INSTANCE_ISO_8601;
            } else {
                rule = TimeZoneNumberRule.INSTANCE_COLON;
            }
            break;
        case '\'': // literal text
            final String sub = token.substring(1);
            if (sub.length() == 1) {
                rule = new CharacterLiteral(sub.charAt(0));
            } else {
                rule = new StringLiteral(sub);
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal pattern component: " + token);
        }

        rules.add(rule);
    }

    return rules;
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDatePrinter.java

/**
 * <p>Returns a list of Rules given a pattern.</p>
 *
 * @return a {@code List} of Rule objects
 * @throws IllegalArgumentException if pattern is invalid
 *//*from   w ww. jav a  2 s . co m*/
protected List<Rule> parsePattern() {
    final DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
    final List<Rule> rules = new ArrayList<>();

    final String[] ERAs = symbols.getEras();
    final String[] months = symbols.getMonths();
    final String[] shortMonths = symbols.getShortMonths();
    final String[] weekdays = symbols.getWeekdays();
    final String[] shortWeekdays = symbols.getShortWeekdays();
    final String[] AmPmStrings = symbols.getAmPmStrings();

    final int length = mPattern.length();
    final int[] indexRef = new int[1];

    for (int i = 0; i < length; i++) {
        indexRef[0] = i;
        final String token = parseToken(mPattern, indexRef);
        i = indexRef[0];

        final int tokenLen = token.length();
        if (tokenLen == 0) {
            break;
        }

        Rule rule;
        final char c = token.charAt(0);

        switch (c) {
        case 'G': // era designator (text)
            rule = new TextField(Calendar.ERA, ERAs);
            break;
        case 'y': // year (number)
        case 'Y': // week year
            if (tokenLen == 2) {
                rule = TwoDigitYearField.INSTANCE;
            } else {
                rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen);
            }
            if (c == 'Y') {
                rule = new WeekYear((NumberRule) rule);
            }
            break;
        case 'M': // month in year (text and number)
            if (tokenLen >= 4) {
                rule = new TextField(Calendar.MONTH, months);
            } else if (tokenLen == 3) {
                rule = new TextField(Calendar.MONTH, shortMonths);
            } else if (tokenLen == 2) {
                rule = TwoDigitMonthField.INSTANCE;
            } else {
                rule = UnpaddedMonthField.INSTANCE;
            }
            break;
        case 'd': // day in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
            break;
        case 'h': // hour in am/pm (number, 1..12)
            rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
            break;
        case 'H': // hour in day (number, 0..23)
            rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
            break;
        case 'm': // minute in hour (number)
            rule = selectNumberRule(Calendar.MINUTE, tokenLen);
            break;
        case 's': // second in minute (number)
            rule = selectNumberRule(Calendar.SECOND, tokenLen);
            break;
        case 'S': // millisecond (number)
            rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
            break;
        case 'E': // day in week (text)
            rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
            break;
        case 'u': // day in week (number)
            rule = new DayInWeekField(selectNumberRule(Calendar.DAY_OF_WEEK, tokenLen));
            break;
        case 'D': // day in year (number)
            rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
            break;
        case 'F': // day of week in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
            break;
        case 'w': // week in year (number)
            rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
            break;
        case 'W': // week in month (number)
            rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
            break;
        case 'a': // am/pm marker (text)
            rule = new TextField(Calendar.AM_PM, AmPmStrings);
            break;
        case 'k': // hour in day (1..24)
            rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
            break;
        case 'K': // hour in am/pm (0..11)
            rule = selectNumberRule(Calendar.HOUR, tokenLen);
            break;
        case 'X': // ISO 8601 
            rule = Iso8601_Rule.getRule(tokenLen);
            break;
        case 'z': // time zone (text)
            if (tokenLen >= 4) {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG);
            } else {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT);
            }
            break;
        case 'Z': // time zone (value)
            if (tokenLen == 1) {
                rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
            } else if (tokenLen == 2) {
                rule = Iso8601_Rule.ISO8601_HOURS_COLON_MINUTES;
            } else {
                rule = TimeZoneNumberRule.INSTANCE_COLON;
            }
            break;
        case '\'': // literal text
            final String sub = token.substring(1);
            if (sub.length() == 1) {
                rule = new CharacterLiteral(sub.charAt(0));
            } else {
                rule = new StringLiteral(sub);
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal pattern component: " + token);
        }

        rules.add(rule);
    }

    return rules;
}