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

The following examples show how to use com.ibm.icu.util.Calendar#HOUR_OF_DAY . 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: 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 3
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 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: 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 7
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;
 }
 
Example 8
Source File: DateIntervalInfo.java    From fitnotifications with Apache License 2.0 3 votes vote down vote up
/**
 * Provides a way for client to build interval patterns.
 * User could construct DateIntervalInfo by providing
 * a list of skeletons and their patterns.
 * <P>
 * For example:
 * <pre>
 * DateIntervalInfo dIntervalInfo = new DateIntervalInfo();
 * dIntervalInfo.setIntervalPattern("yMd", Calendar.YEAR, "'from' yyyy-M-d 'to' yyyy-M-d");
 * dIntervalInfo.setIntervalPattern("yMMMd", Calendar.MONTH, "'from' yyyy MMM d 'to' MMM d");
 * dIntervalInfo.setIntervalPattern("yMMMd", Calendar.DAY, "yyyy MMM d-d");
 * dIntervalInfo.setFallbackIntervalPattern("{0} ~ {1}");
 * </pre>
 *
 * Restriction:
 * Currently, users can only set interval patterns when the following
 * calendar fields are different: ERA, YEAR, MONTH, DATE,  DAY_OF_MONTH,
 * DAY_OF_WEEK, AM_PM,  HOUR, HOUR_OF_DAY, MINUTE, and SECOND.
 * Interval patterns when other calendar fields are different are
 * not supported.
 *
 * @param skeleton         the skeleton on which interval pattern based
 * @param lrgDiffCalUnit   the largest different calendar unit.
 * @param intervalPattern  the interval pattern on the largest different
 *                         calendar unit.
 *                         For example, if lrgDiffCalUnit is
 *                         "year", the interval pattern for en_US when year
 *                         is different could be "'from' yyyy 'to' yyyy".
 * @throws IllegalArgumentException  if setting interval pattern on
 *                            a calendar field that is smaller
 *                            than the MINIMUM_SUPPORTED_CALENDAR_FIELD
 * @throws UnsupportedOperationException  if the object is frozen
 * @stable ICU 4.0
 */
public void setIntervalPattern(String skeleton,
                               int lrgDiffCalUnit,
                               String intervalPattern)
{
    if ( frozen ) {
        throw new UnsupportedOperationException("no modification is allowed after DII is frozen");
    }
    if ( lrgDiffCalUnit > MINIMUM_SUPPORTED_CALENDAR_FIELD ) {
        throw new IllegalArgumentException("calendar field is larger than MINIMUM_SUPPORTED_CALENDAR_FIELD");
    }
    if (fIntervalPatternsReadOnly) {
        fIntervalPatterns = cloneIntervalPatterns(fIntervalPatterns);
        fIntervalPatternsReadOnly = false;
    }
    PatternInfo ptnInfo = setIntervalPatternInternally(skeleton,
                      CALENDAR_FIELD_TO_PATTERN_LETTER[lrgDiffCalUnit],
                      intervalPattern);
    if ( lrgDiffCalUnit == Calendar.HOUR_OF_DAY ) {
        setIntervalPattern(skeleton,
                           CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.AM_PM],
                           ptnInfo);
        setIntervalPattern(skeleton,
                           CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.HOUR],
                           ptnInfo);
    } else if ( lrgDiffCalUnit == Calendar.DAY_OF_MONTH ||
                lrgDiffCalUnit == Calendar.DAY_OF_WEEK ) {
        setIntervalPattern(skeleton,
                           CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.DATE],
                           ptnInfo);
    }
}