From 7147d0b857baa8153b2d18b9368e15e6c4e00a62 Mon Sep 17 00:00:00 2001 From: Morten Haraldsen Date: Wed, 31 Jan 2024 19:08:07 +0100 Subject: [PATCH 1/4] Attempt to setup codecov --- .github/workflows/build.yml | 47 ++++++++++++++++++++----------------- pom.xml | 2 +- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cd6a76d..b52dfcb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,28 +1,33 @@ name: Build on: - push: - branches: - - main - paths: [ '**.java', '.github/workflows/build.yml', 'pom.xml' ] - pull_request: + push: + branches: + - main + paths: [ '**.java', '.github/workflows/build.yml', 'pom.xml' ] + pull_request: jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - java: [ 8, 11, 17, 21 ] - name: Java ${{ matrix.java }} - steps: - - uses: actions/checkout@v3 + build: + runs-on: ubuntu-latest + strategy: + matrix: + java: [ 8, 11, 17, 21 ] + name: Java ${{ matrix.java }} + steps: + - uses: actions/checkout@v3 - - name: Setup JDK - uses: actions/setup-java@v3 - with: - distribution: temurin - java-version: ${{ matrix.java }} - cache: maven + - name: Setup JDK + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: ${{ matrix.java }} + cache: maven - - name: Build - run: mvn -ntp -B verify \ No newline at end of file + - name: Build + run: mvn -ntp -B -Pcoverage verify + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2493c45..c26a03e 100644 --- a/pom.xml +++ b/pom.xml @@ -353,7 +353,7 @@ limitations under the License. org.jacoco jacoco-maven-plugin - 0.8.8 + 0.8.11 From 4bec9cfcfbbe005be01f92caddab662bf9501380 Mon Sep 17 00:00:00 2001 From: Morten Haraldsen Date: Wed, 31 Jan 2024 19:15:06 +0100 Subject: [PATCH 2/4] Cleanup using methods and constants --- .../com/ethlo/time/internal/ITUParser.java | 56 +++++++++++++++---- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/ethlo/time/internal/ITUParser.java b/src/main/java/com/ethlo/time/internal/ITUParser.java index 9b4b254..e32b3b8 100644 --- a/src/main/java/com/ethlo/time/internal/ITUParser.java +++ b/src/main/java/com/ethlo/time/internal/ITUParser.java @@ -50,6 +50,8 @@ public class ITUParser static final char ZULU_UPPER = 'Z'; private static final char ZULU_LOWER = 'z'; public static final int MAX_FRACTION_DIGITS = 9; + public static final int RADIX = 10; + public static final int DIGITS_IN_NANO = 9; private ITUParser() { @@ -165,7 +167,7 @@ public static DateTime parseLenient(final String chars, final ParseConfig parseC // Date portion // YEAR - final int years = parsePositiveInt(chars, offset, offset + 4); + final int years = parseYears(chars, offset); if (4 == availableLength) { return new DateTime(Field.YEAR, years, 0, 0, 0, 0, 0, 0, null, 0, availableLength); @@ -173,7 +175,7 @@ public static DateTime parseLenient(final String chars, final ParseConfig parseC // MONTH assertPositionContains(Field.MONTH, chars, offset + 4, DATE_SEPARATOR); - final int month = parsePositiveInt(chars, offset + 5, offset + 7); + final int month = parseMonth(chars, offset); if (7 == availableLength) { return new DateTime(Field.MONTH, years, month, 0, 0, 0, 0, 0, null, 0, availableLength); @@ -181,7 +183,7 @@ public static DateTime parseLenient(final String chars, final ParseConfig parseC // DAY assertPositionContains(Field.DAY, chars, offset + 7, DATE_SEPARATOR); - final int days = parsePositiveInt(chars, offset + 8, offset + 10); + final int days = parseDays(chars, offset); if (10 == availableLength) { return new DateTime(Field.DAY, years, month, days, 0, 0, 0, 0, null, 0, availableLength); @@ -189,11 +191,11 @@ public static DateTime parseLenient(final String chars, final ParseConfig parseC // HOURS assertAllowedDateTimeSeparator(offset, chars, parseConfig); - final int hours = parsePositiveInt(chars, offset + 11, offset + 13); + final int hours = parseHours(chars, offset); // MINUTES assertPositionContains(Field.MINUTE, chars, offset + 13, TIME_SEPARATOR); - final int minutes = parsePositiveInt(chars, offset + 14, offset + 16); + final int minutes = parseMinutes(chars, offset); if (availableLength == 16) { // Have only minutes @@ -204,6 +206,36 @@ public static DateTime parseLenient(final String chars, final ParseConfig parseC return handleTime(offset, parseConfig, chars, years, month, days, hours, minutes); } + private static int parseSeconds(int offset, String chars) + { + return parsePositiveInt(chars, offset + 17, offset + 19); + } + + private static int parseMinutes(String chars, int offset) + { + return parsePositiveInt(chars, offset + 14, offset + 16); + } + + private static int parseHours(String chars, int offset) + { + return parsePositiveInt(chars, offset + 11, offset + 13); + } + + private static int parseDays(String chars, int offset) + { + return parsePositiveInt(chars, offset + 8, offset + 10); + } + + private static int parseMonth(String chars, int offset) + { + return parsePositiveInt(chars, offset + 5, offset + 7); + } + + private static int parseYears(String chars, int offset) + { + return parsePositiveInt(chars, offset, offset + 4); + } + private static DateTime handleTimeResolution(final int offset, ParseConfig parseConfig, int year, int month, int day, int hour, int minute, String chars) { final int length = chars.length() - offset; @@ -231,7 +263,7 @@ else if (c == PLUS || c == MINUS) } else if (length == 19) { - final int seconds = parsePositiveInt(chars, offset + 17, offset + 19); + final int seconds = parseSeconds(offset, chars); return new DateTime(Field.SECOND, year, month, day, hour, minute, seconds, 0, null, 0, length); } @@ -240,7 +272,7 @@ else if (length == 19) private static DateTime handleSecondResolution(int offset, int year, int month, int day, int hour, int minute, String chars, TimezoneOffset timezoneOffset) { - final int seconds = parsePositiveInt(chars, offset + 17, offset + 19); + final int seconds = parseSeconds(offset, chars); final int charLength = Field.SECOND.getRequiredLength() + (timezoneOffset != null ? timezoneOffset.getRequiredLength() : 0); return new DateTime(Field.SECOND, year, month, day, hour, minute, seconds, 0, timezoneOffset, 0, charLength); } @@ -260,24 +292,24 @@ private static DateTime handleFractionalSeconds(int offset, ParseConfig parseCon else { fractionDigits++; - nanos = nanos * 10 + (c - ZERO); + nanos = nanos * RADIX + (c - ZERO); idx++; } } assertFractionDigits(chars, fractionDigits, offset + (idx - 1)); - // Scale to nanos + // Scale to nanoseconds int pos = fractionDigits; - while (pos < 9) + while (pos < DIGITS_IN_NANO) { - nanos *= 10; + nanos *= RADIX; pos++; } final TimezoneOffset timezoneOffset = parseTimezone(offset, parseConfig, chars, idx); final int charLength = (idx + (timezoneOffset != null ? timezoneOffset.getRequiredLength() : 0)) - offset; - final int second = parsePositiveInt(chars, offset + 17, offset + 19); + final int second = parseSeconds(offset, chars); return new DateTime(Field.NANO, year, month, day, hour, minute, second, nanos, timezoneOffset, fractionDigits, charLength); } From 6c9650f74fd8b1968b6afbd83d24635d09dc0863 Mon Sep 17 00:00:00 2001 From: Morten Haraldsen Date: Wed, 31 Jan 2024 19:15:22 +0100 Subject: [PATCH 3/4] Add codecov badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d7aa179..e6bc565 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![javadoc](https://javadoc.io/badge2/com.ethlo.time/itu/javadoc.svg)](https://javadoc.io/doc/com.ethlo.time/itu/latest/com/ethlo/time/ITU.html) [![Hex.pm](https://img.shields.io/hexpm/l/plug.svg)](LICENSE) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/598913bc1fe9405c82be73d9a4f105c8)](https://app.codacy.com/gh/ethlo/itu/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) +[![codecov](https://codecov.io/gh/ethlo/itu/graph/badge.svg?token=V3H15LKC5V)](https://codecov.io/gh/ethlo/itu) An extremely fast parser and formatter of specific ISO-8601 format date and date-times. From 7311af60bf6087d6c17b4d551f9491970f1893cd Mon Sep 17 00:00:00 2001 From: Morten Haraldsen Date: Wed, 31 Jan 2024 19:15:37 +0100 Subject: [PATCH 4/4] Add header to test --- .../com/ethlo/time/ParsePositionTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/test/java/com/ethlo/time/ParsePositionTest.java b/src/test/java/com/ethlo/time/ParsePositionTest.java index bc57071..8e34738 100644 --- a/src/test/java/com/ethlo/time/ParsePositionTest.java +++ b/src/test/java/com/ethlo/time/ParsePositionTest.java @@ -1,5 +1,25 @@ package com.ethlo.time; +/*- + * #%L + * Internet Time Utility + * %% + * Copyright (C) 2017 - 2024 Morten Haraldsen (ethlo) + * %% + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows;