Java Code Examples for java.time.format.DateTimeFormatter#ISO_INSTANT

The following examples show how to use java.time.format.DateTimeFormatter#ISO_INSTANT . 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: PutSQL.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private DateTimeFormatter getDateTimeFormatter(String pattern) {
    switch(pattern) {
        case "BASIC_ISO_DATE": return DateTimeFormatter.BASIC_ISO_DATE;
        case "ISO_LOCAL_DATE": return DateTimeFormatter.ISO_LOCAL_DATE;
        case "ISO_OFFSET_DATE": return DateTimeFormatter.ISO_OFFSET_DATE;
        case "ISO_DATE": return DateTimeFormatter.ISO_DATE;
        case "ISO_LOCAL_TIME": return DateTimeFormatter.ISO_LOCAL_TIME;
        case "ISO_OFFSET_TIME": return DateTimeFormatter.ISO_OFFSET_TIME;
        case "ISO_TIME": return DateTimeFormatter.ISO_TIME;
        case "ISO_LOCAL_DATE_TIME": return DateTimeFormatter.ISO_LOCAL_DATE_TIME;
        case "ISO_OFFSET_DATE_TIME": return DateTimeFormatter.ISO_OFFSET_DATE_TIME;
        case "ISO_ZONED_DATE_TIME": return DateTimeFormatter.ISO_ZONED_DATE_TIME;
        case "ISO_DATE_TIME": return DateTimeFormatter.ISO_DATE_TIME;
        case "ISO_ORDINAL_DATE": return DateTimeFormatter.ISO_ORDINAL_DATE;
        case "ISO_WEEK_DATE": return DateTimeFormatter.ISO_WEEK_DATE;
        case "ISO_INSTANT": return DateTimeFormatter.ISO_INSTANT;
        case "RFC_1123_DATE_TIME": return DateTimeFormatter.RFC_1123_DATE_TIME;
        default: return DateTimeFormatter.ofPattern(pattern);
    }
}
 
Example 2
Source File: DataStoreJerseyTest.java    From emodb with Apache License 2.0 6 votes vote down vote up
/** Test getTimeline() with timestamp start/end instead of UUIDs. */
@Test
public void testGetTimelineRESTTimestampsForward() throws Exception {
    Date start = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2012-03-15 16:12:34.567");
    Date end = new Date();
    UUID startUuid = TimeUUIDs.uuidForTimestamp(start);
    UUID endUuid = TimeUUIDs.getPrevious(TimeUUIDs.uuidForTimeMillis(end.getTime() + 1));
    when(_server.getTimeline("table-name", "row-key", true, false, startUuid, endUuid, false, 10, ReadConsistency.STRONG))
            .thenReturn(Iterators.<Change>emptyIterator());

    DateTimeFormatter format = DateTimeFormatter.ISO_INSTANT;
    URI uri = UriBuilder.fromUri("/sor/1")
            .segment("table-name", "row-key", "timeline")
            .queryParam("start", format.format(start.toInstant()))
            .queryParam("end", format.format(end.toInstant()))
            .queryParam("reversed", "false")
            .build();
    _resourceTestRule.client().resource(uri)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .header(ApiKeyRequest.AUTHENTICATION_HEADER, APIKEY_TABLE)
            .get(new GenericType<List<Change>>() {
            });

    verify(_server).getTimeline("table-name", "row-key", true, false, startUuid, endUuid, false, 10, ReadConsistency.STRONG);
    verifyNoMoreInteractions(_server);
}
 
Example 3
Source File: DataStoreJerseyTest.java    From emodb with Apache License 2.0 6 votes vote down vote up
/** Test getTimeline() with timestamp start/end instead of UUIDs. */
@Test
public void testGetTimelineRESTTimestampsReversed() throws Exception {
    Date start = new Date();
    Date end = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2012-03-15 16:12:34.567");
    UUID startUuid = TimeUUIDs.getPrevious(TimeUUIDs.uuidForTimeMillis(start.getTime() + 1));
    UUID endUuid = TimeUUIDs.uuidForTimestamp(end);
    when(_server.getTimeline("table-name", "row-key", true, false, startUuid, endUuid, true, 10, ReadConsistency.STRONG))
            .thenReturn(Iterators.<Change>emptyIterator());

    DateTimeFormatter format = DateTimeFormatter.ISO_INSTANT;
    URI uri = UriBuilder.fromUri("/sor/1")
            .segment("table-name", "row-key", "timeline")
            .queryParam("start", format.format(start.toInstant()))
            .queryParam("end", format.format(end.toInstant()))
            .build();
    _resourceTestRule.client().resource(uri)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .header(ApiKeyRequest.AUTHENTICATION_HEADER, APIKEY_TABLE)
            .get(new GenericType<List<Change>>() {
            });

    verify(_server).getTimeline("table-name", "row-key", true, false, startUuid, endUuid, true, 10, ReadConsistency.STRONG);
    verifyNoMoreInteractions(_server);
}
 
