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

The following examples show how to use com.ibm.icu.util.TimeZone#getDefault() . 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: TimeZoneNamesImpl.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the transient fields, called from the constructor and
 * readObject.
 *
 * @param locale The locale
 */
private void initialize(ULocale locale) {
    ICUResourceBundle bundle = (ICUResourceBundle)ICUResourceBundle.getBundleInstance(
            ICUData.ICU_ZONE_BASE_NAME, locale);
    _zoneStrings = (ICUResourceBundle)bundle.get(ZONE_STRINGS_BUNDLE);

    // TODO: Access is synchronized, can we use a non-concurrent map?
    _tzNamesMap = new ConcurrentHashMap<String, ZNames>();
    _mzNamesMap = new ConcurrentHashMap<String, ZNames>();
    _namesFullyLoaded = false;

    _namesTrie = new TextTrieMap<NameInfo>(true);
    _namesTrieFullyLoaded = false;

    // Preload zone strings for the default time zone
    TimeZone tz = TimeZone.getDefault();
    String tzCanonicalID = ZoneMeta.getCanonicalCLDRID(tz);
    if (tzCanonicalID != null) {
        loadStrings(tzCanonicalID);
    }
}
 
Example 2
Source File: TimeZoneGenericNames.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Private method initializing the instance of <code>TimeZoneGenericName</code>.
 * This method should be called from a constructor and readObject.
 */
private void init() {
    if (_tznames == null) {
        _tznames = TimeZoneNames.getInstance(_locale);
    }
    _genericLocationNamesMap = new ConcurrentHashMap<String, String>();
    _genericPartialLocationNamesMap = new ConcurrentHashMap<String, String>();

    _gnamesTrie = new TextTrieMap<NameInfo>(true);
    _gnamesTrieFullyLoaded = false;

    // Preload zone strings for the default time zone
    TimeZone tz = TimeZone.getDefault();
    String tzCanonicalID = ZoneMeta.getCanonicalCLDRID(tz);
    if (tzCanonicalID != null) {
        loadStrings(tzCanonicalID);
    }
}
 
Example 3
Source File: Formatter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public Object execute( Object[] arguments, IScriptFunctionContext scriptContext )
		throws BirtException
{
	if ( scriptContext != null )
	{
		locale = (ULocale) scriptContext
				.findProperty( org.eclipse.birt.core.script.functionservice.IScriptFunctionContext.LOCALE );
		timeZone = (TimeZone) scriptContext
				.findProperty( org.eclipse.birt.core.script.functionservice.IScriptFunctionContext.TIMEZONE );
	}
	if ( timeZone == null )
	{
		timeZone = TimeZone.getDefault( );
	}
	return executor.execute( arguments, scriptContext );
}
 
Example 4
Source File: APITestCase.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
@Before
   public void apiSetUp() throws Exception
{

	
	defaultTimeZone = TimeZone.getDefault( );
	TimeZone.setDefault( TimeZone.getTimeZone( "GMT" ) );
	DataEngineContext context = DataEngineContext.newInstance( DataEngineContext.DIRECT_PRESENTATION,
			this.scriptContext,
			null,
			null,
			null );
	context.setTmpdir( this.getTempDir( ) );
	PlatformConfig cfg = new PlatformConfig();
	cfg.setTempDir(this.getTempDir( ));
	dataEngine = DataEngine.newDataEngine( cfg, context );
	prepareDataSource( );
}
 
Example 5
Source File: ExecutionContext.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * create a new context. Call close to finish using the execution context
 */
public ExecutionContext( EngineTask engineTask )
{
	if ( engineTask != null )
	{
		task = engineTask;
		engine = (ReportEngine) task.getEngine( );
		log = task.getLogger( );
	}
	else
	{
		log = Logger.getLogger( ExecutionContext.class.getName( ) );
	}

	ulocale = ULocale.getDefault( );
	timeZone = TimeZone.getDefault( );
	eventHandlerManager = new EventHandlerManager( );
}
 
Example 6
Source File: DateGroupCalculator.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @param intervalStart
 * @param intervalRange
 * @throws BirtException
 */
