Java Code Examples for org.apache.commons.lang3.time.DateUtils#addMilliseconds()

The following examples show how to use org.apache.commons.lang3.time.DateUtils#addMilliseconds() . 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: ActionChainFactory.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Schedules an Action Chain for execution.
 * @param actionChain the action chain to execute
 * @param date first action's minimum timestamp
 * @throws TaskomaticApiException if there was a Taskomatic error
 */
public static void schedule(ActionChain actionChain, Date date)
    throws TaskomaticApiException {

    log.debug("Scheduling Action Chain " +  actionChain + " to date " + date);
    Map<Server, Action> latest = new HashMap<Server, Action>();
    int maxSortOrder = getNextSortOrderValue(actionChain);
    Date dateInOrder = new Date(date.getTime());
    Map<Server, List<Action>> minionActions = new HashMap<Server, List<Action>>();

    for (int sortOrder = 0; sortOrder < maxSortOrder; sortOrder++) {
        for (ActionChainEntry entry : getActionChainEntries(actionChain, sortOrder)) {
            Server server = entry.getServer();
            Action action = entry.getAction();

            log.debug("Scheduling Action " + action + " to server " + server);
            ActionFactory.addServerToAction(server.getId(), action);
            action.setPrerequisite(latest.get(server));
            action.setEarliestAction(dateInOrder);

            // Increment 'earliest' time by a millisecond for each chain action in
            // order to sort them correctly for display
            dateInOrder = DateUtils.addMilliseconds(dateInOrder, 1);
            latest.put(server, action);
        }
    }

    // Trigger Action Chain execution for Minions via Taskomatic
    taskomaticApi.scheduleActionChainExecution(actionChain);
    log.debug("Action Chain " + actionChain + " scheduled to date " + date);
}
 
Example 2
Source File: OnClickHelper.java    From MVPAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
/**
 * Tries to occupy the onclick enabler.
 * @param waitMs the time interval to occupy
 * @return if noone occupied it, returns true, else false
 */
public static boolean occupy(int waitMs){
    if(occupiedUntil != null && occupiedUntil.after(new Date())){
        return false;
    }
    occupiedUntil = DateUtils.addMilliseconds(new Date(), waitMs);
    return true;
}
 
Example 3
Source File: OnClickHelper.java    From RxAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
/**
 * Tries to occupy the onclick enabler.
 * @param waitMs the time interval to occupy
 * @return if noone occupied it, returns true, else false
 */
public static boolean occupy(int waitMs){
    if(occupiedUntil != null && occupiedUntil.after(new Date())){
        return false;
    }
    occupiedUntil = DateUtils.addMilliseconds(new Date(), waitMs);
    return true;
}
 
Example 4
Source File: AbstractWorkflowIT.java    From telekom-workflow-engine with MIT License 5 votes vote down vote up
protected void assertWoit( long refNum,
                           long woinRefNum,
                           int tokenId,
                           WorkItemStatus status,
                           String signal,
                           Integer delayInMs,
                           String bean,
                           String method,
                           String role,
                           String userName,
                           Object arguments,
                           Object result ){
    WorkItem woit = findInArchive( woinRefNum ) ? archiveDao.findWoitByRefNum( refNum ) : workItemDao.findByRefNum( refNum );
    Assert.assertEquals( refNum, (long)woit.getRefNum() );
    Assert.assertEquals( woinRefNum, (long)woit.getWoinRefNum() );
    Assert.assertEquals( tokenId, woit.getTokenId() );
    Assert.assertEquals( status, woit.getStatus() );
    Assert.assertEquals( signal, woit.getSignal() );
    if( delayInMs != null ){
        Date min = DateUtils.addMilliseconds( new Date(), -(int)delayInMs );
        Date max = DateUtils.addMilliseconds( new Date(), delayInMs );
        Assert.assertTrue( min.before( woit.getDueDate() ) );
        Assert.assertTrue( max.after( woit.getDueDate() ) );
    }
    Assert.assertEquals( bean, woit.getBean() );
    Assert.assertEquals( method, woit.getMethod() );
    Assert.assertEquals( role, woit.getRole() );
    Assert.assertEquals( userName, woit.getUserName() );
    if( WorkItemType.TASK.equals( woit.getType() ) ){
        Assert.assertArrayEquals( (Object[])arguments, JsonUtil.deserialize( woit.getArguments(), Object[].class ) );
    }
    else if( WorkItemType.HUMAN_TASK.equals( woit.getType() ) ){
        Assert.assertEquals( arguments, JsonUtil.deserializeHashMap( woit.getArguments(), String.class, Object.class ) );
    }
    Assert.assertEquals( result, JsonUtil.deserialize( woit.getResult() ) );
}
 
