So I have a LocalDateTime parser which accepts a date as a String. I have wrote several tests for it e.g. checking for leap year and some more.
Now I want a JUnit test to check for a leap second. I did some research and found that probably it is not possible with java.time(?). So far I found a suitable date on which a leap second occured.
Here is what I've tried so far:
@Test
@DisplayName("Check for leap second")
void shouldLeapSecondOccurReturnExactlyTwoMinuteSpan() {
String leapSecond = "2015-06-30T23:59:00+0000";
String leapSecond2 = "2015-07-01T00:01:00";
Assertions.assertTrue(DateConvertUtils.parseIso8601ToUTC(leapSecond)
.isEqual(LocalDateTime.parse(leapSecond2).minusSeconds(120)));
}
While DateConvertUtils contains my above mentioned parser and a custom DateTimeFormatter.
I appreciate any help to the right direction.
Well, leap seconds are ignored by most libraries including
java.time-package. My lib Time4J however, supports it. Example using your input:Objects of type Moment can be easily converted to/from
java.time.Instantif you are willing to loose the possible leap second information (in case you have2015-06-30T23:60Z).Good to know: You really need at least a class connected to UTC timeline. Classes like
LocalDateTimehave no concept of time zones so they have no connection to UTC and are unusable for determining leap seconds by definition.More background information can be found in my DZone paper.