public DateGroupCalculator(Object intervalStart, double intervalRange, ULocale locale, TimeZone timeZone ) throws BirtException
{
	super( intervalStart, intervalRange );
	range = (int)Math.round( intervalRange );
	range = (range == 0 ? 1 : range);
	if ( intervalStart != null )
		this.intervalStart = DataTypeUtil.toDate( intervalStart );
	this.locale = locale == null ? ULocale.getDefault( ):locale;
	this.timeZone = timeZone == null ? TimeZone.getDefault( ):timeZone;
	Calendar c = Calendar.getInstance( this.locale );
	c.setTimeZone( this.timeZone );
	c.clear( );
	c.set( 1970, 0, 1 );
	defaultStart = c.getTime( );
	
	this.dateTimeUtil = new DateTimeUtil( this.locale, this.timeZone );
}
 
Example 7
Source File: DateIntervalFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Get the TimeZone
 * @return A copy of the TimeZone associated with this date interval formatter.
 * @stable ICU 53
 */
public TimeZone getTimeZone()
{
    if ( fDateFormat != null ) {
        // Here we clone, like other getters here, but unlike
        // DateFormat.getTimeZone() and Calendar.getTimeZone()
        // which return the TimeZone from the Calendar's zone variable
        return (TimeZone)(fDateFormat.getTimeZone().clone());
    }
    // If fDateFormat is null (unexpected), return default timezone.
    return TimeZone.getDefault();
}
 
Example 8
Source File: ExcelContext.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void initialize( IEmitterServices service ) throws EngineException
{
	if ( service == null )
	{
		return;
	}
	out = EmitterUtil.getOuputStream( service, "report.xls" );
	if ( service.getReportEngine( ) != null )
	{
		this.tempFileDir = service.getReportEngine( ).getConfig( )
				.getTempDir( );
	}
	IReportContext reportContext = service.getReportContext( );
	if ( reportContext != null )
	{
		Locale locale = reportContext.getLocale( );
		this.locale = locale == null ? ULocale.getDefault( ) : ULocale
				.forLocale( locale );
		this.timeZone = reportContext.getTimeZone( );
		if ( timeZone == null )
		{
			timeZone = TimeZone.getDefault( );
		}
	}
	IRenderOption renderOption = service.getRenderOption( );
	Object option = renderOption
			.getOption( IExcelRenderOption.OPTION_MULTIPLE_SHEET );
	if ( option instanceof Boolean )
		enableMultipleSheet = (Boolean) option;
	this.reportContext = service.getReportContext( );
}
 
Example 9
Source File: ExcelEmitter.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public TimeZone getTimeZone()
{
	if ( service != null )
	{
		IReportContext reportContext = service.getReportContext( );
		if ( reportContext != null )
		{
			return reportContext.getTimeZone( );
		}
	}
	return TimeZone.getDefault( );
}
 
Example 10
Source File: ReportContent.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public ITOCTree getTOCTree( String format, ULocale locale )
{
	if ( tocTree == null )
	{
		return null;
	}
	return new TOCView( tocTree, report.getReportDesign( ), locale,
			TimeZone.getDefault( ) );
}
 
Example 11
Source File: OdsEmitter.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public TimeZone getTimeZone()
{
	if ( service != null )
	{
		IReportContext reportContext = service.getReportContext( );
		if ( reportContext != null )
		{
			return reportContext.getTimeZone( );
		}
	}
	return TimeZone.getDefault( );
}
 
Example 12
Source File: TimeDimensionUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static void setContext( IScriptFunctionContext context )
{
 scriptContext = context;
if ( scriptContext != null )
{
	timeZone = (TimeZone) scriptContext.findProperty( org.eclipse.birt.core.script.functionservice.IScriptFunctionContext.TIMEZONE );
}
if( timeZone == null )
{
	timeZone = TimeZone.getDefault( );
}
}
 
Example 13
Source File: DataEngineContext.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**	
 * @param mode
 * @param scope
 * @param reader
 * @param writer
 * @throws BirtException
 */
public DataEngineContext( int mode, Scriptable scope,
		IDocArchiveReader reader, IDocArchiveWriter writer, ClassLoader classLoader, ScriptContext context )
		throws BirtException
{
	Object[] params = {
			Integer.valueOf( mode ), scope, reader, writer, classLoader
	};
	logger.entering( DataEngineContext.class.getName( ),
			"DataEngineContext", //$NON-NLS-1$
			params );
	
	if ( !( mode == MODE_GENERATION
			|| mode == MODE_PRESENTATION || mode == DIRECT_PRESENTATION || mode == MODE_UPDATE ) )
		throw new DataException( ResourceConstants.RD_INVALID_MODE );

	if ( writer == null && mode == MODE_GENERATION )
		throw new DataException( ResourceConstants.RD_INVALID_ARCHIVE );

	if ( reader == null && mode == MODE_PRESENTATION )
		throw new DataException( ResourceConstants.RD_INVALID_ARCHIVE );

	if ( reader == null && mode == MODE_UPDATE )
		throw new DataException( ResourceConstants.RD_INVALID_ARCHIVE );

	this.classLoader = classLoader;
	this.mode = mode;
	this.scope = scope;
	this.reader = reader;
	this.writer = writer;
	this.cacheOption = CACHE_USE_DEFAULT;
	this.scriptContext = context;
	this.currentLocale = ULocale.getDefault( );
	this.currentTimeZone = TimeZone.getDefault( );
	logger.exiting( DataEngineContext.class.getName( ), "DataEngineContext" ); //$NON-NLS-1$
}
 
