Example usage for java.time ZonedDateTime withSecond

List of usage examples for java.time ZonedDateTime withSecond

Introduction

In this page you can find the example usage for java.time ZonedDateTime withSecond.

Prototype

public ZonedDateTime withSecond(int second) 

Source Link

Document

Returns a copy of this ZonedDateTime with the second-of-minute altered.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    ZonedDateTime n = dateTime.withSecond(1234);
    System.out.println(n);/*w  w w . j  av  a 2 s  .co  m*/
}

From source file:io.stallion.jobs.JobCoordinator.java

@Override
public void run() {

    if (Settings.instance().getLocalMode()
            && ("prod".equals(Settings.instance().getEnv()) || "qa".equals(Settings.instance().getEnv()))) {
        Log.info(/*from w  w w  . j av a2s.  co m*/
                "Running localMode, environment is QA or PROD, thus not running jobs. Do not want to run production jobs locally!");
        return;
    }

    while (!shouldShutDown) {
        try {
            executeJobsForCurrentTime(utcNow());
        } catch (Exception e) {
            Log.exception(e, "Error executing jobs in the main job coordinator loop!!!");
        }

        // Find the seconds until the next minute, sleep until 10 seconds into the next minute
        ZonedDateTime now = utcNow();
        ZonedDateTime nextMinute = now.withSecond(0).plusMinutes(1);
        Long waitSeconds = (nextMinute.toInstant().getEpochSecond() - now.toInstant().getEpochSecond()) + 10;
        try {
            Thread.sleep(waitSeconds * 1000);
        } catch (InterruptedException e) {
            break;
        }

    }

    // Shut down the thread pool
    // Wait for everything to exit

}

From source file:io.stallion.jobs.JobCoordinator.java

/**
 * This really should not be a public method, but needs to be so unittests can access it.
 * This is called by the main run() loop to actually find jobs to run and trigger their running
 * @param now/*from  ww  w.  j  a v  a 2 s . co  m*/
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public void executeJobsForCurrentTime(ZonedDateTime now)
        throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    now = now.withSecond(0).withNano(0);
    Log.finest("Checking for jobs to execute this period");
    for (JobStatus jobStatus : JobStatusController.instance().findJobsForPeriod(now)) {
        JobDefinition definition = JobCoordinator.instance().getJobDefinition(jobStatus.getName());
        lastRanAtByJobName.put(definition.getName(), now.toInstant().toEpochMilli());
        Log.info("Dispatching job {0}", definition.getName());
        // Now start-up a thread to actually run the job
        Class<? extends Job> jobClass = definition.getJobClass();
        Job job = jobClass.newInstance();
        JobInstanceDispatcher dispatcher = new JobInstanceDispatcher(jobStatus, definition, job, false, now);
        if (synchronousMode) {
            dispatcher.run();
        } else {
            pool.execute(dispatcher);
        }

    }
}

From source file:io.stallion.jobs.Schedule.java

/**
 * Returns true if this schedule matches the passed in datetime
 * @param dt/*from ww w  . j av a 2 s .  c om*/
 * @return
 */
public boolean matchesDateTime(ZonedDateTime dt) {
    ZonedDateTime now = dt.withSecond(0).withNano(0);
    ZonedDateTime nextRun = nextAt(now).withSecond(0).withNano(0);
    if (now.isEqual(nextRun)) {
        return true;
    }
    return false;
}

From source file:org.qcert.camp.translator.SemRule2CAMP.java

/**
 * Incomplete but evolving translation for object allocations involving temporal constructs
 * @param ast the object allocation (SemNewObject)
 * @return the translation//from w ww  .ja  va2s.co  m
 */
private CampPattern translateTemporalAllocation(SemNewObject ast) {
    List<SemValue> args = ast.getArguments();
    if (DATE_TYPE.equals(ast.getType().getDisplayName())) {
        Iterator<SemValue> argIter = args.iterator();
        ZonedDateTime translation = ZonedDateTime.ofInstant(Instant.EPOCH, ZoneId.systemDefault())
                .withYear(intFrom(argIter.next())).withMonth(intFrom(argIter.next()))
                .withDayOfMonth(intFrom(argIter.next()));
        if (argIter.hasNext())
            translation = translation.withHour(intFrom(argIter.next()));
        if (argIter.hasNext())
            translation = translation.withMinute(intFrom(argIter.next()));
        if (argIter.hasNext())
            translation = translation.withSecond(intFrom(argIter.next()));
        ConstPattern constant = new ConstPattern(translation.toString());
        return new UnaryPattern(UnaryOperator.ATimeFromString, constant);
    }
    if (TIME_TYPE.equals(ast.getType().getDisplayName()) && args.size() == 1) {
        long epochMilli = longFrom(args.get(0));
        LocalTime translation = ZonedDateTime.ofInstant(Instant.ofEpochMilli(epochMilli), ZoneOffset.UTC)
                .toLocalTime();
        // TODO this should really be a unique CAMP type corresponding to the TTRL type for LocalTimeComponentValue
        return new ConstPattern(translation.toString());
    }
    return notImplemented("Translation of temporal allocation: " + ast);
}