Java Code Examples for com.ibm.icu.util.Calendar#YEAR

The following examples show how to use com.ibm.icu.util.Calendar#YEAR . 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: TemporalExpressions.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
/**
 * @param start Starting date, defaults to current system time
 * @param freqType One of the following integer values: <code>Calendar.SECOND
 * Calendar.MINUTE Calendar.HOUR Calendar.DAY_OF_MONTH Calendar.MONTH
 * Calendar.YEAR</code>
 * @param freqCount A positive integer
 */
public Frequency(Date start, int freqType, int freqCount) {
    if (freqType != Calendar.SECOND && freqType != Calendar.MINUTE
            && freqType != Calendar.HOUR && freqType != Calendar.DAY_OF_MONTH
            && freqType != Calendar.MONTH && freqType != Calendar.YEAR) {
        throw new IllegalArgumentException("Invalid freqType argument");
    }
    if (freqCount < 1) {
        throw new IllegalArgumentException("freqCount argument must be a positive integer");
    }
    if (start != null) {
        this.start = (Date) start.clone();
    } else {
        this.start = new Date();
    }
    this.sequence = SEQUENCE_FREQ + freqType;
    this.freqType = freqType;
    this.freqCount = freqCount;
    if (Debug.verboseOn()) {
        Debug.logVerbose("Created " + this, module);
    }
}
 
Example 2
Source File: ChartUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Convers Scale unit type to ICU Calendar constant.
 * 
 * @param unitType
 *            Scale unit type
 * @return Calendar constant or -1 if not found
 */
public static int convertUnitTypeToCalendarConstant( ScaleUnitType unitType )
{
	switch ( unitType.getValue( ) )
	{
		case ScaleUnitType.DAYS :
			return Calendar.DATE;
		case ScaleUnitType.HOURS :
			return Calendar.HOUR_OF_DAY;
		case ScaleUnitType.MINUTES :
			return Calendar.MINUTE;
		case ScaleUnitType.MONTHS :
			return Calendar.MONTH;
		case ScaleUnitType.SECONDS :
			return Calendar.SECOND;
		case ScaleUnitType.WEEKS :
			return Calendar.WEEK_OF_YEAR;
		case ScaleUnitType.YEARS :
			return Calendar.YEAR;
		case ScaleUnitType.QUARTERS :
			return CDateTime.QUARTER;
	}
	return -1;
}
 
Example 3
Source File: DateIntervalFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * @internal
 * @deprecated This API is ICU internal only.
 */
@Deprecated
public String getPatterns(Calendar fromCalendar,
        Calendar toCalendar, 
        Output<String> part2) {
    // First, find the largest different calendar field.
    int field;
    if ( fromCalendar.get(Calendar.ERA) != toCalendar.get(Calendar.ERA) ) {
        field = Calendar.ERA;
    } else if ( fromCalendar.get(Calendar.YEAR) != 
                toCalendar.get(Calendar.YEAR) ) {
        field = Calendar.YEAR;
    } else if ( fromCalendar.get(Calendar.MONTH) !=
                toCalendar.get(Calendar.MONTH) ) {
        field = Calendar.MONTH;
    } else if ( fromCalendar.get(Calendar.DATE) !=
                toCalendar.get(Calendar.DATE) ) {
        field = Calendar.DATE;
    } else if ( fromCalendar.get(Calendar.AM_PM) !=
                toCalendar.get(Calendar.AM_PM) ) {
        field = Calendar.AM_PM;
    } else if ( fromCalendar.get(Calendar.HOUR) !=
                toCalendar.get(Calendar.HOUR) ) {
        field = Calendar.HOUR;
    } else if ( fromCalendar.get(Calendar.MINUTE) !=
                toCalendar.get(Calendar.MINUTE) ) {
        field = Calendar.MINUTE;
    } else if ( fromCalendar.get(Calendar.SECOND) !=
                toCalendar.get(Calendar.SECOND) ) {
        field = Calendar.SECOND;
    } else {
        return null;
    }
    PatternInfo intervalPattern = fIntervalPatterns.get(
            DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field]);
    part2.value = intervalPattern.getSecondPart();
    return intervalPattern.getFirstPart();
}
 
