Java Code Examples for java.time.Instant.parse()

The following are Jave code examples for showing how to use parse() of the java.time.Instant class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: pure-bliss-with-pure-java-functions   File: OfflineDevicesJobTests.java   View Source Code Vote up 6 votes
@Test
public void thatPushNotificationIsSentWhenLastThresholdWasPassedAndLastSentNotificationWasForPreviousThreshold() throws Exception {
    Duration firstThreshold = Duration.ofDays(1);
    Duration secondThreshold = Duration.ofDays(2);
    Instant disconnectInstant = Instant.parse("2010-10-10T10:10:00.00Z");
    Instant lastOfflineNotificationInstant = disconnectInstant.plus(firstThreshold).plusSeconds(1);
    Instant jobRunInstant = disconnectInstant.plus(secondThreshold).plusSeconds(1);

    when(pushNotificationService.getLastOfflineNotificationInstant(any(Device.class))).thenReturn(Optional.of(lastOfflineNotificationInstant));

    when(clock.instant()).thenReturn(disconnectInstant);

    offlineDevicesJob.onConfigurationUpdate(Arrays.asList(firstThreshold, secondThreshold));
    offlineDevicesJob.onDeviceDisconnect(new Device(UUID.randomUUID()));

    when(clock.instant()).thenReturn(jobRunInstant);

    offlineDevicesJob.run();

    verify(pushNotificationService, times(1)).sendOfflineNotification(any(Device.class));
}
 
Example 2
Project: pure-bliss-with-pure-java-functions   File: OfflineDevicesJobTests.java   View Source Code Vote up 6 votes
@Test
public void thatPushNotificationIsSentWhenThresholdWasPassedAndNoNotificationWasEverSent() throws Exception {
    Duration firstThreshold = Duration.ofDays(1);
    Duration secondThreshold = Duration.ofDays(2);
    Instant disconnectInstant = Instant.parse("2010-10-10T10:10:00.00Z");
    Instant jobRunInstant = disconnectInstant.plus(firstThreshold).plusSeconds(1);

    when(pushNotificationService.getLastOfflineNotificationInstant(any(Device.class))).thenReturn(Optional.empty());

    when(clock.instant()).thenReturn(disconnectInstant);

    offlineDevicesJob.onConfigurationUpdate(Arrays.asList(firstThreshold, secondThreshold));
    offlineDevicesJob.onDeviceDisconnect(new Device(UUID.randomUUID()));

    when(clock.instant()).thenReturn(jobRunInstant);

    offlineDevicesJob.run();

    verify(pushNotificationService, times(1)).sendOfflineNotification(any(Device.class));
}
 
Example 3
Project: swblocks-decisiontree   File: InputTest.java   View Source Code Vote up 6 votes
@Test
public void testConstructionOfInput() {
    final Instant evaluationTime = Instant.parse("2013-03-28T00:00:00Z");
    final Input input = Input.create("TestRuleSetName",
            DecisionTreeRuleSet.convertNamesToWeightedDrivers(Arrays.asList("driver1", "driver2")),
            evaluationTime);
    assertEquals("TestRuleSetName", input.getRuleSetName());

    assertEquals("*", input.getValueForDriverName("driver1"));
    assertEquals("*", input.getValueForDriverName("driver2"));
    assertEquals(evaluationTime, input.getEvaluationDate());

    assertEquals(Arrays.asList("*", "*"), input.getEvaluationInputs());

    assertEquals("Input{driverMap={WeightedDriver{name='driver1', weight=4}=*, " +
            "WeightedDriver{name='driver2', weight=2}=*}, " +
            "ruleSetName='TestRuleSetName', " +
            "evaluationDate=2013-03-28T00:00:00Z}", input.toString());
}
 
