Example usage for java.time Instant minus

List of usage examples for java.time Instant minus

Introduction

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

Prototype

@Override
public Instant minus(long amountToSubtract, TemporalUnit unit) 

Source Link

Document

Returns a copy of this instant with the specified amount subtracted.

Usage

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
    instant = instant.minus(100, ChronoUnit.DAYS);
    System.out.println(instant);//from w w  w.  j a va  2 s.  c o m

}

From source file:io.pivotal.strepsirrhini.chaosloris.reaper.EventReaperTest.java

@Test
public void doReap() {
    Schedule schedule = new Schedule("test-schedule", "test-name");
    this.scheduleRepository.saveAndFlush(schedule);

    Application application = new Application(UUID.randomUUID());
    this.applicationRepository.saveAndFlush(application);

    Chaos chaos = new Chaos(application, 0.1, schedule);
    this.chaosRepository.saveAndFlush(chaos);

    Instant now = Instant.now();

    Event event1 = new Event(chaos, now.minus(3, DAYS), Collections.emptyList(), Integer.MIN_VALUE);
    this.eventRepository.saveAndFlush(event1);

    Event event2 = new Event(chaos, now, Collections.emptyList(), Integer.MIN_VALUE);
    this.eventRepository.saveAndFlush(event2);

    Event event3 = new Event(chaos, now.plus(3, DAYS), Collections.emptyList(), Integer.MIN_VALUE);
    this.eventRepository.saveAndFlush(event3);

    this.eventReaper.doReap().as(StepVerifier::create).expectNext(1L).expectComplete().verify();

    List<Event> events = this.eventRepository.findAll();
    assertThat(events).containsExactly(event2, event3);
}

From source file:io.pivotal.strepsirrhini.chaosloris.data.EventRepositoryTest.java

@Test
public void findByExecutedAtBefore() throws ExecutionException, InterruptedException {
    Schedule schedule = new Schedule("test-schedule", "test-name");
    this.scheduleRepository.saveAndFlush(schedule);

    Application application = new Application(UUID.randomUUID());
    this.applicationRepository.saveAndFlush(application);

    Chaos chaos = new Chaos(application, 0.1, schedule);
    this.chaosRepository.saveAndFlush(chaos);

    Instant now = Instant.now();

    Event event1 = new Event(chaos, now.minus(1, DAYS), Collections.emptyList(), Integer.MIN_VALUE);
    this.eventRepository.saveAndFlush(event1);

    Event event2 = new Event(chaos, now, Collections.emptyList(), Integer.MIN_VALUE);
    this.eventRepository.saveAndFlush(event2);

    Event event3 = new Event(chaos, now.plus(1, DAYS), Collections.emptyList(), Integer.MIN_VALUE);
    this.eventRepository.saveAndFlush(event3);

    List<Event> events = this.eventRepository.findByExecutedAtBefore(now.minus(1, HOURS));
    assertThat(events).containsExactly(event1);
}

From source file:edu.usu.sdl.openstorefront.report.SubmissionsReport.java

private void updateReportTimeRange() {
    if (report.getReportOption().getPreviousDays() != null) {
        Instant instant = Instant.now();
        instant = instant.minus(1, ChronoUnit.DAYS);
        report.getReportOption().setStartDts(TimeUtil.beginningOfDay(new Date(instant.toEpochMilli())));
        report.getReportOption().setEndDts(TimeUtil.endOfDay(new Date(instant.toEpochMilli())));
    }//from  w ww  .  ja va2  s .c  om
    if (report.getReportOption().getStartDts() == null) {
        report.getReportOption().setStartDts(TimeUtil.beginningOfDay(new Date()));
    }
    if (report.getReportOption().getEndDts() == null) {
        report.getReportOption().setEndDts(TimeUtil.endOfDay(new Date()));
    }
}

From source file:org.jhk.pulsing.web.service.prod.PulseService.java

/**
 * Hmmm should work in DRPC from storm+trident to get notified of new batch and then send 
 * the message to client component for new set? Look into it since familiar only w/ trident
 * /*from   w  w w. java 2s  .c  o  m*/
 * @param numMinutes
 * @return
 */
