Package edu.uams.dbmi.util.iso8601

Examples of edu.uams.dbmi.util.iso8601.Iso8601DateTime


    assertNotNull(d1.getCalendarForDay());
  }
 
  @Test
  public void testIso8601Date_YearWeek() {
    Iso8601Date d1 = new Iso8601Date(
        Iso8601Date.DateConfiguration.YEAR_WEEK, 1755, 33);
    assertEquals(d1.getCentury(), 17);
    assertEquals(d1.getYear(), 1755);
    assertEquals(d1.getWeekOfYear(), 33);
    assertFalse(d1.isCentury());
    assertFalse(d1.isYear());
    assertFalse(d1.isMonth());
    assertTrue(d1.isWeek());
    assertFalse(d1.isDay());
    assertNotNull(d1.getCalendarForFirstDayInInterval());
  }
View Full Code Here


    assertNotNull(d1.getCalendarForFirstDayInInterval());
  }
 
  @Test
  public void testIso8601Date_YearWeekDay() {
    Iso8601Date d1 = new Iso8601Date(
        Iso8601Date.DateConfiguration.YEAR_WEEK_DAY, 1755, 33, 5);
    assertEquals(d1.getCentury(), 17);
    assertEquals(d1.getYear(), 1755);
    assertEquals(d1.getWeekOfYear(), 33);
    assertEquals(d1.getDayOfWeek(), 5);
    assertFalse(d1.isCentury());
    assertFalse(d1.isYear());
    assertFalse(d1.isMonth());
    assertFalse(d1.isWeek());
    assertTrue(d1.isDay());
    assertNotNull(d1.getCalendarForDay());
  }
View Full Code Here

    assertNotNull(d1.getCalendarForDay());
  }
 
  @Test
  public void testIso8601Date_YearDayOfYear() {
    Iso8601Date d1 = new Iso8601Date(
        Iso8601Date.DateConfiguration.YEAR_DAY_OF_YEAR, 1972, 221);
    assertEquals(d1.getCentury(), 19);
    assertEquals(d1.getYear(), 1972);
    assertEquals(d1.getDayOfYear(), 221);
    assertFalse(d1.isCentury());
    assertFalse(d1.isYear());
    assertFalse(d1.isMonth());
    assertFalse(d1.isWeek());
    assertTrue(d1.isDay());
    assertNotNull(d1.getCalendarForDay());
  }
