/** * Returns a cached date format for the current locale. * * @return a cached date format for the current locale */ private DateFormat getDateFormat() { if (fDateFormat == null) fDateFormat= DateFormat.getTimeInstance(DateFormat.SHORT); return fDateFormat; }
/** * Convenience overload. * @stable ICU 2.0 */ static final public DateFormat getTimeInstance(Calendar cal, int timeStyle) { return getTimeInstance(cal, timeStyle, ULocale.getDefault(Category.FORMAT)); }
@Override protected String resolve(TemplateContext context) { return DateFormat.getTimeInstance().format(new java.util.Date()); } }
@Override protected String resolve(TemplateContext context) { return DateFormat.getTimeInstance().format(new java.util.Date()); } }
/** * Convenience overload. * @stable ICU 2.0 */ static final public DateFormat getTimeInstance(Calendar cal, int timeStyle) { return getTimeInstance(cal, timeStyle, ULocale.getDefault(Category.FORMAT)); }
/** * Creates a {@link DateFormat} object that can be used to format times in * the calendar system specified by <code>cal</code>. * @param cal The calendar system for which a time format is desired. * * @param timeStyle The type of time format desired. This can be * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, * etc. * * @see DateFormat#getTimeInstance * @stable ICU 2.0 */ static final public DateFormat getTimeInstance(Calendar cal, int timeStyle) { return getTimeInstance(cal, timeStyle, ULocale.getDefault(Category.FORMAT)); }
/** * Creates a {@link DateFormat} object that can be used to format times in * the calendar system specified by <code>cal</code>. * <p> * <b>Note:</b> When this functionality is moved into the core JDK, this method * will probably be replaced by a new overload of {@link DateFormat#getInstance}. * <p> * @param cal The calendar system for which a time format is desired. * * @param timeStyle The type of time format desired. This can be * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, * etc. * * @param locale The locale for which the time format is desired. * * @see DateFormat#getTimeInstance * @stable ICU 3.2 */ static final public DateFormat getTimeInstance(Calendar cal, int timeStyle, ULocale locale) { DateFormat df = getTimeInstance(timeStyle, locale); df.setCalendar(cal); return df; }
/** * Creates a {@link DateFormat} object that can be used to format times in * the calendar system specified by <code>cal</code>. * <p> * <b>Note:</b> When this functionality is moved into the core JDK, this method * will probably be replaced by a new overload of {@link DateFormat#getInstance}. * <p> * @param cal The calendar system for which a time format is desired. * * @param timeStyle The type of time format desired. This can be * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, * etc. * * @param locale The locale for which the time format is desired. * * @see DateFormat#getTimeInstance * @stable ICU 3.2 */ static final public DateFormat getTimeInstance(Calendar cal, int timeStyle, ULocale locale) { DateFormat df = getTimeInstance(timeStyle, locale); df.setCalendar(cal); return df; }
/** * Creates a {@link DateFormat} object that can be used to format times in * the calendar system specified by <code>cal</code>. * <p> * <b>Note:</b> When this functionality is moved into the core JDK, this method * will probably be replaced by a new overload of {@link DateFormat#getInstance}. * <p> * @param cal The calendar system for which a time format is desired. * * @param timeStyle The type of time format desired. This can be * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, * etc. * * @param locale The locale for which the time format is desired. * * @see DateFormat#getTimeInstance * @stable ICU 2.0 */ static final public DateFormat getTimeInstance(Calendar cal, int timeStyle, Locale locale) { DateFormat df = getTimeInstance(timeStyle, locale); df.setCalendar(cal); return df; }
/** * Creates a {@link DateFormat} object that can be used to format times in * the calendar system specified by <code>cal</code>. * <p> * <b>Note:</b> When this functionality is moved into the core JDK, this method * will probably be replaced by a new overload of {@link DateFormat#getInstance}. * <p> * @param cal The calendar system for which a time format is desired. * * @param timeStyle The type of time format desired. This can be * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, * etc. * * @param locale The locale for which the time format is desired. * * @see DateFormat#getTimeInstance * @stable ICU 2.0 */ static final public DateFormat getTimeInstance(Calendar cal, int timeStyle, Locale locale) { DateFormat df = getTimeInstance(timeStyle, locale); df.setCalendar(cal); return df; }
/** * Get the time string the finished job * * @return String or <code>null</code> if this is not one of the finished * jobs. */ private String getTimeString() { Date date = FinishedJobs.getInstance().getFinishDate(info); if (date != null) { return DateFormat.getTimeInstance(DateFormat.SHORT).format(date); } return null; }
protected SimpleDateFormat getDateFormat(Locale locale) { SimpleDateFormat dateFormat = null; if (this.variant.equals(DATE)) { //dateFormat = I18nSupport.getInstance().getDateFormat(style, locale); dateFormat = (SimpleDateFormat)DateFormat.getDateInstance(style, locale); } else if (this.variant.equals(TIME)) { //dateFormat = I18nSupport.getInstance().getTimeFormat(style, locale); dateFormat = (SimpleDateFormat)DateFormat.getTimeInstance(style, locale); } else if (this.variant.equals(DATE_TIME)) { //dateFormat = I18nSupport.getInstance().getDateTimeFormat(style, style, locale); dateFormat = (SimpleDateFormat)DateFormat.getDateTimeInstance(style, style, locale); } String pattern = (String)localizedPatterns.get(locale); if (pattern != null) // Note: this was previously using applyLocalizedPattern() which allows to use // a locale-specific pattern syntax, e.g. in french "j" (jour) for "d" and // "a" (annee) for "y". But the localized pattern syntax is very little known and thus // led to some weird pattern syntax error messages. dateFormat.applyPattern(pattern); else if (nonLocalizedPattern != null) dateFormat.applyPattern(nonLocalizedPattern); dateFormat.setLenient(lenient); return dateFormat; }
private DateFormat getInstance(int dstyle, int tstyle, Locale locale) { com.ibm.icu.text.DateFormat icuDfmt; ULocale actual = ICULocaleServiceProvider.toULocaleNoSpecialVariant(locale); if (dstyle == NONE) { icuDfmt = com.ibm.icu.text.DateFormat.getTimeInstance(tstyle, actual); } else if (tstyle == NONE) { icuDfmt = com.ibm.icu.text.DateFormat.getDateInstance(dstyle, actual); } else { icuDfmt = com.ibm.icu.text.DateFormat.getDateTimeInstance(dstyle, tstyle, actual); } if (!(icuDfmt instanceof com.ibm.icu.text.SimpleDateFormat)) { // icuDfmt must be always SimpleDateFormat return null; } return SimpleDateFormatICU.wrap((com.ibm.icu.text.SimpleDateFormat)icuDfmt); } }
/** * Retrieve the default hour format character for the supplied locale. * * @param locale * the locale * @return the hour format character * @see <a href="http://bugs.icu-project.org/trac/ticket/9997">ICU bug 9997</a> */ private static char defaultHourFormat(ULocale locale) { // Use short time format, just as ICU4J does internally. And as suggested in // <http://unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems>. SimpleDateFormat df = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT, locale); Skeleton skeleton = Skeleton.fromPattern(df.toPattern()); if (skeleton.has(DateField.Hour)) { return skeleton.getSymbol(DateField.Hour); } return 'H'; }
/** * Returns a label for identifying a node in the edition tree viewer. * This implementation extracts the value for the key "workspaceTreeFormat" or * "treeFormat" (in that order) from the resource bundle * and passes it as the format argument to <code>MessageFormat.format</code>. * The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string) * is the formatted modification date of the given input element. * <p> * Subclasses may override to create their own label. * </p> * * @param edition the edition for which a label must be returned * @param item if a path has been specified in <code>edition</code> a sub element of the given edition; otherwise the same as edition * @param date this date will be returned as part of the formatted string * @return a label of a node in the edition tree viewer * @since 2.0 */ protected String getShortEditionLabel(ITypedElement edition, ITypedElement item, Date date) { String format= null; if (edition instanceof ResourceNode) format= Utilities.getString(fBundle, "workspaceTreeFormat", null); //$NON-NLS-1$ if (format == null) format= Utilities.getString(fBundle, "treeFormat", null); //$NON-NLS-1$ if (format == null) format= "x{0}"; //$NON-NLS-1$ String ds= DateFormat.getTimeInstance().format(date); return formatString(format, ds); }
/** * Returns a label for identifying a node in the edition tree viewer. * This implementation extracts the value for the key "workspaceTreeFormat" or * "treeFormat" (in that order) from the resource bundle * and passes it as the format argument to <code>MessageFormat.format</code>. * The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string) * is the formatted modification date of the given input element. * <p> * Subclasses may override to create their own label. * </p> * * @param edition the edition for which a label must be returned * @param item if a path has been specified in <code>edition</code> a sub element of the given edition; otherwise the same as edition * @param date this date will be returned as part of the formatted string * @return a label of a node in the edition tree viewer * @since 2.0 */ protected String getShortEditionLabel(ITypedElement edition, ITypedElement item, Date date) { String format= null; if (edition instanceof ResourceNode) format= Utilities.getString(fBundle, "workspaceTreeFormat", null); //$NON-NLS-1$ if (format == null) format= Utilities.getString(fBundle, "treeFormat", null); //$NON-NLS-1$ if (format == null) format= "x{0}"; //$NON-NLS-1$ String ds= DateFormat.getTimeInstance().format(date); return formatString(format, ds); }
/** * {@icu} Returns a <code>DateFormat</code> appropriate to this calendar. * Subclasses wishing to specialize this behavior should override * {@link #handleGetDateFormat}. * @stable ICU 2.0 */ public DateFormat getDateTimeFormat(int dateStyle, int timeStyle, Locale loc) { if (dateStyle != DateFormat.NONE) { if (timeStyle == DateFormat.NONE) { return DateFormat.getDateInstance((Calendar)this.clone(), dateStyle, loc); } else { return DateFormat.getDateTimeInstance((Calendar)this.clone(), dateStyle, timeStyle, loc); } } else if (timeStyle != DateFormat.NONE) { return DateFormat.getTimeInstance((Calendar)this.clone(), timeStyle, loc); } else { return null; } }
/** * {@icu} Returns a <code>DateFormat</code> appropriate to this calendar. * Subclasses wishing to specialize this behavior should override * {@link #handleGetDateFormat}. * @stable ICU 2.0 */ public DateFormat getDateTimeFormat(int dateStyle, int timeStyle, Locale loc) { if (dateStyle != DateFormat.NONE) { if (timeStyle == DateFormat.NONE) { return DateFormat.getDateInstance((Calendar)this.clone(), dateStyle, loc); } else { return DateFormat.getDateTimeInstance((Calendar)this.clone(), dateStyle, timeStyle, loc); } } else if (timeStyle != DateFormat.NONE) { return DateFormat.getTimeInstance((Calendar)this.clone(), timeStyle, loc); } else { return null; } }
private void addICUPatterns(PatternInfo returnInfo, ULocale uLocale) { // first load with the ICU patterns for (int i = DateFormat.FULL; i <= DateFormat.SHORT; ++i) { SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(i, uLocale); addPattern(df.toPattern(), false, returnInfo); df = (SimpleDateFormat) DateFormat.getTimeInstance(i, uLocale); addPattern(df.toPattern(), false, returnInfo); if (i == DateFormat.SHORT) { consumeShortTimePattern(df.toPattern(), returnInfo); } } }
/** * This function can be overridden by subclasses to use different heuristics. * <b>It MUST return a 'safe' value, * one whose modification will not affect this object.</b> * * @param dateStyle * @param timeStyle * @draft ICU 3.6 * @provisional This API might change or be removed in a future release. */ protected DateFormat guessDateFormat(int dateStyle, int timeStyle) { DateFormat result; ULocale dfLocale = getAvailableLocale(TYPE_DATEFORMAT); if (dfLocale == null) { dfLocale = ULocale.ROOT; } if (timeStyle == DF_NONE) { result = DateFormat.getDateInstance(getCalendar(), dateStyle, dfLocale); } else if (dateStyle == DF_NONE) { result = DateFormat.getTimeInstance(getCalendar(), timeStyle, dfLocale); } else { result = DateFormat.getDateTimeInstance(getCalendar(), dateStyle, timeStyle, dfLocale); } return result; }