Example 4
Project: boohee_v5.6   File: Jdk8DateCodec.java   View Source Code Vote up 5 votes
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
    JSONLexer lexer = parser.getLexer();
    if (lexer.token() == 4) {
        String text = lexer.stringVal();
        lexer.nextToken();
        if (type == LocalDateTime.class) {
            return LocalDateTime.parse(text);
        }
        if (type == LocalDate.class) {
            return LocalDate.parse(text);
        }
        if (type == LocalTime.class) {
            return LocalTime.parse(text);
        }
        if (type == ZonedDateTime.class) {
            return ZonedDateTime.parse(text);
        }
        if (type == OffsetDateTime.class) {
            return OffsetDateTime.parse(text);
        }
        if (type == OffsetTime.class) {
            return OffsetTime.parse(text);
        }
        if (type == ZoneId.class) {
            return ZoneId.of(text);
        }
        if (type == Period.class) {
            return Period.parse(text);
        }
        if (type == Duration.class) {
            return Duration.parse(text);
        }
        if (type == Instant.class) {
            return Instant.parse(text);
        }
        return null;
    }
    throw new UnsupportedOperationException();
}
 
Example 5
Project: kafka-connect-github-source   File: TimestampValidator.java   View Source Code Vote up 5 votes
@Override
public void ensureValid(String name, Object value) {
    String timestamp = (String) value;
    try {
        Instant.parse(timestamp);
    } catch (DateTimeParseException e) {
        throw new ConfigException(name, value, "Wasn't able to parse the timestamp, make sure it is formatted according to ISO-8601 standards");
    }


}
 
Example 6
Project: Supreme-Bot   File: Util.java   View Source Code Vote up 5 votes
public static final Instant stringToInstant(String text) {
    try {
        return Instant.parse(text);
    } catch (Exception ex) {
        try {
            return Instant.ofEpochMilli(Long.parseLong(text));
        } catch (Exception ex2) {
            try {
                return Timestamp.valueOf(text).toInstant();
            } catch (Exception ex3) {
                return null;
            }
        }
    }
}
 
Example 7
Project: ripostiglio   File: SimpleEventFactoryTest.java   View Source Code Vote up 5 votes
@Test
public void createAnItemEvictedEvent() throws Exception {

  Instant fixedInstant = Instant.parse("2017-04-07T10:02:05.456Z");
  Clock clock = Clock.fixed(fixedInstant, ZoneId.of("+02:00"));
  Item item = anItem().withName("item name").build();

  Event<Item> event = new SimpleEventFactory(clock).newItemEvictedEvent(item);

  assertThat(event.created(), is(fixedInstant));
  assertThat(event.body(), is(item));
}
 
Example 8
Project: ripostiglio   File: SimpleEventFactoryTest.java   View Source Code Vote up 5 votes
@Test
public void createAnItemStoredEvent() throws Exception {

  Instant fixedInstant = Instant.parse("2017-03-21T22:35:18.123Z");
  Clock clock = Clock.fixed(fixedInstant, ZoneId.of("+01:00"));
  Item item = anItem().withName("item name").build();

  Event<Item> event = new SimpleEventFactory(clock).newItemStoredEvent(item);

  assertThat(event.created(), is(fixedInstant));
  assertThat(event.body(), is(item));
}
 
Example 9
Project: scalable-coffee-shop   File: CoffeeBrewFinished.java   View Source Code Vote up 4 votes
public CoffeeBrewFinished(JsonObject jsonObject) {
    this(UUID.fromString(jsonObject.getString("orderId")), Instant.parse(jsonObject.getString("instant")));
}
 
Example 10
Project: xm-uaa   File: SystemEvent.java   View Source Code Vote up 4 votes
public void setStartDate(String startDate) {
    if (StringUtils.isNotBlank(startDate)) {
        this.startDate = Instant.parse(startDate);
    }
}
 
Example 11
Project: scalable-coffee-shop   File: CoffeeBrewStarted.java   View Source Code Vote up 4 votes
public CoffeeBrewStarted(JsonObject jsonObject) {
    this(new OrderInfo(jsonObject.getJsonObject("orderInfo")), Instant.parse(jsonObject.getString("instant")));
}
 
Example 12
Project: scalable-coffee-shop   File: OrderFinished.java   View Source Code Vote up 4 votes
public OrderFinished(JsonObject jsonObject) {
    this(UUID.fromString(jsonObject.getString("orderId")), Instant.parse(jsonObject.getString("instant")));
}
 
Example 13
Project: qpp-conversion-tool   File: UnprocessedCpcFileDataTest.java   View Source Code Vote up 4 votes
private static Stream<Instant> createdDateProvider() {
	Instant firstDateInstant = Instant.parse("2017-01-01T08:00:00.846Z");
	Instant secondDateInstant = Instant.parse("2018-01-01T08:00:00.846Z");
	return Stream.of(firstDateInstant, secondDateInstant);
}
 
