rdf4j icon indicating copy to clipboard operation
rdf4j copied to clipboard

Values.literal does not work for Instant

Open barthanssens opened this issue 3 years ago • 4 comments

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

barthanssens avatar Aug 01 '22 21:08 barthanssens

Note: unlike e.g. LocalDateTime, an Instant does not support getting year, month, ... ChronoField

barthanssens avatar Aug 02 '22 12:08 barthanssens

@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.

abrokenjester avatar Aug 27 '22 22:08 abrokenjester

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?

hmottestad avatar Aug 28 '22 13:08 hmottestad

Thanks for the heads-up, looking into it tomorrow

Indeed, was thinking about simple instanceof check.

barthanssens avatar Aug 28 '22 21:08 barthanssens