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

The following examples show how to use com.ibm.icu.util.Calendar#DATE . 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: 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 2
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 3
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 4
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 5
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 6
Source File: CDateTime.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private static final int getDefaultUnit( CDateTime c )
{
	if ( c.isTimeOnly( ) )
	{
		return Calendar.SECOND;
	}
	if ( c.isFullDateTime( ) )
	{
		return Calendar.MILLISECOND;
	}
	return Calendar.DATE;
}
 
Example 7
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;
}