@Override protected Instant parse(String instantAsString) { return Instant.parse(instantAsString); }
@Override protected Instant parse(@Nullable final String input) throws Exception { return Instant.parse(input); } }
/** * Maps {@code stringValue} to {@code Instant}. * * @param stringValue source value as a {@code String} * @return mapped {@code stringValue} to {@code Instant} * @see Instant#parse(CharSequence) */ public static Instant toInstant(String stringValue) { return Instant.parse(stringValue); }
@Override protected Instant parse(String instantAsString) { return Instant.parse(instantAsString); }
@Override public Instant unconvert(final String stringValue) { return Instant.parse(stringValue); } }
@Override public Instant parse(String text, Locale locale) throws ParseException { if (text.length() > 0 && Character.isDigit(text.charAt(0))) { // assuming UTC instant a la "2007-12-03T10:15:30.00Z" return Instant.parse(text); } else { // assuming RFC-1123 value a la "Tue, 3 Jun 2008 11:05:30 GMT" return Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(text)); } }
@Override public Instant parse(String text, Locale locale) throws ParseException { if (text.length() > 0 && Character.isDigit(text.charAt(0))) { // assuming UTC instant a la "2007-12-03T10:15:30.00Z" return Instant.parse(text); } else { // assuming RFC-1123 value a la "Tue, 3 Jun 2008 11:05:30 GMT" return Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(text)); } }
@Override public long getCreated() { String date = json.get(CREATED).getAsString(); Instant instant = Instant.parse(date); return instant.toEpochMilli(); }
@Override protected Instant[] getSortedTestData() { return new Instant[] { Instant.EPOCH, Instant.parse("1970-01-01T00:00:00.001Z"), Instant.parse("1990-10-14T02:42:25.123Z"), Instant.parse("1990-10-14T02:42:25.123000001Z"), Instant.parse("1990-10-14T02:42:25.123000002Z"), Instant.parse("2013-08-12T14:15:59.478Z"), Instant.parse("2013-08-12T14:15:59.479Z"), Instant.parse("2040-05-12T18:00:45.999Z"), Instant.MAX }; } }
public DVChainTrade( @JsonProperty("_id") String id, @JsonProperty("createdAt") String createdAt, @JsonProperty("price") BigDecimal price, @JsonProperty("limitPrice") BigDecimal limitPrice, @JsonProperty("quantity") BigDecimal quantity, @JsonProperty("side") String side, @JsonProperty("user") DVChainUser user, @JsonProperty("asset") String asset, @JsonProperty("status") String status) { this.id = id; this.createdAt = Instant.parse(createdAt); this.price = price; this.quantity = quantity; this.side = side; this.user = user; this.asset = asset; this.status = status; this.limitPrice = limitPrice; }
@Override public Instant convert(byte[] source) { return Instant.parse(toString(source)); } }
private static void sendResponse( Channel channel, SocketAddress remoteAddress, ByteBuf id, int index, int report) { if (channel != null) { ByteBuf response = Unpooled.buffer(); response.writeBytes("SM".getBytes(StandardCharsets.US_ASCII)); response.writeByte(3); // protocol version response.writeByte(MSG_DATE_RECORD_ACK); response.writeBytes(id); response.writeInt( (int) ChronoUnit.SECONDS.between(Instant.parse("2000-01-01T00:00:00.00Z"), Instant.now())); response.writeByte(index); response.writeByte(report - 0x200); short checksum = (short) 0xF5A0; for (int i = 0; i < response.readableBytes(); i += 2) { checksum ^= response.getShortLE(i); } response.writeShort(checksum); channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } }
@Override public Instant fromString(final String str) { try { return Instant.parse(str); } catch (final DateTimeParseException ex) { final ConversionException exception = new ConversionException("Cannot parse value as instant", ex); exception.add("value", str); throw exception; } } }
@Test public void testCreateTokenWithUnorderedEvents() { DomainEventMessage<String> event1 = createEvent(0, Instant.parse("2007-12-03T10:15:30.00Z")); DomainEventMessage<String> event2 = createEvent(1, Instant.parse("2007-12-03T10:15:40.00Z")); DomainEventMessage<String> event3 = createEvent(2, Instant.parse("2007-12-03T10:15:50.00Z")); DomainEventMessage<String> event4 = createEvent(3, Instant.parse("2007-12-03T10:15:45.00Z")); DomainEventMessage<String> event5 = createEvent(4, Instant.parse("2007-12-03T10:15:42.00Z")); testSubject.appendEvents(event1, event2, event3, event4, event5); TrackingToken tokenAt = testSubject.createTokenAt(Instant.parse("2007-12-03T10:15:45.00Z")); List<EventMessage<?>> readEvents = testSubject.readEvents(tokenAt, false) .collect(toList()); assertEventStreamsById(Arrays.asList(event3, event4, event5), readEvents); }
@Test public void testCreateTokenAt() { DomainEventMessage<String> event1 = createEvent(0, Instant.parse("2007-12-03T10:15:00.00Z")); DomainEventMessage<String> event2 = createEvent(1, Instant.parse("2007-12-03T10:15:40.00Z")); DomainEventMessage<String> event3 = createEvent(2, Instant.parse("2007-12-03T10:15:35.00Z")); testSubject.appendEvents(event1, event2, event3); TrackingToken tokenAt = testSubject.createTokenAt(Instant.parse("2007-12-03T10:15:30.00Z")); List<EventMessage<?>> readEvents = testSubject.readEvents(tokenAt, false) .collect(toList()); assertEventStreamsById(Arrays.asList(event2, event3), readEvents); }
@Test public void testCreateTokenAtExactTime() { DomainEventMessage<String> event1 = createEvent(0, Instant.parse("2007-12-03T10:15:30.00Z")); DomainEventMessage<String> event2 = createEvent(1, Instant.parse("2007-12-03T10:15:40.00Z")); DomainEventMessage<String> event3 = createEvent(2, Instant.parse("2007-12-03T10:15:35.00Z")); testSubject.appendEvents(event1, event2, event3); TrackingToken tokenAt = testSubject.createTokenAt(Instant.parse("2007-12-03T10:15:30.00Z")); List<EventMessage<?>> readEvents = testSubject.readEvents(tokenAt, false) .collect(toList()); assertEventStreamsById(Arrays.asList(event1, event2, event3), readEvents); }
@Test public void testCreateTailToken() { DomainEventMessage<String> event1 = createEvent(0, Instant.parse("2007-12-03T10:15:00.00Z")); DomainEventMessage<String> event2 = createEvent(1, Instant.parse("2007-12-03T10:15:40.00Z")); DomainEventMessage<String> event3 = createEvent(2, Instant.parse("2007-12-03T10:15:35.00Z")); testSubject.appendEvents(event1, event2, event3); TrackingToken headToken = testSubject.createTailToken(); List<EventMessage<?>> readEvents = testSubject.readEvents(headToken, false) .collect(toList()); assertEventStreamsById(Arrays.asList(event1, event2, event3), readEvents); }
@Test public void testCreateHeadToken() { DomainEventMessage<String> event1 = createEvent(0, Instant.parse("2007-12-03T10:15:00.00Z")); DomainEventMessage<String> event2 = createEvent(1, Instant.parse("2007-12-03T10:15:40.00Z")); DomainEventMessage<String> event3 = createEvent(2, Instant.parse("2007-12-03T10:15:35.00Z")); testSubject.appendEvents(event1, event2, event3); TrackingToken headToken = testSubject.createHeadToken(); List<EventMessage<?>> readEvents = testSubject.readEvents(headToken, false) .collect(toList()); assertTrue(readEvents.isEmpty()); }
@Test public void testReadingDocumentWithFirstAMoveWithEpoch() { Instant hourly = Instant.parse("2018-02-12T00:59:59.999Z"); Instant minutely = Instant.parse("2018-02-12T00:00:59.999Z"); Date epochHourlyFirstCycle = Date.from(hourly); Date epochMinutelyFirstCycle = Date.from(minutely); Date epochHourlySecondCycle = Date.from(hourly.plusMillis(1)); Date epochMinutelySecondCycle = Date.from(minutely.plusMillis(1)); doTestEpochMove(epochHourlyFirstCycle.getTime(), RollCycles.MINUTELY); doTestEpochMove(epochHourlySecondCycle.getTime(), RollCycles.MINUTELY); doTestEpochMove(epochHourlyFirstCycle.getTime(), RollCycles.HOURLY); doTestEpochMove(epochHourlySecondCycle.getTime(), RollCycles.HOURLY); doTestEpochMove(epochHourlyFirstCycle.getTime(), RollCycles.DAILY); doTestEpochMove(epochHourlySecondCycle.getTime(), RollCycles.DAILY); doTestEpochMove(epochMinutelyFirstCycle.getTime(), RollCycles.MINUTELY); doTestEpochMove(epochMinutelySecondCycle.getTime(), RollCycles.MINUTELY); doTestEpochMove(epochMinutelyFirstCycle.getTime(), RollCycles.HOURLY); doTestEpochMove(epochMinutelySecondCycle.getTime(), RollCycles.HOURLY); doTestEpochMove(epochMinutelyFirstCycle.getTime(), RollCycles.DAILY); doTestEpochMove(epochMinutelySecondCycle.getTime(), RollCycles.DAILY); }
@Override public ValidationResult validate(final String subject, final String input, final ValidationContext context) { try { Instant.parse(input); return new ValidationResult.Builder().subject(subject).input(input).explanation("Valid ISO8061 Instant Date").valid(true).build(); } catch (final Exception e) { return new ValidationResult.Builder().subject(subject).input(input).explanation("Not a valid ISO8061 Instant Date, please enter in UTC time").valid(false).build(); } } };