Skip to content

Commit

Permalink
Fix #11 (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: Morten <[email protected]>
  • Loading branch information
ethlo and Morten authored Mar 27, 2023
1 parent 818a00f commit 402e2f5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/ethlo/time/internal/EthloITU.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ private int getFractions(final char[] chars, final int idx, final int len)
fractions = uncheckedParsePositiveInt(chars, 20, idx);
switch (len)
{
case 0:
throw new DateTimeException("Must have at least 1 fraction digit");
case 1:
return fractions * 100_000_000;
case 2:
Expand Down
58 changes: 26 additions & 32 deletions src/test/java/com/ethlo/time/CorrectnessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,40 @@

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

@Tag("CorrectnessTest")
public abstract class CorrectnessTest extends AbstractTest
{
private final String[] validFormats =
{
"2017-02-21T15:27:39Z", "2017-02-21T15:27:39.123Z",
"2017-02-21T15:27:39.123456Z", "2017-02-21T15:27:39.123456789Z",
"2017-02-21T15:27:39+00:00", "2017-02-21T15:27:39.123+00:00",
"2017-02-21T15:27:39.123456+00:00", "2017-02-21T15:27:39.123456789+00:00",
"2017-02-21T15:27:39.1+00:00", "2017-02-21T15:27:39.12+00:00",
"2017-02-21T15:27:39.123+00:00", "2017-02-21T15:27:39.1234+00:00",
"2017-02-21T15:27:39.12345+00:00", "2017-02-21T15:27:39.123456+00:00",
"2017-02-21T15:27:39.1234567+00:00", "2017-02-21T15:27:39.12345678+00:00",
"2017-02-21T15:27:39.123456789+00:00"
};

private final String[] invalidFormats = {
@ParameterizedTest
@ValueSource(strings = {
"2017-02-21T15:27:39Z", "2017-02-21T15:27:39.123Z",
"2017-02-21T15:27:39.123456Z", "2017-02-21T15:27:39.123456789Z",
"2017-02-21T15:27:39+00:00", "2017-02-21T15:27:39.123+00:00",
"2017-02-21T15:27:39.123456+00:00", "2017-02-21T15:27:39.123456789+00:00",
"2017-02-21T15:27:39.1+00:00", "2017-02-21T15:27:39.12+00:00",
"2017-02-21T15:27:39.123+00:00", "2017-02-21T15:27:39.1234+00:00",
"2017-02-21T15:27:39.12345+00:00", "2017-02-21T15:27:39.123456+00:00",
"2017-02-21T15:27:39.1234567+00:00", "2017-02-21T15:27:39.12345678+00:00",
"2017-02-21T15:27:39.123456789+00:00"
})
void testValid(String valid)
{
final OffsetDateTime result = parser.parseDateTime(valid);
assertThat(result).isNotNull();
}

@ParameterizedTest
@ValueSource(strings = {
"2017-02-21T15:27:39.+00:00",
"2017-02-21T15:27:39", "2017-02-21T15:27:39.123",
"2017-02-21T15:27:39.123456", "2017-02-21T15:27:39.123456789",
"2017-02-21T15:27:39+0000", "2017-02-21T15:27:39.123+0000",
"201702-21T15:27:39.123456+0000", "20170221T15:27:39.123456789+0000"};

@Test
void testValid()
{
for (final String valid : validFormats)
{
final OffsetDateTime result = parser.parseDateTime(valid);
assertThat(result).isNotNull();
}
}

@Test
void testInvalid()
"201702-21T15:27:39.123456+0000", "20170221T15:27:39.123456789+0000"})
void testInvalid(final String invalid)
{
for (final String valid : invalidFormats)
{
assertThrows(DateTimeException.class, () -> parser.parseDateTime(valid));
}
assertThrows(DateTimeException.class, () -> parser.parseDateTime(invalid));
}

@Test
Expand Down

0 comments on commit 402e2f5

Please sign in to comment.