Exemple #1
0
 /** 単純な文字列解析。 */
 @Test
 public void parse() {
   Date date = Date.valueOf("12340102", Date.Format.SIMPLE);
   assertThat(date.getYear(), is(1234));
   assertThat(date.getMonth(), is(1));
   assertThat(date.getDay(), is(2));
 }
Exemple #2
0
 /** parses standard date string. */
 @Test
 public void parse_standard() {
   Date date = Date.valueOf("1234-01-02", Date.Format.STANDARD);
   assertThat(date.getYear(), is(1234));
   assertThat(date.getMonth(), is(1));
   assertThat(date.getDay(), is(2));
 }
Exemple #3
0
 /** 大きな日付の文字列解析。 */
 @Test
 public void parse_big() {
   Date date = Date.valueOf("29991231", Date.Format.SIMPLE);
   assertThat(date.getYear(), is(2999));
   assertThat(date.getMonth(), is(12));
   assertThat(date.getDay(), is(31));
 }
Exemple #4
0
 /** 最初の日付の文字列解析。 */
 @Test
 public void parse_zero() {
   Date date = Date.valueOf("00010101", Date.Format.SIMPLE);
   assertThat(date.getYear(), is(1));
   assertThat(date.getMonth(), is(1));
   assertThat(date.getDay(), is(1));
 }
Exemple #5
0
 /** optionの解析。 */
 @Test
 public void parse_option() {
   StringOption option = new StringOption("20100615");
   Date date = Date.valueOf(option, Date.Format.SIMPLE);
   assertThat(date.getYear(), is(2010));
   assertThat(date.getMonth(), is(6));
   assertThat(date.getDay(), is(15));
 }
Exemple #6
0
  @SuppressWarnings("deprecation")
  @Test
  public void date() throws SQLException {
    connectWithJulianDayModeActivated();
    Date d1 = new Date(System.currentTimeMillis());

    stat.execute("create table t (c1);");
    PreparedStatement prep = conn.prepareStatement("insert into t values(?);");
    prep.setDate(1, d1);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select c1 from t;");
    assertTrue(rs.next());
    assertEquals(d1.getYear(), rs.getDate(1).getYear());
    assertEquals(d1.getMonth(), rs.getDate(1).getMonth());
    assertEquals(d1.getDay(), rs.getDate(1).getDay());
    rs.close();
  }
Exemple #7
0
  void checkCalendar(int start, int end) {
    GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    calendar.clear();

    calendar.set(Calendar.YEAR, start);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DATE, 1);

    Date date = new Date();
    date.setElapsedDays(DateUtil.getDayFromDate(start, 1, 1));
    while (calendar.get(Calendar.YEAR) <= end) {

      String calString = calendar.toString();
      assertThat("Year: " + calString, date.getYear(), is(calendar.get(Calendar.YEAR)));
      assertThat("Month: " + calString, date.getMonth(), is(calendar.get(Calendar.MONTH) + 1));
      assertThat("Date: " + calString, date.getDay(), is(calendar.get(Calendar.DATE)));

      calendar.add(Calendar.DATE, 1);
      date.setElapsedDays(date.getElapsedDays() + 1);
    }
  }