@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 Date fromString(String rawValue) { try { return TimeUtils. newInstance(). from( ISODateTimeFormat. dateTimeParser(). parseDateTime(rawValue)). toSqlDate(); } catch (Exception e) { throw new ObjectParseException(e,Date.class,rawValue); } }
@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); } }
@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); } }
@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 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 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())); }
private XMLGregorianCalendar xmlGregorianCalendar() { return TimeUtils. newInstance(). from(this.dateTime.get()). toXMLGregorianCalendar(); }
@Test public void testDataDSL() { Date date=new Date(); Name<String> name = NamingScheme.getDefault().name("name"); DataSet initialData = getInitialData(TEMPLATE_ID,name.id(),false,date); DataSetHelper helper=DataSetUtils.newHelper(initialData); DateTime firstValue= helper. managedIndividual(name,TEMPLATE_ID). property(READ_ONLY_PROPERTY). firstValue(DateTime.class); assertThat(firstValue,notNullValue()); assertThat(TimeUtils.newInstance().from(firstValue).toDate(),equalTo(date)); }
@Test public void testNewTypeLiteral$temporal$sqlDate() { checkNewTypeLiteral( TimeUtils. newInstance(). from(this.dateTime.get()). toSqlDate()); }
@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 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 testNewLiteral$temporal$date() { checkNewLiteral( TimeUtils. newInstance(). from(this.dateTime.get()). toDate()); }
@Test public void testNewLiteral$temporal$xmlGregorianCalendar() { checkNewLiteral( TimeUtils. newInstance(). from(this.dateTime.get()). toXMLGregorianCalendar()); }
@Test public void testNewTypeLiteral$temporal$gregorianCalendar() { checkNewTypeLiteral( TimeUtils. newInstance(). from(this.dateTime.get()). toGregorianCalendar()); }