Example 14
Source File: DateGroupCalculator.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public DateGroupCalculator( Object intervalStart, double intervalRange, ULocale locale, TimeZone timeZone ) throws BirtException
{
	super( intervalStart, intervalRange );
	ULocale aLocale = locale == null ? ULocale.getDefault( ):locale;
	TimeZone aZone = timeZone == null? TimeZone.getDefault( ):timeZone;
	
	Calendar c = Calendar.getInstance( aLocale );
	c.setTimeZone( aZone );
	c.clear( );
	c.set( 1970, 0, 1 );
	this.defaultStart = c.getTime( );
	this.dateTimeUtil = new DateTimeUtil( aLocale, aZone );
}
 
Example 15
Source File: BirtDateTime.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public Object execute( Object[] arguments, IScriptFunctionContext scriptContext )
		throws BirtException
{
	if ( scriptContext != null )
	{
		Object locale = scriptContext.findProperty(
				org.eclipse.birt.core.script.functionservice.IScriptFunctionContext.LOCALE );
		if ( !( locale instanceof ULocale ) )
		{
			locale = ULocale.getDefault( );
		}
		if ( threadLocale.get( ) != locale )
		{
			threadLocale.set( (ULocale) locale );
			List<SimpleDateFormat> sdfList = new ArrayList<SimpleDateFormat>( );
			sdfList.add(
					new SimpleDateFormat( "MMM", threadLocale.get( ) ) );
			sdfList.add(
					new SimpleDateFormat( "MMMM", threadLocale.get( ) ) );
			sdfList.add(
					new SimpleDateFormat( "EEE", threadLocale.get( ) ) );
			sdfList.add(
					new SimpleDateFormat( "EEEE", threadLocale.get( ) ) );
			threadSDFArray.set( sdfList );
		}

		Object timeZone = scriptContext.findProperty(
				org.eclipse.birt.core.script.functionservice.IScriptFunctionContext.TIMEZONE );
		if ( !( timeZone instanceof TimeZone ) )
		{
			timeZone = TimeZone.getDefault( );
		}
		if ( threadTimeZone.get( ) != timeZone )
		{
			threadTimeZone.set( (TimeZone) timeZone );
		}
	}
	return this.executor.execute( arguments, scriptContext );
}
 
Example 16
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( );
}
 
Example 17
Source File: DateTimeUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public DateTimeUtil( ULocale locale, TimeZone timeZone )
{
	this.locale = locale == null? ULocale.getDefault( ):locale;
	this.timeZone = timeZone == null?TimeZone.getDefault( ):timeZone;
}
 
Example 18
Source File: ChineseDateFormat.java    From fitnotifications with Apache License 2.0 2 votes vote down vote up
/**
 * Construct a ChineseDateFormat from a date format pattern, numbering system override and locale
 * @param pattern the pattern
 * @param override The override string.  A numbering system override string can take one of the following forms:
 *     1). If just a numbering system name is specified, it applies to all numeric fields in the date format pattern.
 *     2). To specify an alternate numbering system on a field by field basis, use the field letters from the pattern
 *         followed by an = sign, followed by the numbering system name.  For example, to specify that just the year
 *         be formatted using Hebrew digits, use the override "y=hebr".  Multiple overrides can be specified in a single
 *         string by separating them with a semi-colon. For example, the override string "m=thai;y=deva" would format using
 *         Thai digits for the month and Devanagari digits for the year.
 * @param locale the locale
 * @deprecated ICU 50
 */
@Deprecated
public ChineseDateFormat(String pattern, String override, ULocale locale) {
   super(pattern, new ChineseDateFormatSymbols(locale),
           new ChineseCalendar(TimeZone.getDefault(), locale), locale, true, override);
}