Java Code Examples for com.ibm.icu.util.Calendar#clear()
The following examples show how to use
com.ibm.icu.util.Calendar#clear() .
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: DateGroupCalculator.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * * @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 2
Source File: TimeMemberUtil.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * * @param d * @return */ private static Calendar getCalendar( Date d ) { Calendar c = Calendar.getInstance( timeZone, defaultLocale ); if ( d == null ) { c.clear( ); c.set( 1970, 0, 1 ); } else { c.setTime( d ); } return c; }
Example 3
Source File: BirtDateTime.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * * @param d * @return */ private static Calendar getCalendar( Date d ) { Calendar c = null; if ( d instanceof java.sql.Date ) { c = Calendar.getInstance( TimeZone.getDefault( ), threadLocale.get( ) ); } else { c = Calendar.getInstance( threadTimeZone.get( ), threadLocale.get( ) ); } if ( d == null ) { c.clear( ); c.set( 1970, 0, 1 ); } else { c.setTime( d ); } return c; }
Example 4
Source File: DataTypeUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * * @param date * @return */ private static java.sql.Time toSqlTime( Date date ) { Calendar calendar = Calendar.getInstance( ); calendar.clear( ); calendar.setTimeInMillis( date.getTime( ) ); calendar.set( Calendar.YEAR, 1970 ); calendar.set( Calendar.MONTH, 0 ); calendar.set( Calendar.DAY_OF_MONTH, 1 ); return new java.sql.Time( calendar.getTimeInMillis( ) ); }
Example 5
Source File: PreviousNPeriodsFunction.java From birt with Eclipse Public License 1.0 | 5 votes |
public TimeMember getResult( TimeMember member ) { String[] levels = member.getLevelType( ); int[] values = member.getMemberValue( ); Calendar cal = new GregorianCalendar( TimeMemberUtil.getTimeZone( ), TimeMemberUtil.getDefaultLocale( ) ); cal.clear( ); translateToCal( cal, levels, values ); if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_YEAR ) ) cal.add( Calendar.YEAR, offset ); else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_QUARTER ) ) cal.add( Calendar.MONTH, offset * 3 ); else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_MONTH ) ) cal.add( Calendar.MONTH, offset ); else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH ) ) cal.add( Calendar.WEEK_OF_MONTH, offset ); else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR ) ) cal.add( Calendar.WEEK_OF_YEAR, offset ); else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH ) ) cal.add( Calendar.DAY_OF_MONTH, offset ); else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR ) ) cal.add( Calendar.DAY_OF_YEAR, offset ); else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK ) ) cal.add( Calendar.DAY_OF_WEEK, offset ); int[] newValues = getValueFromCal( cal, levels ); TimeMember newMember = new TimeMember( newValues, levels ); return newMember; }
Example 6
Source File: TimeFunctionManager.java From birt with Eclipse Public License 1.0 | 5 votes |
private static String getFormattedDateStringFromTimeMember( TimeMember member, ULocale locale ) throws BirtException { Calendar calendar = Calendar.getInstance( locale ); calendar.clear( ); calendar.set( Calendar.YEAR, member.getMemberValue( )[0] ); calendar.set( Calendar.MONTH, member.getMemberValue( )[1]-1 ); calendar.set( Calendar.DAY_OF_MONTH, member.getMemberValue( )[2] ); java.sql.Date date = (java.sql.Date) DataTypeUtil.toSqlDate( calendar.getTime( ) ); DateFormatter formatter = new DateFormatter(locale); return formatter.format( date ); }
Example 7
Source File: DataTypeUtilTest.java From birt with Eclipse Public License 1.0 | 5 votes |
@Test public void testToDate2( ) { String[] dateStrings = { "Jan 11, 2002", "Jan 11, 2002", "Feb 12, 1981 6:17 AM" }; String[] timeZoneIDs = { "GMT+00:00", "GMT-02:00", "GMT+03:00" }; Calendar calendar = Calendar.getInstance( ); calendar.setTimeZone( TimeZone.getTimeZone( "GMT+00:00" ) ); Date[] resultDates = new Date[3]; calendar.clear( ); calendar.set(2002,0,11,0,0,0); resultDates[0] = calendar.getTime( ); calendar.clear( ); calendar.set(2002,0,11,2,0,0); resultDates[1] = calendar.getTime( ); calendar.clear( ); calendar.set(1981,1,12,3,17,0 ); resultDates[2] = calendar.getTime( ); for ( int i = 0; i < dateStrings.length; i++ ) { try { Date dateResult = DataTypeUtil.toDate( dateStrings[i], ULocale.US, TimeZone.getTimeZone( timeZoneIDs[i] ) ); assertEquals( dateResult, resultDates[i] ); } catch ( BirtException e ) { fail( "Should not throw Exception." ); } } }
Example 8
Source File: DataTypeUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * * @param hour * @param minute * @param second * @return */ private static Time toSqlTime( int hour, int minute, int second ) { Calendar calendar = Calendar.getInstance( ); calendar.clear( ); calendar.set( Calendar.HOUR_OF_DAY, hour ); calendar.set( Calendar.MINUTE, minute ); calendar.set( Calendar.SECOND, second ); return new java.sql.Time( calendar.getTimeInMillis( ) ); }
Example 9
Source File: SecuredHierarchy.java From birt with Eclipse Public License 1.0 | 5 votes |
public SecuredHierarchy( IDocumentManager documentManager, String dimensionName, String hierarchyName, Set<String> notAccessibleLevels ) { super( documentManager, dimensionName, hierarchyName ); this.notAccessibleLevels = notAccessibleLevels; Calendar calendar = Calendar.getInstance( ); calendar.clear( ); calendar.set( 0, 0, 1, 0, 0, 0 ); this.nullTime = calendar.getTimeInMillis( ); }
Example 10
Source File: DataTypeUtilTest.java From birt with Eclipse Public License 1.0 | 5 votes |
private Time getTime( int hour, int minute, int second, int millis ) { Calendar calendar = Calendar.getInstance( ); calendar.clear( ); calendar.set( Calendar.HOUR_OF_DAY, hour ); calendar.set( Calendar.MINUTE, minute ); calendar.set( Calendar.SECOND, second ); return new java.sql.Time( calendar.getTimeInMillis( ) ); }
Example 11
Source File: BirtDateTime.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Returns a timestamp value which is midnight of the current date. * * @return */ private static Date today( ) { Calendar calendar = Calendar.getInstance( threadTimeZone.get( ) ); calendar.set( Calendar.HOUR_OF_DAY, 0 ); calendar.clear( Calendar.MINUTE ); calendar.clear( Calendar.SECOND ); calendar.clear( Calendar.MILLISECOND ); return calendar.getTime( ); }
Example 12
Source File: DateUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * * @param date * @return */ private static java.sql.Date toSqlDate( Date date ) { Calendar calendar = Calendar.getInstance( ); calendar.clear( ); calendar.setTimeInMillis( date.getTime( ) ); calendar.set( Calendar.HOUR_OF_DAY, 0 ); calendar.set( Calendar.MINUTE, 0 ); calendar.set( Calendar.SECOND, 0 ); calendar.set( Calendar.MILLISECOND, 0 ); return new java.sql.Date( calendar.getTimeInMillis( ) ); }
Example 13
Source File: DateUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * * @param hour * @param minute * @param second * @return */ private static Time toSqlTime( int hour, int minute, int second ) { Calendar calendar = Calendar.getInstance( ); calendar.clear( ); calendar.set( Calendar.HOUR_OF_DAY, hour ); calendar.set( Calendar.MINUTE, minute ); calendar.set( Calendar.SECOND, second ); return new java.sql.Time( calendar.getTimeInMillis( ) ); }
Example 14
Source File: DateUtil.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * * @param date * @return */ private static java.sql.Time toSqlTime( Date date ) { Calendar calendar = Calendar.getInstance( ); calendar.clear( ); calendar.setTimeInMillis( date.getTime( ) ); calendar.set( Calendar.YEAR, 1970 ); calendar.set( Calendar.MONTH, 0 ); calendar.set( Calendar.DAY_OF_MONTH, 1 ); calendar.set( Calendar.MILLISECOND, 0 ); return new java.sql.Time( calendar.getTimeInMillis( ) ); }
Example 15
Source File: FormatterImpl.java From org.openntf.domino with Apache License 2.0 | 4 votes |
public Calendar parseDateToCalWithFormat(final String image, final String format, final boolean[] noDT, final boolean parseLenient) { Calendar ret = getInstance(iLocale); ret.setLenient(false); ParsePosition p = new ParsePosition(0); ret.clear(); SimpleDateFormat sdf = new SimpleDateFormat(format, iLocale); sdf.parse(image, ret, p); boolean contDate = ret.isSet(YEAR) || ret.isSet(MONTH) || ret.isSet(DAY_OF_MONTH); boolean contTime = ret.isSet(HOUR_OF_DAY) || ret.isSet(HOUR) || ret.isSet(MINUTE) || ret.isSet(SECOND); boolean illegalDateString = !contDate && !contTime; if (!illegalDateString && !parseLenient) { int lh = image.length(); int errInd = p.getErrorIndex(); illegalDateString = (errInd < 0 && p.getIndex() < lh) || (errInd >= 0 && errInd < lh); } if (illegalDateString) throw new IllegalArgumentException("Illegal date string '" + image + "' for format '" + format + "'"); // System.out.println("Y=" + ret.isSet(YEAR) + " M=" + ret.isSet(MONTH) + " D=" + ret.isSet(DAY_OF_MONTH) // + " H=" + ret.isSet(HOUR_OF_DAY) + "m=" + ret.isSet(MINUTE) + " S=" + ret.isSet(SECOND)); if (!ret.isSet(YEAR)) ret.set(YEAR, 1970); if (!ret.isSet(MONTH)) ret.set(MONTH, 0); if (!ret.isSet(DAY_OF_MONTH)) ret.set(DAY_OF_MONTH, 1); if (!ret.isSet(HOUR_OF_DAY) && !ret.isSet(HOUR)) ret.set(HOUR_OF_DAY, 0); if (!ret.isSet(MINUTE)) ret.set(MINUTE, 0); if (!ret.isSet(SECOND)) ret.set(SECOND, 0); try { ret.getTime(); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Parsing '" + image + "' against '" + format + "' gives Calendar exception: " + e.getMessage()); } noDT[0] = !contDate; noDT[1] = !contTime; return ret; }
Example 16
Source File: AggregationTest.java From birt with Eclipse Public License 1.0 | 4 votes |
@Test public void test4( ) throws Exception { QueryDefinition query = newReportQuery( ); Calendar c = Calendar.getInstance( ); c.clear( ); // 3 grouping levels: CITY, STORE, SALE_DATE(by month) GroupDefinition g1 = new GroupDefinition( "G1" ); g1.setKeyExpression( "row.e1" ); query.addGroup( g1 ); GroupDefinition g2 = new GroupDefinition( "G2" ); g2.setKeyExpression( "row.e2" ); query.addGroup( g2 ); GroupDefinition g3 = new GroupDefinition( "G3" ); g3.setKeyExpression( "row.e3" ); g3.setInterval( GroupDefinition.MONTH_INTERVAL ); g3.setIntervalRange( 1 ); c.set( 2004, 9, 1 ); g3.setIntervalStart( c.getTime( ) ); query.addGroup( g3 ); SortDefinition sort = new SortDefinition( ); sort.setExpression( "row.e3" ); sort.setSortDirection( ISortDefinition.SORT_ASC ); query.addSort( sort ); query.addBinding( new Binding( "e1", new ScriptExpression( "dataSetRow.CITY" ) ) ); query.addBinding( new Binding( "e2", new ScriptExpression( "dataSetRow.STORE" ) ) ); query.addBinding( new Binding( "e3", new ScriptExpression( "dataSetRow.SALE_DATE" ) ) ); query.addBinding( new Binding( "e4", new ScriptExpression( "dataSetRow.SKU" ) ) ); query.addBinding( new Binding( "e10", new ScriptExpression( "dataSetRow.PRICE" ) ) ); query.addBinding( new Binding( "e11", new ScriptExpression( "dataSetRow.QUANTITY" ) ) ); // Aggregate: count at city level IBinding e5 = new Binding( "e5" ); e5.setAggrFunction( "COUNT" ); e5.addAggregateOn( "G1" ); query.addBinding( e5 ); // Aggregate: count at city level but added to Store group IBinding e6 = new Binding( "e6"); e6.setAggrFunction( "COUNT" ); e6.addAggregateOn( "G1" ); query.addBinding( e6 ); // Aggregate: day total sales IBinding e7 = new Binding( "e7", new ScriptExpression("dataSetRow.PRICE*dataSetRow.QUANTITY")); e7.setAggrFunction( "SUM" ); e7.addAggregateOn( "G3" ); query.addBinding( e7 ); FilterDefinition f1 = new FilterDefinition( new ConditionalExpression( "row[\"e7\"]" , IConditionalExpression.OP_TOP_N, "1" ), false ); query.addFilter( f1 ); FilterDefinition f2 = new FilterDefinition( new ScriptExpression( "row[\"e10\"] < 200" ) ); query.addFilter( f2 ); IBinding e81 = new Binding( "e81", new ScriptExpression("dataSetRow.PRICE*dataSetRow.QUANTITY")); e81.setAggrFunction( "SUM" ); query.addBinding( e81 ); // Aggregate: Percent of grand total IBinding e8 = new Binding( "e8", new ScriptExpression( "dataSetRow.PRICE * dataSetRow.QUANTITY / row.e81" )); query.addBinding( e8 ); // Aggregate: a moving ave with a filtering condition IBinding e9 = new Binding( "e9", new ScriptExpression( "dataSetRow.PRICE")); e9.setAggrFunction( "MOVINGAVE" ); e9.setFilter( new ScriptExpression ("dataSetRow.QUANTITY>1") ); e9.addArgument( new ScriptExpression( "3") ); query.addBinding( e9 ); String[] exprs = new String[]{ "e1", "e2", "e3", "e4", "e10", "e11", "e5", "e6", "e7", "e8", "e9" }; outputQueryResult( executeQuery( query ), exprs ); checkOutputFile(); }
Example 17
Source File: AggregationTest.java From birt with Eclipse Public License 1.0 | 4 votes |
@Test public void test7( ) throws Exception { QueryDefinition query = newReportQuery( ); Calendar c = Calendar.getInstance( ); c.clear( ); // 3 grouping levels: CITY, STORE, SALE_DATE(by month) GroupDefinition g1 = new GroupDefinition( "G1" ); g1.setKeyExpression( "row.e1" ); query.addGroup( g1 ); GroupDefinition g2 = new GroupDefinition( "G2" ); g2.setKeyExpression( "row.e2" ); query.addGroup( g2 ); GroupDefinition g3 = new GroupDefinition( "G3" ); g3.setKeyExpression( "row.e3" ); g3.setInterval( GroupDefinition.MONTH_INTERVAL ); g3.setIntervalRange( 1 ); c.set( 2004, 9, 1 ); g3.setIntervalStart( c.getTime( ) ); query.addGroup( g3 ); SortDefinition sort = new SortDefinition( ); sort.setExpression( "row.e3" ); sort.setSortDirection( ISortDefinition.SORT_ASC ); query.addSort( sort ); query.addBinding( new Binding( "e1", new ScriptExpression( "dataSetRow.CITY" ) ) ); query.addBinding( new Binding( "e2", new ScriptExpression( "dataSetRow.STORE" ) ) ); query.addBinding( new Binding( "e3", new ScriptExpression( "dataSetRow.SALE_DATE" ) ) ); query.addBinding( new Binding( "e4", new ScriptExpression( "dataSetRow.SKU" ) ) ); query.addBinding( new Binding( "e10", new ScriptExpression( "dataSetRow.PRICE" ) ) ); query.addBinding( new Binding( "e11", new ScriptExpression( "dataSetRow.QUANTITY" ) ) ); // Aggregate: count at city level IBinding e5 = new Binding( "e5" ); e5.setAggrFunction( "COUNT" ); e5.addAggregateOn( "G1" ); query.addBinding( e5 ); // Aggregate: count at city level but added to Store group IBinding e6 = new Binding( "e6"); e6.setAggrFunction( "COUNT" ); e6.addAggregateOn( "G1" ); query.addBinding( e6 ); // Aggregate: day total sales IBinding e7 = new Binding( "e7", new ScriptExpression("dataSetRow.PRICE*dataSetRow.QUANTITY")); e7.setAggrFunction( "SUM" ); e7.addAggregateOn( "G3" ); query.addBinding( e7 ); FilterDefinition f1 = new FilterDefinition( new ConditionalExpression( "row[\"e7\"]" , IConditionalExpression.OP_TOP_N, "1" ) ); query.addFilter( f1 ); FilterDefinition f2 = new FilterDefinition( new ScriptExpression( "row[\"e10\"] < 200" ), false ); query.addFilter( f2 ); IBinding e81 = new Binding( "e81", new ScriptExpression("dataSetRow.PRICE*dataSetRow.QUANTITY")); e81.setAggrFunction( "SUM" ); query.addBinding( e81 ); // Aggregate: Percent of grand total IBinding e8 = new Binding( "e8", new ScriptExpression( "dataSetRow.PRICE * dataSetRow.QUANTITY / row.e81" )); query.addBinding( e8 ); // Aggregate: a moving ave with a filtering condition IBinding e9 = new Binding( "e9", new ScriptExpression( "dataSetRow.PRICE")); e9.setAggrFunction( "MOVINGAVE" ); e9.setFilter( new ScriptExpression ("dataSetRow.QUANTITY>1") ); e9.addArgument( new ScriptExpression( "3") ); query.addBinding( e9 ); String[] exprs = new String[]{ "e1", "e2", "e3", "e4", "e10", "e11", "e5", "e6", "e7", "e8", "e9" }; outputQueryResult( executeQuery( query ), exprs ); checkOutputFile(); }
Example 18
Source File: AggregationTest.java From birt with Eclipse Public License 1.0 | 4 votes |
@Test public void test2( ) throws Exception { QueryDefinition query = newReportQuery( ); Calendar c = Calendar.getInstance( ); c.clear( ); // 3 grouping levels: CITY, STORE, SALE_DATE(by month) GroupDefinition g1 = new GroupDefinition( "G1" ); g1.setKeyExpression( "row.e1" ); query.addGroup( g1 ); GroupDefinition g2 = new GroupDefinition( "G2" ); g2.setKeyExpression( "row.e2" ); query.addGroup( g2 ); GroupDefinition g3 = new GroupDefinition( "G3" ); g3.setKeyExpression( "row.e3" ); g3.setInterval( GroupDefinition.MONTH_INTERVAL ); g3.setIntervalRange( 1 ); c.set( 2004, 9, 1 ); g3.setIntervalStart( c.getTime( ) ); query.addGroup( g3 ); SortDefinition sort = new SortDefinition( ); sort.setExpression( "row.e3" ); sort.setSortDirection( ISortDefinition.SORT_ASC ); query.addSort( sort ); query.addBinding( new Binding( "e1", new ScriptExpression( "dataSetRow.CITY" ) ) ); query.addBinding( new Binding( "e2", new ScriptExpression( "dataSetRow.STORE" ) ) ); query.addBinding( new Binding( "e3", new ScriptExpression( "dataSetRow.SALE_DATE" ) ) ); query.addBinding( new Binding( "e4", new ScriptExpression( "dataSetRow.SKU" ) ) ); query.addBinding( new Binding( "e10", new ScriptExpression( "dataSetRow.PRICE" ) ) ); query.addBinding( new Binding( "e11", new ScriptExpression( "dataSetRow.QUANTITY" ) ) ); // Aggregate: count at city level IBinding e5 = new Binding( "e5" ); e5.setAggrFunction( "COUNT" ); e5.addAggregateOn( "G1" ); query.addBinding( e5 ); // Aggregate: count at city level but added to Store group IBinding e6 = new Binding( "e6"); e6.setAggrFunction( "COUNT" ); e6.addAggregateOn( "G1" ); query.addBinding( e6 ); // Aggregate: day total sales IBinding e7 = new Binding( "e7", new ScriptExpression("dataSetRow.PRICE*dataSetRow.QUANTITY")); e7.setAggrFunction( "SUM" ); e7.addAggregateOn( "G3" ); query.addBinding( e7 ); FilterDefinition f1 = new FilterDefinition( new ConditionalExpression( "row[\"e7\"]" , IConditionalExpression.OP_TOP_N, "2" ) ); query.addFilter( f1 ); IBinding e81 = new Binding( "e81", new ScriptExpression("dataSetRow.PRICE*dataSetRow.QUANTITY")); e81.setAggrFunction( "SUM" ); query.addBinding( e81 ); // Aggregate: Percent of grand total IBinding e8 = new Binding( "e8", new ScriptExpression( "dataSetRow.PRICE * dataSetRow.QUANTITY / row.e81" )); query.addBinding( e8 ); // Aggregate: a moving ave with a filtering condition IBinding e9 = new Binding( "e9", new ScriptExpression( "dataSetRow.PRICE")); e9.setAggrFunction( "MOVINGAVE" ); e9.setFilter( new ScriptExpression ("dataSetRow.QUANTITY>1") ); e9.addArgument( new ScriptExpression( "3") ); query.addBinding( e9 ); String[] exprs = new String[]{ "e1", "e2", "e3", "e4", "e10", "e11", "e5", "e6", "e7", "e8", "e9" }; outputQueryResult( executeQuery( query ), exprs ); checkOutputFile(); }
Example 19
Source File: WeekToDateFunciton.java From birt with Eclipse Public License 1.0 | 4 votes |
public List<TimeMember> getResult( TimeMember member ) { List timeMembers = new ArrayList<TimeMember>( ); String[] levelTypes = member.getLevelType( ); int[] values = member.getMemberValue( ); Calendar cal = new GregorianCalendar( TimeMemberUtil.getTimeZone( ), TimeMemberUtil.getDefaultLocale( ) ); cal.clear( ); String baseType = translateToCal( cal, levelTypes, values ); if ( isCurrent ) { int weekDay = cal.get( Calendar.DAY_OF_WEEK ); while ( weekDay < 7 ) { cal.add( Calendar.DAY_OF_YEAR, 1 ); weekDay = cal.get( Calendar.DAY_OF_WEEK ); } } if ( baseType.equals( WEEK ) ) { timeMembers.add( member ); } else if ( baseType.equals( DAY ) ) { int weekday = cal.get( Calendar.DAY_OF_WEEK ); int[] tmp; Calendar newCal = new GregorianCalendar( TimeMemberUtil.getTimeZone( ), TimeMemberUtil.getDefaultLocale( ) ); for ( int i = 1; i <= weekday; i++ ) { newCal.setTimeInMillis( cal.getTimeInMillis( ) - ( weekday - i ) * dayTimeInMills ); tmp = getValueFromCal( newCal, levelTypes ); TimeMember timeMember = new TimeMember( tmp, levelTypes ); timeMembers.add( timeMember ); } } return timeMembers; }
Example 20
Source File: MonthToDateFunction.java From birt with Eclipse Public License 1.0 | 4 votes |
public List<TimeMember> getResult( TimeMember member ) { List timeMembers = new ArrayList<TimeMember>( ); String[] levelTypes = member.getLevelType( ); int[] values = member.getMemberValue( ); Calendar cal = new GregorianCalendar( TimeMemberUtil.getTimeZone( ), TimeMemberUtil.getDefaultLocale( ) ); cal.clear( ); String baseType = translateToCal( cal, levelTypes, values ); if ( isCurrent ) { int month = cal.get( Calendar.MONTH ); while ( true ) { if ( cal.get( Calendar.MONTH ) != month ) { cal.add( Calendar.DAY_OF_YEAR, -1 ); break; } cal.add( Calendar.DAY_OF_YEAR, 1 ); } } int[] tmp; if ( baseType.equals( MONTH ) ) { timeMembers.add( member ); } else if ( baseType.equals( WEEK ) ) { retrieveWeek( timeMembers, cal, levelTypes, "monthToDate" ); } else if ( baseType.equals( DAY ) ) { int dayOfMonth = cal.get( Calendar.DAY_OF_MONTH ); for ( int i = 1; i <= dayOfMonth; i++ ) { cal.set( Calendar.DAY_OF_MONTH, i ); tmp = getValueFromCal( cal, levelTypes ); TimeMember timeMember = new TimeMember( tmp, levelTypes ); timeMembers.add( timeMember ); } } return timeMembers; }