java.time.LocalDateTime Java Examples

The following examples show how to use java.time.LocalDateTime. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DateUtilTests.java    From lion with Apache License 2.0 7 votes vote down vote up
@Test
public void testDate() {
    System.out.println(DateUtil.getCurrentYear());
    System.out.println(DateUtil.getCurrentYearMonth());
    System.out.println(DateUtil.getCurrentDate());
    System.out.println(DateUtil.getCurrentDateShort());
    System.out.println(DateUtil.getCurrentDate("yyyy/MM/dd"));
    System.out.println(DateUtil.getCurrentDateTime());
    System.out.println(DateUtil.getCurrentDateTimeShort());
    System.out.println(DateUtil.getCurrentDateTime("yyyy/MM/dd HH:mm:ss"));
    System.out.println(DateUtil.getTimestamp());
    System.out.println(DateUtil.intervalDays(LocalDate.of(2020, 5, 7), LocalDate.of(2020, 5, 9)));
    System.out.println(DateUtil.intervalHours(LocalDateTime.of(2020, 5, 7, 12, 30, 10), LocalDateTime.of(2020, 5, 7, 13, 30, 12)));
    System.out.println(DateUtil.intervalMinutes(LocalDateTime.of(2020, 5, 7, 12, 30, 10), LocalDateTime.of(2020, 5, 7, 13, 30, 12)));
    System.out.println(DateUtil.intervalMillis(LocalDateTime.of(2020, 5, 7, 12, 30, 10), LocalDateTime.of(2020, 5, 7, 13, 30, 12)));
}
 
Example #2
Source File: TCKLocalDate.java    From openjdk-jdk9 with GNU General Public License v2.0 7 votes vote down vote up
@DataProvider(name="epochSecond")
Object[][] provider_toEpochSecond() {
    return new Object[][] {
        {LocalDate.of(1858, 11, 17).toEpochSecond(LocalTime.MIDNIGHT, OFFSET_PONE), -3506720400L},
        {LocalDate.of(1, 1, 1).toEpochSecond(LocalTime.NOON, OFFSET_PONE), -62135557200L},
        {LocalDate.of(1995, 9, 27).toEpochSecond(LocalTime.of(5, 30), OFFSET_PTWO), 812172600L},
        {LocalDate.of(1970, 1, 1).toEpochSecond(LocalTime.MIDNIGHT, OFFSET_MTWO), 7200L},
        {LocalDate.of(-1, 12, 31).toEpochSecond(LocalTime.NOON, OFFSET_PONE), -62167266000L},
        {LocalDate.of(1, 1, 1).toEpochSecond(LocalTime.MIDNIGHT, OFFSET_PONE),
                Instant.ofEpochSecond(-62135600400L).getEpochSecond()},
        {LocalDate.of(1995, 9, 27).toEpochSecond(LocalTime.NOON, OFFSET_PTWO),
                Instant.ofEpochSecond(812196000L).getEpochSecond()},
        {LocalDate.of(1995, 9, 27).toEpochSecond(LocalTime.of(5, 30), OFFSET_MTWO),
                LocalDateTime.of(1995, 9, 27, 5, 30).toEpochSecond(OFFSET_MTWO)},
    };
}
 
Example #3
Source File: TCKOffsetDateTime.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.of(2012, 3, 4, 1, 1, 1, 100, ZoneOffset.UTC), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.MAX, OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.MIN, OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
            {OffsetDateTime.MAX, OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.of(OffsetDateTime.MAX.toLocalDateTime(), ZoneOffset.ofHours(-18)), null},
            {OffsetDateTime.MIN, OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.of(OffsetDateTime.MIN.toLocalDateTime(), ZoneOffset.ofHours(18)), null},


            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE),
                    ZonedDateTime.of(2012, 3, 4, 1, 1, 1, 100, ZONE_GAZA), ZonedDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZONE_GAZA), null},

            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException.class},
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), LocalTime.of(22, 3, 0), null, DateTimeException.class},
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetTime.of(22, 3, 0, 0, ZoneOffset.UTC), null, DateTimeException.class},
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null, null, NullPointerException.class},

    };
}
 