Example 4
Source File: JdbcCommon.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static DateTimeFormatter getDateTimeFormatter(String pattern) {
    switch(pattern) {
        case "BASIC_ISO_DATE": return DateTimeFormatter.BASIC_ISO_DATE;
        case "ISO_LOCAL_DATE": return DateTimeFormatter.ISO_LOCAL_DATE;
        case "ISO_OFFSET_DATE": return DateTimeFormatter.ISO_OFFSET_DATE;
        case "ISO_DATE": return DateTimeFormatter.ISO_DATE;
        case "ISO_LOCAL_TIME": return DateTimeFormatter.ISO_LOCAL_TIME;
        case "ISO_OFFSET_TIME": return DateTimeFormatter.ISO_OFFSET_TIME;
        case "ISO_TIME": return DateTimeFormatter.ISO_TIME;
        case "ISO_LOCAL_DATE_TIME": return DateTimeFormatter.ISO_LOCAL_DATE_TIME;
        case "ISO_OFFSET_DATE_TIME": return DateTimeFormatter.ISO_OFFSET_DATE_TIME;
        case "ISO_ZONED_DATE_TIME": return DateTimeFormatter.ISO_ZONED_DATE_TIME;
        case "ISO_DATE_TIME": return DateTimeFormatter.ISO_DATE_TIME;
        case "ISO_ORDINAL_DATE": return DateTimeFormatter.ISO_ORDINAL_DATE;
        case "ISO_WEEK_DATE": return DateTimeFormatter.ISO_WEEK_DATE;
        case "ISO_INSTANT": return DateTimeFormatter.ISO_INSTANT;
        case "RFC_1123_DATE_TIME": return DateTimeFormatter.RFC_1123_DATE_TIME;
        default: return DateTimeFormatter.ofPattern(pattern);
    }
}
 
Example 5
Source File: InstantDeserializer.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected InstantDeserializer(InstantDeserializer<T> base, DateTimeFormatter f)
{
    super((Class<T>) base.handledType(), f);
    parsedToValue = base.parsedToValue;
    fromMilliseconds = base.fromMilliseconds;
    fromNanoseconds = base.fromNanoseconds;
    adjust = base.adjust;
    replaceZeroOffsetAsZ = (_formatter == DateTimeFormatter.ISO_INSTANT);
    _adjustToContextTZOverride = base._adjustToContextTZOverride;
}
 
Example 6
Source File: InstantDeserializer.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected InstantDeserializer(InstantDeserializer<T> base, DateTimeFormatter f, Boolean leniency)
{
    super((Class<T>) base.handledType(), f, leniency);
    parsedToValue = base.parsedToValue;
    fromMilliseconds = base.fromMilliseconds;
    fromNanoseconds = base.fromNanoseconds;
    adjust = base.adjust;
    replaceZeroOffsetAsZ = (_formatter == DateTimeFormatter.ISO_INSTANT);
    _adjustToContextTZOverride = base._adjustToContextTZOverride;
}
 
Example 7
Source File: GraphQLLocalDateTime.java    From graphql-java-datetime with Apache License 2.0 4 votes vote down vote up
public GraphQLLocalDateTime(boolean zoneConversionEnabled) {
    this(DEFAULT_NAME, zoneConversionEnabled, DateTimeFormatter.ISO_INSTANT);
}
 
Example 8
Source File: GraphQLLocalDateTime.java    From graphql-java-datetime with Apache License 2.0 4 votes vote down vote up
public GraphQLLocalDateTime(final String name, boolean zoneConversionEnabled) {
    this(name, zoneConversionEnabled, DateTimeFormatter.ISO_INSTANT);
}
 
Example 9
Source File: ScanUploadSchedulingServiceTest.java    From emodb with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(dataProvider = "every10minutes")
public void testParticipationNotification(Instant now)
        throws Exception {
    StashStateListener stashStateListener = mock(StashStateListener.class);
    LifeCycleRegistry lifecycle = mock(LifeCycleRegistry.class);

    ScheduledExecutorService participationExecutorService = spy(Executors.newScheduledThreadPool(1));

    Clock clock = Clock.fixed(Instant.ofEpochMilli(now.toEpochMilli()), ZoneId.systemDefault());

    // Start one hour in the future
    String startTime = DateTimeFormatter.ofPattern("HH:mmX").withZone(ZoneOffset.UTC).format(now.plus(Duration.ofHours(1)));

    ScheduledDailyScanUpload upload = new ScheduledDailyScanUpload(
            "daily", startTime, DateTimeFormatter.ISO_INSTANT, ScanDestination.discard(), DateTimeFormatter.ISO_INSTANT,
            ImmutableList.of("catalog_global:cat"), 5, true, false, 1000000, Duration.ofMinutes(10));

    ScanParticipationService service = new ScanParticipationService(
            ImmutableList.of(upload), stashStateListener, lifecycle, clock);

    service.setScheduledExecutorService(participationExecutorService);

    try {
        service.start();

        // Verify the runnable was scheduled one hour in the future, with 60 seconds of slop to account for the actual
        // scheduling taking place at anytime within the current minute.
        ArgumentCaptor<Runnable> runnable = ArgumentCaptor.forClass(Runnable.class);
        verify(participationExecutorService).scheduleAtFixedRate(
                runnable.capture(),
                longThat(withinNSeconds(60, Duration.ofHours(1).toMillis())),
                eq(Duration.ofDays(1).toMillis()),
                eq(TimeUnit.MILLISECONDS));


        // Verify running the scheduled executable announces the scan participation.
        verify(stashStateListener, never()).announceStashParticipation();
        runnable.getValue().run();
        verify(stashStateListener, times(1)).announceStashParticipation();
    } finally {
        service.stop();
        participationExecutorService.shutdownNow();
    }

}
 
Example 10
Source File: InstantXmlAdapter.java    From threeten-jaxb with Apache License 2.0 4 votes vote down vote up
public InstantXmlAdapter() {
    super(DateTimeFormatter.ISO_INSTANT, Instant::from);
}