com.ibm.icu.util.TimeZone Java Examples

The following examples show how to use com.ibm.icu.util.TimeZone. 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: 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 #2
Source File: TOCView.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public TOCView( ITreeNode tree, ReportDesignHandle handle, ULocale locale,
		TimeZone timeZone, String format, ViewFilter filter )
{
	if ( "viewer".equals( format ) )
	{
		this.format = "html";
	}
	else
	{
		this.format = format;
	}
	this.filter = filter;
	this.locale = locale;
	this.timeZone = timeZone;
	this.formatUtil = new TOCFormatUtil( locale, timeZone );
	if ( handle != null )
	{
		this.styleUtil = new TOCStyleUtil( handle );
	}
	this.root = new ViewNode( this, null, tree );
}
 
Example #3
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 #4
Source File: ReportDocumentReader.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @deprecated
 */
public ITOCTree getTOCTree( String format, ULocale locale, TimeZone timeZone )
{
	try
	{
		ITreeNode root = getTOCTree( );
		if ( root != null )
		{
			ReportDesignHandle report = ( (ReportRunnable) getOnPreparedRunnable( ) )
					.getReport( );
			return new TOCView( root, report, locale, timeZone, format );
		}
	}
	catch ( EngineException ex )
	{
		logger.log( Level.WARNING, ex.getMessage( ), ex );
	}
	return null;
}
 
