Java Code Examples for com.ibm.icu.text.DateFormat#getDateInstance()
The following examples show how to use
com.ibm.icu.text.DateFormat#getDateInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalizationPreferences.java From fitnotifications with Apache License 2.0 | 6 votes |
/** * 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; }
Example 2
Source File: DateFormatWrapperFactory.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Returns a preferred format specifier for tick labels that represent axis * values that will be computed based on the difference between cdt1 and * cdt2 * * @param iUnit * The unit for which a preferred pattern is being requested * @param locale * The locale for format style * @param keepHierarchy * indicates if the format should keep hierarchy * * @return A preferred datetime format for the given unit */ public static final IDateFormatWrapper getPreferredDateFormat( int iUnit, ULocale locale, boolean keepHierarchy ) { IDateFormatWrapper df = null; String pattern = ChartUtil.createDefaultFormatPattern( iUnit, keepHierarchy ); df = new CommonDateFormatWrapper( new SimpleDateFormat( pattern, locale ) ); // Special cases for dynamic patterns switch ( iUnit ) { case Calendar.MONTH : if ( keepHierarchy ) { df = new MonthDateFormat( locale ); } break; case Calendar.DAY_OF_MONTH :// Same as DATE if ( keepHierarchy ) { df = new CommonDateFormatWrapper( DateFormat.getDateInstance( DateFormat.MEDIUM, locale ) ); } break; } return df; }
Example 3
Source File: DateFormatWrapperFactory.java From birt with Eclipse Public License 1.0 | 5 votes |
public String toLocalizedPattern( ) { DateFormat df = DateFormat.getDateInstance( DateFormat.LONG, locale ); if ( df instanceof SimpleDateFormat ) { return ( (SimpleDateFormat) df ).toLocalizedPattern( ) + "\n" //$NON-NLS-1$ + new SimpleDateFormat( "HH:mm", locale ).toLocalizedPattern( ); //$NON-NLS-1$ } return "MMMM d, yyyy HH:mm"; //$NON-NLS-1$ }
Example 4
Source File: DateFormatWrapperFactory.java From birt with Eclipse Public License 1.0 | 5 votes |
public String toLocalizedPattern( ) { DateFormat df = DateFormat.getDateInstance( DateFormat.MEDIUM, locale ); if ( df instanceof SimpleDateFormat ) { String pattern = ( (SimpleDateFormat) df ).toLocalizedPattern( ); return pattern.replaceAll( "(-|/)?d+(\\.|,|/|-)?\\s?", "" ).trim( ); //$NON-NLS-1$ //$NON-NLS-2$ } return "MMM yyyy"; //$NON-NLS-1$ }
Example 5
Source File: DateTimePropertyType.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Validates the locale-dependent value for the date time type, validate the * <code>value</code> in the locale-dependent way and convert the * <code>value</code> into a Date object. * * @return object of type Date or null if <code>value</code> is null. */ public Object validateInputString( Module module, DesignElement element, PropertyDefn defn, String value ) throws PropertyValueException { if ( StringUtil.isBlank( value ) ) { return null; } // Parse the input in locale-dependent way. ULocale locale = module == null ? ThreadResources.getLocale( ) : module .getLocale( ); DateFormat formatter = DateFormat.getDateInstance( DateFormat.SHORT, locale ); try { return formatter.parse( value ); } catch ( ParseException e ) { logger.log( Level.SEVERE, "Invalid date value:" + value ); //$NON-NLS-1$ throw new PropertyValueException( value, PropertyValueException.DESIGN_EXCEPTION_INVALID_VALUE, DATE_TIME_TYPE ); } }
Example 6
Source File: DateFormatWrapperFactory.java From birt with Eclipse Public License 1.0 | 4 votes |
public String format( Date date ) { StringBuffer str = new StringBuffer( ); FieldPosition pos = new FieldPosition( DateFormat.DATE_FIELD ); DateFormat df = DateFormat.getDateInstance( DateFormat.MEDIUM, locale ); if ( tz != null ) { df.setTimeZone( tz ); } df.format( date, str, pos ); int endIndex; if ( pos.getEndIndex( ) >= str.length( ) ) { endIndex = pos.getEndIndex( ); } else { endIndex = pos.getEndIndex( ) + ( str.charAt( pos.getEndIndex( ) ) == ',' ? 2 : 1 ); } if ( endIndex >= str.length( ) ) // means date is the last one, need // to remove separator { endIndex = pos.getBeginIndex( ); while ( endIndex > 0 ) { char ch = str.charAt( endIndex - 1 ); if ( ch == ' ' || ch == ',' || ch == '/' || ch == '-' || ch == '.' ) { endIndex--; } else { break; } } return str.substring( 0, endIndex ); } return str.substring( 0, pos.getBeginIndex( ) ) + str.substring( endIndex ); }
Example 7
Source File: FeaturesTest.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * */ @Test public void testResultIteratorFindGroup3( ) throws Exception { String[] bindingNameGroup = new String[]{ "GROUP_SALE_DATE", "GROUP_AMOUNT" }; IBaseExpression[] bindingExprGroup = new IBaseExpression[]{ new ScriptExpression( "dataSetRow[\"SALE_DATE\"]" ), new ScriptExpression( "dataSetRow.AMOUNT" ) }; GroupDefinition[] groupDefn = new GroupDefinition[]{ new GroupDefinition( "group1" ), new GroupDefinition( "group2" ) }; groupDefn[0].setKeyExpression( "row.GROUP_SALE_DATE" ); groupDefn[1].setKeyExpression( "row.GROUP_AMOUNT" ); String[] bindingNameRow = new String[]{ "ROW_COUNTRY", "ROW_CITY", "ROW_SALE_DATE", "ROW_AMOUNT" }; IBaseExpression[] bindingExprRow = new IBaseExpression[]{ new ScriptExpression( "dataSetRow[\"COUNTRY\"]", 0 ), new ScriptExpression( "dataSetRow.CITY", 0 ), new ScriptExpression( "dataSetRow.SALE_DATE", 0 ), new ScriptExpression( "dataSetRow.AMOUNT", 0 ) }; QueryDefinition queryDefn = this.createQuery( bindingNameGroup, bindingExprGroup, groupDefn, null, null, null, null, null, null, bindingNameRow, bindingExprRow ); IResultIterator it = executeQuery( queryDefn ); it.next( ); DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT, Locale.US ); testFindGroup( it, new Object[]{ df.format( df.parse( "05/01/2004" ) ) }, 5 ); testFindGroup( it, new Object[]{ df.format( df.parse( "06/01/2004" ) ), "100" }, 3 ); testFindGroup( it, new Object[]{ df.format( df.parse( "06/01/2004" ) ), new Integer( 100 ) }, 3 ); testFindGroup( it, new Object[]{ df.format( df.parse( "06/05/2004" ) ), "400" }, 1 ); try { testFindGroup( it, new Object[]{ "CHINA", "abc" }, 6 ); fail( "Should convert fails" ); } catch ( BirtException e ) { System.out.println( e.getLocalizedMessage( ) ); } }
Example 8
Source File: FormatterImpl.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public String formatCalDateOnly(final Calendar cal) { DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, iLocale); df.setCalendar(cal); return df.format(cal.getTime()); }