Example 4
Source File: ICalRecurConverter.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(TemporalExpressions.Frequency expr) {
    if (this.dateStart == null) {
        this.dateStart = new DtStart(new net.fortuna.ical4j.model.Date(expr.getStartDate()));
    }
    int freqCount = expr.getFreqCount();
    int freqType = expr.getFreqType();
    switch (freqType) {
    case Calendar.SECOND:
        this.state.addRecur((new Recur(Recur.SECONDLY, freqCount)));
        break;
    case Calendar.MINUTE:
        this.state.addRecur((new Recur(Recur.MINUTELY, freqCount)));
        break;
    case Calendar.HOUR:
        this.state.addRecur((new Recur(Recur.HOURLY, freqCount)));
        break;
    case Calendar.DAY_OF_MONTH:
        this.state.addRecur((new Recur(Recur.DAILY, freqCount)));
        break;
    case Calendar.MONTH:
        this.state.addRecur((new Recur(Recur.MONTHLY, freqCount)));
        break;
    case Calendar.YEAR:
        this.state.addRecur((new Recur(Recur.YEARLY, freqCount)));
        break;
    default:
        break;
    }
}
 
Example 5
Source File: UomWorker.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public static int[] uomTimeToCalTime(String uomId) {
    if ("TF_ms".equals(uomId)) {
        return new int[] { Calendar.MILLISECOND, 1 };
    } else if ("TF_s".equals(uomId)) {
        return new int[] { Calendar.SECOND, 1 };
    } else if ("TF_min".equals(uomId)) {
        return new int[] { Calendar.MINUTE, 1 };
    } else if ("TF_hr".equals(uomId)) {
        return new int[] { Calendar.HOUR, 1 };
    } else if ("TF_day".equals(uomId)) {
        return new int[] { Calendar.DAY_OF_YEAR, 1 };
    } else if ("TF_wk".equals(uomId)) {
        return new int[] { Calendar.WEEK_OF_YEAR, 1 };
    } else if ("TF_mon".equals(uomId)) {
        return new int[] { Calendar.MONTH, 1 };
    } else if ("TF_yr".equals(uomId)) {
        return new int[] { Calendar.YEAR, 1 };
    } else if ("TF_decade".equals(uomId)) {
        return new int[] { Calendar.YEAR, 10 };
    } else if ("TF_score".equals(uomId)) {
        return new int[] { Calendar.YEAR, 20 };
    } else if ("TF_century".equals(uomId)) {
        return new int[] { Calendar.YEAR, 100 };
    } else if ("TF_millenium".equals(uomId)) {
        return new int[] { Calendar.YEAR, 1000 };
    }

    return null;
}
 
Example 6
Source File: SeriesNameFormat.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Convert GroupingUnit type to CDateUnit type.
 * 
 * @param groupingUnitType
 *            the GroupingUnit type.
 * @return CDateUnit type of integer.
 * @since 2.3, it is merged from <code>DataProcessor</code>, make the
 *        method to be a static usage.
 */
private static int groupingUnit2CDateUnit(
		GroupingUnitType groupingUnitType )
{
	if ( groupingUnitType != null )
	{
		switch ( groupingUnitType.getValue( ) )
		{
			case GroupingUnitType.SECONDS :
				return Calendar.SECOND;
			case GroupingUnitType.MINUTES :
				return Calendar.MINUTE;
			case GroupingUnitType.HOURS :
				return Calendar.HOUR_OF_DAY;
			case GroupingUnitType.DAYS :
				return Calendar.DATE;
			case GroupingUnitType.WEEKS :
				return Calendar.WEEK_OF_YEAR;
			case GroupingUnitType.MONTHS :
				return Calendar.MONTH;
			case GroupingUnitType.YEARS :
				return Calendar.YEAR;
			case GroupingUnitType.QUARTERS :
				return GroupingUnitType.QUARTERS;
		}
	}

	return Calendar.MILLISECOND;
}
 
Example 7
Source File: GroupingUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Convert GroupingUnit type to CDateUnit type.
 * 
 * @param groupingUnitType the GroupingUnit type.
 * @return CDateUnit type of integer.
    * @since 2.3, it is merged from <code>DataProcessor</code>, make the method to be a static usage.
 */