Example #4
Source File: TCKZoneRules.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void test_Paris_getOffsetInfo_gap() {
    ZoneRules test = europeParis();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 30, 2, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, OFFSET_PONE, GAP);
    assertEquals(trans.isGap(), true);
    assertEquals(trans.isOverlap(), false);
    assertEquals(trans.getOffsetBefore(), OFFSET_PONE);
    assertEquals(trans.getOffsetAfter(), OFFSET_PTWO);
    assertEquals(trans.getInstant(), createInstant(2008, 3, 30, 1, 0, ZoneOffset.UTC));
    assertEquals(trans.isValidOffset(OFFSET_ZERO), false);
    assertEquals(trans.isValidOffset(OFFSET_PONE), false);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Gap at 2008-03-30T02:00+01:00 to +02:00]");

    assertFalse(trans.equals(null));
    assertFalse(trans.equals(OFFSET_PONE));
    assertTrue(trans.equals(trans));

    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
 
Example #5
Source File: EntityTypeSerializer.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
public EntityTypeSerializer()
{
    // TODO A ton more types need to be added here
    dataTypes.put( String.class.getName(), XMLSchema.STRING );
    dataTypes.put( Integer.class.getName(), XMLSchema.INT );
    dataTypes.put( Boolean.class.getName(), XMLSchema.BOOLEAN );
    dataTypes.put( Byte.class.getName(), XMLSchema.BYTE );
    dataTypes.put( BigDecimal.class.getName(), XMLSchema.DECIMAL );
    dataTypes.put( Double.class.getName(), XMLSchema.DOUBLE );
    dataTypes.put( Long.class.getName(), XMLSchema.LONG );
    dataTypes.put( Short.class.getName(), XMLSchema.SHORT );
    dataTypes.put( Instant.class.getName(), XMLSchema.LONG );
    dataTypes.put( OffsetDateTime.class.getName(), XMLSchema.DATETIME );
    dataTypes.put( ZonedDateTime.class.getName(), XMLSchema.DATETIME );
    dataTypes.put( LocalDateTime.class.getName(), XMLSchema.DATETIME );
    dataTypes.put( LocalDate.class.getName(), XMLSchema.DATE );
    dataTypes.put( LocalTime.class.getName(), XMLSchema.TIME );
    dataTypes.put( Duration.class.getName(), XMLSchema.DURATION );
    dataTypes.put( Period.class.getName(), XMLSchema.DURATION );
}
 
