@Override public Date fromString(String rawValue) { try { return TimeUtils. newInstance(). from( ISODateTimeFormat. dateTimeParser(). parseDateTime(rawValue)). toSqlDate(); } catch (Exception e) { throw new ObjectParseException(e,Date.class,rawValue); } }
public TimeUtils withLocale(Locale locale) { return new TimeUtils(this.datatypeFactory,this.timezone,locale,this.defaults); }
TripleSetBuilder(ResourceResolver resourceResolver, URI base) { this.resourceResolver=resourceResolver; this.base = base; this.localResources=new HashMap<Object,Resource<?>>(); this.visitedIndividuals=new ArrayList<Object>(); this.triples=new TripleSet(); // TODO: Make this configurable --> See Literals class this.timeUtils=TimeUtils.newInstance(); }
@Override public void visitTypedLiteral(TypedLiteral<?> literal) { Object value = literal.get(); if(value instanceof DateTime) { value=TripleSetBuilder.this.timeUtils.from((DateTime)value).toXMLGregorianCalendar(); } else if(value instanceof Duration) { value=TripleSetBuilder.this.timeUtils.from((Duration)value).toDuration(); } append(typedLiteral(value,literal.type())); } @Override
@Override public XMLGregorianCalendar fromString(String rawValue) { try { return TimeUtils. newInstance(). from( ISODateTimeFormat. dateTimeParser(). parseDateTime(rawValue)). toXMLGregorianCalendar(); } catch (Exception e) { throw new ObjectParseException(e,XMLGregorianCalendar.class,rawValue); } }
public TimeUtils withDefaults(XMLGregorianCalendar defaults) { return new TimeUtils(this.datatypeFactory,this.timezone,this.locale,defaults); }
@Override public Duration fromString(String rawValue) { try { Period period = ISOPeriodFormat.standard().parsePeriod(rawValue); return TimeUtils.newInstance().from(period.toStandardDuration()).toDuration(); } catch (Exception e) { throw new ObjectParseException(e,Duration.class,rawValue); } }
public TimeUtils withTimeZone(TimeZone timezone) { return new TimeUtils(this.datatypeFactory,timezone,this.locale,this.defaults); }
private XMLGregorianCalendar xmlGregorianCalendar() { return TimeUtils. newInstance(). from(this.dateTime.get()). toXMLGregorianCalendar(); }
public static TimeUtils newInstance() { try { return new TimeUtils( DatatypeFactory.newInstance(), TimeZone.getDefault(), Locale.getDefault(), null); } catch (DatatypeConfigurationException e) { throw new AssertionError("Could not create factory",e); } }
@Test public void testNewTypeLiteral$temporal$sqlDate() { checkNewTypeLiteral( TimeUtils. newInstance(). from(this.dateTime.get()). toSqlDate()); }
@Test public void testXMLGregorianCalendarRoundtrip() throws Exception { XMLGregorianCalendar date = TimeUtils.newInstance().from(this.now).toXMLGregorianCalendar(); assertThat(ObjectUtil.fromString(XMLGregorianCalendar.class, dateTimeAsISOString()),equalTo(date)); assertThat(ObjectUtil.toString(date),equalTo(dateTimeAsISOString())); }
@Test public void testNewLiteral$temporal$sqlTime() { checkNewLiteral( Datatypes.TIME, TimeUtils. newInstance(). from(this.dateTime.get()). toSqlTime()); }
@Test public void testNewLiteral$temporal$gregorianCalendar() { checkNewLiteral( TimeUtils. newInstance(). from(this.dateTime.get()). toGregorianCalendar()); }
@Test public void testUtilDateRoundtrip() throws Exception { Date date = TimeUtils.newInstance().from(this.now).toDate(); assertThat(ObjectUtil.fromString(Date.class, dateTimeAsISOString()),equalTo(date)); assertThat(ObjectUtil.toString(date),equalTo(dateTimeAsISOString())); }
@Test public void testNewTypeLiteral$temporal$date() { checkNewTypeLiteral( TimeUtils. newInstance(). from(this.dateTime.get()). toDate()); }
@Test public void testNewTypeLiteral$temporal$sqlTime() { checkNewTypeLiteral( TimeUtils. newInstance(). from(this.dateTime.get()). toSqlTime()); }
@Test public void testNewLiteral$temporal$sqlDate() { checkNewLiteral( Datatypes.DATE, TimeUtils. newInstance(). from(this.dateTime.get()). toSqlDate()); }
@Test public void testNewTypeLiteral$temporal$xmlGregorianCalendar() { checkNewTypeLiteral( TimeUtils. newInstance(). from(this.dateTime.get()). toXMLGregorianCalendar()); }
@Test public void testSqlDateRoundtrip() throws Exception { Date date = TimeUtils.newInstance().from(this.now).toSqlDate(); assertThat(ObjectUtil.fromString(java.sql.Date.class, dateTimeAsISOString()),equalTo(date)); assertThat(ObjectUtil.toString(date),equalTo(dateTimeAsISOString())); }