Example usage for java.util Calendar SECOND

List of usage examples for java.util Calendar SECOND

Introduction

In this page you can find the example usage for java.util Calendar SECOND.

Prototype

int SECOND

To view the source code for java.util Calendar SECOND.

Click Source Link

Document

Field number for get and set indicating the second within the minute.

Usage

From source file:net.carinae.dev.async.dao.QueuedTaskHolderDaoJPA2.java

@Override
public QueuedTaskHolder findRandomStalledTask() {

    Calendar TOO_LONG_AGO = Calendar.getInstance();
    TOO_LONG_AGO.add(Calendar.SECOND, -7200);

    // select qth from QueuedTask where 
    //      qth.startedStamp != null AND
    //      qth.startedStamp < TOO_LONG_AGO
    CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();
    CriteriaQuery<QueuedTaskHolder> cq = cb.createQuery(QueuedTaskHolder.class);
    Root<QueuedTaskHolder> qth = cq.from(QueuedTaskHolder.class);
    cq.select(qth).where(cb.and(cb.isNull(qth.get(QueuedTaskHolder_.completedStamp)),
            cb.lessThan(qth.get(QueuedTaskHolder_.startedStamp), TOO_LONG_AGO)));

    List<QueuedTaskHolder> stalledTasks = this.entityManager.createQuery(cq).getResultList();

    if (stalledTasks.isEmpty()) {
        return null;
    } else {//www . j  a  va2s. c o  m
        Random rand = new Random(System.currentTimeMillis());
        return stalledTasks.get(rand.nextInt(stalledTasks.size()));
    }

}

From source file:com.silverpeas.calendar.DateTimeTest.java

@Test
public void createsAtASpecifiedShorterDateTime() {
    Calendar now = getInstance();
    now.set(Calendar.SECOND, 0);
    now.set(Calendar.MILLISECOND, 0);
    DateTime expected = new DateTime(now.getTime());
    DateTime actual = DateTime.dateTimeAt(now.get((Calendar.YEAR)), now.get(Calendar.MONTH),
            now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE));
    assertEquals(expected.getTime(), actual.getTime(), 100);
}

From source file:io.wcm.devops.conga.plugins.aem.util.JsonContentLoaderTest.java

@Test
public void testCalendarEcmaFormat() {
    Map<String, Object> props = getDeep(content, "jcr:content");

    Calendar calendar = (Calendar) props.get("cq:lastModified");
    assertNotNull(calendar);/*  ww w  .  j a  v  a 2  s.co m*/

    calendar.setTimeZone(TimeZone.getTimeZone("GMT+2"));

    assertEquals(2014, calendar.get(Calendar.YEAR));
    assertEquals(4, calendar.get(Calendar.MONTH) + 1);
    assertEquals(22, calendar.get(Calendar.DAY_OF_MONTH));

    assertEquals(15, calendar.get(Calendar.HOUR_OF_DAY));
    assertEquals(11, calendar.get(Calendar.MINUTE));
    assertEquals(24, calendar.get(Calendar.SECOND));
}

From source file:com.acc.fulfilmentprocess.actions.order.ScheduleForCleanUpAction.java

@Override
public Transition executeAction(final OrderProcessModel process) {
    ServicesUtil.validateParameterNotNull(process, "process cannot be null");
    final OrderModel order = process.getOrder();
    ServicesUtil.validateParameterNotNull(order, "order cannot be null");
    if (Boolean.FALSE.equals(order.getFraudulent())) {
        return Transition.NOK;
    }/*w  ww.  j av  a  2s . co m*/
    final FraudReportModel lastReport = getLastFraudReportModelWithFraudStatus(order.getFraudReports());
    if (lastReport == null) {
        return Transition.NOK;
    }
    final Date lastModification = lastReport.getTimestamp();
    final Date currentDate = getTimeService().getCurrentTime();
    final Calendar threshold = Calendar.getInstance();
    threshold.setTime(currentDate);
    threshold.add(Calendar.SECOND, -getMinPeriodWaitingForCleanUpInSeconds().intValue());
    if (lastModification.before(threshold.getTime())) {
        return Transition.OK;
    } else {
        return Transition.NOK;
    }
}

From source file:erpsystem.chart.Charts.java

