Search in sources :

Example 21 with TemporalInstant

use of org.apache.rya.indexing.TemporalInstant in project incubator-rya by apache.

the class TemporalInstantTest method zoneTestTest.

@Test
public void zoneTestTest() throws Exception {
    // arbitrary zone, BRST=Brazil, better if not local.
    final String ZONETestDateInBRST = "2014-12-31T23:59:59-02:00";
    final String ZONETestDateInZulu = "2015-01-01T01:59:59Z";
    final String ZONETestDateInET = "2014-12-31T20:59:59-05:00";
    TemporalInstant instant = new TemporalInstantRfc3339(DateTime.parse(ZONETestDateInBRST));
    Assert.assertEquals("Test our test Zulu, ET  strings.", ZONETestDateInET, DateTime.parse(ZONETestDateInZulu).withZone(DateTimeZone.forID("-05:00")).toString(ISODateTimeFormat.dateTimeNoMillis()));
    Assert.assertEquals("Test our test BRST,Zulu strings.", ZONETestDateInZulu, DateTime.parse(ZONETestDateInBRST).withZone(DateTimeZone.UTC).toString(ISODateTimeFormat.dateTimeNoMillis()));
    Assert.assertTrue("Key must be normalized to time zone Zulu: " + instant.getAsKeyString(), instant.getAsKeyString().endsWith("Z"));
    Assert.assertEquals("Key must be normalized from BRST -02:00", ZONETestDateInZulu, instant.getAsKeyString());
    Assert.assertArrayEquals(StringUtils.getBytesUtf8(instant.getAsKeyString()), instant.getAsKeyBytes());
    Assert.assertTrue("Ignore original time zone.", !ZONETestDateInBRST.equals(instant.getAsReadable(DateTimeZone.forID("-07:00"))));
    Assert.assertEquals("Use original time zone.", ZONETestDateInBRST, instant.getAsDateTime().toString(TemporalInstantRfc3339.FORMATTER));
    Assert.assertEquals("Time at specified time zone.", ZONETestDateInET, instant.getAsReadable(DateTimeZone.forID("-05:00")));
    instant = new TemporalInstantRfc3339(DateTime.parse(ZONETestDateInZulu));
    Assert.assertEquals("expect a time with specified time zone.", ZONETestDateInET, instant.getAsReadable(DateTimeZone.forID("-05:00")));
}
Also used : TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) TemporalInstant(org.apache.rya.indexing.TemporalInstant) Test(org.junit.Test)

Example 22 with TemporalInstant

use of org.apache.rya.indexing.TemporalInstant in project incubator-rya by apache.

the class TemporalInstantTest method constructorTest.

@Test
public void constructorTest() throws Exception {
    TemporalInstant instant = new // 
    TemporalInstantRfc3339(// 
    2014, // 
    12, // 
    30, 12, 59, 59);
    // YYYY-MM-DDThh:mm:ssZ
    String stringTestDate01 = "2014-12-30T12:59:59Z";
    Date dateTestDate01 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(stringTestDate01);
    Assert.assertEquals(stringTestDate01, instant.getAsKeyString());
    Assert.assertArrayEquals(StringUtils.getBytesUtf8(instant.getAsKeyString()), instant.getAsKeyBytes());
    Assert.assertTrue("Key must be normalized to time zone Zulu", instant.getAsKeyString().endsWith("Z"));
    // show the local time us.
    // Warning, if test is run in the London, or Zulu time zone, this test will be same as above, with the Z.
    // TimeZone.setDefault(TimeZone.getTimeZone("UTC")); // this does not affect the library, don't use.
    String stringLocalTestDate01 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(dateTestDate01);
    // for ET, will be: "2014-12-30T07:59:59-05:00"
    // instant.getAsDateTime().withZone(null);
    // System.out.println("===System.getProperty(user.timezone)="+System.getProperty("user.timezone")); //=ET
    // System.out.println("===============TimeZone.getDefault()="+TimeZone.getDefault());				//=ET
    // System.out.println("===========DateTimeZone.getDefault()="+DateTimeZone.getDefault());			//=UTC (wrong!)
    // the timezone default gets set to UTC by some prior test, fix it here.
    DateTimeZone newTimeZone = null;
    try {
        String id = System.getProperty("user.timezone");
        if (id != null) {
            newTimeZone = DateTimeZone.forID(id);
        }
    } catch (RuntimeException ex) {
    // ignored
    }
    if (newTimeZone == null) {
        newTimeZone = DateTimeZone.forTimeZone(TimeZone.getDefault());
    }
    DateTimeZone.setDefault(newTimeZone);
    // null timezone means use the default:
    Assert.assertEquals("Joda time library (actual) should use same local timezone as Java date (expected).", stringLocalTestDate01, instant.getAsReadable(null));
}
Also used : TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) TemporalInstant(org.apache.rya.indexing.TemporalInstant) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) DateTimeZone(org.joda.time.DateTimeZone) Test(org.junit.Test)

Aggregations

TemporalInstant (org.apache.rya.indexing.TemporalInstant)22 TemporalInstantRfc3339 (org.apache.rya.indexing.TemporalInstantRfc3339)21 RyaURI (org.apache.rya.api.domain.RyaURI)15 Geometry (com.vividsolutions.jts.geom.Geometry)14 Test (org.junit.Test)14 Coordinate (com.vividsolutions.jts.geom.Coordinate)12 EventStorage (org.apache.rya.indexing.geotemporal.storage.EventStorage)11 Event (org.apache.rya.indexing.geotemporal.model.Event)9 TemporalInterval (org.apache.rya.indexing.TemporalInterval)7 DateTime (org.joda.time.DateTime)5 BindingSet (org.openrdf.query.BindingSet)5 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)5 MapBindingSet (org.openrdf.query.impl.MapBindingSet)5 ArrayList (java.util.ArrayList)4 MongoEventStorage (org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage)4 IOException (java.io.IOException)3 Matcher (java.util.regex.Matcher)3 RyaStatement (org.apache.rya.api.domain.RyaStatement)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 ParseException (com.vividsolutions.jts.io.ParseException)2