Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Haraldsen committed Feb 4, 2024
1 parent 818f6dc commit ba80572
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/ethlo/time/DateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
* #L%
*/

import static com.ethlo.time.internal.fixed.ITUFormatter.finish;
import static com.ethlo.time.internal.fixed.ITUParser.DATE_SEPARATOR;
import static com.ethlo.time.internal.fixed.ITUParser.SEPARATOR_UPPER;
import static com.ethlo.time.internal.fixed.ITUParser.TIME_SEPARATOR;
import static com.ethlo.time.internal.fixed.ITUFormatter.finish;
import static com.ethlo.time.internal.util.LeapSecondHandler.LEAP_SECOND_SECONDS;

import java.time.DateTimeException;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/ethlo/time/ITU.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public static DateTime parseLenient(String text)

/**
* Allows parsing leniently with {@link ParseConfig to control some aspects of the parsing}
* @param text The text to parse
*
* @param text The text to parse
* @param parseConfig The configuration to use for parsing
* @return The date-time parsed
*/
Expand All @@ -81,10 +82,9 @@ public static DateTime parseLenient(String text, ParseConfig parseConfig)
}

/**
*
* @param text The text to parse
* @param text The text to parse
* @param parseConfig The configuration to use for parsing
* @param position The position to start parsing from. The index (and the errorIndex, if an error occurs) is updated after the parsing process has completed
* @param position The position to start parsing from. The index (and the errorIndex, if an error occurs) is updated after the parsing process has completed
* @return The date-time parsed
*/
public static DateTime parseLenient(String text, ParseConfig parseConfig, ParsePosition position)
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/ethlo/time/ParseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
* #L%
*/

import static com.ethlo.time.internal.fixed.ITUParser.SEPARATOR_LOWER;
import static com.ethlo.time.internal.fixed.ITUParser.SEPARATOR_SPACE;
import static com.ethlo.time.internal.fixed.ITUParser.SEPARATOR_UPPER;

import java.util.Arrays;
import java.util.Optional;

import static com.ethlo.time.internal.fixed.ITUParser.*;

public class ParseConfig
{
private static final char[] DEFAULT_DATE_TIME_SEPARATORS = new char[]{SEPARATOR_UPPER, SEPARATOR_LOWER, SEPARATOR_SPACE};
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/ethlo/time/internal/fixed/ITUFormatter.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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.ethlo.time.Field;
import com.ethlo.time.token.DateTimeToken;

public class TimeZoneOffsetToken implements DateTimeToken
public class ZoneOffsetToken implements DateTimeToken
{
@Override
public int read(final String text, final ParsePosition parsePosition)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/ethlo/time/internal/util/ArrayUtils.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
4 changes: 2 additions & 2 deletions src/main/java/com/ethlo/time/token/DateTimeToken.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
4 changes: 2 additions & 2 deletions src/main/java/com/ethlo/time/token/DateTimeTokens.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.ethlo.time.internal.token.FractionsToken;
import com.ethlo.time.internal.token.SeparatorToken;
import com.ethlo.time.internal.token.SeparatorsToken;
import com.ethlo.time.internal.token.TimeZoneOffsetToken;
import com.ethlo.time.internal.token.ZoneOffsetToken;

public class DateTimeTokens

Check warning on line 30 in src/main/java/com/ethlo/time/token/DateTimeTokens.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/ethlo/time/token/DateTimeTokens.java#L30

Added line #L30 was not covered by tests
{
Expand Down Expand Up @@ -55,6 +55,6 @@ public static DateTimeToken fractions()

public static DateTimeToken zoneOffset()
{
return new TimeZoneOffsetToken();
return new ZoneOffsetToken();
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/ethlo/time/ParsePositionTest.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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import com.ethlo.time.DateTime;
import com.ethlo.time.ITU;
import com.ethlo.time.internal.token.FractionsToken;
import com.ethlo.time.internal.token.TimeZoneOffsetToken;
import com.ethlo.time.internal.token.ZoneOffsetToken;

public class ConfigurableDateTimeParserTest
{
Expand Down Expand Up @@ -168,37 +168,37 @@ void reachEndOfFractions()
void readTimeZoneZuluUpper()
{
final ParsePosition pos = new ParsePosition(0);
assertThat(new TimeZoneOffsetToken().read("Z", pos)).isEqualTo(0);
assertThat(new ZoneOffsetToken().read("Z", pos)).isEqualTo(0);
}

@Test
void readTimeZoneZuluLower()
{
final ParsePosition pos = new ParsePosition(0);
assertThat(new TimeZoneOffsetToken().read("z", pos)).isEqualTo(0);
assertThat(new ZoneOffsetToken().read("z", pos)).isEqualTo(0);
}

@Test
void readTimeZoneUnexpectedChar()
{
final ParsePosition pos = new ParsePosition(0);
final DateTimeParseException exc = assertThrows(DateTimeParseException.class, () -> new TimeZoneOffsetToken().read("X", pos));
final DateTimeParseException exc = assertThrows(DateTimeParseException.class, () -> new ZoneOffsetToken().read("X", pos));
assertThat(exc).hasMessage("Expected character [Z, z, +, -] at position 1, found X: X");
}

@Test
void readTimeZoneTooShort()
{
final ParsePosition pos = new ParsePosition(0);
final DateTimeParseException exc = assertThrows(DateTimeParseException.class, () -> new TimeZoneOffsetToken().read("-06:0", pos));
final DateTimeParseException exc = assertThrows(DateTimeParseException.class, () -> new ZoneOffsetToken().read("-06:0", pos));
assertThat(exc).hasMessage("Invalid timezone offset: -06:0");
}

@Test
void readTimeZoneNegative()
{
final ParsePosition pos = new ParsePosition(0);
final int secs = new TimeZoneOffsetToken().read("-06:30", pos);
final int secs = new ZoneOffsetToken().read("-06:30", pos);
assertThat(secs).isEqualTo(-23400);
}

Expand Down
11 changes: 5 additions & 6 deletions src/test/java/com/ethlo/time/token/DateTimeParsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ public class DateTimeParsers
separators('-'),
digits(DAY, 2)
);

public static DateTimeParser of(DateTimeToken... tokens)
{
return ConfigurableDateTimeParser.of(tokens);
}

private static final DateTimeParser LOCAL_TIME = of(
digits(HOUR, 2),
separators(':'),
Expand All @@ -54,6 +48,11 @@ public static DateTimeParser of(DateTimeToken... tokens)
fractions()
);

public static DateTimeParser of(DateTimeToken... tokens)
{
return ConfigurableDateTimeParser.of(tokens);
}

public static DateTimeParser localDate()
{
return DATE;
Expand Down

0 comments on commit ba80572

Please sign in to comment.