Package com.skaringa.util

Examples of com.skaringa.util.ISO8601DateTimeFormat


   */
  private DateFormat newFormatter(String xmlType) {
    if ("xsd:date".equals(xmlType)) {
      return new ISO8601DateFormat(TimeZone.getDefault());
    }
    return new ISO8601DateTimeFormat(TimeZone.getDefault());
  }
View Full Code Here


   */
  public void testFormat() {
    TimeZone tz = TimeZone.getTimeZone("GMT+01");
    Calendar cal = Calendar.getInstance(tz);
    cal.set(1962, Calendar.JANUARY, 19, 8, 40, 0);
    ISO8601DateTimeFormat formatter = new ISO8601DateTimeFormat(tz);

    String res = formatter.format(cal.getTime());

    assertEquals(
      "ISO 8601 date formatter produces wrong output",
      "1962-01-19T08:40:00+01:00",
      res);
View Full Code Here

   * Test the formatting and parsing
   */
  public void testFormatAndParse() {
    Calendar cal = new GregorianCalendar(1962, 0, 19, 8, 40);
    Date myBirthDay = cal.getTime();
    ISO8601DateTimeFormat formatter = new ISO8601DateTimeFormat();
    String serial = formatter.format(myBirthDay);

    ParsePosition pos = new ParsePosition(0);
    Date parsedDate = formatter.parse(serial, pos);
    assertNotNull(
      "Parsing of " + serial + " failed at position " + pos.getIndex(),
      parsedDate);
    assertEquals(
      "ISO 8601 date parser produces wrong result",
View Full Code Here

   * @throws Exception If the test failes.
   */
  public void testParse() throws Exception {
    Calendar cal = Calendar.getInstance();

    ISO8601DateTimeFormat formatter = new ISO8601DateTimeFormat();

    // east
    Date parsedDate = formatter.parse("1970-01-01T01:00:00+01:00");
    cal.setTime(parsedDate);
    cal.setTimeZone(TimeZone.getTimeZone("GMT+01"));
    assertEquals(1970, cal.get(Calendar.YEAR));
    assertEquals(Calendar.JANUARY, cal.get(Calendar.MONTH));
    assertEquals(1, cal.get(Calendar.DAY_OF_MONTH));
    assertEquals(1, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, cal.get(Calendar.MINUTE));
    assertEquals(0, cal.get(Calendar.SECOND));

    // west
    parsedDate = formatter.parse("1969-12-31T19:00:02-05:00");
    cal.setTime(parsedDate);
    cal.setTimeZone(TimeZone.getTimeZone("GMT-05"));
    assertEquals(1969, cal.get(Calendar.YEAR));
    assertEquals(Calendar.DECEMBER, cal.get(Calendar.MONTH));
    assertEquals(31, cal.get(Calendar.DAY_OF_MONTH));
    assertEquals(19, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, cal.get(Calendar.MINUTE));
    assertEquals(2, cal.get(Calendar.SECOND));

    // GMT
    parsedDate = formatter.parse("2003-03-18T10:30:02Z");
    cal.setTime(parsedDate);
    cal.setTimeZone(TimeZone.getTimeZone("GMT"));
    assertEquals(2003, cal.get(Calendar.YEAR));
    assertEquals(Calendar.MARCH, cal.get(Calendar.MONTH));
    assertEquals(18, cal.get(Calendar.DAY_OF_MONTH));
    assertEquals(10, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(30, cal.get(Calendar.MINUTE));
    assertEquals(2, cal.get(Calendar.SECOND));

    // default TZ
    parsedDate = formatter.parse("1999-07-28T19:27:02");
    cal.setTime(parsedDate);
    cal.setTimeZone(TimeZone.getDefault());
    assertEquals(1999, cal.get(Calendar.YEAR));
    assertEquals(Calendar.JULY, cal.get(Calendar.MONTH));
    assertEquals(28, cal.get(Calendar.DAY_OF_MONTH));
View Full Code Here

   * @throws Exception If the test failes.
   */
  public void testParseWithoutSeconds() throws Exception {
    Calendar cal = Calendar.getInstance();

    ISO8601DateTimeFormat formatter = new ISO8601DateTimeFormat();

    // GMT
    Date parsedDate = formatter.parse("2003-04-01T12:34Z");
    cal.setTime(parsedDate);
    cal.setTimeZone(TimeZone.getTimeZone("GMT"));
    assertEquals(2003, cal.get(Calendar.YEAR));
    assertEquals(Calendar.APRIL, cal.get(Calendar.MONTH));
    assertEquals(1, cal.get(Calendar.DAY_OF_MONTH));
    assertEquals(12, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(34, cal.get(Calendar.MINUTE));
    assertEquals(0, cal.get(Calendar.SECOND));

    // east
    parsedDate = formatter.parse("2003-04-01T12:34-05:00");
    cal.setTime(parsedDate);
    cal.setTimeZone(TimeZone.getTimeZone("GMT-05"));
    assertEquals(2003, cal.get(Calendar.YEAR));
    assertEquals(Calendar.APRIL, cal.get(Calendar.MONTH));
    assertEquals(1, cal.get(Calendar.DAY_OF_MONTH));
    assertEquals(12, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(34, cal.get(Calendar.MINUTE));
    assertEquals(0, cal.get(Calendar.SECOND));

    // default TZ
    parsedDate = formatter.parse("2003-04-01T12:34");
    cal.setTime(parsedDate);
    cal.setTimeZone(TimeZone.getDefault());
    assertEquals(2003, cal.get(Calendar.YEAR));
    assertEquals(Calendar.APRIL, cal.get(Calendar.MONTH));
    assertEquals(1, cal.get(Calendar.DAY_OF_MONTH));
View Full Code Here

  /**
   * Test reporting of parsing error
   */
  public void testParseException() {
    String wrong = "1999-mar-01T00:00:00Z";
    ISO8601DateTimeFormat formatter = new ISO8601DateTimeFormat();

    ParsePosition pos = new ParsePosition(0);
    Date res = formatter.parse(wrong, pos);

    assertNull("A null value should have been returned.", res);

    assertEquals(
      "The wrong parse position is reported in case of error.",
View Full Code Here

   */
  public void testTimeZone() throws Exception {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+00"));
    cal.set(2000, 0, 1, 0, 0, 0);
    Date gmt = cal.getTime();
    ISO8601DateTimeFormat formatter =
      new ISO8601DateTimeFormat(TimeZone.getTimeZone("GMT+00"));
    String gmtStr = formatter.format(gmt);
    assertEquals(
      "ISO 8601 date handling of timezones failed.",
      "2000-01-01T00:00:00Z",
      gmtStr);

    ISO8601DateTimeFormat parser =
      new ISO8601DateTimeFormat(TimeZone.getTimeZone("GMT+01"));
    Date met = parser.parse(gmtStr);
    String metStr = parser.format(met);

    assertEquals(
      "ISO 8601 date handling of timezones failed.",
      "2000-01-01T01:00:00+01:00",
      metStr);
View Full Code Here

TOP

Related Classes of com.skaringa.util.ISO8601DateTimeFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.