Example #5
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 #6
Source File: ZoneMeta.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an immutable set of canonical system time zone IDs.
 * The result set is a subset of {@link #getSystemZIDs()}, but not
 * including aliases, such as "US/Eastern".
 * @return An immutable set of canonical system time zone IDs.
 */
private static synchronized Set<String> getCanonicalSystemZIDs() {
    Set<String> canonicalSystemZones = null;
    if (REF_CANONICAL_SYSTEM_ZONES != null) {
        canonicalSystemZones = REF_CANONICAL_SYSTEM_ZONES.get();
    }
    if (canonicalSystemZones == null) {
        Set<String> canonicalSystemIDs = new TreeSet<String>();
        String[] allIDs = getZoneIDs();
        for (String id : allIDs) {
            // exclude Etc/Unknown
            if (id.equals(TimeZone.UNKNOWN_ZONE_ID)) {
                continue;
            }
            String canonicalID = getCanonicalCLDRID(id);
            if (id.equals(canonicalID)) {
                canonicalSystemIDs.add(id);
            }
        }
        canonicalSystemZones = Collections.unmodifiableSet(canonicalSystemIDs);
        REF_CANONICAL_SYSTEM_ZONES = new SoftReference<Set<String>>(canonicalSystemZones);
    }
    return canonicalSystemZones;
}
 
Example #7
Source File: SimpleDateFormat.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Formats a date or time, which is the standard millis
 * since January 1, 1970, 00:00:00 GMT.
 * <p>Example: using the US locale:
 * "yyyy.MM.dd G 'at' HH:mm:ss zzz" -&gt;&gt; 1996.07.10 AD at 15:08:56 PDT
 * @param cal the calendar whose date-time value is to be formatted into a date-time string
 * @param toAppendTo where the new date-time text is to be appended
 * @param pos the formatting position. On input: an alignment field,
 * if desired. On output: the offsets of the alignment field.
 * @return the formatted date-time string.
 * @see DateFormat
 * @stable ICU 2.0
 */
@Override
public StringBuffer format(Calendar cal, StringBuffer toAppendTo,
                           FieldPosition pos) {
    TimeZone backupTZ = null;
    if (cal != calendar && !cal.getType().equals(calendar.getType())) {
        // Different calendar type
        // We use the time and time zone from the input calendar, but
        // do not use the input calendar for field calculation.
        calendar.setTimeInMillis(cal.getTimeInMillis());
        backupTZ = calendar.getTimeZone();
        calendar.setTimeZone(cal.getTimeZone());
        cal = calendar;
    }
    StringBuffer result = format(cal, getContext(DisplayContext.Type.CAPITALIZATION), toAppendTo, pos, null);
    if (backupTZ != null) {
        // Restore the original time zone
        calendar.setTimeZone(backupTZ);
    }
    return result;
}
 
Example #8
Source File: JavaTimeZone.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an instance of JavaTimeZone with the given timezone ID.
 * @param id A timezone ID, either a system ID or a custom ID.
 * @return An instance of JavaTimeZone for the given ID, or null
 * when the ID cannot be understood.
 */
public static JavaTimeZone createTimeZone(String id) {
    java.util.TimeZone jtz = null;

    if (AVAILABLESET.contains(id)) {
        jtz = java.util.TimeZone.getTimeZone(id);
    }

    if (jtz == null) {
        // Use ICU's canonical ID mapping
        boolean[] isSystemID = new boolean[1];
        String canonicalID = TimeZone.getCanonicalID(id, isSystemID);
        if (isSystemID[0] && AVAILABLESET.contains(canonicalID)) {
            jtz = java.util.TimeZone.getTimeZone(canonicalID);
        }
    }

    if (jtz == null) {
        return null;
    }

    return new JavaTimeZone(jtz, id);
}
 
Example #9
Source File: DateTimeFormatObject.java    From es6draft with MIT License 6 votes vote down vote up
private DateFormat createDateFormat() {
    ULocale locale = ULocale.forLanguageTag(this.locale);
    // calendar and numberingSystem are already handled in language-tag
    // assert locale.getKeywordValue("calendar").equals(calendar);
    // assert locale.getKeywordValue("numbers").equals(numberingSystem);
    SimpleDateFormat dateFormat = new SimpleDateFormat(pattern.get(), locale);
    if (timeZone != null) {
        dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
    }
    Calendar calendar = dateFormat.getCalendar();
    if (calendar instanceof GregorianCalendar) {
        // format uses a proleptic Gregorian calendar with no year 0
        GregorianCalendar gregorian = (GregorianCalendar) calendar;
        gregorian.setGregorianChange(new Date(Long.MIN_VALUE));
    }
    return dateFormat;
}
 
Example #10
Source File: DateTimeUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @param d
 * @return
 */
private  Calendar getCalendar( Date d )
{
	if ( d == null )
		throw new java.lang.IllegalArgumentException( "date value is null!" );
	Calendar c = Calendar.getInstance( locale );
	if( d instanceof java.sql.Date )
	{
		c.setTimeZone( TimeZone.getDefault( ) );
	}
	else
	{
		c.setTimeZone( timeZone );
	}
	c.setTime( d );
	return c;
}
 
Example #11
Source File: ViewingTest2.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
@After
   public void viewing2TearDown() throws Exception
{
	if( myPreDataEngine != null )
	{
		myPreDataEngine.shutdown( );
		myPreDataEngine.clearCache( dataSource, dataSet );
		myPreDataEngine = null;
	}
	if( myPreDataEngine2 != null )
	{
		myPreDataEngine2.shutdown( );
		myPreDataEngine2.clearCache( dataSource, dataSet );
		myPreDataEngine2 = null;
	}
	TimeZone.setDefault( this.currentTimeZone  );
}
 
Example #12
Source File: OlsonTimeZone.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
@Override
public TimeZone cloneAsThawed() {
    OlsonTimeZone tz = (OlsonTimeZone)super.cloneAsThawed();
    if (finalZone != null) {
        // TODO Do we really need this?
        finalZone.setID(getID());
        tz.finalZone = (SimpleTimeZone) finalZone.clone();
    }

    // Following data are read-only and never changed.
    // Therefore, shallow copies should be sufficient.
    //
    // transitionTimes64
    // typeMapData
    // typeOffsets

    tz.isFrozen = false;
    return tz;
}
 
Example #13
Source File: DataTypeUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Convert a string to a Date instance according to the TimeZone value
 * 
 * @param source
 * @param timeZone
 * @return
 * @throws BirtException
 */
public static Date toDate( String source, TimeZone timeZone ) throws BirtException
{
	assert timeZone != null;
	try
	{
		return toDateISO8601( source, timeZone );
	}
	catch ( BirtException e )
	{
		try
		{
			// format the String for JRE default locale
			return toDate( source, JRE_DEFAULT_LOCALE, timeZone );
		}
		catch ( BirtException use )
		{
			// format the String for Locale.US
			return toDate( source, DEFAULT_LOCALE, timeZone );
		}
	}
}
 
Example #14
Source File: ParameterValidationUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Validates the input value at the given locale. The format is: short date
 * and medium time.
 * 
 * @param value
 *            the value to validate
 * @param locale
 *            the locale information
 * @param timeZone
 *            the time zone information
 * @return the date value if validation is successful
 * @throws ValidationValueException
 *             if the value is invalid
 */

private static final Date doValidateDateTime( String value, ULocale locale,
		TimeZone timeZone ) throws ValidationValueException
{
	try
	{
		return DataTypeUtil.toDate( value, locale, timeZone );
	}
	catch ( BirtException e )
	{
		throw new ValidationValueException( value,
				PropertyValueException.DESIGN_EXCEPTION_INVALID_VALUE,
				DesignChoiceConstants.PARAM_TYPE_DATETIME );
	}
}
 
Example #15
Source File: TimeZoneGenericNames.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the display name of the time zone for the given name type
 * at the given date, or null if the display name is not available.
 *
 * @param tz the time zone
 * @param type the generic name type - see {@link GenericNameType}
 * @param date the date
 * @return the display name of the time zone for the given name type
 * at the given date, or null.
 */
public String getDisplayName(TimeZone tz, GenericNameType type, long date) {
    String name = null;
    String tzCanonicalID = null;
    switch (type) {
    case LOCATION:
        tzCanonicalID = ZoneMeta.getCanonicalCLDRID(tz);
        if (tzCanonicalID != null) {
            name = getGenericLocationName(tzCanonicalID);
        }
        break;
    case LONG:
    case SHORT:
        name = formatGenericNonLocationName(tz, type, date);
        if (name == null) {
            tzCanonicalID = ZoneMeta.getCanonicalCLDRID(tz);
            if (tzCanonicalID != null) {
                name = getGenericLocationName(tzCanonicalID);
            }
        }
        break;
    }
    return name;
}
 
Example #16
Source File: DateFormatterTest.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void testDateFormatterExtraction( ) throws Exception
{
	dataExTask.selectResultSet( "ELEMENT_69" );
	String[] columnNames = new String[]{
			"CUSTOMERNUMBER", "CHECKNUMBER", "PAYMENTDATE", "now", "now"
	};
	dataExTask.setTimeZone( TimeZone.getTimeZone( "GMT+8" ) );
	dataExTask.selectColumns( columnNames );
	dataExTask.setLocale( ULocale.CHINESE );
	ByteArrayOutputStream out = new ByteArrayOutputStream( );
	CSVDataExtractionOption option = new CSVDataExtractionOption( );
	option.setTimeZone( java.util.TimeZone.getTimeZone( "GMT+5" ) );
	option.setLocale( Locale.ENGLISH );
	option.setOutputFormat( "csv" );
	option.setOutputStream( out );
	Map<Object, String> formatters = new HashMap<Object, String>( );
	formatters.put( 1, "Fixed" );
	formatters.put( 2, "<" );
	formatters.put( 3, "yyyy-MM-dd" );
	formatters.put( "now", "yyyy-MM-dd HH:mm:ss.sss ZZZ" );
	formatters.put( 5, "Long Date" );
	option.setFormatter( formatters );
	dataExTask.extract( option );
	String result = new String( out.toByteArray( ) );
	System.out.println( result );
}
 
Example #17
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 #18
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 #19
Source File: DataSetIterator.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
DateTimeAttributeProcessor( String timeType, ULocale locale, TimeZone zone )
{
	this.timeType = timeType;
	this.calendar = Calendar.getInstance( locale );
	if( zone!= null )
		this.calendar.setTimeZone( zone );
}
 
Example #20
Source File: ZoneMeta.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an immutable set of canonical system time zone IDs that
 * are associated with actual locations.
 * The result set is a subset of {@link #getCanonicalSystemZIDs()}, but not
 * including IDs, such as "Etc/GTM+5".
 * @return An immutable set of canonical system time zone IDs that
 * are associated with actual locations.
 */
private static synchronized Set<String> getCanonicalSystemLocationZIDs() {
    Set<String> canonicalSystemLocationZones = null;
    if (REF_CANONICAL_SYSTEM_LOCATION_ZONES != null) {
        canonicalSystemLocationZones = REF_CANONICAL_SYSTEM_LOCATION_ZONES.get();
    }
    if (canonicalSystemLocationZones == null) {
        Set<String> canonicalSystemLocationIDs = new TreeSet<String>();
        String[] allIDs = getZoneIDs();
        for (String id : allIDs) {
            // exclude Etc/Unknown
            if (id.equals(TimeZone.UNKNOWN_ZONE_ID)) {
                continue;
            }
            String canonicalID = getCanonicalCLDRID(id);
            if (id.equals(canonicalID)) {
                String region = getRegion(id);
                if (region != null && !region.equals(kWorld)) {
                    canonicalSystemLocationIDs.add(id);
                }
            }
        }
        canonicalSystemLocationZones = Collections.unmodifiableSet(canonicalSystemLocationIDs);
        REF_CANONICAL_SYSTEM_LOCATION_ZONES = new SoftReference<Set<String>>(canonicalSystemLocationZones);
    }
    return canonicalSystemLocationZones;
}
 
Example #21
Source File: OdsUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Excel 2007 using 1900 date base system.Date time is combined by date component and time component.
 * In the 1900 date base system, the lower limit of day component is January 1, 1900, which has serial value 1. 
 * The upper-limit is December 31, 9999, which has serial value 2,958,465.
 * The time component of a serial value ranges in value from 0–0.99999999, and represents times from 0:00:00 (12:00:00 AM) 
 * to 23:59:59 (11:59:59 P.M.), respectively.
 * Going forward in time, the time component of a serial value increases by 1/86,400 each second.
 * @param d
 * @param zone
 * @return
 */
public static String getDay( Date d, TimeZone zone )
{
	Calendar currentDay = Calendar.getInstance( zone );
	currentDay.setTime( d );
	int hours = currentDay.get(Calendar.HOUR_OF_DAY);
	int minutes = currentDay.get(Calendar.MINUTE);
	int seconds = currentDay.get(Calendar.SECOND);
	double timeComponent = ( hours * SECONDS_PER_HOUR + minutes
			* SECONDS_PER_MINUTE + seconds )
			/ SECONDS_PER_DAY;
	if ( timeComponent < 0 || timeComponent > 1 )
	{
		logger.log( Level.WARNING, "Invalid time!" );
		timeComponent = 0;
	}
	long currentTimeInMillis = currentDay.getTimeInMillis( );
	int dayComponent = (int) ( ( currentTimeInMillis - BASE_DATE_TIME ) / MILLISECS_PER_DAY );
	if ( dayComponent < 0 || dayComponent > 2958463 )
	{
		logger.log( Level.WARNING, "Invaild day" );
		dayComponent = 0;
	}
	if ( dayComponent <= 59 )
		dayComponent = dayComponent + 1;
	else
		dayComponent = dayComponent + 2;
	double dateTime = dayComponent + timeComponent;
	return Double.toString( dateTime );
}
 
Example #22
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 #23
Source File: RelativeDateFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * initializes fCalendar from parameters.  Returns fCalendar as a convenience.
 * @param zone  Zone to be adopted, or NULL for TimeZone::createDefault().
 * @param locale Locale of the calendar
 * @param status Error code
 * @return the newly constructed fCalendar
 */
private Calendar initializeCalendar(TimeZone zone, ULocale locale) {
    if (calendar == null) {
        if(zone == null) {
            calendar = Calendar.getInstance(locale);
        } else {
            calendar = Calendar.getInstance(zone, locale);
        }
    }
    return calendar;
}
 
Example #24
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 #25
Source File: TimeZoneFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Private method returning the time zone's specific format string.
 *
 * @param tz the time zone
 * @param stdType the name type used for standard time
 * @param dstType the name type used for daylight time
 * @param date the date
 * @param timeType when null, actual time type is set
 * @return the time zone's specific format name string
 */
private String formatSpecific(TimeZone tz, NameType stdType, NameType dstType, long date, Output<TimeType> timeType) {
    assert(stdType == NameType.LONG_STANDARD || stdType == NameType.SHORT_STANDARD);
    assert(dstType == NameType.LONG_DAYLIGHT || dstType == NameType.SHORT_DAYLIGHT);

    boolean isDaylight = tz.inDaylightTime(new Date(date));
    String name = isDaylight?
            getTimeZoneNames().getDisplayName(ZoneMeta.getCanonicalCLDRID(tz), dstType, date) :
            getTimeZoneNames().getDisplayName(ZoneMeta.getCanonicalCLDRID(tz), stdType, date);

    if (name != null && timeType != null) {
        timeType.value = isDaylight ? TimeType.DAYLIGHT : TimeType.STANDARD;
    }
    return name;
}
 
Example #26
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 #27
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 #28
Source File: ColumnBindingTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 */
@Before
   public void columnBindingSetUp() throws Exception
{

	
	TimeZone.setDefault( TimeZone.getTimeZone("GMT+0")  );
}
 
Example #29
Source File: DateFormatter.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public DateFormatter( String pattern, ULocale localeLoc, TimeZone timeZone )
{
	if ( localeLoc != null )
		locale = localeLoc;
	if ( timeZone != null )
		this.timeZone = timeZone;
	applyPattern( pattern );
}
 
Example #30
Source File: ParameterValidationUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Validates the input date time string with the given format. The format
 * can be pre-defined choices or the pattern string.
 * 
 * @param format
 *            the format to validate
 * @param value
 *            the value to validate
 * @param locale
 *            the locale information
 * @param timeZone
 *            the time zone information
 * @return the date value if validation is successful
 * @throws ValidationValueException
 *             if the value to validate is invalid
 */

static private Date doValidateDateTimeByPattern( String format,
		String value, ULocale locale, TimeZone timeZone )
		throws ValidationValueException
{
	assert !StringUtil.isBlank( format );
	if ( StringUtil.isBlank( value ) )
		return null;

	try
	{
		DateFormatter formatter = null;
		if ( timeZone != null )
		{
			formatter = new DateFormatter( locale, timeZone );
		}
		else
		{
			formatter = new DateFormatter( locale );
		}
		formatter.applyPattern( format );
		return formatter.parse( value );
	}
	catch ( ParseException e )
	{
		throw new ValidationValueException( value,
				PropertyValueException.DESIGN_EXCEPTION_INVALID_VALUE,
				DesignChoiceConstants.PARAM_TYPE_DATETIME );
	}
}