I'll try DateTimeStruct again, but that basically means I need my own copy of the class, since I currently cannot extend it to override the private constructor?
On Thu, Nov 14, 2013 at 2:15 PM, Andy Seaborne <a...@apache.org> wrote: > Hi there, > > DateTimeStruct is, well, a struct. The fields are public. You could write a > builder to target that. The default constructor could be made public. The > statics are specific patterns for the XSD date/time datatypes with > validation. > > DateTimeStruct represents the Date/time Seven-property model of XSD. It can > produce the string for xsd:date or xsd:dateTime but not the gregorial g* > datatypes. > > java.util.calendar is OK as a value but, in the details, unusable for XSD > types. Why not set DateTimeStruct fields? > > javax.xml.datatype.XMLGregorianCalendar could be of use - it has getters and > setters. > > For DateTimeStruct or XMLGregorianCalendar, you can then use > > createTypedLiteral(String lex, RDFDatatype dtype) > > >> Not all mandatory - the >> format can be YYYY, YYYY-MM, YYYY-MM-DD. > > You could build the lexical form. > > Andy > > > On 14/11/13 02:02, Martynas Jusevičius wrote: >> >> Hey, >> >> I have datetime components as 3 separate literals, with xsd:gYear, >> xsd:gMonth, xsd:gDay respective datatypes. Not all mandatory - the >> format can be YYYY, YYYY-MM, YYYY-MM-DD. >> >> Now how do I combine those into a single xsd:dateTime Literal? A >> concrete use case would be converting time:inDateTime values into >> time:inXSDDateTime values: >> http://www.w3.org/TR/owl-time/#calclock >> >> I came up with the code below which seems to work but is not pretty >> (and doesn't deal with time). I also looked at DateTimeStruct but >> either way there seemed to be some datatype mismatch. I think it would >> make more sense for DateTimeStruct to use the builder pattern instead >> of static methods. >> >> Is there a better way? >> >> if >> (resource.hasProperty(ResourceFactory.createProperty("http://www.w3.org/2006/time#inDateTime"))) >> { >> Calendar calendar = Calendar.getInstance(); >> Resource dateTimeDesc = >> >> resource.getPropertyResourceValue(ResourceFactory.createProperty("http://www.w3.org/2006/time#inDateTime")); >> >> if >> (dateTimeDesc.hasProperty(ResourceFactory.createProperty("http://www.w3.org/2006/time#year"))) >> { >> RDFNode object = >> >> dateTimeDesc.getProperty(ResourceFactory.createProperty("http://www.w3.org/2006/time#year")).getObject(); >> if (object.isLiteral()) >> { >> Literal literal = object.asLiteral(); >> calendar.set(Calendar.YEAR, >> Integer.parseInt(literal.getLexicalForm())); >> } >> } >> else throw new DateTimeParseException("time:year value is >> missing"); >> >> if >> (dateTimeDesc.hasProperty(ResourceFactory.createProperty("http://www.w3.org/2006/time#month"))) >> { >> RDFNode object = >> >> dateTimeDesc.getProperty(ResourceFactory.createProperty("http://www.w3.org/2006/time#month")).getObject(); >> if (object.isLiteral()) >> { >> Literal literal = object.asLiteral(); >> calendar.set(Calendar.MONTH, >> Integer.parseInt(literal.getLexicalForm())); >> } >> } >> >> if >> (dateTimeDesc.hasProperty(ResourceFactory.createProperty("http://www.w3.org/2006/time#day"))) >> { >> RDFNode object = >> >> dateTimeDesc.getProperty(ResourceFactory.createProperty("http://www.w3.org/2006/time#day")).getObject(); >> if (object.isLiteral()) >> { >> Literal literal = object.asLiteral(); >> calendar.set(Calendar.DAY_OF_MONTH, >> Integer.parseInt(literal.getLexicalForm())); >> } >> } >> >> calendar.set(Calendar.HOUR, 0); >> calendar.set(Calendar.MINUTE, 0); >> calendar.set(Calendar.SECOND, 0); >> Literal dateTime = >> resource.getModel().createTypedLiteral(calendar); >> >> resource.addLiteral(ResourceFactory.createProperty("http://www.w3.org/2006/time#inXSDDateTime"), >> dateTime); >> } >> >> Martynas >> graphityhq.com >> >