Example #6
Source File: TestDateTimeSchema.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
private void testDateTimeSchema() {
  Date date = new Date();
  TestMgr.check(date.getTime(), dateTimeSchemaInf.getDate(date).getTime());
  TestMgr.check(date.getTime(), dateTimeSchemaInf.getDatePath(date).getTime());
  TestMgr.check(date.getTime(), dateTimeSchemaInf.postDate(date).getTime());

  LocalDate localDate = LocalDate.of(2020, 2, 1);
  TestMgr.check(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
      dateTimeSchemaInf.getLocalDate(localDate).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
  TestMgr.check(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
      dateTimeSchemaInf.getLocalDatePath(localDate).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
  TestMgr.check(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
      dateTimeSchemaInf.postLocalDate(localDate).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));

  LocalDateTime localDateTime = LocalDateTime.of(2020, 2, 1, 23, 23, 30, 333);
  TestMgr.check(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")),
      dateTimeSchemaInf.getLocalDateTime(localDateTime)
          .format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")));
  TestMgr.check(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")),
      dateTimeSchemaInf.getLocalDateTimePath(localDateTime)
          .format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")));
  TestMgr.check(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")),
      dateTimeSchemaInf.postLocalDateTime(localDateTime)
          .format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")));
}
 
Example #7
Source File: ProcessInstanceVariableResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testGetProcessInstanceLocalDateTimeVariable() throws Exception {

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    LocalDateTime now = LocalDateTime.now();
    LocalDateTime nowWithoutNanos = now.truncatedTo(ChronoUnit.MILLIS);
    runtimeService.setVariable(processInstance.getId(), "variable", now);

    CloseableHttpResponse response = executeRequest(
            new HttpGet(
                    SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "variable")),
            HttpStatus.SC_OK);

    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());

    closeResponse(response);
    assertThat(responseNode).isNotNull();
    assertThatJson(responseNode)
            .when(Option.IGNORING_EXTRA_FIELDS)
            .isEqualTo("{"
                    + "  name: 'variable',"
                    + "  type: 'localDateTime',"
                    + "  value: '" + nowWithoutNanos.toString() + "'"
                    + "}");
}
 
Example #8
Source File: WechatAppAlert.java    From redis-manager with Apache License 2.0 6 votes vote down vote up
private String buildMessage(List<AlertRecord> alertRecordList) {
    AlertRecord firstRecord = alertRecordList.get(0);
    StringBuffer message = new StringBuffer();
    message.append("Group Name: ").append(firstRecord.getGroupName()).append(NEW_LINE)
            .append("Cluster Name: ").append(firstRecord.getClusterName()).append(NEW_LINE);
    alertRecordList.forEach(alertRecord -> {
        message.append("Redis Node: ").append(alertRecord.getRedisNode()).append(NEW_LINE)
                .append("Alert Rule: ").append(alertRecord.getAlertRule()).append(NEW_LINE)
                .append("Actual Value: ").append(alertRecord.getActualData()).append(NEW_LINE);
        String ruleInfo = alertRecord.getRuleInfo();
        if (!Strings.isNullOrEmpty(ruleInfo)) {
            message.append("Rule Info: ").append(alertRecord.getRuleInfo()).append(NEW_LINE);
        }
        message.append(NEW_LINE);
    });
    message.append("Time: ").append(LocalDateTime.now().format(TIME_FORMATTER));
    return message.toString();
}
 
Example #9
Source File: RoleOrg.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@Builder
public RoleOrg(Long id, LocalDateTime createTime, Long createUser,
               Long roleId, Long orgId) {
    this.id = id;
    this.createTime = createTime;
    this.createUser = createUser;
    this.roleId = roleId;
    this.orgId = orgId;
}
 
Example #10
Source File: LocalDateTimeDeserTest.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeserializationAsEmptyArrayEnabled() throws Throwable
{
    LocalDateTime value = READER
           .with(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)
           .with(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT)
           .readValue("[]");
    assertNull(value);
}
 
Example #11
Source File: InstantColumn.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
public DateTimeColumn asLocalDateTimeColumn(ZoneId zone) {
  LocalDateTime[] output = new LocalDateTime[data.size()];
  for (int i = 0; i < data.size(); i++) {
    Instant instant = PackedInstant.asInstant(data.getLong(i));
    if (instant == null) {
      output[i] = null;
    } else {
      output[i] = LocalDateTime.ofInstant(instant, zone);
    }
  }
  return DateTimeColumn.create(name(), output);
}
 
Example #12
Source File: SimulationResult.java    From cucumber-performance with MIT License 5 votes vote down vote up
public SimulationResult(SimulationResult result) {
	super(result.getName(), new Result(result.getResult().getStatus(),result.getResultDuration(),result.getResult().getError()) ,LocalDateTime.from(result.getStart()), LocalDateTime.from(result.getStop()));

	for (GroupResult gr: result.getChildResults())
	{
		totalRan += gr.getChildResults().size();
		GroupResult ngr = new GroupResult(gr);
		childResults.add(ngr);
	}
	this.updateStatus(childResults);
}
 
Example #13
Source File: TCKZonedDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_with_adjuster_LocalDate_retainOffset2() {
    ZoneId newYork = ZoneId.of("America/New_York");
    LocalDateTime ldt = LocalDateTime.of(2008, 11, 3, 1, 30);
    ZonedDateTime base = ZonedDateTime.of(ldt, newYork);
    assertEquals(base.getOffset(), ZoneOffset.ofHours(-5));
    ZonedDateTime test = base.with(LocalDate.of(2008, 11, 2));
    assertEquals(test.getOffset(), ZoneOffset.ofHours(-5));
}
 
Example #14
Source File: ArticleCommentRepositoryTests.java    From jakduk-api with MIT License 5 votes vote down vote up
@Before
public void setUp(){
    ArticleComment articleComment = repository.findTopByOrderByIdAsc().get();
    LocalDateTime localDateTime = DateUtils.dateToLocalDateTime(new ObjectId(articleComment.getId()).getDate());
    Long hours = ChronoUnit.MINUTES.between(localDateTime, LocalDateTime.now());
    LocalDateTime randomDate = localDateTime.plusMinutes(new Random().nextInt((int) (hours + 1)));
    randomArticleComment = repository.findTopByIdLessThanEqualOrderByIdDesc(new ObjectId(DateUtils.localDateTimeToDate(randomDate))).get();
}
 
Example #15
Source File: MockOrderStore.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
private Order newOrder() {
    final Order order = new Order();
    order.setId(1L);
    order.setDate(LocalDateTime.now().minusHours(2));
    order.setStatus(OrderStatus.SHIPPED);

    final ShoppingCart cart = mockShoppingCart.getShoppingCart();
    order.setSelections(cart.getSelections());
    order.setPrice(cart.getPrice());

    return order;
}
 
Example #16
Source File: PoloniexLendingHistory.java    From poloniex-api-java with MIT License 5 votes vote down vote up
public PoloniexLendingHistory(String id, String currency, BigDecimal rate, BigDecimal amount, BigDecimal duration, BigDecimal interest, BigDecimal fee, BigDecimal earned, LocalDateTime open, LocalDateTime close)
{
    this.id = id;
    this.currency = currency;
    this.rate = rate;
    this.amount = amount;
    this.duration = duration;
    this.interest = interest;
    this.fee = fee;
    this.earned = earned;
    this.open = open;
    this.close = close;
}
 
Example #17
Source File: Timestamp.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts this {@code Timestamp} object to a {@code LocalDateTime}.
 * <p>
 * The conversion creates a {@code LocalDateTime} that represents the
 * same year, month, day of month, hours, minutes, seconds and nanos
 * date-time value as this {@code Timestamp} in the local time zone.
 *
 * @return a {@code LocalDateTime} object representing the same date-time value
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public LocalDateTime toLocalDateTime() {
    return LocalDateTime.of(getYear() + 1900,
                            getMonth() + 1,
                            getDate(),
                            getHours(),
                            getMinutes(),
                            getSeconds(),
                            getNanos());
}
 
Example #18
Source File: DateUtils.java    From Raincat with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Parse date string.
 *
 * @param date the date
 * @return the string
 */
public static String parseDate(Date date) {
    Instant instant = date.toInstant();
    ZoneId zone = ZoneId.systemDefault();
    LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
    return formaterLocalDateTime(localDateTime);
}
 
Example #19
Source File: DateUtil.java    From charging_pile_cloud with MIT License 5 votes vote down vote up
/**
 * date转localDateTime并减一定的天数
 *
 * @param date
 * @return
 */
public static LocalDateTime dateToLocalDateTimeMiusDay(Date date, int dayNum) {
    if (date == null) {
        return null;
    }
    Instant instant = date.toInstant();
    ZoneId zoneId = ZoneId.systemDefault();
    return instant.atZone(zoneId).toLocalDateTime().minusDays(dayNum);
}
 
Example #20
Source File: TCKZoneIdPrinterParser.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("data_print")
public void test_print(LocalDateTime ldt, ZoneId zone, String expected) {
    ZonedDateTime zdt = ldt.atZone(zone);
    builder.appendZoneId();
    String output = builder.toFormatter().format(zdt);
    assertEquals(output, expected);
}
 
Example #21
Source File: AuthorizationCodeGrantTypeHandler.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public JsonObject createAccessToken(String clientId, MultivaluedMap<String, String> params) throws Exception {
    //1. code is required
    String code = params.getFirst("code");
    if (code == null || "".equals(code)) {
        throw new WebApplicationException("invalid_grant");
    }
    AuthorizationCode authorizationCode = entityManager.find(AuthorizationCode.class, code);
    if (!authorizationCode.getExpirationDate().isAfter(LocalDateTime.now())) {
        throw new WebApplicationException("code Expired !");
    }
    String redirectUri = params.getFirst("redirect_uri");
    //redirecturi match
    if (authorizationCode.getRedirectUri() != null && !authorizationCode.getRedirectUri().equals(redirectUri)) {
        //redirectUri params should be the same as the requested redirectUri.
        throw new WebApplicationException("invalid_grant");
    }
    //client match
    if (!clientId.equals(authorizationCode.getClientId())) {
        throw new WebApplicationException("invalid_grant");
    }

    //3. JWT Payload or claims
    String accessToken = getAccessToken(clientId, authorizationCode.getUserId(), authorizationCode.getApprovedScopes());
    String refreshToken = getRefreshToken(clientId, authorizationCode.getUserId(), authorizationCode.getApprovedScopes());

    return Json.createObjectBuilder()
            .add("token_type", "Bearer")
            .add("access_token", accessToken)
            .add("expires_in", expiresInMin * 60)
            .add("scope", authorizationCode.getApprovedScopes())
            .add("refresh_token", refreshToken)
            .build();
}
 
Example #22
Source File: Station.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Builder
public Station(Long id, LocalDateTime createTime, Long createUser, LocalDateTime updateTime, Long updateUser,
               String name, RemoteData<Long, Org> orgId, Boolean status, String describe) {
    this.id = id;
    this.createTime = createTime;
    this.createUser = createUser;
    this.updateTime = updateTime;
    this.updateUser = updateUser;
    this.name = name;
    this.org = orgId;
    this.status = status;
    this.describe = describe;
}
 
Example #23
Source File: TCKZonedDateTime.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minus_TemporalAmount_Duration() {
    Duration duration = Duration.ofSeconds(4L * 60 * 60 + 5L * 60 + 6L);
    ZonedDateTime t = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 12, 30, 59, 500), ZONE_0100);
    ZonedDateTime expected = ZonedDateTime.of(LocalDateTime.of(2008, 6, 1, 8, 25, 53, 500), ZONE_0100);
    assertEquals(t.minus(duration), expected);
}
 
