public ZonedDateTime plusNanos(long amount) { return dt.plusNanos(amount); }
public ZonedDateTime plusNanos(long amount) { return dt.plusNanos(amount); }
public ZonedDateTime getEndTime() { if (startTime == null) { return null; } return startTime.plusNanos( duration * 1000); }
public ZonedDateTime plusNanos(long amount) { return dt.plusNanos(amount); }
/** * Returns a copy of this {@code ZonedDateTime} with the specified period in nanoseconds subtracted. * <p> * This operates on the instant time-line, such that subtracting one nano will * always be a duration of one nano earlier. * This may cause the local date-time to change by an amount other than one nano. * Note that this is a different approach to that used by days, months and years. * <p> * This instance is immutable and unaffected by this method call. * * @param nanos the nanos to subtract, may be negative * @return a {@code ZonedDateTime} based on this date-time with the nanoseconds subtracted, not null * @throws DateTimeException if the result exceeds the supported date range */ public ZonedDateTime minusNanos(long nanos) { return (nanos == Long.MIN_VALUE ? plusNanos(Long.MAX_VALUE).plusNanos(1) : plusNanos(-nanos)); }
@Override public String marshal(ZonedDateTime value) { if (value == null) { return null; } if (value.getNano() == 0 && OMIT_MILLIS_IF_ZERO.get()) { return formatterNoMillis.format(value); } else { return formatter.format( // round to millis value.plusNanos(500000).truncatedTo(ChronoUnit.MILLIS) ); } } }
@Test public void constructor_sets_header_properties_correctly() { // Arrange UUID aggregateId = UUID.randomUUID(); Random random = new Random(); long version = random.nextInt(Integer.MAX_VALUE) + 1L; ZonedDateTime occurrenceTime = ZonedDateTime.now().plusNanos(random.nextInt()); // Act IssueCreatedForTesting sut = new IssueCreatedForTesting( aggregateId, version, occurrenceTime); // Assert Assert.assertEquals(aggregateId, sut.getAggregateId()); Assert.assertEquals(version, sut.getVersion()); Assert.assertEquals(occurrenceTime, sut.getOccurrenceTime()); }
@Test public void sut_serializes_properties_of_ZonedDateTime_correctly() { // Arrange Random random = new Random(); MessageWithZonedDateTimeProperty message = new MessageWithZonedDateTimeProperty( ZonedDateTime.now(Clock.systemUTC()).plusNanos(random.nextInt())); JacksonMessageSerializer sut = new JacksonMessageSerializer(); // Act String value = sut.serialize(message); System.out.println("The serialized value is '" + value + "'."); Object actual = sut.deserialize(value); // Assert Assert.assertNotNull("The actual value is null.", actual); Assert.assertTrue( "The actual value is not an instance of MessageWithZonedDateTimeProperty.", actual instanceof MessageWithZonedDateTimeProperty); MessageWithZonedDateTimeProperty actualMessage = (MessageWithZonedDateTimeProperty)actual; Assert.assertEquals( message.getDateTime().toEpochSecond(), actualMessage.getDateTime().toEpochSecond()); }