Package com.skaringa.util

Examples of com.skaringa.util.ISO8601DateFormat


   * @param xmlType may be 'xsd:dateTime' or 'xsd:date'
   * @return a <code>DateFormat</code> value
   */
  private DateFormat newFormatter(String xmlType) {
    if ("xsd:date".equals(xmlType)) {
      return new ISO8601DateFormat(TimeZone.getDefault());
    }
    return new ISO8601DateTimeFormat(TimeZone.getDefault());
  }
View Full Code Here


   * Test the formatting
   */
  public void testFormat() {
    Calendar cal = new GregorianCalendar(1962, 0, 19);
    cal.setTimeZone(TimeZone.getTimeZone("GMT+01"));
    ISO8601DateFormat formatter = new ISO8601DateFormat();
    String res = formatter.format(cal.getTime());

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

    Collection calendars = new ArrayList();
    calendars.add(new GregorianCalendar(1962, 0, 19));
    calendars.add(new GregorianCalendar(20, 1, 1));
    calendars.add(new GregorianCalendar(2003, 10, 1));

    ISO8601DateFormat formatter = new ISO8601DateFormat();

    Iterator it = calendars.iterator();
    while (it.hasNext()) {
      Calendar cal = (Calendar) it.next();
      Date date = cal.getTime();

      String serial = formatter.format(date);

      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();

    ISO8601DateFormat formatter = new ISO8601DateFormat();

    // east
    Date parsedDate = formatter.parse("1970-01-01+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));

    // west
    parsedDate = formatter.parse("1969-12-31-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));

    // GMT
    parsedDate = formatter.parse("2003-03-18Z");
    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));

    // no TZ
    parsedDate = formatter.parse("1999-07-28");
    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

  /**
   * Test reporting of parsing error.
   */
  public void testParseException() {
    String wrong = "1999-mar-01";
    ISO8601DateFormat formatter = new ISO8601DateFormat();

    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

TOP

Related Classes of com.skaringa.util.ISO8601DateFormat

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.