public static int groupingUnit2CDateUnit( GroupingUnitType groupingUnitType )
{
	if ( groupingUnitType != null )
	{
		switch ( groupingUnitType.getValue( ) )
		{
			case GroupingUnitType.SECONDS :
				return Calendar.SECOND;
			case GroupingUnitType.MINUTES :
				return Calendar.MINUTE;
			case GroupingUnitType.HOURS :
				return Calendar.HOUR_OF_DAY;
			case GroupingUnitType.DAYS :
			case GroupingUnitType.DAY_OF_MONTH :
				return Calendar.DAY_OF_MONTH;
			case GroupingUnitType.DAY_OF_QUARTER :
				return CDateTime.DAY_OF_QUARTER;
			case GroupingUnitType.DAY_OF_WEEK :
				return Calendar.DAY_OF_WEEK;
			case GroupingUnitType.DAY_OF_YEAR :
				return Calendar.DAY_OF_YEAR;
			case GroupingUnitType.WEEKS :
			case GroupingUnitType.WEEK_OF_MONTH :
				return Calendar.WEEK_OF_MONTH;
			case GroupingUnitType.WEEK_OF_YEAR :
				return Calendar.WEEK_OF_YEAR;
			case GroupingUnitType.MONTHS :
				return Calendar.MONTH;
			case GroupingUnitType.QUARTERS :
				return CDateTime.QUARTER;
			case GroupingUnitType.YEARS :
				return Calendar.YEAR;
			case GroupingUnitType.WEEK_OF_QUARTER :
				return CDateTime.WEEK_OF_QUARTER;
		}
	}

	return Calendar.MILLISECOND;
}
 
Example 8
Source File: CDateTime.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the most significant datetime unit in which there's a difference
 * or 0 if there is no difference.
 * 
 * @return The least significant 'Calendar' unit in which a difference
 *         occurred
 */
public static final int getDifference( CDateTime cdt1, CDateTime cdt2 )
{
	if ( cdt1.getYear( ) != cdt2.getYear( ) )
	{
		return Calendar.YEAR;
	}
	else if ( cdt1.getMonth( ) != cdt2.getMonth( ) )
	{
		return Calendar.MONTH;
	}
	else if ( cdt1.getDay( ) != cdt2.getDay( ) )
	{
		return Calendar.DATE;
	}
	else if ( cdt1.getHour( ) != cdt2.getHour( ) )
	{
		return Calendar.HOUR_OF_DAY;
	}
	else if ( cdt1.getMinute( ) != cdt2.getMinute( ) )
	{
		return Calendar.MINUTE;
	}
	else if ( cdt1.getSecond( ) != cdt2.getSecond( ) )
	{
		return Calendar.SECOND;
	}
	else
	{
		return 0;
	}
}
 
Example 9
Source File: CDateTime.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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
 * 
 * @return A preferred datetime format pattern for the given unit
 */
public static final String getPreferredFormat( int iUnit )
{
	if ( iUnit == Calendar.YEAR )
	{
		return "yyyy"; //$NON-NLS-1$
	}
	else if ( iUnit == Calendar.MONTH )
	{
		return "MMM yyyy"; //$NON-NLS-1$
	}
	else if ( iUnit == Calendar.DATE )
	{
		return "MM-dd-yyyy"; //$NON-NLS-1$
	}
	else if ( iUnit == Calendar.HOUR_OF_DAY )
	{
		return "MM-dd-yy\nHH:mm"; //$NON-NLS-1$
	}
	else if ( iUnit == Calendar.MINUTE )
	{
		return "HH:mm:ss"; //$NON-NLS-1$
	}
	else if ( iUnit == Calendar.SECOND )
	{
		return "HH:mm:ss"; //$NON-NLS-1$
	}
	return null;
}
 
Example 10
Source File: CDateTime.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Walks through all values in a datetime array and computes the least
 * significant unit for which a difference was noted.
 * 
 * @param cdta
 *            A datetime array for which the least significant unit
 *            difference is to be computed
 * 
 * @return The least significant unit for which a difference in datetime
 *         values was noted
 */