private static String toString(Calendar calendar) {
    String result = "";
    int y = calendar.get(Calendar.YEAR);
    int m = calendar.get(Calendar.MONTH) + 1;
    int d = calendar.get(Calendar.DAY_OF_MONTH);
    int h = calendar.get(Calendar.HOUR_OF_DAY);
    int mm = calendar.get(Calendar.MINUTE);
    int s = calendar.get(Calendar.SECOND);
    result += d + "/" + m + "/" + y + ":" + h + "/" + mm + "/" + s;
    return result;
}

From source file:com.lfv.yada.net.server.ServerLogger.java

public synchronized void resume(int h, int m, int s) {
    // Create a calendar
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.set(Calendar.HOUR_OF_DAY, h);
    cal.set(Calendar.MINUTE, m);/*www.j a  v  a 2s  . co m*/
    cal.set(Calendar.SECOND, s);
    resumeTime = cal.getTimeInMillis();
    startTime = System.currentTimeMillis();
    suspendTime = 0;
}

From source file:adalid.commons.util.TimeUtils.java

public static synchronized Date getDate(java.util.Date date) {
    if (date == null) {
        return currentDate();
    }/*from w w  w. j a v a2  s.c  o  m*/
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date.getTime());
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return new Date(c.getTimeInMillis());
}

From source file:com.adobe.acs.commons.http.headers.impl.WeeklyExpiresHeaderFilterTest.java

@Test
public void testAdjustExpiresSameDayPast() throws Exception {

    Calendar actual = Calendar.getInstance();
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);

    Calendar expected = Calendar.getInstance();
    expected.setTime(actual.getTime());//from w  w w . ja  va  2 s  . c om
    expected.add(Calendar.DAY_OF_WEEK, 7);

    int dayOfWeek = expected.get(Calendar.DAY_OF_WEEK);
    properties.put(WeeklyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_WEEK, dayOfWeek);

    filter.doActivate(componentContext);
    filter.adjustExpires(actual);

    assertTrue(DateUtils.isSameInstant(expected, actual));
    assertEquals(dayOfWeek, actual.get(Calendar.DAY_OF_WEEK));
}

From source file:org.activiti.crystalball.simulator.PlaybackTest.java

@Test
public void testPlaybackRun() throws Exception {
    System.setProperty("_SIM_DB_PATH", System.getProperty("tempDir", "target") + "/Playback-test");
    System.setProperty("liveDB", "target/Playback");

    ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
            "/org/activiti/crystalball/simulator/PlaybackSimEngine-h2-context.xml");

    HistoryService simHistoryService = (HistoryService) appContext.getBean("simHistoryService");

    // init identity service
    IdentityService identityService = (IdentityService) appContext.getBean("simIdentityService");
    identityService.saveGroup(identityService.newGroup("Group1"));
    identityService.saveUser(identityService.newUser("user1"));
    identityService.createMembership("user1", "Group1");

    SimulationRun simRun = (SimulationRun) appContext.getBean(SimulationRun.class);

    RepositoryService simRepositoryService = (RepositoryService) appContext.getBean("simRepositoryService");

    // deploy processes
    simRepositoryService.createDeployment()
            .addClasspathResource("org/activiti/crystalball/simulator/Playback.bpmn").deploy();

    Calendar c = Calendar.getInstance();
    c.clear();//from  w  ww  .j a  v a  2 s . co m
    c.set(2013, 3, 3);
    Date startDate = c.getTime();
    c.add(Calendar.SECOND, 10);
    Date finishDate = c.getTime();
    // run simulation for 10 seconds
    simRun.execute(startDate, finishDate);

    assertEquals(3, simHistoryService.createHistoricProcessInstanceQuery().count());
    List<HistoricProcessInstance> processInstances = simHistoryService.createHistoricProcessInstanceQuery()
            .orderByProcessInstanceStartTime().asc().list();
    HistoricProcessInstance processInstance = processInstances.get(0);
    HistoricVariableInstance variableInstance = simHistoryService.createHistoricVariableInstanceQuery()
            .processInstanceId(processInstance.getId()).variableName("x").singleResult();
    assertEquals(3, ((Integer) variableInstance.getValue()).intValue());

    processInstance = processInstances.get(1);
    variableInstance = simHistoryService.createHistoricVariableInstanceQuery()
            .processInstanceId(processInstance.getId()).variableName("x").singleResult();
    assertEquals(2, ((Integer) variableInstance.getValue()).intValue());

    processInstance = processInstances.get(2);
    variableInstance = simHistoryService.createHistoricVariableInstanceQuery()
            .processInstanceId(processInstance.getId()).variableName("x").singleResult();
    assertEquals(3, ((Integer) variableInstance.getValue()).intValue());

    appContext.close();
}