Java Code Examples for com.ibm.icu.util.Calendar#setTimeInMillis()

The following examples show how to use com.ibm.icu.util.Calendar#setTimeInMillis() . 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: DateUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * 
   * @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 2
Source File: DataTypeUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * mask out time info for sql Date
   * @param date
   * @return
   */
  private static java.sql.Date maskSQLDate( java.sql.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 3
Source File: DataTypeUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * 
   * @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 4
Source File: DataTypeUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
* 
* @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: TimeLabel.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private String getShowText( String type )
{
	//		StringBuffer retValue = new StringBuffer( );

	Calendar calendar = Calendar.getInstance( TimeZone.getTimeZone( id ) );
	calendar.setTimeInMillis( time );

	SimpleDateFormat formatter = new SimpleDateFormat( formatType );
	String result = formatter.format( calendar.getTime( ) );
	return result;

}
 
Example 6
Source File: TimeUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return Time instance of current time point
 */
public TimePoint getTimePoint( )
{
	Calendar calendar = Calendar.getInstance( );
	calendar.setTimeInMillis( System.currentTimeMillis( ) );
	return new TimePoint( calendar );
}
 
Example 7
Source File: TimeUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Return string format of current time
 * 
 * @return current time
 */
public String getTime()
{
	Calendar calendar = Calendar.getInstance( );
	calendar.setTimeInMillis( System.currentTimeMillis( ) );
	return getTimeStr( calendar );
}
 
Example 8
Source File: DateUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * 
   * @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 9
Source File: SimpleDateFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
private void initializeDefaultCenturyStart(long baseTime) {
    defaultCenturyBase = baseTime;
    // clone to avoid messing up date stored in calendar object
    // when this method is called while parsing
    Calendar tmpCal = (Calendar)calendar.clone();
    tmpCal.setTimeInMillis(baseTime);
    tmpCal.add(Calendar.YEAR, -80);
    defaultCenturyStart = tmpCal.getTime();
    defaultCenturyStartYear = tmpCal.get(Calendar.YEAR);
}
 
Example 10
Source File: UomWorker.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public static Calendar addUomTime(Calendar cal, Timestamp startTime, String uomId, int value) {
    if (cal == null) {
        cal = Calendar.getInstance();
    }
    if (startTime != null) {
        cal.setTimeInMillis(startTime.getTime());
    }
    int[] conv = uomTimeToCalTime(uomId);

    // conversion multiplier * value by type
    cal.add(conv[0], (value * conv[1]));
    return cal;
}
 
Example 11
Source File: EntitySyncServices.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/**
 * Clean EntitySyncRemove Info
 *@param dctx The DispatchContext that this service is operating in
 *@param context Map containing the input parameters
 *@return Map with the result of the service, the output parameters
 */
public static Map<String, Object> cleanSyncRemoveInfo(DispatchContext dctx, Map<String, ? extends Object> context) {
    Debug.logInfo("Running cleanSyncRemoveInfo", module);
    Delegator delegator = dctx.getDelegator();
    Locale locale = (Locale) context.get("locale");

    try {
        // find the largest keepRemoveInfoHours value on an EntitySyncRemove and kill everything before that, if none found default to 10 days (240 hours)
        double keepRemoveInfoHours = 24;

        List<GenericValue> entitySyncRemoveList = EntityQuery.use(delegator).from("EntitySync").queryList();
        for (GenericValue entitySyncRemove: entitySyncRemoveList) {
            Double curKrih = entitySyncRemove.getDouble("keepRemoveInfoHours");
            if (curKrih != null) {
                double curKrihVal = curKrih;
                if (curKrihVal > keepRemoveInfoHours) {
                    keepRemoveInfoHours = curKrihVal;
                }
            }
        }


        int keepSeconds = (int) Math.floor(keepRemoveInfoHours * 3600);

        Calendar nowCal = Calendar.getInstance();
        nowCal.setTimeInMillis(System.currentTimeMillis());
        nowCal.add(Calendar.SECOND, -keepSeconds);
        Timestamp keepAfterStamp = new Timestamp(nowCal.getTimeInMillis());

        int numRemoved = delegator.removeByCondition("EntitySyncRemove", EntityCondition.makeCondition(ModelEntity.STAMP_TX_FIELD, EntityOperator.LESS_THAN, keepAfterStamp));
        Debug.logInfo("In cleanSyncRemoveInfo removed [" + numRemoved + "] values with TX timestamp before [" + keepAfterStamp + "]", module);

        return ServiceUtil.returnSuccess();
    } catch (GenericEntityException e) {
        Debug.logError(e, "Error cleaning out EntitySyncRemove info: " + e.toString(), module);
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EntityExtErrorCleaningEntitySyncRemove", UtilMisc.toMap("errorString", e.toString()), locale));
    }
}
 
Example 12
Source File: UtilDateTime.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/** Returns timestamp without seconds and milliseconds (SCIPIO). */
public static Timestamp getMinuteBasedTimestamp(Timestamp stamp) {
    if (stamp == null) {
        return null;
    }
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(stamp.getTime());
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return new Timestamp(cal.getTimeInMillis());
}
 
Example 13
Source File: UtilDateTime.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public static Calendar toCalendar(java.sql.Timestamp stamp) {
    Calendar cal = Calendar.getInstance();
    if (stamp != null) {
        cal.setTimeInMillis(stamp.getTime());
    }
    return cal;
}
 
Example 14
Source File: DateTimeConverters.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public java.sql.Date convert(Number obj) throws ConversionException {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(obj.longValue());
    cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return new java.sql.Date(cal.getTimeInMillis());
}
 
Example 15
Source File: DateTimeElementImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public Calendar getValueAsCalendar( )
{
	Calendar calendar = Calendar.getInstance( );
	calendar.setTimeInMillis( data );
	return calendar;
}
 
Example 16
Source File: DateTimeDataElementImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public final Calendar getValueAsCalendar( )
{
	final Calendar c = Calendar.getInstance( );
	c.setTimeInMillis( value );
	return c;
}
 
Example 17
Source File: WeekToDateFunciton.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
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 18
Source File: TimeDurationTests.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unlikely-arg-type") // SCIPIO: This is for "stringDuration.equals(TimeDurationTests.class)", assuming intentional unless upstream decides otherwise
private static TimeDuration assertDurationLoop(String label, Calendar right, int years, int months, int days, int hours, int minutes, int seconds, int milliseconds, TimeDuration lastString, boolean isNegative) {
    StringBuilder sb = new StringBuilder();
    sb.append(years != 0 ? years : "");
    sb.append(':').append(months != 0 ? months : "");
    sb.append(':').append(days != 0 ? days : "");
    sb.append(':').append(hours != 0 ? hours : "");
    sb.append(':').append(minutes != 0 ? minutes : "");
    sb.append(':').append(seconds != 0 ? seconds : "");
    sb.append(':').append(milliseconds != 0 ? milliseconds : "");
    String durationString = years + ":" + months + ":" + days + ":" + hours + ":" + minutes + ":" + seconds + ":" + milliseconds;
    TimeDuration stringDuration = TimeDuration.parseDuration(sb.toString());
    right.setTimeInMillis(0);
    if (years != 0) {
        right.set(Calendar.YEAR, 1970 + Math.abs(years));
    }
    if (months != 0) {
        right.set(Calendar.MONTH, Math.abs(months));
    }
    right.set(Calendar.DAY_OF_MONTH, Math.abs(days) + 1);
    if (hours != 0) {
        right.set(Calendar.HOUR, Math.abs(hours));
    }
    if (minutes != 0) {
        right.set(Calendar.MINUTE, Math.abs(minutes));
    }
    if (seconds != 0) {
        right.set(Calendar.SECOND, Math.abs(seconds));
    }
    if (milliseconds != 0) {
        right.set(Calendar.MILLISECOND, Math.abs(milliseconds));
    }
    TimeDuration calDuration = isNegative ? new TimeDuration(right, zero) : new TimeDuration(zero, right);
    assertDurationFields(label + "(parseString[0])", years, months, days, hours, minutes, seconds, milliseconds, durationString, TimeDuration.parseDuration(durationString), isNegative, false);
    assertDurationFields(label + "(parseString)", years, months, days, hours, minutes, seconds, milliseconds, durationString, stringDuration, isNegative, false);
    assertDurationFields(label + "(cal)", years, months, days, hours, minutes, seconds, milliseconds, durationString, calDuration, isNegative, false);
    Calendar added = calDuration.addToCalendar((Calendar) zero.clone());
    TimeDuration addDuration = new TimeDuration(zero, added);
    assertDurationFields(label + "(cal[add])", years, months, days, hours, minutes, seconds, milliseconds, durationString, addDuration, isNegative, false);
    assertEquals(label + ".compareTo(string, cal)", 0, doCompare(stringDuration, calDuration));
    assertEquals(label + ".compareTo(string, string)", 0, doCompare(stringDuration, stringDuration));
    assertEquals(label + ".compareTo(cal, cal)", 0, doCompare(calDuration, calDuration));
    assertEquals(label + ".compareTo(cal, string)", 0, doCompare(calDuration, stringDuration));
    assertEquals(label + ".equals(cal, cal)", calDuration, calDuration);
    assertEquals(label + ".equals(cal, string)", calDuration, stringDuration);
    assertEquals(label + ".equals(string, cal)", stringDuration, calDuration);
    assertEquals(label + ".equals(string, string)", stringDuration, stringDuration);
    assertFalse(label + ".not-equals(string, this)", stringDuration.equals(TimeDurationTests.class));
    if (lastString != null) {
        assertFalse(label + ".not-equals(string, lastString)", stringDuration.equals(lastString));
    }
    return stringDuration;
}