Skip to content

Commit

Permalink
Use exception for signaling leap second
Browse files Browse the repository at this point in the history
  • Loading branch information
ethlo committed Aug 12, 2019
1 parent 7276929 commit 2714120
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/main/java/com/ethlo/time/FastInternetDateTimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
public class FastInternetDateTimeUtil extends AbstractRfc3339 implements W3cDateTimeUtil
{
public static final int LEAP_SECOND_SECONDS = 60;
private final StdJdkInternetDateTimeUtil delegate = new StdJdkInternetDateTimeUtil();

private static final char PLUS = '+';
private static final char MINUS = '-';
private static final char DATE_SEPARATOR = '-';
Expand All @@ -48,6 +46,7 @@ public class FastInternetDateTimeUtil extends AbstractRfc3339 implements W3cDate
private static final char ZULU_UPPER = 'Z';
private static final char ZULU_LOWER = 'z';
private static final int[] widths = new int[]{100_000_000, 10_000_000, 1_000_000, 100_000, 10_000, 1_000, 100, 10, 1};
private final StdJdkInternetDateTimeUtil delegate = new StdJdkInternetDateTimeUtil();

@Override
public OffsetDateTime parseDateTime(String s)
Expand Down Expand Up @@ -414,7 +413,7 @@ else if (remaining == 0)
&& utcMinute == 59)
{
// Consider it a leap second
return OffsetDateTime.of(year, month, day, hour, minute, 59, fractions, offset).plusSeconds(1);
throw new LeapSecondException(OffsetDateTime.of(year, month, day, hour, minute, 59, fractions, offset).plusSeconds(1), second);
}
}
return OffsetDateTime.of(year, month, day, hour, minute, second, fractions, offset);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/ethlo/time/LeapSecondException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.ethlo.time;

public class LeapSecondException extends Throwable
{
}
4 changes: 2 additions & 2 deletions src/test/java/com/ethlo/time/FastCorrectnessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down

0 comments on commit 2714120

Please sign in to comment.