List of usage examples for java.text DateFormatSymbols getMonths
public String[] getMonths()
From source file:org.apache.click.extras.control.DateField.java
/** * Return the names of months and weekdays as a script. *///from ww w . j ava 2s. c o m 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.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 w w .j ava 2 s.c om 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 ww . ja v a 2 s . c om 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.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 w w . j ava2 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 ww w .j a v a 2 s . 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:DateFormatUtils.java
/** * <p>Returns a list of Rules given a pattern.</p> * //from ww w. j a va 2s.co 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:CalendarUtils.java
/** * Parses strings the way that CVS supports it... very human readable */// w w w. j av a2 s. c o 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 + "'."); }
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();/*from ww w .ja va2s . 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; }
From source file:com.lp.server.fertigung.ejbfac.FertigungFacBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) public int wiederholendeLoseAnlegen(TheClientDto theClientDto) { int iAnzahlAngelegterLose = 0; DateFormatSymbols symbols = new DateFormatSymbols(theClientDto.getLocUi()); String[] defaultMonths = symbols.getMonths(); int iStandarddurchlaufzeit = 0; try {//from w w w . ja v a 2 s. c om ParametermandantDto parameter = getParameterFac().getMandantparameter(theClientDto.getMandant(), ParameterFac.KATEGORIE_FERTIGUNG, ParameterFac.INTERNEBESTELLUNG_DEFAULTDURCHLAUFZEIT); iStandarddurchlaufzeit = ((Integer) parameter.getCWertAsObject()).intValue(); } catch (RemoteException ex2) { throwEJBExceptionLPRespectOld(ex2); } Session session = FLRSessionFactory.getFactory().openSession(); Criteria crit = session.createCriteria(FLRWiederholendelose.class); crit.add(Restrictions.eq("mandant_c_nr", theClientDto.getMandant())); crit.add(Restrictions.eq(FertigungFac.FLR_WIEDERHOLENDELOSE_B_VERSTECKT, Helper.boolean2Short(false))); List<?> resultList = crit.list(); Iterator<?> resultListIterator = resultList.iterator(); while (resultListIterator.hasNext()) { FLRWiederholendelose flrWiederholendelose = (FLRWiederholendelose) resultListIterator.next(); // Naechster faelliger Termin nach Heute Calendar cBeginn = Calendar.getInstance(); cBeginn.setTimeInMillis(flrWiederholendelose.getT_termin().getTime()); String intervall = flrWiederholendelose.getAuftragwiederholungsintervall_c_nr(); Timestamp tHeute = Helper.cutTimestamp(new Timestamp(System.currentTimeMillis())); while (cBeginn.getTimeInMillis() < tHeute.getTime()) { if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_2WOECHENTLICH)) { cBeginn.set(Calendar.DAY_OF_MONTH, cBeginn.get(Calendar.DAY_OF_MONTH) + 14); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_WOECHENTLICH)) { cBeginn.set(Calendar.DAY_OF_MONTH, cBeginn.get(Calendar.DAY_OF_MONTH) + 7); } if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_JAHR)) { cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 1); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_2JAHR)) { cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 2); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_3JAHR)) { cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 3); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_4JAHR)) { cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 4); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_5JAHR)) { cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 5); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_MONATLICH)) { cBeginn.set(Calendar.MONTH, cBeginn.get(Calendar.MONTH) + 1); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_QUARTAL)) { cBeginn.set(Calendar.MONTH, cBeginn.get(Calendar.MONTH) + 3); } } Timestamp tBeginndatumFuerLos = new Timestamp(cBeginn.getTimeInMillis()); // Voreilende Tage abziehen String monatsname = defaultMonths[cBeginn.get(Calendar.MONTH)]; int iJahr = cBeginn.get(Calendar.YEAR); int iTageVoreilend = flrWiederholendelose.getI_tagevoreilend(); cBeginn.set(Calendar.DAY_OF_MONTH, cBeginn.get(Calendar.DAY_OF_MONTH) - iTageVoreilend); Timestamp tAnlagedatum = new Timestamp(cBeginn.getTimeInMillis()); if (tAnlagedatum.before(tHeute) || tAnlagedatum.equals(tHeute)) { // try { Query query = em.createNamedQuery("LosfindWiederholendeloseIIdTProduktionsbeginnMandantCNr"); query.setParameter(1, flrWiederholendelose.getI_id()); query.setParameter(2, tBeginndatumFuerLos); query.setParameter(3, theClientDto.getMandant()); Collection<?> cl = query.getResultList(); // if (cl.isEmpty()) { // throw new EJBExceptionLP(EJBExceptionLP.FEHLER, null); // } LosDto[] lose = assembleLosDtos(cl); // Wenn noch nicht angelegt if (lose.length == 0) { WiederholendeloseDto dto = wiederholendeloseFindByPrimaryKey(flrWiederholendelose.getI_id()); String projektname = ""; if (dto.getCProjekt() != null) { projektname += dto.getCProjekt() + " "; } projektname += monatsname + " " + iJahr; if (projektname.length() > 50) { projektname = projektname.substring(0, 49); } LosDto losDto = new LosDto(); losDto.setWiederholendeloseIId(dto.getIId()); losDto.setCProjekt(projektname); losDto.setFertigungsgruppeIId(dto.getFertigungsgruppeIId()); losDto.setKostenstelleIId(dto.getKostenstelleIId()); losDto.setLagerIIdZiel(dto.getLagerIIdZiel()); losDto.setMandantCNr(theClientDto.getMandant()); losDto.setNLosgroesse(dto.getNLosgroesse()); losDto.setPartnerIIdFertigungsort(dto.getPartnerIIdFertigungsort()); losDto.setStuecklisteIId(dto.getStuecklisteIId()); losDto.setTProduktionsbeginn(new java.sql.Date(tBeginndatumFuerLos.getTime())); // Produktionsende try { int laufzeit = iStandarddurchlaufzeit; if (dto.getStuecklisteIId() != null) { StuecklisteDto stuecklisteDto = getStuecklisteFac() .stuecklisteFindByPrimaryKey(dto.getStuecklisteIId(), theClientDto); if (stuecklisteDto.getNDefaultdurchlaufzeit() != null) { laufzeit = stuecklisteDto.getNDefaultdurchlaufzeit().intValue(); } } Calendar cTemp = Calendar.getInstance(); cTemp.setTimeInMillis(tBeginndatumFuerLos.getTime()); cTemp.set(Calendar.DAY_OF_MONTH, cTemp.get(Calendar.DAY_OF_MONTH) + laufzeit); losDto.setTProduktionsende(new java.sql.Date(cTemp.getTime().getTime())); context.getBusinessObject(FertigungFac.class).createLos(losDto, theClientDto); } catch (RemoteException ex1) { throwEJBExceptionLPRespectOld(ex1); } iAnzahlAngelegterLose++; } // } // catch (FinderException ex) { // throw new EJBExceptionLP(EJBExceptionLP.FEHLER, ex); // } } } return iAnzahlAngelegterLose; }