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.hengyi.japp.tools.DateTimeUtil.java

public static Date toDate(LocalDateTime localDateTime) {
    return localDateTime == null ? null : Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}

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

@Test
public void testGetTask() throws Throwable {
    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_OK);
    TasksApi tasksApi = new TasksApi(this.restClient);

    Task task = tasksApi.getTask("foo");
    assertEquals(task, responseTask);//w w  w  . j  a  v a 2 s  . c  om
}

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

@Test
public void testGetTask() throws Throwable {
    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_OK);
    TasksApi tasksApi = new TasksRestApi(this.restClient);

    Task task = tasksApi.getTask("foo");
    assertEquals(task, responseTask);/*from  w  w w  .java  2  s  . c  o  m*/
}

From source file:com.javiermoreno.springboot.mvc.users.UserManagementServiceImplIT.java

@Test
public void checkNewUserIsSavedAndContainsCorrectPasswordHash() {
    DailyUser user = new DailyUser();
    user.setEmail("alice@wonderland.com");
    user.setBirthday(/*from ww  w.  j a va2s  .c  o  m*/
            Date.from(LocalDate.of(1976, Month.DECEMBER, 12).atStartOfDay(ZoneId.systemDefault()).toInstant()));
    service.registerNewUser(user, "secret", true);

    Assert.assertNotSame("Id correctly assigned", 0, user.getId());
    Assert.assertEquals("Password md5 is correctely encoded.", "5ebe2294ecd0e0f08eab7690d2a6ee69",
            user.getPassword());
}

From source file:org.sakaiproject.component.app.scheduler.jobs.cm.processor.sis.AbstractCMProcessor.java

public Date getDate(String str) {
    if (StringUtils.isBlank(str)) {
        return null;
    }/*from   w w  w.ja  v  a  2  s  .  c  o m*/
    DateTimeFormatter df = DateTimeFormatter.ofPattern(dateFormat);
    try {
        return Date.from(LocalDate.parse(str, df).atStartOfDay(ZoneId.systemDefault()).toInstant());
    } catch (DateTimeParseException dtpe) {
        throw new RuntimeException("Cannot parse the date from: " + str, dtpe);
    }
}

From source file:org.ng200.openolympus.validation.ContestDtoValidator.java

public void validate(final ContestDto contest, final Errors errors) {
    if (errors.hasErrors()) {
        return;//  w w  w .j ava2s  . c o m
    }
    final Date start = contest.getStartTime();
    final Date end = Date
            .from(contest.getStartTime().toInstant().plusMillis(contest.getDuration() * 1000 * 60));
    if (this.contestService.intersects(start, end) != null) {
        errors.rejectValue("startTime", "", "contest.add.form.errors.contestIntersects");
    }
}

From source file:com.fluke.realtime.data.RediffParser.java

public void fillData() {
    Timestamp lastUpdated = dao.getLastTimeStamp(name);
    Timestamp currentTime = Timestamp.from(Calendar.getInstance().toInstant());
    int lastMins = lastUpdated != null ? Util.getMinutes(Date.from(lastUpdated.toInstant())) : ((9 * 60) + 15);
    int currentMins = Util.getMinutes(Date.from(currentTime.toInstant()));
    if (currentMins - lastMins < 4) {
        //lost data of less than 4 mins. no need to process further
        return;//from   w  w w  . ja  va 2s  .  com
    }
    YahooIntradayParser parser = new YahooIntradayParser();
    IntradayDetails data = parser.getIntradayDetails(name);
    fillOldData(data);
}

From source file:com.chadekin.jadys.syntax.SqlNativeQuerySectionDetailedITest.java

@Test
public void shouldBuildAllSqlQuerySection() {
    // Arrange/*from  w  w  w. j ava2s . c  o m*/
    Calendar calendar = Calendar.getInstance();
    LocalDate localDate = LocalDate.of(2016, Month.DECEMBER, 14);
    Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
    String internalSql = DynamicSqlFactory.newQuery().select("cus.Id_").count("*", "cus.numberOfLocation")
            .from("dct_customer").as("cus").join("dct_location", "loc").on("loc.customerId").equal("cus.id_")
            .where("cus.companyId").equal(142576).and("cus.customerId").equal(1258).and("cus.customerName")
            .like("BSD GmbH").and("zipCode").like(StringUtils.EMPTY).and("cus.city").like("Paris")
            .and("country").like(null).and("cus.externalId").like("456753").and("cus.customerType")
            .like(CustomerType.KEY_ACCOUNT).and("cus.modifiedDate").greaterThanOrEqual("2016-10-14")
            .and("cus.modifiedDate").lessThanOrEqual(date).and("cus.modifiedByUserId")
            .in(Lists.newArrayList(125, 36, 587)).groupBy("loc.customerId").having("COUNT(loc.customerId)")
            .equal(2).orderBy("cus.externalId").asc().build();

    // Act
    String sql = DynamicSqlFactory.newQuery().select().count().from(internalSql).as("subQuery").build();

    // Assert
    assertThatSelect(sql);
    assertThatFrom(sql);
    assertThatJoin(sql);
    assertThatWhere(sql);
    assertThatAnd(sql);
    assertThatGroupBy(sql);
    assertThatHaving(sql);
    assertThatOrderBy(sql);
    assertThatAll(sql);
}

From source file:ta4jexamples.indicators.IndicatorsToChart.java

/**
 * Builds a JFreeChart time series from a Ta4j time series and an indicator.
 * @param tickSeries the ta4j time series
 * @param indicator the indicator/*from  ww w.j  ava2s . c  o  m*/
 * @param name the name of the chart time series
 * @return the JFreeChart time series
 */
private static org.jfree.data.time.TimeSeries buildChartTimeSeries(TimeSeries tickSeries,
        Indicator<Decimal> indicator, String name) {
    org.jfree.data.time.TimeSeries chartTimeSeries = new org.jfree.data.time.TimeSeries(name);
    for (int i = 0; i < tickSeries.getTickCount(); i++) {
        Tick tick = tickSeries.getTick(i);
        chartTimeSeries.add(new Day(Date.from(tick.getEndTime().toInstant())),
                indicator.getValue(i).toDouble());
    }
    return chartTimeSeries;
}

From source file:ta4jexamples.analysis.BuyAndSellSignalsToChart.java

/**
 * Builds a JFreeChart time series from a Ta4j time series and an indicator.
 * @param tickSeries the ta4j time series
 * @param indicator the indicator//ww  w  .  jav  a 2 s .  co  m
 * @param name the name of the chart time series
 * @return the JFreeChart time series
 */
private static org.jfree.data.time.TimeSeries buildChartTimeSeries(TimeSeries tickSeries,
        Indicator<Decimal> indicator, String name) {
    org.jfree.data.time.TimeSeries chartTimeSeries = new org.jfree.data.time.TimeSeries(name);
    for (int i = 0; i < tickSeries.getTickCount(); i++) {
        Tick tick = tickSeries.getTick(i);
        chartTimeSeries.add(new Minute(Date.from(tick.getEndTime().toInstant())),
                indicator.getValue(i).toDouble());
    }
    return chartTimeSeries;
}