Esempio n. 1
0
  /**
   * Tests the parsing of an ISO8601 formatted date
   *
   * @throws Exception Forwards all exceptions to JUnit.
   */
  @Ignore("todo: Import the latest changes to enable the below test case.")
  public void itestParse() throws Exception {
    GregorianCalendar cal = new GregorianCalendar(2006, 05, 30, 23, 59, 54);
    cal.set(Calendar.MILLISECOND, 321);
    cal.setTimeZone(TimeZone.getTimeZone("UTC"));
    XMPDateTime dt = XMPDateTimeFactory.createFromCalendar(cal);
    XMPDateTime parsed = ISO8601Converter.parse("2006-06-30T23:59:54.321Z");
    assertEquals(0, dt.compareTo(parsed));

    cal.set(Calendar.MILLISECOND, 0);
    dt = XMPDateTimeFactory.createFromCalendar(cal);
    assertEquals(0, dt.compareTo(ISO8601Converter.parse("2006-06-30T23:59:54Z")));

    cal.set(Calendar.SECOND, 0);
    dt = XMPDateTimeFactory.createFromCalendar(cal);
    assertEquals(0, dt.compareTo(ISO8601Converter.parse("2006-06-30T23:59Z")));

    cal.set(Calendar.HOUR_OF_DAY, 0);
    dt = XMPDateTimeFactory.createFromCalendar(cal);
    assertEquals(0, dt.compareTo(ISO8601Converter.parse("2006-06-30T00:59Z")));

    cal.set(Calendar.MINUTE, 0);
    dt = XMPDateTimeFactory.createFromCalendar(cal);
    assertEquals(0, dt.compareTo(ISO8601Converter.parse("2006-06-30T00:00Z")));

    // Issue reported by S7, dates w/o timezone have to be accepted
    // toDo: Import latest version to run the following test
    // dt = ISO8601Converter.parse("2006-10-13T17:45:26.16");
    // assertEquals("2006-10-13T17:45:26.16", dt.toString());

    dt = ISO8601Converter.parse("2006-10-13T17:45:26.16Z");
    assertEquals("2006-10-13T17:45:26.16Z", dt.toString());

    dt = ISO8601Converter.parse("2006-10-13T17:45:26");
    assertEquals("2006-10-13T17:45:26", dt.toString());

    dt = ISO8601Converter.parse("2006-10-13T17:45:26+5:30");
    assertEquals("2006-10-13T17:45:26+05:30", dt.toString());

    dt = ISO8601Converter.parse("2006-10-13T17:45");
    assertEquals("2006-10-13T17:45", dt.toString());

    dt = ISO8601Converter.parse("2006-10-13T17:45-06");
    assertEquals("2006-10-13T17:45-06:00", dt.toString());

    dt = ISO8601Converter.parse("2006-10-13T17");
    assertEquals("2006-10-13T17:00", dt.toString());

    dt = ISO8601Converter.parse("2006-10-13T17Z");
    assertEquals("2006-10-13T17:00Z", dt.toString());

    dt = ISO8601Converter.parse("2006-10-13T17-03:00");
    assertEquals("2006-10-13T17:00-03:00", dt.toString());

    dt = ISO8601Converter.parse("2006-10-13");
    assertEquals("2006-10-13", dt.toString());
  }
Esempio n. 2
0
  /**
   * Test date variants:
   *
   * <ul>
   *   <li>YYYY
   *   <li>YYYY-MM
   *   <li>YYYY-MM-DD
   *   <li>YYYY-MM-DDThh:mm (according to our spec, this also allowed, even if not allowed in
   *       ISO8601)
   *   <li>YYYY-MM-DDThh:mmTZD
   *   <li>YYYY-MM-DDThh:mm:ssTZD
   *   <li>YYYY-MM-DDThh:mm:ss.sTZD
   * </ul>
   *
   * @throws Exception Forward test exceptions
   */
  public void testRender() throws Exception {
    XMPDateTime dt = XMPDateTimeFactory.create(2006, 12, 31, 23, 59, 59, 987654321);
    dt.setTimeZone(TimeZone.getTimeZone("UTC"));
    assertEquals("2006-12-31T23:59:59.987654321Z", ISO8601Converter.render(dt));

    dt.setNanoSecond(0);
    assertEquals("2006-12-31T23:59:59Z", ISO8601Converter.render(dt));

    dt.setSecond(0);
    assertEquals("2006-12-31T23:59Z", ISO8601Converter.render(dt));

    dt.setMinute(0);
    assertEquals("2006-12-31T23:00Z", ISO8601Converter.render(dt));

    // Following method is available in the latest version of
    // XMPDateTimeFactory class.
    // todo: Import the latest version from the Granite's build.
    // dt = XMPDateTimeFactory.create(2006, 12, 31);
    // assertEquals("2006-12-31", ISO8601Converter.render(dt));

    dt.setHour(0);
    dt.setTimeZone(TimeZone.getTimeZone("Asia/Dushanbe"));
    assertEquals("2006-12-31T00:00+05:00", ISO8601Converter.render(dt));

    dt.setTimeZone(new SimpleTimeZone(-8000000, ""));
    assertEquals("2006-12-31T00:00-02:13", ISO8601Converter.render(dt));
  }
Esempio n. 3
0
  /**
   * Sanitiy test: the current Date and a random date. TODO test against a reg exp?
   *
   * @throws XMPException
   */
  public void testRenderCurrentTime() throws XMPException {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTimeInMillis(new Random().nextLong());

    // restrict date to 0000 - 9999?
    cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) % 10000);

    // select random Timezone
    String[] zones = TimeZone.getAvailableIDs();
    String zone = zones[new Random().nextInt(zones.length) + 1];
    cal.setTimeZone(TimeZone.getTimeZone(zone));
    XMPDateTimeFactory.createFromCalendar(cal);
  }