Java Code Examples for com.ibm.icu.util.TimeZone#getTimeZone()

The following examples show how to use com.ibm.icu.util.TimeZone#getTimeZone() . 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: TOCViewTest.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void testTocFind() throws Exception
{
	ITreeNode tree = createTocNormal( );
	TOCView view = new TOCView( tree, null, ULocale.ENGLISH, TimeZone
			.getTimeZone( "GMT+08:00" ), "html" );
	
	checkTocNode(view, "/", null, 3);
	checkTocNode(view, "__TOC_0", "report header", 0);
	checkTocNode(view, "__TOC_1", "table", 2);
	checkTocNode(view, "__TOC_1_0", "group 1", 2);
	checkTocNode(view, "__TOC_1_0_0", "detail 1", 0);
	checkTocNode(view, "__TOC_1_0_1", "detail 2", 0);
	checkTocNode(view, "__TOC_1_1", "group 2", 2);
	checkTocNode(view, "__TOC_1_1_0", "detail 3", 0);
	checkTocNode(view, "__TOC_1_1_1", "detail 4", 0);
	checkTocNode(view, "__TOC_2_0", "chart 1", 0);
	checkTocNode(view, "__TOC_2_1", "chart 2", 0);
	assertTrue( view.findTOC( "__TOC_0_0" ) == null );
	assertTrue( view.findTOC( "__TOC_1_1_2" ) == null );
	assertTrue( view.findTOC( "__TOC_1_1_1_0" ) == null );
	assertTrue( view.findTOC( "__TOC_3" ) == null );
}
 
Example 2
Source File: TimeZoneFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance of TimeZone for the given offset
 * @param offset the offset
 * @return A TimeZone with the given offset
 */
private TimeZone getTimeZoneForOffset(int offset) {
    if (offset == 0) {
        // when offset is 0, we should use "Etc/GMT"
        return TimeZone.getTimeZone(TZID_GMT);
    }
    return ZoneMeta.getCustomTimeZone(offset);
}
 
Example 3
Source File: TOCViewTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void testTocViewNormal( ) throws EngineException, IOException
{
	ITreeNode tree = createTocNormal( );
	System.out.println( toString( tree ) );
	TOCView view = new TOCView( tree, null, ULocale.ENGLISH, TimeZone
			.getTimeZone( "GMT+08:00" ), "html" );
	String output = toString( view.getRoot( ) );
	System.out.println( output );
	assertEquals( TOC_NORMAL_GOLDEN.replaceAll( "\\s", "" ), output
			.replaceAll( "\\s", "" ) );
}
 
Example 4
Source File: TOCViewTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void testTocViewWithFormat( ) throws EngineException, IOException
{
	ITreeNode tree = createTocWithFormat( );
	System.out.println( toString( tree ) );
	TOCView view = new TOCView( tree, null, ULocale.ENGLISH, TimeZone
			.getTimeZone( "GMT+08:00" ), "html" );
	String output = toString( view.getRoot( ) );
	System.out.println( output );
	assertEquals( TOC_WITH_FORMAT_GOLDEN.replaceAll( "\\s", "" ), output
			.replaceAll( "\\s", "" ) );
}
 
Example 5
Source File: TOCViewTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void testTocViewWithEmptyGorup( ) throws EngineException,
		IOException
{
	ITreeNode tree = createTocWithEmptyGroup( );
	System.out.println( toString( tree ) );
	TOCView view = new TOCView( tree, null, ULocale.ENGLISH, TimeZone
			.getTimeZone( "GMT+08:00" ), "html" );
	String output = toString( view.getRoot( ) );
	System.out.println( output );
	assertEquals( TOC_WITH_EMPTY_GROUP_GOLDEN.replaceAll( "\\s", "" ),
			output.replaceAll( "\\s", "" ) );

}
 
Example 6
Source File: TimeLabel.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * when the TimeZone is changed ,update the time
 * 
 * @param oldID
 * @param newID
 * @return true
 */
