Example usage for java.text DateFormatSymbols getWeekdays

List of usage examples for java.text DateFormatSymbols getWeekdays

Introduction

In this page you can find the example usage for java.text DateFormatSymbols getWeekdays.

Prototype

public String[] getWeekdays() 

Source Link

Document

Gets weekday strings.

Usage

From source file:DateFormatUtils.java

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

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

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

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

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

        Rule rule;
        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 >= 4) {
                rule = selectNumberRule(Calendar.YEAR, tokenLen);
            } else {
                rule = TwoDigitYearField.INSTANCE;
            }
            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, mTimeZoneForced, mLocale, TimeZone.LONG);
            } else {
                rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, 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
            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.exoplatform.calendar.webui.popup.UIEventForm.java

/**
 * Build the repeating summary, i.e: daily every 2 days, until 02/03/2011. <br/>
 * The summary structure is defined in resource bundle, it contains some parameters and </br> 
 * will be replaced by values from repeatEvent. <br/> 
 * <p>There are 6 parameters: {count}, {until}, {interval}, {byDays}, {theDay}, {theNumber}.<br/>
 * Some labels in resource bundle to define numbers (the first, the second, ...) which were used in summary
 * @param repeatEvent the repeating event
 * @return summary string about repeating event
 * @throws Exception/* w  w w  .  j av a2 s.co  m*/
 */
public String buildRepeatSummary(CalendarEvent repeatEvent) throws Exception {
    CalendarSetting calSetting = CalendarUtils.getCurrentUserCalendarSetting();
    WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
    Locale locale = context.getParentAppRequestContext().getLocale();
    DateFormat format = new SimpleDateFormat(calSetting.getDateFormat(), locale);
    DateFormatSymbols symbols = new DateFormatSymbols(locale);
    String[] dayOfWeeks = symbols.getWeekdays();

    String summary = "";
    if (repeatEvent == null)
        return "";
    String repeatType = repeatEvent.getRepeatType();
    if (CalendarEvent.RP_NOREPEAT.equals(repeatType) || repeatType == null)
        return "";
    int interval = (int) repeatEvent.getRepeatInterval();
    int count = (int) repeatEvent.getRepeatCount();
    Date until = repeatEvent.getRepeatUntilDate();
    String endType = RP_END_NEVER;
    if (count > 0)
        endType = RP_END_AFTER;
    if (until != null)
        endType = RP_END_BYDATE;

    String pattern = "";
    if (repeatType.equals(CalendarEvent.RP_DAILY)) {
        if (interval == 1) {
            //pattern = "Daily";
            pattern = getLabel("daily");
        } else {
            //pattern = "Every {interval} days";
            pattern = getLabel("every-day");
        }
        if (endType.equals(RP_END_AFTER)) {
            //pattern = "Daily, {count} times";
            //pattern = "Every {interval} days, {count} times";
            pattern += ", ";
            pattern += getLabel("count-times");
        }
        if (endType.equals(RP_END_BYDATE)) {
            //pattern = "Daily, until {until}";
            //pattern = "Every {interval} days, until {until}";
            pattern += ", ";
            pattern += getLabel("until");
        }

        summary = pattern.replace("{interval}", String.valueOf(interval))
                .replace("{count}", String.valueOf(repeatEvent.getRepeatCount()))
                .replace("{until}", repeatEvent.getRepeatUntilDate() == null ? ""
                        : format.format(repeatEvent.getRepeatUntilDate()));
        return summary;
    }

    if (repeatType.equals(CalendarEvent.RP_WEEKLY)) {
        if (interval == 1) {
            //pattern = "Weekly on {byDays}";
            pattern = getLabel("weekly");
        } else {
            //pattern = "Every {interval} weeks on {byDays}";
            pattern = getLabel("every-week");
        }
        if (endType.equals(RP_END_AFTER)) {
            //pattern = "Weekly on {byDays}, {count} times";
            //pattern = "Every {interval} weeks on {byDays}, {count} times";
            pattern += ", ";
            pattern += getLabel("count-times");
        }
        if (endType.equals(RP_END_BYDATE)) {
            //pattern = "Weekly on {byDays}, until {until}";
            //pattern = "Every {interval} weeks on {byDays}, until {until}";
            pattern += ", ";
            pattern += getLabel("until");
        }

        String[] weeklyByDays = repeatEvent.getRepeatByDay();
        StringBuffer byDays = new StringBuffer();
        for (int i = 0; i < weeklyByDays.length; i++) {
            if (i == 0) {
                byDays.append(dayOfWeeks[UIRepeatEventForm.convertToDayOfWeek(weeklyByDays[0])]);
            } else {
                byDays.append(", ");
                byDays.append(dayOfWeeks[UIRepeatEventForm.convertToDayOfWeek(weeklyByDays[i])]);
            }
        }
        summary = pattern.replace("{interval}", String.valueOf(interval))
                .replace("{count}", String.valueOf(repeatEvent.getRepeatCount()))
                .replace("{until}",
                        repeatEvent.getRepeatUntilDate() == null ? ""
                                : format.format(repeatEvent.getRepeatUntilDate()))
                .replace("{byDays}", byDays.toString());
        return summary;

    }

    if (repeatType.equals(CalendarEvent.RP_MONTHLY)) {
        String monthlyType = UIRepeatEventForm.RP_MONTHLY_BYMONTHDAY;
        if (repeatEvent.getRepeatByDay() != null && repeatEvent.getRepeatByDay().length > 0)
            monthlyType = UIRepeatEventForm.RP_MONTHLY_BYDAY;

        if (interval == 1) {
            // pattern = "Monthly on" 
            pattern = getLabel("monthly");
        } else {
            // pattern = "Every {interval} months on
            pattern = getLabel("every-month");
        }

        if (monthlyType.equals(UIRepeatEventForm.RP_MONTHLY_BYDAY)) {
            // pattern = "Monthly on {theNumber} {theDay}
            // pattern = "Every {interval} months on {theNumber} {theDay}
            pattern += " ";
            pattern += getLabel("monthly-by-day");
        } else {
            // pattern = "Monthly on day {theDay}
            // pattern = "Every {interval} months on day {theDay}
            pattern += " ";
            pattern += getLabel("monthly-by-month-day");
        }

        if (endType.equals(RP_END_AFTER)) {
            pattern += ", ";
            pattern += getLabel("count-times");
        }
        if (endType.equals(RP_END_BYDATE)) {
            pattern += ", ";
            pattern += getLabel("until");
        }

        String theNumber = ""; // the first, the second, the third, ...
        String theDay = ""; // in monthly by day, it's Monday, Tuesday, ... (day of week), in monthly by monthday, it's 1-31 (day of month)
        if (monthlyType.equals(UIRepeatEventForm.RP_MONTHLY_BYDAY)) {
            java.util.Calendar temp = CalendarUtils.getInstanceOfCurrentCalendar();
            temp.setTime(repeatEvent.getFromDateTime());
            int weekOfMonth = temp.get(java.util.Calendar.WEEK_OF_MONTH);
            java.util.Calendar temp2 = CalendarUtils.getInstanceOfCurrentCalendar();
            temp2.setTime(temp.getTime());
            temp2.add(java.util.Calendar.DATE, 7);
            if (temp2.get(java.util.Calendar.MONTH) != temp.get(java.util.Calendar.MONTH))
                weekOfMonth = 5;
            int dayOfWeek = temp.get(java.util.Calendar.DAY_OF_WEEK);
            String[] weekOfMonths = new String[] { getLabel("summary-the-first"),
                    getLabel("summary-the-second"), getLabel("summary-the-third"),
                    getLabel("summary-the-fourth"), getLabel("summary-the-last") };
            theNumber = weekOfMonths[weekOfMonth - 1];
            theDay = dayOfWeeks[dayOfWeek];
        } else {
            java.util.Calendar temp = CalendarUtils.getInstanceOfCurrentCalendar();
            temp.setTime(repeatEvent.getFromDateTime());
            int dayOfMonth = temp.get(java.util.Calendar.DAY_OF_MONTH);
            theDay = String.valueOf(dayOfMonth);
        }
        summary = pattern.replace("{interval}", String.valueOf(interval))
                .replace("{count}", String.valueOf(repeatEvent.getRepeatCount()))
                .replace("{until}",
                        repeatEvent.getRepeatUntilDate() == null ? ""
                                : format.format(repeatEvent.getRepeatUntilDate()))
                .replace("{theDay}", theDay).replace("{theNumber}", theNumber);
        return summary;
    }

    if (repeatType.equals(CalendarEvent.RP_YEARLY)) {
        if (interval == 1) {
            // pattern = "Yearly on {theDay}"
            pattern = getLabel("yearly");
        } else {
            // pattern = "Every {interval} years on {theDay}" 
            pattern = getLabel("every-year");
        }

        if (endType.equals(RP_END_AFTER)) {
            // pattern = "Yearly on {theDay}, {count} times"
            // pattern = "Every {interval} years on {theDay}, {count} times" 
            pattern += ", ";
            pattern += getLabel("count-times");
        }
        if (endType.equals(RP_END_BYDATE)) {
            // pattern = "Yearly on {theDay}, until {until}"
            // pattern = "Every {interval} years on {theDay}, until {until}" 
            pattern += ", ";
            pattern += getLabel("until");
        }

        String theDay = format.format(repeatEvent.getFromDateTime()); //
        summary = pattern.replace("{interval}", String.valueOf(interval))
                .replace("{count}", String.valueOf(repeatEvent.getRepeatCount()))
                .replace("{until}", repeatEvent.getRepeatUntilDate() == null ? ""
                        : format.format(repeatEvent.getRepeatUntilDate()))
                .replace("{theDay}", theDay);
        return summary;
    }
    return summary;
}

From source file:com.tmendes.birthdaydroid.StatisticsFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_statistics, container, false);

    ctx = container.getContext();// ww  w.  j a  v a2 s.co  m
    BirthDayDataList data = BirthDayDataList.getBirthDayDataList(this.ctx);
    DateFormatSymbols dfs = new DateFormatSymbols();

    int contactsCounter = data.getList().size();

    Map<Integer, Integer> ageStat = data.getAgeStats();
    Map<String, Integer> signStat = data.getSignStats();
    Map<Integer, Integer> monthStat = data.getMonthStats();
    Map<Integer, Integer> weekStat = data.getWeekStats();

    Button buttonAges = (Button) v.findViewById(R.id.buttonAges);
    Button buttonSign = (Button) v.findViewById(R.id.buttonSign);
    Button buttonMonth = (Button) v.findViewById(R.id.buttonMonth);
    Button buttonWeek = (Button) v.findViewById(R.id.buttonWeek);

    Iterator it;

    it = ageStat.entrySet().iterator();

    String dialogData = ctx.getResources().getString(R.string.statistics_contacts_counter, contactsCounter);

    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        int age = (int) pair.getKey();
        int number = (int) pair.getValue();
        dialogData += ctx.getResources().getString(R.string.statistics_int_int, number, age);
    }

    final String finalDialogDataAges = dialogData;
    buttonAges.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
            alertDialog.setTitle(ctx.getResources().getString(R.string.statistics_age_title));
            alertDialog.setMessage(finalDialogDataAges);
            alertDialog.show();
        }

    });

    it = signStat.entrySet().iterator();
    dialogData = ctx.getResources().getString(R.string.statistics_contacts_counter, contactsCounter);
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        String sign = (String) pair.getKey();
        int number = (int) pair.getValue();
        dialogData += ctx.getResources().getString(R.string.statistics_int_string, number, sign);
    }

    final String finalDialogDataSign = dialogData;
    buttonSign.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
            alertDialog.setTitle(ctx.getResources().getString(R.string.statistics_sign_title));
            alertDialog.setMessage(finalDialogDataSign);
            alertDialog.show();
        }

    });

    it = monthStat.entrySet().iterator();
    dialogData = ctx.getResources().getString(R.string.statistics_contacts_counter, contactsCounter);
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        int month = (int) pair.getKey();
        int number = (int) pair.getValue();
        dialogData += ctx.getResources().getString(R.string.statistics_int_string, number,
                dfs.getMonths()[month]);
    }

    final String finalDialogDataMonth = dialogData;
    buttonMonth.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
            alertDialog.setTitle(ctx.getResources().getString(R.string.statistics_month_title));
            alertDialog.setMessage(finalDialogDataMonth);
            alertDialog.show();
        }

    });

    it = weekStat.entrySet().iterator();
    dialogData = ctx.getResources().getString(R.string.statistics_contacts_counter, contactsCounter);
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        int week = (int) pair.getKey();
        int number = (int) pair.getValue();
        dialogData += ctx.getResources().getString(R.string.statistics_int_string, number,
                dfs.getWeekdays()[week]);
    }

    final String finalDialogDataWeek = dialogData;
    buttonWeek.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
            alertDialog.setTitle(ctx.getResources().getString(R.string.statistics_week_title));
            alertDialog.setMessage(finalDialogDataWeek);
            alertDialog.show();
        }

    });

    return v;

}