Example 14
Project: scalable-coffee-shop   File: OrderAccepted.java   View Source Code Vote up 4 votes
public OrderAccepted(JsonObject jsonObject) {
    this(new OrderInfo(jsonObject.getJsonObject("orderInfo")), Instant.parse(jsonObject.getString("instant")));
}
 
Example 15
Project: scalable-coffee-shop   File: OrderBeansValidated.java   View Source Code Vote up 4 votes
public OrderBeansValidated(JsonObject jsonObject) {
    this(UUID.fromString(jsonObject.getString("orderId")), Instant.parse(jsonObject.getString("instant")));
}
 
Example 16
Project: swblocks-decisiontree   File: DomainSerialiser.java   View Source Code Vote up 4 votes
private static InputDriver getSingleDriver(final String currentDriver,
                                           final DriverCache cache,
                                           final InputValueType type) {
    InputDriver inputDriver = cache.get(currentDriver, type);

    if (inputDriver == null) {
        switch (type) {
            case STRING:
                inputDriver = new StringDriver(currentDriver);
                break;
            case REGEX:
                inputDriver = new RegexDriver(currentDriver.replace(RegexDriver.REGEX_PREFIX + ":", ""));
                break;
            case DATE_RANGE:
                final StringTokenizer tokenizer = new StringTokenizer(
                        currentDriver.replace(DateRangeDriver.DR_PREFIX + ":",""), "|", false);
                EhSupport.ensure(tokenizer.countTokens() == 2, "DateRange driver incorrectly formatted");
                inputDriver = new DateRangeDriver(currentDriver, new Range<>(Instant.parse(tokenizer.nextToken()),
                        Instant.parse(tokenizer.nextToken())));
                break;
            case INTEGER_RANGE:
                final StringTokenizer intTokenizer = new StringTokenizer(
                        currentDriver.replace(IntegerRangeDriver.IR_PREFIX + ":", ""), "|", true);
                EhSupport.ensure(intTokenizer.countTokens() == 2 || intTokenizer.countTokens() == 3,
                        "Integer Range driver incorrectly formatted");
                if (intTokenizer.countTokens() == 3) {
                    final String minValue = intTokenizer.nextToken();
                    intTokenizer.nextToken();
                    final String maxValue = intTokenizer.nextToken();
                    inputDriver = new IntegerRangeDriver(currentDriver, new Range<>(Integer.parseInt(minValue),
                            Integer.parseInt(maxValue)));
                } else {
                    final String firstToken = intTokenizer.nextToken();
                    if ("|".equals(firstToken)) {
                        inputDriver = new IntegerRangeDriver(currentDriver, new Range<>(MIN_INTEGER,
                                Integer.parseInt(intTokenizer.nextToken())));
                    } else {
                        inputDriver = new IntegerRangeDriver(currentDriver, new Range<>(Integer.parseInt(firstToken),
                                MAX_INTEGER));
                    }
                }
                break;
            default:
                inputDriver = null;
                break;
        }
        if (inputDriver != null) {
            cache.put(inputDriver);
        }
    }
    return inputDriver;
}
 
Example 17
Project: pgcodekeeper   File: TimestampPgData.java   View Source Code Vote up 4 votes
@Override
public Instant valueFromString(String s) {
    return Instant.parse(s);
}
 
Example 18
Project: scalable-coffee-shop   File: OrderDelivered.java   View Source Code Vote up 4 votes
public OrderDelivered(JsonObject jsonObject) {
    this(UUID.fromString(jsonObject.getString("orderId")), Instant.parse(jsonObject.getString("instant")));
}
 
Example 19
Project: scalable-coffee-shop   File: OrderFinished.java   View Source Code Vote up 4 votes
public OrderFinished(JsonObject jsonObject) {
    this(UUID.fromString(jsonObject.getString("orderId")), Instant.parse(jsonObject.getString("instant")));
}
 
Example 20
Project: scalable-coffee-shop   File: BeansFetched.java   View Source Code Vote up 2 votes
public BeansFetched(final JsonObject jsonObject) {
    this(jsonObject.getString("beanOrigin"), Instant.parse(jsonObject.getString("instant")));

}