List of usage examples for java.text DateFormatSymbols getWeekdays
public String[] getWeekdays()
From source file:moller.javapeg.program.gui.frames.ImageRepositoryStatisticsViewer.java
private String getWeekDayAsString(int weekDayAsInt) { DateFormatSymbols symbols = new DateFormatSymbols( new Locale(getConfiguration().getLanguage().getgUILanguageISO6391())); String[] dayNames = symbols.getWeekdays(); return dayNames[weekDayAsInt]; }
From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java
private static String[] mapWeekdaysStartingWithSunday(DateFormatSymbols symbols) { String[] weekdays = new String[7]; String[] localeWeekdays = symbols.getWeekdays(); weekdays[0] = localeWeekdays[Calendar.SUNDAY]; weekdays[1] = localeWeekdays[Calendar.MONDAY]; weekdays[2] = localeWeekdays[Calendar.TUESDAY]; weekdays[3] = localeWeekdays[Calendar.WEDNESDAY]; weekdays[4] = localeWeekdays[Calendar.THURSDAY]; weekdays[5] = localeWeekdays[Calendar.FRIDAY]; weekdays[6] = localeWeekdays[Calendar.SATURDAY]; return weekdays; }
From source file:org.sakaiproject.tool.section.jsf.backingbean.AddSectionsBean.java
protected void initDaysOfWeek() { ResourceLoader rl = new ResourceLoader(); DateFormatSymbols dfs = new DateFormatSymbols(rl.getLocale()); daysOfWeek = dfs.getWeekdays(); }
From source file:com.icesoft.faces.component.selectinputdate.SelectInputDateRenderer.java
private static String[] mapWeekdaysLong(DateFormatSymbols symbols) { String[] weekdays = new String[7]; String[] localeWeekdays = symbols.getWeekdays(); weekdays[0] = localeWeekdays[Calendar.MONDAY]; weekdays[1] = localeWeekdays[Calendar.TUESDAY]; weekdays[2] = localeWeekdays[Calendar.WEDNESDAY]; weekdays[3] = localeWeekdays[Calendar.THURSDAY]; weekdays[4] = localeWeekdays[Calendar.FRIDAY]; weekdays[5] = localeWeekdays[Calendar.SATURDAY]; weekdays[6] = localeWeekdays[Calendar.SUNDAY]; return weekdays; }
From source file:org.richfaces.renderkit.CalendarRendererBase.java
protected Map<String, String[]> getSymbolsMap(FacesContext facesContext, UICalendar calendar) { Map<String, String[]> map = new HashMap<String, String[]>(); Locale locale = calendar.getAsLocale(calendar.getLocale()); Calendar cal = calendar.getCalendar(); int maximum = cal.getActualMaximum(Calendar.DAY_OF_WEEK); int minimum = cal.getActualMinimum(Calendar.DAY_OF_WEEK); int monthMax = cal.getActualMaximum(Calendar.MONTH); int monthMin = cal.getActualMinimum(Calendar.MONTH); DateFormatSymbols symbols = new DateFormatSymbols(locale); String[] weekDayLabels = ComponentUtil.asArray(calendar.getWeekDayLabels()); if (weekDayLabels == null) { weekDayLabels = symbols.getWeekdays(); weekDayLabels = shiftDates(minimum, maximum, weekDayLabels); }/*w ww. ja v a 2 s . co m*/ String[] weekDayLabelsShort = ComponentUtil.asArray(calendar.getWeekDayLabelsShort()); if (weekDayLabelsShort == null) { weekDayLabelsShort = symbols.getShortWeekdays(); weekDayLabelsShort = shiftDates(minimum, maximum, weekDayLabelsShort); } String[] monthLabels = ComponentUtil.asArray(calendar.getMonthLabels()); if (monthLabels == null) { monthLabels = symbols.getMonths(); monthLabels = shiftDates(monthMin, monthMax, monthLabels); } String[] monthLabelsShort = ComponentUtil.asArray(calendar.getMonthLabelsShort()); if (monthLabelsShort == null) { monthLabelsShort = symbols.getShortMonths(); monthLabelsShort = shiftDates(monthMin, monthMax, monthLabelsShort); } map.put(WEEK_DAY_LABELS, weekDayLabels); map.put(WEEK_DAY_LABELS_SHORT, weekDayLabelsShort); map.put(MONTH_LABELS, monthLabels); map.put(MONTH_LABELS_SHORT, monthLabelsShort); return map; }
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 *///w w w .ja v a 2s . 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.apache.click.extras.control.DateField.java
/** * Return the names of months and weekdays as a script. *//*w w w.j av a 2 s . com*/ protected void addCalenderTranslations(List<Element> headElements) { JsScript script = new JsScript(); script.setId("datefield-js-setup-global"); if (!headElements.contains(script)) { DateFormatSymbols dfs = new DateFormatSymbols(getLocale()); HtmlStringBuffer buffer = new HtmlStringBuffer(150); buffer.append("Date.months=new Array("); generateJavaScriptArray(buffer, dfs.getMonths(), 0, 12); buffer.append(");\n"); buffer.append("Date.monthAbbreviations=new Array("); generateJavaScriptArray(buffer, dfs.getShortMonths(), 0, 12); buffer.append(");\n"); buffer.append("Date.dayNames=new Array("); generateJavaScriptArray(buffer, dfs.getWeekdays(), Calendar.SUNDAY, Calendar.SATURDAY + 1); buffer.append(");\n"); buffer.append("Date.dayAbbreviations=new Array("); generateJavaScriptArray(buffer, dfs.getShortWeekdays(), Calendar.SUNDAY, Calendar.SATURDAY + 1); buffer.append(");\n"); String[] weekdays = null; if (getMessages().containsKey("calendar-weekdays-heading")) { String headings = getMessage("calendar-weekdays-heading"); weekdays = StringUtils.splitPreserveAllTokens("," + headings, ','); } else { weekdays = dfs.getShortWeekdays(); } String[] days = new String[7]; int firstDayOfWeek = getFirstDayOfWeek() - 1; for (int i = 0; i < 7; i++) { days[i] = weekdays[(i + firstDayOfWeek) % 7 + 1]; } buffer.append("Date.weekdays=new Array("); generateJavaScriptArray(buffer, days, 0, 7); buffer.append(");\n"); buffer.append("Date.first_day_of_week=").append(firstDayOfWeek).append(";\n"); if (getMessages().containsKey("calendar-ok")) { buffer.append("_translations[\"OK\"] = \""); buffer.append(getMessage("calendar-ok")); buffer.append("\";\n"); } if (getMessages().containsKey("calendar-now")) { buffer.append("_translations[\"Now\"] = \""); buffer.append(getMessage("calendar-now")); buffer.append("\";\n"); } if (getMessages().containsKey("calendar-today")) { buffer.append("_translations[\"Today\"] = \""); buffer.append(getMessage("calendar-today")); buffer.append("\";\n"); } if (getMessages().containsKey("calendar-clear")) { buffer.append("_translations[\"Clear\"] = \""); buffer.append(getMessage("calendar-clear")); buffer.append("\";\n"); } script.setContent(buffer.toString()); headElements.add(script); } }
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 */// w ww . ja v 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 */// ww w . j av a2s.c om 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; }
From source file:CalendarUtils.java
/** * Parses strings the way that CVS supports it... very human readable *//*w w w.j av a2 s. co m*/ public static Calendar parse(String original, Locale locale) { //Get the symbol names DateFormatSymbols symbols = new DateFormatSymbols(locale); //Prep the string to parse String value = original.toLowerCase().trim(); //Get the current date/time Calendar now = Calendar.getInstance(); if (value.endsWith(" ago")) { //If this was a date that was "ago" the current time... //Strip out the ' ago' part value = value.substring(0, value.length() - 4); //Split the value and unit int start = value.indexOf(" "); if (start < 0) { throw new RuntimeException("Could not find space in between value and unit"); } String unit = value.substring(start + 1); value = value.substring(0, start); //We support "a week", so we need to parse the value as "a" int val = 0; if (value.equals("a") || value.equals("an")) { val = 1; } else { val = Integer.parseInt(value); } //Determine the unit if (unit.equals("milliseconds") || unit.equals("millisecond")) { now.add(Calendar.MILLISECOND, -val); } else if (unit.equals("seconds") || unit.equals("second")) { now.add(Calendar.SECOND, -val); } else if (unit.equals("minutes") || unit.equals("minute")) { now.add(Calendar.MINUTE, -val); } else if (unit.equals("hours") || unit.equals("hour")) { now.add(Calendar.HOUR, -val); } else if (unit.equals("days") || unit.equals("day")) { now.add(Calendar.DATE, -val); } else if (unit.equals("weeks") || unit.equals("week")) { now.add(Calendar.DATE, -val * 7); } else if (unit.equals("fortnights") || unit.equals("fortnight")) { now.add(Calendar.DATE, -val * 14); } else if (unit.equals("months") || unit.equals("month")) { now.add(Calendar.MONTH, -val); } else if (unit.equals("years") || unit.equals("year")) { now.add(Calendar.YEAR, -val); } else { throw new RuntimeException("We do not understand that many units ago"); } return now; } else if (value.startsWith("last ")) { //If this was the last time a certain field was met //Strip out the 'last ' part value = value.substring(5); //Get the current date/time String[] strings = symbols.getWeekdays(); for (int i = 0; i < strings.length; i++) { if (value.equalsIgnoreCase(strings[i])) { //How many days after Sunday int daysAgo = now.get(Calendar.DAY_OF_WEEK) - i; if (daysAgo <= 0) { daysAgo += 7; } now.add(Calendar.DATE, -daysAgo); return now; } } strings = symbols.getMonths(); for (int i = 0; i < strings.length; i++) { if (value.equalsIgnoreCase(strings[i])) { //How many days after January int monthsAgo = now.get(Calendar.MONTH) - i; if (monthsAgo <= 0) { monthsAgo += 12; } now.add(Calendar.MONTH, -monthsAgo); return now; } } if (value.equals("week")) { now.add(Calendar.DATE, -7); return now; } } else if (value.equals("yesterday")) { now.add(Calendar.DATE, -1); return now; } else if (value.equals("tomorrow")) { now.add(Calendar.DATE, 1); return now; } //Try to parse the date a number of different ways for (int i = 0; i < dateFormats.length; i++) { try { Date datetime = dateFormats[i].parse(original); Calendar cal = Calendar.getInstance(); cal.setTime(datetime); return cal; } catch (ParseException pe) { //we ignore this and just keep trying } } throw new RuntimeException("Unable to parse '" + original + "'."); }