Example usage for java.time Instant plusSeconds

List of usage examples for java.time Instant plusSeconds

Introduction

In this page you can find the example usage for java.time Instant plusSeconds.

Prototype

public Instant plusSeconds(long secondsToAdd) 

Source Link

Document

Returns a copy of this instant with the specified duration in seconds added.

Usage

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
    instant = instant.plusSeconds(10000);
    System.out.println(instant);/*w ww  . j  a  v a 2 s.  c o m*/

}

From source file:DelayedJob.java

public static void main(String[] args) throws InterruptedException {
    BlockingQueue<DelayedJob> queue = new DelayQueue<>();
    Instant now = Instant.now();

    queue.put(new DelayedJob("A", now.plusSeconds(9)));
    queue.put(new DelayedJob("B", now.plusSeconds(3)));
    queue.put(new DelayedJob("C", now.plusSeconds(6)));
    queue.put(new DelayedJob("D", now.plusSeconds(1)));

    while (queue.size() > 0) {
        System.out.println("started...");
        DelayedJob job = queue.take();/* w  ww  .j a v a 2 s  .c  om*/
        System.out.println("Job: " + job);
    }
    System.out.println("Finished.");
}

From source file:Main.java

public static void main(String[] args) {

    // same time in millis
    Instant now = Instant.ofEpochMilli(1262347200000l);

    // native plusSeconds() method to add 10 seconds
    Instant nowPlusTenSeconds = now.plusSeconds(10);

    // no native support for units like days.
    Instant nowPlusTwoDays = now.plus(2, ChronoUnit.DAYS);
    Instant nowMinusTwoDays = now.minus(Duration.ofDays(2));

    System.out.println(nowPlusTenSeconds);
    System.out.println(nowPlusTwoDays);
    System.out.println(nowMinusTwoDays);
}

From source file:cn.edu.zjnu.acm.judge.admin.AdminController.java

@PostMapping("/admin/contests")
public String addContest(@RequestParam(value = "title", required = false) String title,
        @RequestParam(value = "description", required = false) String description,
        @RequestParam(value = "start") @DateTimeFormat(pattern = "yyyy-M-d H:m") LocalDateTime start,
        @RequestParam("length") @Pattern(regexp = "\\d+:[0-5]?[0-9]:[0-5]?[0-9]") String length, Model model) {
    Instant startTime = start.atZone(ZoneId.systemDefault()).toInstant();
    String[] split = length.split(":", 3);
    long h = Long.parseLong(split[0]);
    int m = Integer.parseInt(split[1]);
    int s = Integer.parseInt(split[2]);
    Instant endTime = startTime.plusSeconds(h * 3600 + m * 60 + s);

    Contest contest = Contest.builder().title(title).description(description).startTime(startTime)
            .endTime(endTime).build();//  w  ww  .  j  a v a2 s. c o m
    contestMapper.save(contest);

    model.addAttribute("contestId", contest.getId());
    model.addAttribute("startTime", startTime);
    model.addAttribute("endTime", endTime);

    return "admin/contests/add";
}

From source file:com.onyxscheduler.domain.SchedulerIT.java

@Test(timeout = FIRE_THRESHOLD_TIMEOUT_IN_MILLIS)
public void shouldFireMultipleTimesWithTwoPastTriggers()
        throws Scheduler.DuplicateJobKeyException, InterruptedException {
    CountDownLatch latch = new CountDownLatch(2);
    latchProvider.setLatch(latch);//from   ww  w .  j  ava2  s  . co m
    Instant pastDate = buildPastDate();
    CountDownJob job = CountDownJob.buildFromTriggers(
            ImmutableSet.of(Trigger.fromFixedTime(pastDate), Trigger.fromFixedTime(pastDate.plusSeconds(1))));

    scheduler.scheduleJob(job);

    latch.await();
}

From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java

