Java Code Examples for org.threeten.bp.Instant#ofEpochSecond()

The following examples show how to use org.threeten.bp.Instant#ofEpochSecond() . 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: TestDateTimeParsing.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void test_parse_fromField_InstantSeconds_NanoOfSecond() {
    DateTimeFormatter fmt = new DateTimeFormatterBuilder()
        .appendValue(INSTANT_SECONDS).appendLiteral('.').appendValue(NANO_OF_SECOND).toFormatter();
    TemporalAccessor acc = fmt.parse("86402.123456789");
    Instant expected = Instant.ofEpochSecond(86402, 123456789);
    assertEquals(acc.isSupported(INSTANT_SECONDS), true);
    assertEquals(acc.isSupported(NANO_OF_SECOND), true);
    assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
    assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
    assertEquals(acc.getLong(INSTANT_SECONDS), 86402L);
    assertEquals(acc.getLong(NANO_OF_SECOND), 123456789L);
    assertEquals(acc.getLong(MICRO_OF_SECOND), 123456L);
    assertEquals(acc.getLong(MILLI_OF_SECOND), 123L);
    assertEquals(Instant.from(acc), expected);
}
 
Example 2
Source File: TestDateTimeParsing.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void test_parse_fromField_InstantSeconds() {
    DateTimeFormatter fmt = new DateTimeFormatterBuilder()
        .appendValue(INSTANT_SECONDS).toFormatter();
    TemporalAccessor acc = fmt.parse("86402");
    Instant expected = Instant.ofEpochSecond(86402);
    assertEquals(acc.isSupported(INSTANT_SECONDS), true);
    assertEquals(acc.isSupported(NANO_OF_SECOND), true);
    assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
    assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
    assertEquals(acc.getLong(INSTANT_SECONDS), 86402L);
    assertEquals(acc.getLong(NANO_OF_SECOND), 0L);
    assertEquals(acc.getLong(MICRO_OF_SECOND), 0L);
    assertEquals(acc.getLong(MILLI_OF_SECOND), 0L);
    assertEquals(Instant.from(acc), expected);
}
 
Example 3
Source File: DateTimeFormatterBuilder.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public boolean print(DateTimePrintContext context, StringBuilder buf) {
    ZoneId zone = context.getValue(TemporalQueries.zoneId());
    if (zone == null) {
        return false;
    }
    if (zone.normalized() instanceof ZoneOffset) {
        buf.append(zone.getId());
        return true;
    }
    TemporalAccessor temporal = context.getTemporal();
    boolean daylight = false;
    if (temporal.isSupported(INSTANT_SECONDS)) {
        Instant instant = Instant.ofEpochSecond(temporal.getLong(INSTANT_SECONDS));
        daylight = zone.getRules().isDaylightSavings(instant);
    }
    TimeZone tz = TimeZone.getTimeZone(zone.getId());
    int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT);
    String text = tz.getDisplayName(daylight, tzstyle, context.getLocale());
    buf.append(text);
    return true;
}
 
Example 4
Source File: DebugView.java    From u2020-mvp with Apache License 2.0 5 votes vote down vote up
private void setupBuildSection() {
    buildNameView.setText(BuildConfig.VERSION_NAME);
    buildCodeView.setText(String.valueOf(BuildConfig.VERSION_CODE));
    buildShaView.setText(BuildConfig.GIT_SHA);

    TemporalAccessor buildTime = Instant.ofEpochSecond(BuildConfig.GIT_TIMESTAMP);
    buildDateView.setText(DATE_DISPLAY_FORMAT.format(buildTime));
}
 
Example 5
Source File: TestDateTimeParsing.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@DataProvider(name = "instantNoZone")
Object[][] data_instantNoZone() {
    return new Object[][] {
        {INSTANT, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).toInstant()},
        {INSTANTSECONDS, "86402", Instant.ofEpochSecond(86402)},
        {INSTANTSECONDS_NOS, "86402.123456789", Instant.ofEpochSecond(86402, 123456789)},
    };
}
 
Example 6
Source File: DateTimeBuilder.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void mergeInstantFields0(ZoneId selectedZone) {
    Instant instant = Instant.ofEpochSecond(fieldValues.remove(INSTANT_SECONDS));
    ChronoZonedDateTime<?> zdt = chrono.zonedDateTime(instant, selectedZone);
    if (date == null) {
        addObject(zdt.toLocalDate());
    } else {
        resolveMakeChanges(INSTANT_SECONDS, zdt.toLocalDate());
    }
    addFieldValue(SECOND_OF_DAY, (long) zdt.toLocalTime().toSecondOfDay());
}
 
Example 7
Source File: DebugView.java    From u2020 with Apache License 2.0 5 votes vote down vote up
private void setupBuildSection() {
  buildNameView.setText(BuildConfig.VERSION_NAME);
  buildCodeView.setText(String.valueOf(BuildConfig.VERSION_CODE));
  buildShaView.setText(BuildConfig.GIT_SHA);

  TemporalAccessor buildTime = Instant.ofEpochSecond(BuildConfig.GIT_TIMESTAMP);
  buildDateView.setText(DATE_DISPLAY_FORMAT.format(buildTime));
}
 
Example 8
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public Instant apply(FromDecimalArguments a) {
  return Instant.ofEpochSecond(a.integer, a.fraction);
}
 
Example 9
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public Instant apply(FromDecimalArguments a) {
  return Instant.ofEpochSecond(a.integer, a.fraction);
}
 
Example 10
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public Instant apply(FromDecimalArguments a) {
  return Instant.ofEpochSecond(a.integer, a.fraction);
}
 
Example 11
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public Instant apply(FromDecimalArguments a) {
  return Instant.ofEpochSecond(a.integer, a.fraction);
}
 
Example 12
Source File: CustomInstantDeserializer.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public Instant apply(FromDecimalArguments a) {
  return Instant.ofEpochSecond(a.integer, a.fraction);
}
 
Example 13
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public Instant apply(FromDecimalArguments a) {
  return Instant.ofEpochSecond(a.integer, a.fraction);
}
 
Example 14
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public Instant apply(FromDecimalArguments a) {
  return Instant.ofEpochSecond(a.integer, a.fraction);
}
 
Example 15
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public Instant apply(FromDecimalArguments a) {
  return Instant.ofEpochSecond(a.integer, a.fraction);
}
 
Example 16
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public Instant apply(FromDecimalArguments a) {
  return Instant.ofEpochSecond(a.integer, a.fraction);
}
 
Example 17
Source File: CustomInstantDeserializer.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Override
public Instant apply(FromDecimalArguments a) {
  return Instant.ofEpochSecond(a.integer, a.fraction);
}
 
Example 18
Source File: ChronoZonedDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Converts this date-time to an {@code Instant}.
 * <p>
 * This returns an {@code Instant} representing the same point on the
 * time-line as this date-time. The calculation combines the
 * {@linkplain #toLocalDateTime() local date-time} and
 * {@linkplain #getOffset() offset}.
 *
 * @return an {@code Instant} representing the same instant, not null
 */
public Instant toInstant() {
    return Instant.ofEpochSecond(toEpochSecond(), toLocalTime().getNano());
}
 
Example 19
Source File: ChronoLocalDateTime.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Converts this date-time to an {@code Instant}.
 * <p>
 * This combines this local date-time and the specified offset to form
 * an {@code Instant}.
 *
 * @param offset  the offset to use for the conversion, not null
 * @return an {@code Instant} representing the same instant, not null
 */
public Instant toInstant(ZoneOffset offset) {
    return Instant.ofEpochSecond(toEpochSecond(offset), toLocalTime().getNano());
}