Search in sources :

Example 61 with GregorianCalendar

use of java.util.GregorianCalendar in project j2objc by google.

the class DateTest method test_setMonthI.

/**
     * java.util.Date#setMonth(int)
     */
public void test_setMonthI() {
    // Test for method void java.util.Date.setMonth(int)
    Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9).getTime();
    d.setMonth(0);
    assertEquals("Set incorrect month", 0, d.getMonth());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 62 with GregorianCalendar

use of java.util.GregorianCalendar in project j2objc by google.

the class DateTest method test_getMinutes.

/**
     * java.util.Date#getMinutes()
     */
public void test_getMinutes() {
    // Test for method int java.util.Date.getMinutes()
    Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9).getTime();
    assertEquals("Returned incorrect minutes", 9, d.getMinutes());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 63 with GregorianCalendar

use of java.util.GregorianCalendar in project j2objc by google.

the class DateTest method test_getDate.

/**
     * java.util.Date#getDate()
     */
public void test_getDate() {
    // Test for method int java.util.Date.getDate()
    Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9).getTime();
    assertEquals("Returned incorrect date", 13, d.getDate());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 64 with GregorianCalendar

use of java.util.GregorianCalendar in project j2objc by google.

the class DateTest method test_parseLjava_lang_String.

/**
     * java.util.Date#parse(java.lang.String)
     */
public void test_parseLjava_lang_String() {
    // Test for method long java.util.Date.parse(java.lang.String)
    Date d = new Date(Date.parse("13 October 1998"));
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(d);
    assertEquals("Parsed incorrect month", 9, cal.get(Calendar.MONTH));
    assertEquals("Parsed incorrect year", 1998, cal.get(Calendar.YEAR));
    assertEquals("Parsed incorrect date", 13, cal.get(Calendar.DATE));
    d = new Date(Date.parse("Jan-12 1999"));
    assertTrue("Wrong parsed date 1", d.equals(new GregorianCalendar(1999, 0, 12).getTime()));
    d = new Date(Date.parse("Jan12-1999"));
    assertTrue("Wrong parsed date 2", d.equals(new GregorianCalendar(1999, 0, 12).getTime()));
    d = new Date(Date.parse("Jan12 69-1"));
    cal.setTimeZone(TimeZone.getTimeZone("GMT"));
    cal.clear();
    cal.set(1969, Calendar.JANUARY, 12, 1, 0);
    assertTrue("Wrong parsed date 3", d.equals(cal.getTime()));
    d = new Date(Date.parse("6:45:13 3/2/1200 MST"));
    cal.setTimeZone(TimeZone.getTimeZone("MST"));
    cal.clear();
    cal.set(1200, 2, 2, 6, 45, 13);
    assertTrue("Wrong parsed date 4", d.equals(cal.getTime()));
    d = new Date(Date.parse("Mon, 22 Nov 1999 12:52:06 GMT"));
    cal.setTimeZone(TimeZone.getTimeZone("GMT"));
    cal.clear();
    cal.set(1999, Calendar.NOVEMBER, 22, 12, 52, 06);
    assertTrue("Wrong parsed date 5", d.equals(cal.getTime()));
    try {
        // Regression for HARMONY-259
        Date.parse(null);
        fail("Date.parse(null) should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // expected
    }
    // Regression for HARMONY-102
    assertEquals("Assert 0: parse failure", -5400000, Date.parse("Sat, 1 Jan 1970 +0130 00:00:00"));
    assertEquals("Assert 1: parse failure", 858600000, Date.parse("00:00:00 GMT +0130 Sat, 11 Jan 1970"));
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 65 with GregorianCalendar

use of java.util.GregorianCalendar in project j2objc by google.

the class SimpleDateFormatTest method test_set2DigitYearStartLjava_util_Date.

public void test_set2DigitYearStartLjava_util_Date() {
    // Test for method void
    // java.text.SimpleDateFormat.set2DigitYearStart(java.util.Date)
    SimpleDateFormat f1 = new SimpleDateFormat("yy");
    f1.set2DigitYearStart(new GregorianCalendar(1950, Calendar.JANUARY, 1).getTime());
    Calendar cal = new GregorianCalendar();
    try {
        cal.setTime(f1.parse("49"));
        assertEquals("Incorrect year 2049", 2049, cal.get(Calendar.YEAR));
        cal.setTime(f1.parse("50"));
        int year = cal.get(Calendar.YEAR);
        assertTrue("Incorrect year 1950: " + year, year == 1950);
        f1.applyPattern("y");
        cal.setTime(f1.parse("00"));
        assertEquals("Incorrect year 2000", 2000, cal.get(Calendar.YEAR));
        f1.applyPattern("yyy");
        cal.setTime(f1.parse("50"));
        assertEquals("Incorrect year 50", 50, cal.get(Calendar.YEAR));
    } catch (ParseException e) {
        fail("ParseException");
    }
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

GregorianCalendar (java.util.GregorianCalendar)1278 Calendar (java.util.Calendar)603 Date (java.util.Date)377 Test (org.junit.Test)247 SimpleDateFormat (java.text.SimpleDateFormat)104 Timestamp (java.sql.Timestamp)54 ScheduleExpression (javax.ejb.ScheduleExpression)51 ArrayList (java.util.ArrayList)48 EJBCronTrigger (org.apache.openejb.core.timer.EJBCronTrigger)42 HashMap (java.util.HashMap)41 ParseException (java.text.ParseException)39 TimeZone (java.util.TimeZone)38 SimpleTimeZone (java.util.SimpleTimeZone)35 BigDecimal (java.math.BigDecimal)32 Date (java.sql.Date)30 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)28 SQLException (java.sql.SQLException)20 DateFormat (java.text.DateFormat)18 IOException (java.io.IOException)16 Map (java.util.Map)16