@Override
public Map<Long, String> getTrendingPulseSubscriptions(int numMinutes) {

    Instant current = Instant.now();
    Instant beforeRange = current.minus(numMinutes, ChronoUnit.MINUTES);

    Optional<Set<String>> optTps = redisPulseDao.getTrendingPulseSubscriptions(beforeRange.getEpochSecond(),
            current.getEpochSecond());

    @SuppressWarnings("unchecked")
    Map<Long, String> tpSubscriptions = Collections.EMPTY_MAP;

    if (optTps.isPresent()) {
        tpSubscriptions = PulseServiceUtil.processTrendingPulseSubscribe(optTps.get(), _objectMapper);
    }
    ;

    return tpSubscriptions;
}

From source file:com.netflix.genie.web.tasks.node.DiskCleanupTaskTest.java

/**
 * Make sure we can run successfully when runAsUser is false for the system.
 *
 * @throws IOException    on error//from   w  w w  . j a v a 2  s.c o  m
 * @throws GenieException on error
 */
@Test
public void canRunWithoutSudo() throws IOException, GenieException {
    final JobsProperties jobsProperties = JobsProperties.getJobsPropertiesDefaults();
    jobsProperties.getUsers().setRunAsUserEnabled(false);

    // Create some random junk file that should be ignored
    this.tmpJobDir.newFile(UUID.randomUUID().toString());
    final DiskCleanupProperties properties = new DiskCleanupProperties();
    final Instant threshold = TaskUtils.getMidnightUTC().minus(properties.getRetention(), ChronoUnit.DAYS);

    final String job1Id = UUID.randomUUID().toString();
    final String job2Id = UUID.randomUUID().toString();
    final String job3Id = UUID.randomUUID().toString();
    final String job4Id = UUID.randomUUID().toString();
    final String job5Id = UUID.randomUUID().toString();

    final Job job1 = Mockito.mock(Job.class);
    Mockito.when(job1.getStatus()).thenReturn(JobStatus.INIT);
    final Job job2 = Mockito.mock(Job.class);
    Mockito.when(job2.getStatus()).thenReturn(JobStatus.RUNNING);
    final Job job3 = Mockito.mock(Job.class);
    Mockito.when(job3.getStatus()).thenReturn(JobStatus.SUCCEEDED);
    Mockito.when(job3.getFinished()).thenReturn(Optional.of(threshold.minus(1, ChronoUnit.MILLIS)));
    final Job job4 = Mockito.mock(Job.class);
    Mockito.when(job4.getStatus()).thenReturn(JobStatus.FAILED);
    Mockito.when(job4.getFinished()).thenReturn(Optional.of(threshold));

    this.createJobDir(job1Id);
    this.createJobDir(job2Id);
    this.createJobDir(job3Id);
    this.createJobDir(job4Id);
    this.createJobDir(job5Id);

    final TaskScheduler scheduler = Mockito.mock(TaskScheduler.class);
    final Resource jobDir = Mockito.mock(Resource.class);
    Mockito.when(jobDir.exists()).thenReturn(true);
    Mockito.when(jobDir.getFile()).thenReturn(this.tmpJobDir.getRoot());
    final JobSearchService jobSearchService = Mockito.mock(JobSearchService.class);

    Mockito.when(jobSearchService.getJob(job1Id)).thenReturn(job1);
    Mockito.when(jobSearchService.getJob(job2Id)).thenReturn(job2);
    Mockito.when(jobSearchService.getJob(job3Id)).thenReturn(job3);
    Mockito.when(jobSearchService.getJob(job4Id)).thenReturn(job4);
    Mockito.when(jobSearchService.getJob(job5Id)).thenThrow(new GenieServerException("blah"));

    final DiskCleanupTask task = new DiskCleanupTask(properties, scheduler, jobDir, jobSearchService,
            jobsProperties, Mockito.mock(Executor.class), new SimpleMeterRegistry());
    task.run();
    Assert.assertTrue(new File(jobDir.getFile(), job1Id).exists());
    Assert.assertTrue(new File(jobDir.getFile(), job2Id).exists());
    Assert.assertFalse(new File(jobDir.getFile(), job3Id).exists());
    Assert.assertTrue(new File(jobDir.getFile(), job4Id).exists());
    Assert.assertTrue(new File(jobDir.getFile(), job5Id).exists());
}