@Override
public String getSubmissionStatus(String submissionId) {
    String status = "";
    AssignmentSubmission submission;/*from w  ww  .  ja v a 2 s.co m*/
    try {
        submission = getSubmission(submissionId);
    } catch (PermissionException e) {
        log.warn("Could not get submission with id {}, {}", submissionId, e.getMessage());
        return status;
    }
    Assignment assignment = submission.getAssignment();
    String assignmentReference = AssignmentReferenceReckoner.reckoner().assignment(assignment).reckon()
            .getReference();
    boolean allowGrade = assignment != null && allowGradeSubmission(assignmentReference);

    Instant submitTime = submission.getDateSubmitted();
    Instant returnTime = submission.getDateReturned();
    Instant lastModTime = submission.getDateModified();

    if (submission.getSubmitted() || (!submission.getSubmitted() && allowGrade)) {
        if (submitTime != null) {
            if (submission.getReturned()) {
                if (returnTime != null && returnTime.isBefore(submitTime)) {
                    if (!submission.getGraded()) {
                        status = resourceLoader.getString("gen.resub") + " "
                                + getUsersLocalDateTimeString(submitTime);
                        if (submitTime.isAfter(assignment.getDueDate())) {
                            status = status + resourceLoader.getString("gen.late2");
                        }
                    } else
                        status = resourceLoader.getString("gen.returned");
                } else
                    status = resourceLoader.getString("gen.returned");
            } else if (submission.getGraded() && allowGrade) {
                status = StringUtils.isNotBlank(submission.getGrade()) ? resourceLoader.getString("grad3")
                        : resourceLoader.getString("gen.commented");
            } else {
                if (allowGrade) {
                    // ungraded submission
                    status = resourceLoader.getString("ungra");
                } else {
                    status = resourceLoader.getString("gen.subm4") + " "
                            + getUsersLocalDateTimeString(submitTime);
                }
            }
        } else {
            if (submission.getReturned()) {
                // instructor can return grading to non-submitted user
                status = resourceLoader.getString("gen.returned");
            } else if (submission.getGraded() && allowGrade) {
                // instructor can grade non-submitted ones
                status = StringUtils.isNotBlank(submission.getGrade()) ? resourceLoader.getString("grad3")
                        : resourceLoader.getString("gen.commented");
            } else {
                if (allowGrade) {
                    // show "no submission" to graders
                    status = resourceLoader.getString("listsub.nosub");
                } else {
                    if (assignment.getHonorPledge() && submission.getHonorPledge()) {
                        status = resourceLoader.getString("gen.hpsta");
                    } else {
                        // show "not started" to students
                        status = resourceLoader.getString("gen.notsta");
                    }
                }
            }
        }
    } else {
        if (submission.getGraded()) {
            if (submission.getReturned()) {
                // modified time is after returned time + 10 seconds
                if (lastModTime != null && returnTime != null && lastModTime.isAfter(returnTime.plusSeconds(10))
                        && !allowGrade) {
                    // working on a returned submission now
                    status = resourceLoader.getString("gen.dra2") + " " + resourceLoader.getString("gen.inpro");
                } else {
                    // not submitted submmission has been graded and returned
                    status = resourceLoader.getString("gen.returned");
                }
            } else if (allowGrade) {
                // grade saved but not release yet, show this to graders
                status = StringUtils.isNotBlank(submission.getGrade()) ? resourceLoader.getString("grad3")
                        : resourceLoader.getString("gen.commented");
            } else {
                // submission saved, not submitted.
                status = resourceLoader.getString("gen.dra2") + " " + resourceLoader.getString("gen.inpro");
            }
        } else {
            if (allowGrade)
                status = resourceLoader.getString("ungra");
            else {
                // TODO add a submission state of draft so we can eliminate the date check here
                if (assignment.getHonorPledge() && submission.getHonorPledge()
                        && submission.getDateCreated().equals(submission.getDateModified())) {
                    status = resourceLoader.getString("gen.hpsta");
                } else {
                    // submission saved, not submitted,
                    status = resourceLoader.getString("gen.dra2") + " " + resourceLoader.getString("gen.inpro");
                }
            }
        }
    }

    return status;
}

From source file:org.trellisldp.rosid.file.RDFPatchTest.java

@Test
public void testPatchWriter() throws IOException {
    final File file = new File(resDir1, RESOURCE_JOURNAL);
    final Instant time = now();
    final List<Quad> delete = new ArrayList<>();
    final List<Quad> add = new ArrayList<>();
    final Quad title = rdf.createQuad(Trellis.PreferUserManaged, identifier, DC.title,
            rdf.createLiteral("Title"));
    add.add(title);//from w  w w .j  ava2s  .  c  o  m
    add.add(rdf.createQuad(Trellis.PreferUserManaged, identifier, DC.description,
            rdf.createLiteral("A longer description")));
    RDFPatch.write(file, delete.stream(), add.stream(), time);
    final List<Quad> data1 = RDFPatch.asStream(rdf, file, identifier, time).collect(toList());
    assertEquals(add.size() + 1, data1.size());
    add.forEach(q -> assertTrue(data1.contains(q)));

    final Instant later = time.plusSeconds(10L);
    add.clear();
    delete.add(title);
    add.add(rdf.createQuad(Trellis.PreferUserManaged, identifier, DC.title, rdf.createLiteral("Other Title")));
    add.add(rdf.createQuad(Trellis.PreferUserManaged, identifier, RDFS.label, rdf.createLiteral("Label")));
    RDFPatch.write(file, delete.stream(), add.stream(), later);
    final List<Quad> data2 = RDFPatch.asStream(rdf, file, identifier, later).collect(toList());
    assertEquals(data2.size(), data1.size() - delete.size() + add.size());
    add.forEach(q -> assertTrue(data2.contains(q)));
    delete.forEach(q -> assertFalse(data2.contains(q)));
    assertFalse(data2.contains(title));

    RDFPatch.write(file, empty(), of(rdf.createQuad(LDP.PreferContainment, identifier, LDP.contains,
            rdf.createIRI("trellis:repository/resource/1"))), later.plusSeconds(10L));

    final List<VersionRange> versions = RDFPatch.asTimeMap(file);
    assertEquals(1L, versions.size());
    assertEquals(time.truncatedTo(MILLIS), versions.get(0).getFrom().truncatedTo(MILLIS));
    assertEquals(later.truncatedTo(MILLIS), versions.get(0).getUntil().truncatedTo(MILLIS));
}