public static final int computeUnit( CDateTime[] cdta )
		throws ChartException
{
	if ( cdta.length == 1 )
	{
		return getDefaultUnit( cdta[0] );
	}
	
	int j;
	for ( int k = 0; k < iaUnitTypes.length; k++ )
	{
		for ( int i = 0; i < cdta.length; i++ )
		{
			j = i + 1;
			if ( j > cdta.length - 1 )
			{
				j = 0;
			}

			if ( cdta[i] == null || cdta[j] == null )
			{
				throw new ChartException( ChartEnginePlugin.ID,
						ChartException.VALIDATION,
						"exception.base.orthogonal.null.datadefinition", //$NON-NLS-1$
						Messages.getResourceBundle( ) );
			}

			if ( cdta[i].get( iaUnitTypes[k] ) != cdta[j].get( iaUnitTypes[k] ) )
			{
				return iaUnitTypes[k]; // THE UNIT FOR WHICH A DIFFERENCE
				// WAS NOTED
			}
		}
	}

	// if all no difference, return year as default unit.
	return Calendar.YEAR;
}
 
Example 11
Source File: CDateTime.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * A convenience method provided to return the number of milliseconds
 * available in a given unit
 * 
 * @param iUnit
 *            The unit for which the number of milliseconds are to be
 *            computed
 * 
 * @return The number of milliseconds for the specified unit
 */
public static final double inMillis( int iUnit )
{
	if ( iUnit == Calendar.SECOND )
	{
		return MILLIS_IN_SECOND;
	}
	else if ( iUnit == Calendar.MINUTE )
	{
		return MILLIS_IN_MINUTE;
	}
	else if ( iUnit == Calendar.HOUR )
	{
		return MILLIS_IN_HOUR;
	}
	else if ( iUnit == Calendar.DATE )
	{
		return MILLIS_IN_DAY;
	}
	else if ( iUnit == Calendar.MONTH )
	{
		return MILLIS_IN_DAY * 30.4375;
	}
	else if ( iUnit == Calendar.YEAR )
	{
		return MILLIS_IN_DAY * 365.25;
	}
	return 0;
}
 
Example 12
Source File: TimeDimensionUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static int getFieldIndex( String fieldName )
{
 if( fieldName.equals( YEAR ) )
  return Calendar.YEAR;
 else if( fieldName.equals( MONTH ) )
  return Calendar.MONTH;
 else if( fieldName.equals( WEEK_OF_YEAR ) )
  return Calendar.WEEK_OF_YEAR;
 else if( fieldName.equals( WEEK_OF_MONTH ) )
  return Calendar.WEEK_OF_MONTH;
 else if( fieldName.equals( DAY_OF_MONTH ) )
  return Calendar.DAY_OF_MONTH;
 else if( fieldName.equals( DAY_OF_YEAR ) )
  return Calendar.DAY_OF_YEAR;
 else if( fieldName.equals( DAY_OF_WEEK ) )
  return Calendar.DAY_OF_WEEK;
 else if( fieldName.equals( HOUR ) )
  return Calendar.HOUR;
 else if( fieldName.equals( HOUR_OF_DAY ) )
  return Calendar.HOUR_OF_DAY;
 else if( fieldName.equals( MINUTE ) )
  return Calendar.MINUTE;
 else if( fieldName.equals( SECOND ) )
  return Calendar.SECOND;
 else if( fieldName.equals( MILLISECOND ) )
  return Calendar.MILLISECOND;
 return -1;
}
 
Example 13
Source File: TimeDimensionUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static String getFieldName( int fieldIndex )
 {
switch (fieldIndex) 
{
case Calendar.YEAR:
	return YEAR;
case Calendar.MONTH:
	return MONTH;
case Calendar.WEEK_OF_YEAR:
	return WEEK_OF_YEAR;
case Calendar.WEEK_OF_MONTH:
	return WEEK_OF_MONTH;
case Calendar.DAY_OF_MONTH:
	return DAY_OF_MONTH;
case Calendar.DAY_OF_YEAR:
	return DAY_OF_YEAR;
case Calendar.DAY_OF_WEEK:
	return DAY_OF_WEEK;
case Calendar.HOUR:
	return HOUR;
case Calendar.HOUR_OF_DAY:
	return HOUR_OF_DAY;
case Calendar.MINUTE:
	return MINUTE;
case Calendar.SECOND:
	return SECOND;
case Calendar.MILLISECOND:
	return MILLISECOND;
}
return null;
 }