Example #24
Source File: StringFormatUtils.java    From datakernel with Apache License 2.0 5 votes vote down vote up
public static LocalDateTime parseLocalDateTime(String string) {
	try {
		return LocalDateTime.parse(string, DATE_TIME_FORMATTER);
	} catch (DateTimeParseException e) {
		return LocalDateTime.parse(string);
	}
}
 
Example #25
Source File: TypeHelper.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public static String convertValue(String type, String value) throws AMLException
{
       Class<?> clazz = getClass(type);
       
       if (clazz == null) {
           throw new AMLException("Invalid type: " + type);
       } else if (clazz.equals(Object.class) || clazz.equals(LocalDateTime.class) || clazz.equals(LocalDate.class)
               || clazz.equals(LocalTime.class)) {
           throw new AMLException("Cannot convert " + clazz.getSimpleName());
       }

	return ObjectUtils.defaultIfNull(TypeConverter.convert(clazz, value), value);
}
 
Example #26
Source File: LocalDateTimeEncoding.java    From ndbc with Apache License 2.0 5 votes vote down vote up
@Override
public final void encodeBinary(final LocalDateTime value, final BufferWriter b) {
  final Instant instant = value.atOffset(ZoneOffset.UTC).toInstant();
  final long seconds = instant.getEpochSecond();
  final long micros = instant.getLong(ChronoField.MICRO_OF_SECOND) + (seconds * 1000000);
  b.writeLong(micros - POSTGRES_EPOCH_MICROS);
}
 
