示例#1
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));
  }
示例#2
0
  @Ignore("todo: Import the latest changes to enable the below test case.")
  public void itestRenderAbbreviations() throws Exception {
    // Following method is available in the latest version of XMPDateTime
    // class.
    // todo: Import the latest version from the Granite's build.
    // XMPDateTime dt = XMPDateTimeFactory.create();
    XMPDateTime dt = new XMPDateTimeImpl();
    assertEquals("", ISO8601Converter.render(dt));

    dt.setYear(2010);
    assertEquals("2010", ISO8601Converter.render(dt));

    dt.setMonth(9);
    assertEquals("2010-09", ISO8601Converter.render(dt));

    dt.setDay(30);
    assertEquals("2010-09-30", ISO8601Converter.render(dt));

    // Note: hours and minutes are always rendered together
    dt.setHour(23);
    assertEquals("2010-09-30T23:00", ISO8601Converter.render(dt));

    dt.setMinute(58);
    assertEquals("2010-09-30T23:58", ISO8601Converter.render(dt));

    dt.setSecond(59);
    assertEquals("2010-09-30T23:58:59", ISO8601Converter.render(dt));

    dt.setNanoSecond(999 * 1000000);
    assertEquals("2010-09-30T23:58:59.999", ISO8601Converter.render(dt));

    dt.setTimeZone(TimeZone.getTimeZone("Egypt"));
    assertEquals("2010-09-30T23:58:59.999+02:00", ISO8601Converter.render(dt));
  }