From 437a4c5bf6099f546e2dba00be75c49bc731ce59 Mon Sep 17 00:00:00 2001 From: Morten Haraldsen Date: Fri, 9 Feb 2024 08:45:27 +0100 Subject: [PATCH] Take all examples in README from source code --- README.md | 34 ++++++++++++++++---------------- pom.xml | 16 ++++++++++++--- src/site/sample-code.template.md | 2 +- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 9992a3c..31af9ec 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,9 @@ Below you find some samples of usage of this library. Please check out the [java This is a collection of usage examples for parsing. - -#### parseRfc3339 [» source](src/test/java/samples/parsing/ITUParserSamples.java#L63C5-L69C5) + +#### parseRfc3339 [» source](src/test/java/samples/parsing/ITUParserSamples.java#L63C5-L69C6) The simplest and fastest way to parse an RFC-3339 (ISO-8601 profile) timestamp by far! ```java @@ -59,7 +59,7 @@ assertThat(dateTime.toString()).isEqualTo(text); ``` -#### parseLenient [» source](src/test/java/samples/parsing/ITUParserSamples.java#L74C5-L83C5) +#### parseLenient [» source](src/test/java/samples/parsing/ITUParserSamples.java#L74C5-L83C6) Parses a date-time with flexible granularity. Works for anything from a year to a timestamp with nanoseconds, wih or without timezone offset! ```java @@ -71,10 +71,10 @@ assertThat(formatted).isEqualTo(text); ``` -#### parseLenientWithCustomSeparators [» source](src/test/java/samples/parsing/ITUParserSamples.java#L89C5-L97C5) +#### parseLenientWithCustomSeparators [» source](src/test/java/samples/parsing/ITUParserSamples.java#L89C5-L97C6) In case you encounter the need for a somewhat different time-separator or fraction separator - you can use the `ParseConfig` to set up you preferred delimiters. + you can use the `ParseConfig` to set up you preferred delimiters. ```java final ParseConfig config = ParseConfig.DEFAULT.withDateTimeSeparators('T', '|').withFractionSeparators('.', ','); final DateTime result = ITU.parseLenient("1999-11-22|11:22:17,191", config); @@ -82,7 +82,7 @@ assertThat(result.toString()).isEqualTo("1999-11-22T11:22:17.191"); ``` -#### parsePosition [» source](src/test/java/samples/parsing/ITUParserSamples.java#L102C5-L109C5) +#### parsePosition [» source](src/test/java/samples/parsing/ITUParserSamples.java#L102C5-L109C6) This allows you to track where to start reading. Note that the check for trailing junk is disabled when using ParsePosition. ```java @@ -93,7 +93,7 @@ assertThat(pos.getIndex()).isEqualTo(35); ``` -#### explicitGranularity [» source](src/test/java/samples/parsing/ITUParserSamples.java#L114C5-L134C5) +#### explicitGranularity [» source](src/test/java/samples/parsing/ITUParserSamples.java#L114C5-L134C6) This is useful if you need to handle different granularity with different logic or interpolation. ```java @@ -114,17 +114,17 @@ assertThat(result.toString()).isEqualTo("2017-12-06T00:00Z"); ``` -#### lenientTimestamp [» source](src/test/java/samples/parsing/ITUParserSamples.java#L140C5-L145C5) +#### lenientTimestamp [» source](src/test/java/samples/parsing/ITUParserSamples.java#L140C5-L145C6) In some real world scenarios, it is useful to parse a best-effort timestamp. To ease usage, we can easily convert a raw `DateTime` instance into `Instant`. - Note the limitations and the assumption of UTC time-zone, as mentioned in the javadoc. + Note the limitations and the assumption of UTC time-zone, as mentioned in the javadoc. ```java final Instant instant = ITU.parseLenient("2017-12-06").toInstant(); assertThat(instant.toString()).isEqualTo("2017-12-06T00:00:00Z"); ``` -#### parseCustomFormat [» source](src/test/java/samples/parsing/ITUParserSamples.java#L150C5-L169C5) +#### parseCustomFormat [» source](src/test/java/samples/parsing/ITUParserSamples.java#L150C5-L169C6) In case the format is not supported directly, you can build your own parser. ```java @@ -135,7 +135,7 @@ assertThat(result.toString()).isEqualTo("2000-12-31T23:59:37.123456"); ``` -#### parseUsingInterfaceRfc33939 [» source](src/test/java/samples/parsing/ITUParserSamples.java#L174C5-L181C5) +#### parseUsingInterfaceRfc33939 [» source](src/test/java/samples/parsing/ITUParserSamples.java#L174C5-L181C6) `DateTimerParser` interface for RFC-3339 ```java @@ -146,7 +146,7 @@ assertThat(result.toString()).isEqualTo("2000-12-31T23:59:37.123456"); ``` -#### parseUsingInterfaceLocalTime [» source](src/test/java/samples/parsing/ITUParserSamples.java#L186C5-L193C5) +#### parseUsingInterfaceLocalTime [» source](src/test/java/samples/parsing/ITUParserSamples.java#L186C5-L193C6) `DateTimerParser` interface for local time ```java @@ -157,7 +157,7 @@ assertThat(result.toString()).isEqualTo(text); ``` -#### parseUsingInterfaceLocalDate [» source](src/test/java/samples/parsing/ITUParserSamples.java#L198C5-L205C5) +#### parseUsingInterfaceLocalDate [» source](src/test/java/samples/parsing/ITUParserSamples.java#L198C5-L205C6) `DateTimerParser` interface for local date ```java @@ -175,9 +175,9 @@ assertThat(result.toString()).isEqualTo(text); This is a collection of usage examples for formatting. - -#### formatRfc3339WithUTC [» source](src/test/java/samples/formatting/ITUFormattingSamples.java#L44C5-L52C5) + +#### formatRfc3339WithUTC [» source](src/test/java/samples/formatting/ITUFormattingSamples.java#L44C5-L52C6) The simplest and fastest way to format an RFC-3339 (ISO-8601 profile) timestamp by far! ```java @@ -194,9 +194,9 @@ assertThat(ITU.formatUtc(input)).isEqualTo("2012-12-27T22:07:22Z"); ## Leap-second handling - -#### parseLeapSecond [» source](src/test/java/samples/leapsecond/ITULeapSecondSamples.java#L43C5-L57C5) + +#### parseLeapSecond [» source](src/test/java/samples/leapsecond/ITULeapSecondSamples.java#L43C5-L57C6) Parse a valid leap-second (i.e. it is on a date that would allow for it, and it is also in the list of known actual leap-seconds). ```java diff --git a/pom.xml b/pom.xml index 4cc6821..f8fb86f 100644 --- a/pom.xml +++ b/pom.xml @@ -314,9 +314,9 @@ limitations under the License. - com.ethlo.maven - java-code-extractor-maven-plugin - 1.0.0-SNAPSHOT + com.ethlo.documentation + source-extractor-maven-plugin + 0.1.0 @@ -411,4 +411,14 @@ limitations under the License. + + + + true + + sonatype-nexus-snapshots + Nexus Snapshot repository + https://oss.sonatype.org/content/repositories/snapshots/ + + diff --git a/src/site/sample-code.template.md b/src/site/sample-code.template.md index 7972540..827b567 100644 --- a/src/site/sample-code.template.md +++ b/src/site/sample-code.template.md @@ -2,7 +2,7 @@ {% for method in methods %} -#### {{method.name}} [» source]({{class.path}}/{{class.name}}.java#L{{method.range.begin.line}}C{{method.range.begin.column}}-L{{method.range.end.line}}C{{method.range.end.column}}) +#### {{method.name}} [» source]({{class.path}}/{{class.name}}.java#L{{method.range.begin.line}}C{{method.range.begin.column}}-L{{method.range.end.line}}C{{method.range.end.column + 1}}) {{method.description | trim | raw }}