View Full Code Here

      } else {
        cDay = 30;
      }
     
      for (int dy = 1; dy<=cDay; dy++) {
        Iso8601Date d = new Iso8601Date(
            Iso8601Date.DateConfiguration.YEAR_MONTH_DAY,
            yr, mo, dy);
        Iso8601Date d2 = new Iso8601Date(
            Iso8601Date.DateConfiguration.YEAR_DAY_OF_YEAR,
            yr, dayOfYear);
        assertEquals(d, d2);
        assertEquals(d.getCentury(), 20);
        assertEquals(d.getYear(), yr);
View Full Code Here

  /*
   * The ISO 8601 standard document uses April 12, 1985 as an example, so
   *  let's make sure we get it right.
   */
  public void testApril_12_1985() {
    Iso8601Date d = new Iso8601Date(DateConfiguration.YEAR_MONTH_DAY, 1985,
        4, 12);
    assertEquals(d.getCentury(), 19);
    assertEquals(d.getYear(), 1985);
    assertEquals(d.getMonth(), 4);
    assertEquals(d.getDayOfMonth(), 12);
    assertTrue(d.isDay());
    assertFalse(d.isCentury());
    assertFalse(d.isYear());
    assertFalse(d.isMonth());
    assertFalse(d.isWeek());
    GregorianCalendar c = d.getCalendarForDay();
    assertEquals(c.get(Calendar.YEAR), 1985);
    assertEquals(c.get(Calendar.MONTH), 3);
    assertEquals(c.get(Calendar.DAY_OF_MONTH), 12);
    assertEquals(c.get(Calendar.DAY_OF_YEAR), 102);
    assertEquals(d.getDayOfYear(), 102);
    assertEquals(d.getWeekOfYear(), 15);
    assertEquals(d.getDayOfWeek(), 5);
    assertEquals(c.get(Calendar.WEEK_OF_YEAR), 15);
   
    Iso8601Date d2 = new Iso8601Date(DateConfiguration.YEAR_DAY_OF_YEAR,
        1985, 102);
    assertEquals(d2.getCentury(), 19);
    assertEquals(d2.getYear(), 1985);
    assertEquals(d2.getMonth(), 4);
    assertEquals(d2.getDayOfMonth(), 12);
    assertEquals(d2.getDayOfYear(), 102);
    assertTrue(d2.isDay());
    assertFalse(d2.isCentury());
    assertFalse(d2.isYear());
    assertFalse(d2.isMonth());
    assertFalse(d2.isWeek());
    GregorianCalendar c2 = d2.getCalendarForDay();
    assertEquals(c2.get(Calendar.YEAR), 1985);
    assertEquals(c2.get(Calendar.MONTH), 3);
    assertEquals(c2.get(Calendar.DAY_OF_MONTH), 12);
    assertEquals(c2.get(Calendar.DAY_OF_YEAR), 102);
    assertEquals(d2.getWeekOfYear(), 15);
    assertEquals(d2.getDayOfWeek(), 5);
    assertEquals(c2.get(Calendar.WEEK_OF_YEAR), 15);
   
    Iso8601Date d3 = new Iso8601Date(DateConfiguration.YEAR_WEEK_DAY,
        1985, 15, 5);
    assertEquals(d3.getCentury(), 19);
    assertEquals(d3.getYear(), 1985);
    assertEquals(d3.getWeekOfYear(), 15);
    assertEquals(d3.getDayOfWeek(), 5);
    assertEquals(d3.getMonth(), 4);
    assertEquals(d3.getDayOfMonth(), 12);
    assertEquals(d3.getDayOfYear(), 102);
    assertTrue(d3.isDay());
    assertFalse(d3.isCentury());
    assertFalse(d3.isYear());
    assertFalse(d3.isMonth());
    assertFalse(d3.isWeek());
    assertEquals(d3.getMonth(), 4);
    assertEquals(d3.getDayOfMonth(), 12);
    GregorianCalendar c3 = d3.getCalendarForDay();
    assertEquals(c3.get(Calendar.YEAR), 1985);
    assertEquals(c3.get(Calendar.MONTH), 3);
    assertEquals(c3.get(Calendar.DAY_OF_MONTH), 12);
    assertEquals(c3.get(Calendar.DAY_OF_YEAR), 102);
    assertEquals(c3.get(Calendar.WEEK_OF_YEAR), 15);
View Full Code Here

    }
    assertTrue(expectedErr);   
  }

  private void testYearDayString(Iso8601DateParser parser, String s, int yr, int da) throws Iso8601DateParseException {
    Iso8601Date d1 = parser.parse(s);
    assertNotNull(d1);
    assertTrue(d1.isDay());
    assertEquals(d1.getYear(), yr);
    assertEquals(d1.getCentury(), yr/100);
    assertEquals(d1.getDayOfYear(), da);
    assertFalse(d1.isMonth());
    assertFalse(d1.isWeek());
    assertFalse(d1.isYear());
    assertFalse(d1.isCentury());
    GregorianCalendar cal = d1.getCalendarForDay();
    assertNotNull(cal);
    if (yr > 0) {
      assertEquals(cal.get(Calendar.YEAR), yr);
      assertEquals(cal.get(Calendar.ERA), GregorianCalendar.AD);
    } else {
View Full Code Here

  public void testWeekFormatParse() {
    Iso8601DateParser parser = new Iso8601DateParser();
   
    String s1 = "2010-W01-1";
    try {
      Iso8601Date d1 = parser.parse(s1);
      assertNotNull(d1);
      assertTrue(d1.isDay());
      assertEquals(d1.getYear(), 2010);
      assertEquals(d1.getWeekOfYear(), 1);
      assertEquals(d1.getDayOfWeek(), 1);
    } catch (Iso8601DateParseException e) {
      fail();
      e.printStackTrace();
    }
   
    String s2 = "2010-W01";
    try {
      Iso8601Date d2 = parser.parse(s2);
      assertNotNull(d2);
      assertFalse(d2.isDay());
      assertTrue(d2.isWeek());
      assertEquals(d2.getYear(), 2010);
      assertEquals(d2.getWeekOfYear(), 1);
    } catch (Iso8601DateParseException e) {
      e.printStackTrace();
      fail();
    }
   
    String s3 = "2010W01";
    try {
      Iso8601Date d3 = parser.parse(s3);
      assertNotNull(d3);
      assertFalse(d3.isDay());
      assertTrue(d3.isWeek());
      assertEquals(d3.getYear(), 2010);
      assertEquals(d3.getWeekOfYear(), 1);
    } catch (Iso8601DateParseException e) {
      e.printStackTrace();
      fail();
    }
   
    String s4 = "2010W011";
    try {
      Iso8601Date d4 = parser.parse(s4);
      assertNotNull(d4);
      assertTrue(d4.isDay());
      assertEquals(d4.getYear(), 2010);
      assertEquals(d4.getWeekOfYear(), 1);
      assertEquals(d4.getDayOfWeek(), 1);
    } catch (Iso8601DateParseException e) {
      e.printStackTrace();
      fail();
    }
   
    String s5 = "2010011";
    try {
      Iso8601Date d5 = parser.parse(s5);
      assertNotNull(d5);
      assertTrue(d5.isDay());
      assertEquals(d5.getYear(), 2010);
      assertEquals(d5.getDayOfYear(), 11);
    } catch (Iso8601DateParseException e) {
      e.printStackTrace();
      fail();
    }
   
    String s6 = "2010W1";
    boolean correctError = false;
    try {
      parser.parse(s6);
    } catch (Iso8601DateParseException e) {
      System.err.println(e.getMessage());
      correctError = true;
    } catch (NumberFormatException e1) {
      e1.printStackTrace();
      fail();
    }
    assertTrue(correctError);
   
    String s7 = "201001";
    try {
      Iso8601Date d7 = parser.parse(s7);
      assertNotNull(d7);
      assertTrue(d7.isMonth());
      assertEquals(d7.getYear(), 2010);
      assertEquals(d7.getMonth(), 1);
    } catch (Iso8601DateParseException e) {
      e.printStackTrace();
      fail();
    }
   
View Full Code Here

    }
    assertTrue(error2);
  }

  public void testCenturyString(Iso8601DateParser parser, String c1, int c) throws Iso8601DateParseException {
      Iso8601Date d1 = parser.parse(c1);
      assertNotNull(d1);
      assertTrue(d1.isCentury());
      assertEquals(d1.getCentury(), c);
      assertFalse(d1.isDay());
      assertFalse(d1.isWeek());
      assertFalse(d1.isMonth());
      assertFalse(d1.isYear());
      GregorianCalendar cal = d1.getCalendarForFirstDayInInterval();
      assertNotNull(cal);
      if (c > 0) {
        assertEquals(cal.get(Calendar.YEAR), c*100);
        assertEquals(cal.get(Calendar.ERA), GregorianCalendar.AD);
      } else {
View Full Code Here

    }
    assertTrue(errExpected);
  }
 
  public void testYearString(Iso8601DateParser parser, String s, int c) throws Iso8601DateParseException {
    Iso8601Date d1 = parser.parse(s);
    assertNotNull(d1);
    assertTrue(d1.isYear());
    assertEquals(d1.getYear(), c);
    assertEquals(d1.getCentury(), c/100);
    assertFalse(d1.isDay());
    assertFalse(d1.isWeek());
    assertFalse(d1.isMonth());
    assertFalse(d1.isCentury());
    GregorianCalendar cal = d1.getCalendarForFirstDayInInterval();
    assertNotNull(cal);
    if (c > 0) {
      assertEquals(cal.get(Calendar.YEAR), c);
      assertEquals(cal.get(Calendar.ERA), GregorianCalendar.AD);
    } else {
View Full Code Here

    assertTrue(errExpected);
   
  }

  public void testYearMonthString(Iso8601DateParser parser, String s1, int yr, int mo) throws Iso8601DateParseException {
    Iso8601Date d1 = parser.parse(s1);
    assertNotNull(d1);
    assertTrue(d1.isMonth());
    assertEquals(d1.getYear(), yr);
    assertEquals(d1.getCentury(), yr/100);
    assertEquals(d1.getMonth(), mo);
    assertFalse(d1.isDay());
    assertFalse(d1.isWeek());
    assertFalse(d1.isYear());
    assertFalse(d1.isCentury());
    GregorianCalendar cal = d1.getCalendarForFirstDayInInterval();
    assertNotNull(cal);
    if (yr > 0) {
      assertEquals(cal.get(Calendar.YEAR), yr);
      assertEquals(cal.get(Calendar.ERA), GregorianCalendar.AD);
    } else {
View Full Code Here

TOP

Related Classes of edu.uams.dbmi.util.iso8601.Iso8601DateTime

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.