Example usage for java.util Date from

List of usage examples for java.util Date from

Introduction

In this page you can find the example usage for java.util Date from.

Prototype

public static Date from(Instant instant) 

Source Link

Document

Obtains an instance of Date from an Instant object.

Usage

From source file:com.vmware.photon.controller.api.client.resource.FlavorRestApiTest.java

@Test
public void testDelete() throws IOException {
    Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    FlavorApi flavorApi = new FlavorRestApi(restClient);

    Task task = flavorApi.delete("foo");
    assertEquals(task, responseTask);//from www.  j  av  a2s .co  m
}

From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java

@Test
public void testPerformStartOperationAsync() throws IOException, InterruptedException {
    final Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    VmApi vmApi = new VmApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    vmApi.performStartOperationAsync("foo", new FutureCallback<Task>() {
        @Override// w w  w.ja  va 2  s. c o  m
        public void onSuccess(@Nullable Task result) {
            assertEquals(result, responseTask);
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            fail(t.toString());
            latch.countDown();
        }
    });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java

@Test
public void testPerformStartOperationAsync() throws IOException, InterruptedException {
    final Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    VmApi vmApi = new VmRestApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    vmApi.performStartOperationAsync("foo", new FutureCallback<Task>() {
        @Override//from   w w w .j a va2  s  . c o m
        public void onSuccess(@Nullable Task result) {
            assertEquals(result, responseTask);
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            fail(t.toString());
            latch.countDown();
        }
    });

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
}

From source file:com.esri.geoportal.harvester.ckan.CkanBroker.java

/**
 * Parses ISO date/*from   ww w.j av  a  2  s  . c o  m*/
 *
 * @param strDate ISO date as string
 * @return date object or <code>null</code> if unable to parse date
 */
private Date parseIsoDate(String strDate) {
    try {
        return Date.from(ZonedDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(strDate)).toInstant());
    } catch (Exception ex) {
        return null;
    }
}

From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java

public static Date toDate(LocalDate localDate) throws BusinessException {
    return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}

From source file:org.apache.james.transport.mailets.DSNBounceTest.java

@Test
public void serviceShouldNotUpdateTheMailStateWhenNoSenderPassThroughIsTrue() throws Exception {
    FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME)
            .mailetContext(fakeMailContext).setProperty("passThrough", "true").build();
    dsnBounce.init(mailetConfig);/*from  w  ww . j  a v  a  2 s . c om*/

    FakeMail mail = FakeMail.builder().attribute("delivery-error", "Delivery error")
            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content")).name(MAILET_NAME)
            .recipient("recipient@domain.com").lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z")))
            .remoteAddr("remoteHost").build();

    dsnBounce.service(mail);

    assertThat(mail.getState()).isNull();
}

From source file:org.sonar.server.issue.IssueFieldsSetter.java

private static Date truncateMillis(@Nullable Date d) {
    if (d == null) {
        return null;
    }/*  ww  w  .  j  a v  a  2  s.  co  m*/
    return Date.from(d.toInstant().truncatedTo(ChronoUnit.SECONDS));
}

From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java

public static Date toDate(LocalDateTime localDateTime) throws BusinessException {
    return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}

From source file:org.ng200.openolympus.ContestTest.java

public Task createDummyTask() {
    Task task = new Task();
    task.setDescriptionFile(null);/*from w  w w  .j a v  a 2s.c om*/
    task.setPublished(true);
    task.setTaskLocation(null);
    task.setTimeAdded(Date.from(Instant.now()));
    task = this.taskService.saveTask(task);
    return task;
}

From source file:com.ikanow.aleph2.data_model.utils.TimeUtils.java

/** Returns a date from a human readable date - can only be in the future
 * @param human_readable_date - the date expressed in words, eg "next wednesday".. Uses some simple regexes (1h,d, 1month etc), and Natty (try examples http://natty.joestelmach.com/try.jsp#)
 * @param base_date - for relative date, locks the date to this origin
 * @return the machine readable date, or an error
 *//*from  w w w.j  a  v  a 2  s .  com*/
public static Validation<String, Date> getForwardSchedule(final String human_readable_date,
        Optional<Date> base_date) {
    final Date adjusted_date = base_date.orElse(new Date());
    return _adjustments.stream()
            .map(adjust -> Date.from(adjusted_date.toInstant().plus(adjust._1(), adjust._2()))) // (adjust the date by the increasing adjustment)
            .map(adjusted -> getSchedule(human_readable_date, Optional.of(adjusted)))
            .filter(parsed -> parsed.isSuccess())
            .filter(parsed -> parsed.success().getTime() >= adjusted_date.getTime()).findFirst()
            .orElse(Validation
                    .fail(ErrorUtils.get(ErrorUtils.INVALID_DATETIME_FORMAT_PAST, human_readable_date)));
}