List of usage examples for java.text DateFormatSymbols DateFormatSymbols
private DateFormatSymbols(boolean flag)
From source file:com.jarklee.materialdatetimepicker.time.AmPmCirclesView.java
public void initialize(Context context, TimePickerController controller, int amOrPm) { if (mIsInitialized) { Log.e(TAG, "AmPmCirclesView may only be initialized once."); return;//from w ww .java 2s . c om } Resources res = context.getResources(); if (controller.isThemeDark()) { mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_circle_background_dark_theme); mAmPmTextColor = ContextCompat.getColor(context, R.color.mdtp_white); mAmPmDisabledTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_disabled_dark_theme); mSelectedAlpha = SELECTED_ALPHA_THEME_DARK; } else { mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_white); mAmPmTextColor = ContextCompat.getColor(context, R.color.mdtp_ampm_text_color); mAmPmDisabledTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_disabled); mSelectedAlpha = SELECTED_ALPHA; } mSelectedColor = controller.getAccentColor(); mTouchedColor = Utils.darkenColor(mSelectedColor); mAmPmSelectedTextColor = ContextCompat.getColor(context, R.color.mdtp_white); String typefaceFamily = res.getString(R.string.mdtp_sans_serif); Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL); mPaint.setTypeface(tf); mPaint.setAntiAlias(true); mPaint.setTextAlign(Align.CENTER); mCircleRadiusMultiplier = Float.parseFloat(res.getString(R.string.mdtp_circle_radius_multiplier)); mAmPmCircleRadiusMultiplier = Float.parseFloat(res.getString(R.string.mdtp_ampm_circle_radius_multiplier)); String[] amPmTexts = new DateFormatSymbols(getLocale()).getAmPmStrings(); mAmText = amPmTexts[0]; mPmText = amPmTexts[1]; mAmDisabled = controller.isAmDisabled(); mPmDisabled = controller.isPmDisabled(); setAmOrPm(amOrPm); mAmOrPmPressed = -1; mIsInitialized = true; }
From source file:com.jarklee.materialdatetimepicker.time.AmPmCirclesView.java
public void updateLocale() { String[] amPmTexts = new DateFormatSymbols(getLocale()).getAmPmStrings(); mAmText = amPmTexts[0]; mPmText = amPmTexts[1]; }
From source file:org.glimpse.server.news.dom.DomServerNewsChannelBuilder.java
private List<ServerEntry> getRSSEntries(Document doc) throws Exception { XPath xpath = XPathFactory.newInstance().newXPath(); List<ServerEntry> rssEntries = new LinkedList<ServerEntry>(); NodeList entries = (NodeList) xpath.evaluate("/rss/channel/item", doc, XPathConstants.NODESET); for (int i = 0; i < entries.getLength(); i++) { ServerEntry rssEntry = new ServerEntry(); Element elmEntry = (Element) entries.item(i); String id = (String) xpath.evaluate("link", elmEntry, XPathConstants.STRING); String title = (String) xpath.evaluate("title", elmEntry, XPathConstants.STRING); String entryUrl = (String) xpath.evaluate("link", elmEntry, XPathConstants.STRING); String pubDate = (String) xpath.evaluate("pubDate", elmEntry, XPathConstants.STRING); NodeList enclosureList = (NodeList) xpath.evaluate("enclosure", elmEntry, XPathConstants.NODESET); List<Enclosure> enclosures = new LinkedList<Enclosure>(); for (int j = 0; j < enclosureList.getLength(); j++) { Element elmEnclosure = (Element) enclosureList.item(j); Enclosure enclosure = new Enclosure(); enclosure.setUrl(elmEnclosure.getAttribute("url")); enclosure.setType(elmEnclosure.getAttribute("type")); enclosures.add(enclosure);/*from w w w .j ava 2 s .com*/ } String content = (String) xpath.evaluate("description", elmEntry, XPathConstants.STRING); content += "<p><a href=\"" + entryUrl + "\" target=\"_blank\">Lire la suite</a></p>"; if (StringUtils.isBlank(id)) { id = pubDate; } if (StringUtils.isBlank(entryUrl)) { entryUrl = getRSSLink(doc); } rssEntry.setId(id); rssEntry.setTitle(title); rssEntry.setUrl(entryUrl); rssEntry.setEnclosures(enclosures); rssEntry.setContent(content); if (StringUtils.isNotBlank(pubDate)) { SimpleDateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); formatter.setDateFormatSymbols(new DateFormatSymbols(Locale.ENGLISH)); try { Date date = formatter.parse(pubDate); rssEntry.setDate(date); } catch (Exception e) { // unparsable date logger.warn("Unable to parse date <" + pubDate + ">", e); } } if (StringUtils.isNotBlank(id) && StringUtils.isNotBlank(title) && StringUtils.isNotBlank(entryUrl)) { rssEntries.add(rssEntry); } } return rssEntries; }
From source file:org.pentaho.reporting.libraries.designtime.swing.date.DateCellEditor.java
private static DateFormat createDateFormat(final String parameterFormatString, final Locale locale, final TimeZone timeZone) { if (parameterFormatString != null) { try {/*from ww w . j ava2 s . c o m*/ final SimpleDateFormat dateFormat = new SimpleDateFormat(parameterFormatString, new DateFormatSymbols(locale)); dateFormat.setTimeZone(timeZone); dateFormat.setLenient(true); return dateFormat; } catch (Exception e) { // boo! Not a valid pattern ... // its not a show-stopper either, as the pattern is a mere hint, not a mandatory thing logger.warn("Parameter format-string for date-parameter was not a valid date-format-string", e); } } final SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_FORMAT, new DateFormatSymbols(locale)); dateFormat.setTimeZone(timeZone); dateFormat.setLenient(true); return dateFormat; }
From source file:org.pentaho.reporting.libraries.designtime.swing.date.TimeCellEditor.java
private DateFormat createDateFormat(final String parameterFormatString, final Locale locale, final TimeZone timeZone) { if (parameterFormatString != null) { try {/*ww w. jav a 2 s .c o m*/ final SimpleDateFormat dateFormat = new SimpleDateFormat(parameterFormatString, new DateFormatSymbols(locale)); dateFormat.setTimeZone(timeZone); dateFormat.setLenient(true); return dateFormat; } catch (Exception e) { // boo! Not a valid pattern ... // its not a show-stopper either, as the pattern is a mere hint, not a mandatory thing logger.warn("Parameter format-string for date-parameter was not a valid date-format-string", e); } } final SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_FORMAT, new DateFormatSymbols(locale)); dateFormat.setTimeZone(timeZone); dateFormat.setLenient(true); return dateFormat; }
From source file:com.alkacon.opencms.calendar.CmsCalendarMonthBean.java
/** * Builds the HTML output to create a basic calendar month overview.<p> * /* www . j a v a 2s . c o m*/ * This method serves as a simple example to create a basic html calendar monthly view.<p> * * @param year the year of the month to display * @param month the month to display * @param calendarLocale the Locale for the calendar to determine the start day of the weeks * @param showNavigation if true, navigation links to switch the month are created, otherwise not * @return the HTML output to create a basic calendar month overview */ public String buildCalendarMonth(int year, int month, Locale calendarLocale, boolean showNavigation) { StringBuffer result = new StringBuffer(1024); Map dates = getMonthDaysMatrix(year, month, calendarLocale); Map monthEntries = getEntriesForMonth(year, month); // calculate the start day of the week Calendar calendar = new GregorianCalendar(calendarLocale); int weekStart = calendar.getFirstDayOfWeek(); // store current calendar date Calendar currentCalendar = (Calendar) calendar.clone(); // init the date format symbols DateFormatSymbols calendarSymbols = new DateFormatSymbols(calendarLocale); // open the table result.append("<table class=\""); result.append(getStyle().getStyleTable()); result.append("\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n"); // create the calendar navigation row result.append(buildMonthNavigation(year, month, currentCalendar, calendarLocale, showNavigation)); // create the week day row result.append("<tr>\n"); int currWeekDay = weekStart; for (int i = 1; i <= 7; i++) { result.append("\t<td class=\""); result.append(getStyle().getStyleWeekdays()); result.append("\">"); result.append(calendarSymbols.getShortWeekdays()[currWeekDay]); result.append("</td>\n"); // check if we are at end of week if (currWeekDay == Calendar.SATURDAY) { currWeekDay = 0; } currWeekDay++; } result.append("</tr>\n"); // now create the entry rows result.append("<tr>\n"); // iterate the index entries of the matrix Iterator i = dates.keySet().iterator(); while (i.hasNext()) { Integer index = (Integer) i.next(); result.append("\t<td class=\""); Calendar currDay = (Calendar) dates.get(index); if (currDay != null) { // current index represents a day, create day output String styleDayCell = getStyle().getStyleDay(); if (isCurrentDay(currentCalendar, currDay)) { // for the current day, use another cell style styleDayCell = getStyle().getStyleDayCurrent(); } // get entries for the day List dayEntries = (List) monthEntries.get(currDay.getTime()); if (dayEntries.size() > 0) { // current day has calendar entries int weekdayStatus = 0; int holidayEntries = 0; int commonEntries = dayEntries.size(); StringBuffer dayText = new StringBuffer(128); // check all entries for special weekday status entries for (int k = 0; k < commonEntries; k++) { CmsCalendarEntry entry = (CmsCalendarEntry) dayEntries.get(k); int entryWeekdayStatus = entry.getEntryData().getWeekdayStatus(); if (entryWeekdayStatus > 0) { // entry is a special weekday holidayEntries++; // append special day info to title info dayText.append(entry.getEntryData().getTitle()); dayText.append(" - "); if (entryWeekdayStatus > weekdayStatus) { // increase the status of the weekday weekdayStatus = entryWeekdayStatus; } } } // calculate the count of common calendar entries commonEntries = commonEntries - holidayEntries; // determine the CSS class to use String dayStyle = getWeekdayStyle(currDay.get(Calendar.DAY_OF_WEEK), weekdayStatus); result.append(styleDayCell); result.append("\" title=\""); result.append(dayText); // check the number of common entries and generate output of entry count if (commonEntries <= 0) { // no entry found result.append(getMessages().key("calendar.entries.count.none")); } else if (commonEntries == 1) { // one entry found result.append(getMessages().key("calendar.entries.count.one")); } else { // more than one entry found result.append(getMessages().key("calendar.entries.count.more", new String[] { String.valueOf(commonEntries) })); } result.append("\">"); if (commonEntries > 0) { // common entries present, create link to the overview page result.append("<a href=\""); result.append(createLink(currDay, m_viewUri, true, -1)); result.append("\" class=\""); result.append(getStyle().getStyleDayEntryLink()); result.append("\">"); } result.append("<span class=\""); result.append(dayStyle); result.append("\">"); result.append(currDay.get(Calendar.DAY_OF_MONTH)); result.append("</span>"); if (commonEntries > 0) { // common entries present, close link result.append("</a>"); } } else { // current day has no entries result.append(styleDayCell); result.append("\" title=\""); result.append(getMessages().key("calendar.entries.count.none")); result.append("\">"); result.append("<span class=\""); result.append(getWeekdayStyle(currDay.get(Calendar.DAY_OF_WEEK), I_CmsCalendarEntryData.WEEKDAYSTATUS_WORKDAY)); result.append("\">"); result.append(currDay.get(Calendar.DAY_OF_MONTH)); result.append("</span>"); } } else { // this is an empty cell result.append(getStyle().getStyleDayEmpty()); result.append("\">"); } result.append("</td>\n"); if ((index.intValue() % 7) == 0) { // append closing row tag result.append("</tr>\n"); if (i.hasNext()) { // open next row if more elements are present result.append("<tr>\n"); } } } // close the table result.append("</table>"); return result.toString(); }
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.sakaiproject.tool.section.jsf.JsfUtil.java
/** * Converts a string and a boolean (am) into a java.sql.Time object. * * @param str//from w w w. j a v a 2s . c om * @param am * @return */ public static Time convertStringToTime(String str, boolean am) { if (StringUtils.trimToNull(str) == null) { return null; } // Set the am/pm flag to ensure that the time is parsed properly if (am) { str = str + " " + new DateFormatSymbols(new ResourceLoader().getLocale()).getAmPmStrings()[0]; } else { str = str + " " + new DateFormatSymbols(new ResourceLoader().getLocale()).getAmPmStrings()[1]; } String pattern = (str.indexOf(':') != -1) ? JsfUtil.TIME_PATTERN_LONG : JsfUtil.TIME_PATTERN_SHORT; SimpleDateFormat sdf = new SimpleDateFormat(pattern, new ResourceLoader().getLocale()); sdf.setTimeZone(TimeService.getLocalTimeZone()); Date date; try { date = sdf.parse(str); } catch (ParseException pe) { throw new RuntimeException("A bad date made it through validation! This should never happen!"); } return ConversionUtil.convertDateToTime(date, am); }
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 .ja va 2s . 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 '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.sakaiproject.profile2.util.ProfileUtils.java
/** * Get the localised name of the day (ie Monday for en, Maandag for nl) * @param day int according to Calendar.DAY_OF_WEEK * @param locale locale to render dayname in * @return//from w w w . j a v a 2 s. co m */ public static String getDayName(int day, Locale locale) { //localised daynames String dayNames[] = new DateFormatSymbols(locale).getWeekdays(); String dayName = null; try { dayName = dayNames[day]; } catch (Exception e) { log.error("Profile.getDayName() failed. " + e.getClass() + ": " + e.getMessage()); } return dayName; }