@Test public void testTimeZone() throws DatatypeConfigurationException, ValueExprEvaluationException { DatatypeFactory dtf = DatatypeFactory.newInstance(); ZonedDateTime now = testThisTimeDate; String time = now.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime zTime1 = now.withZoneSameInstant(ZoneId.of("Europe/London")); String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime zTime2 = now.withZoneSameInstant(ZoneId.of("Australia/Sydney")); String time2 = zTime2.format(DateTimeFormatter.ISO_INSTANT); ZonedDateTime zTime3 = now.minusDays(1).withZoneSameInstant(ZoneId.of("Asia/Seoul")); String time3 = zTime3.format(DateTimeFormatter.ISO_INSTANT); Literal nowLocal = VF.createLiteral(dtf.newXMLGregorianCalendar(time)); Literal nowEuropeTZ = VF.createLiteral(dtf.newXMLGregorianCalendar(time1)); Literal nowAustraliaTZ = VF.createLiteral(dtf.newXMLGregorianCalendar(time2)); Literal nowAsiaTZMinusOne = VF.createLiteral(dtf.newXMLGregorianCalendar(time3)); DateTimeWithinPeriod func = new DateTimeWithinPeriod(); assertEquals(TRUE, func.evaluate(VF, nowLocal, nowEuropeTZ, VF.createLiteral(1), OWLTime.SECONDS_URI)); assertEquals(TRUE, func.evaluate(VF, nowLocal, nowAustraliaTZ, VF.createLiteral(1), OWLTime.SECONDS_URI)); assertEquals(FALSE, func.evaluate(VF, nowLocal, nowAsiaTZMinusOne, VF.createLiteral(1), OWLTime.DAYS_URI)); assertEquals(TRUE, func.evaluate(VF, nowLocal, nowAsiaTZMinusOne, VF.createLiteral(2), OWLTime.DAYS_URI)); }
@Override public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException { checkNotNull(valueFactory); checkNotNull(values); try { checkArgument(values.length == 4); checkArgument(values[0] instanceof Literal); checkArgument(values[1] instanceof Literal); checkArgument(values[2] instanceof Literal); checkArgument(values[3] instanceof IRI); Instant dateTime1 = convertToInstant((Literal) values[0]); Instant dateTime2 = convertToInstant((Literal) values[1]); long periodMillis = convertPeriodToMillis((Literal) values[2], (IRI) values[3]); long timeBetween = Math.abs(Duration.between(dateTime1, dateTime2).toMillis()); return valueFactory.createLiteral(timeBetween < periodMillis); } catch (Exception e) { throw new ValueExprEvaluationException(e); } }
DateTimeWithinPeriod implements Function { @Override public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException { checkNotNull(valueFactory); checkNotNull(values); try { checkArgument(values.length == 4); checkArgument(values[0] instanceof Literal); checkArgument(values[1] instanceof Literal); checkArgument(values[2] instanceof Literal); checkArgument(values[3] instanceof IRI); Instant dateTime1 = convertToInstant((Literal) values[0]); Instant dateTime2 = convertToInstant((Literal) values[1]); long periodMillis = convertPeriodToMillis((Literal) values[2], (IRI) values[3]); long timeBetween = Math.abs(Duration.between(dateTime1, dateTime2).toMillis()); return valueFactory.createLiteral(timeBetween < periodMillis); } catch (Exception e) { throw new ValueExprEvaluationException(e); } } }
DateTimeWithinPeriod implements Function { @Override public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException { checkNotNull(valueFactory); checkNotNull(values); try { checkArgument(values.length == 4); checkArgument(values[0] instanceof Literal); checkArgument(values[1] instanceof Literal); checkArgument(values[2] instanceof Literal); checkArgument(values[3] instanceof IRI); Instant dateTime1 = convertToInstant((Literal) values[0]); Instant dateTime2 = convertToInstant((Literal) values[1]); long periodMillis = convertPeriodToMillis((Literal) values[2], (IRI) values[3]); long timeBetween = Math.abs(Duration.between(dateTime1, dateTime2).toMillis()); return valueFactory.createLiteral(timeBetween < periodMillis); } catch (Exception e) { throw new ValueExprEvaluationException(e); } }  }
DateTimeWithinPeriod implements Function { @Override public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException { checkNotNull(valueFactory); checkNotNull(values); try { checkArgument(values.length == 4); checkArgument(values[0] instanceof Literal); checkArgument(values[1] instanceof Literal); checkArgument(values[2] instanceof Literal); checkArgument(values[3] instanceof IRI); Instant dateTime1 = convertToInstant((Literal) values[0]); Instant dateTime2 = convertToInstant((Literal) values[1]); long periodMillis = convertPeriodToMillis((Literal) values[2], (IRI) values[3]); long timeBetween = Math.abs(Duration.between(dateTime1, dateTime2).toMillis()); return valueFactory.createLiteral(timeBetween < periodMillis); } catch (Exception e) { throw new ValueExprEvaluationException(e); } }  @Override String getURI(); @Override Value evaluate(ValueFactory valueFactory, Value... values); }
DateTimeWithinPeriod implements Function { @Override public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException { checkNotNull(valueFactory); checkNotNull(values); try { checkArgument(values.length == 4); checkArgument(values[0] instanceof Literal); checkArgument(values[1] instanceof Literal); checkArgument(values[2] instanceof Literal); checkArgument(values[3] instanceof IRI); Instant dateTime1 = convertToInstant((Literal) values[0]); Instant dateTime2 = convertToInstant((Literal) values[1]); long periodMillis = convertPeriodToMillis((Literal) values[2], (IRI) values[3]); long timeBetween = Math.abs(Duration.between(dateTime1, dateTime2).toMillis()); return valueFactory.createLiteral(timeBetween < periodMillis); } catch (Exception e) { throw new ValueExprEvaluationException(e); } }  @Override String getURI(); @Override Value evaluate(ValueFactory valueFactory, Value... values);  }