Example #27
Source File: LocalDateTimeDeserTest.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeserializationAsTimestamp04Milliseconds02() throws Exception
{
    ObjectReader r = READER
            .without(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
    LocalDateTime value = r.readValue("[2005,11,5,22,31,5,829]");
    LocalDateTime time = LocalDateTime.of(2005, Month.NOVEMBER, 5, 22, 31, 5, 829000000);
    assertEquals("The value is not correct.", time, value);
}
 
Example #28
Source File: LocalWeatherDataSimulator.java    From ElasticUtils with MIT License 5 votes vote down vote up
private LocalWeatherData createLocalWeatherData(final Station station, final LocalDateTime measuredTime) {
    final LocalWeatherData data = new LocalWeatherData();

    data.dateTime = DateUtilities.from(measuredTime, ZoneOffset.UTC);
    data.station = station;
    data.skyCondition = "CLR";
    data.temperature = 22.0f;
    data.stationPressure = 42.12f;
    data.windSpeed = 5.0f;

    return data;
}
 
Example #29
Source File: TestLocalDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_plusMinutes_noChange_oneDay_same() {
    LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.plusMinutes(24 * 60);
    assertSame(t.toLocalTime(), TEST_2007_07_15_12_30_40_987654321.toLocalTime());
}
 
Example #30
Source File: ListFields.java    From catatumbo with Apache License 2.0 4 votes vote down vote up
/**
 * @return the localDateTimeList
 */
public List<LocalDateTime> getLocalDateTimeList() {
  return localDateTimeList;
}