public boolean updateTimeForTimeZone( String oldID, String newID )
{

	TimeZone oldZone = TimeZone.getTimeZone( oldID );
	TimeZone newZone = TimeZone.getTimeZone( newID );

	int oldOff = oldZone.getRawOffset( );
	int newOff = newZone.getRawOffset( );

	time = time + ( newOff - oldOff );
	String text = getShowText( getFormatType( ) );
	setText( text );
	return true;
}
 
Example 7
Source File: TimeOptionDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public boolean updateTimeForTimeZone( String oldID, String newID )
{
	long time = cale.getTimeInMillis( );
	TimeZone oldZone = TimeZone.getTimeZone( oldID );
	TimeZone newZone = TimeZone.getTimeZone( newID );

	int oldOff = oldZone.getRawOffset( );
	int newOff = newZone.getRawOffset( );

	time = time + ( newOff - oldOff );
	cale.setTimeInMillis( time );

	return true;
}
 
Example 8
Source File: DateFormatterTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
@Test
   public void testTimeZone()
{
	String result = null;
	DateFormatter df = null;

	Calendar dateCal = Calendar.getInstance( );
	dateCal.setTimeZone(java.util.TimeZone.getTimeZone("PST"));
	dateCal.set( 1998, 8, 13, 5, 1, 44 );
	Date dateTime = dateCal.getTime( );
	java.sql.Time sqlTime = new java.sql.Time( dateTime.getTime( ) );

	String utcDate = "13 Sep 1998 12:01";
	String utcTime = "12:01:44";
	TimeZone UTCTimeZone = TimeZone.getTimeZone( "UTC" );
	df = new DateFormatter( ULocale.UK, UTCTimeZone );
	result = df.format( dateTime );
	assertTrue( utcDate.equalsIgnoreCase( result ) );
	result = df.format( sqlTime );
	assertTrue( utcTime.equalsIgnoreCase( result ) );

	String japanDate = "1998/09/13 21:01";
	String japanTime = "21:01:44";
	TimeZone japanTimeZone = TimeZone.getTimeZone( "Japan" );
	df = new DateFormatter( ULocale.JAPAN, japanTimeZone );
	result = df.format( dateTime );
	assertTrue( japanDate.equalsIgnoreCase( result ) );
	result = df.format( sqlTime );
	assertTrue( japanTime.equalsIgnoreCase( result ) );
}
 
Example 9
Source File: CommonDataExtractionImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Initializes the common options based on the data extraction option. If
 * the passed option doesn't contain common options, use default values.
 * 
 * @param context
 * @param options
 *            options
 */
private void initCommonOptions( IReportContext context,
		IDataExtractionOption options )
{
	String dateFormat = null;
	ICommonDataExtractionOption commonOptions;
	if ( options instanceof ICommonDataExtractionOption )
	{
		commonOptions = (ICommonDataExtractionOption) options;
	}
	else
	{
		commonOptions = new CommonDataExtractionOption( options.getOptions( ) );
	}

	this.isLocaleNeutral = commonOptions.isLocaleNeutralFormat( );
	this.localeNeutralFlags = commonOptions.getLocaleNeutralFlags( );

	dateFormat = commonOptions.getDateFormat( );
	// get locale info
	Locale aLocale = null;
	if ( commonOptions.getLocale( ) != null )
	{
		aLocale = commonOptions.getLocale( );
	}
	else if ( context != null )
	{
		aLocale = context.getLocale( );
	}
	if ( aLocale == null )
	{
		this.locale = ULocale.forLocale( Locale.getDefault( ) );
	}
	else
	{
		this.locale = ULocale.forLocale( aLocale );
	}

	java.util.TimeZone javaTimeZone = commonOptions.getTimeZone( );
	if ( javaTimeZone != null )
	{
		// convert java time zone to ICU time zone
		this.timeZone = TimeZone.getTimeZone( javaTimeZone.getID( ) );
	}
	else if ( context != null )
	{
		timeZone = context.getTimeZone( );
	}
	else
	{
		timeZone = TimeZone.getDefault( );
	}

	if ( !isLocaleNeutral )
	{
		dateFormatter = createDateFormatter( dateFormat,
				this.locale,
				this.timeZone );
	}
	formatterMap = commonOptions.getFormatter( );
}