Example 5
Source File: AbstractWorkflowIT.java    From telekom-workflow-engine with MIT License 4 votes vote down vote up
protected void simulatePollLockAssign( long woinRefNum, WorkType type, Long woitRefNum, int timeOffset ){
    Date now = DateUtils.addMilliseconds( new Date(), timeOffset + 1000 );
    simulatePollLockAssign( woinRefNum, type, woitRefNum, now );
}
 
Example 6
Source File: DatePlusMilliseconds.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void add_milliseconds_to_date_in_java_with_apachecommons () {

	Calendar newYearsEve = Calendar.getInstance();
	newYearsEve.set(2012, 11, 31, 23, 59, 59);
	
	Date newYearsDay = DateUtils.addMilliseconds(newYearsEve.getTime(), 1000);
	
	SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss M z");

	logger.info(dateFormatter.format(newYearsEve.getTime()));
	logger.info(dateFormatter.format(newYearsDay));

	assertTrue(newYearsDay.after(newYearsEve.getTime()));
}
 
Example 7
Source File: DateMinusMilliseconds.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void subtract_milliseconds_from_date_in_java_apachecommons () {
	
	Calendar newYearsDay = Calendar.getInstance();
	newYearsDay.set(2013, 0, 1, 0, 0, 0);
	
	Date newYearsEve = DateUtils.addMilliseconds(newYearsDay.getTime(), -1000);
	
	SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z");

	logger.info(dateFormatter.format(newYearsDay.getTime()));
	logger.info(dateFormatter.format(newYearsEve));

	assertTrue(newYearsEve.before(newYearsDay.getTime()));
}
 
Example 8
Source File: DateUtil.java    From feilong-core with Apache License 2.0 2 votes vote down vote up
/**
 * 指定日期 <code>date</code>加减毫秒.
 * 
 * <h3>说明:</h3>
 * <blockquote>
 * <ol>
 * <li>结果会自动跨月,跨年计算.</li>
 * <li>传入的参数 <code>date</code> 不会改变</li>
 * </ol>
 * </blockquote>
 * 
 * <h3>示例:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * DateUtil.addMillisecond(2015-09-07 13:35:02.769,5000)     =2015-09-07 13:35:07.769
 * DateUtil.addMillisecond(2015-09-07 13:35:02.769,-5000)    =2015-09-07 13:34:57.769
 * </pre>
 * 
 * </blockquote>
 * 
 * @param date
 *            任意时间
 * @param millisecond
 *            加减毫秒,<span style="color:red">可以是负数</span>,表示前面多少<br>
 * @return 如果 <code>date</code>是null,抛出 {@link java.lang.IllegalArgumentException}<br>
 *         如果 <code>millisecond==0</code>,那么什么都不做,返回 <code>date</code>,参见 {@link GregorianCalendar#add(int, int)}
 * @throws IllegalArgumentException
 *             如果 <code>date</code> 是<code>null</code>
 * @see org.apache.commons.lang3.time.DateUtils#addMilliseconds(Date, int)
 * @since 1.4.1
 */
public static Date addMillisecond(Date date,int millisecond){
    return DateUtils.addMilliseconds(date, millisecond);
}