Skip to content

Commit

Permalink
Merge pull request #2026 from beyonnex-io/bugfix/1951-date-time-neutr…
Browse files Browse the repository at this point in the history
…al-element

#1951 generate EPOCH timestamp as neutral element for string "format" date-time, date, time
  • Loading branch information
thjaeckle authored Sep 27, 2024
2 parents fa6537d + 24d58be commit c25d876
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -492,7 +495,8 @@ private static Optional<JsonValue> provideNeutralElementForDataSchema(final Sing
numberSchema.getExclusiveMaximum().orElse(null));
return Optional.of(JsonValue.of(neutralDouble));
case STRING:
return Optional.of(JsonValue.of(provideNeutralStringElement()));
final String format = dataSchema.getFormat().orElse(null);
return Optional.of(JsonValue.of(provideNeutralStringElement(format)));
case OBJECT:
return Optional.of(JsonObject.empty());
case ARRAY:
Expand Down Expand Up @@ -547,8 +551,13 @@ private static double provideNeutralDoubleElement(@Nullable final Double minimum
return result;
}

private static String provideNeutralStringElement() {
return "";
private static String provideNeutralStringElement(@Nullable final String format) {
return switch (format) {
case "date-time" -> DateTimeFormatter.ISO_INSTANT.format(Instant.EPOCH);
case "date" -> DateTimeFormatter.ISO_LOCAL_DATE.withZone( ZoneId.of("UTC")).format(Instant.EPOCH);
case "time" -> DateTimeFormatter.ISO_OFFSET_TIME.withZone( ZoneId.of("UTC")).format(Instant.EPOCH);
case null, default -> "";
};
}

private CompletionStage<FeatureDefinition> resolveFeatureDefinition(final ThingModel thingModel,
Expand Down

0 comments on commit c25d876

Please sign in to comment.