rdf4j
rdf4j copied to clipboard
Values.literal does not work for Instant
Current Behavior
Values.literal(TemporalAccessor value) should allow for an Instant , but Values.literal(Instant.now()) throws an Exception
Exception in thread "main" java.lang.IllegalArgumentException: value <2022-08-01T21:14:38.470534100Z> cannot be represented by an XML Schema date/time datatype
at org.eclipse.rdf4j.model.base.AbstractLiteral$TemporalAccessorLiteral.<init>(AbstractLiteral.java:712)
at org.eclipse.rdf4j.model.base.AbstractValueFactory.createLiteral(AbstractValueFactory.java:214)
at org.eclipse.rdf4j.model.impl.ValidatingValueFactory.createLiteral(ValidatingValueFactory.java:200)
at org.eclipse.rdf4j.model.util.Values.literal(Values.java:616)
at org.eclipse.rdf4j.model.util.Values.literal(Values.java:600)
Expected Behavior
A literal with type xsd:dateTime is created
Steps To Reproduce
No response
Version
4.1.0
Are you interested in contributing a solution yourself?
Yes
Anything else?
No response
Note: unlike e.g. LocalDateTime, an Instant does not support getting year, month, ... ChronoField
@barthanssens we're getting close to doing a 4.1.1 patch release - do you have a timeline on when you hope to put up a fix for this issue? Would be good if we could fit it in.
Could an easy fix be to do an instanceof check and call .atOffset(ZoneOffset.UTC)?
Or is it that the milliseconds resolution is higher for Instant than for the XML calendar spec?
Thanks for the heads-up, looking into it tomorrow
Indeed, was thinking about simple instanceof check.