Package com.ibm.icu.util

Examples of com.ibm.icu.util.GregorianCalendar


    /**
     * Tests addRowFromValues.
     */
    public void testAddRowFromValues() {
        assertEquals(4, testData.getNumberOfRows());
        GregorianCalendar c1 = new GregorianCalendar(2009, 2, 15);
        c1.setTimeZone(TimeZone.getTimeZone("GMT"));
        GregorianCalendar c2 = new GregorianCalendar(2009, 2, 15, 12, 30, 45);
        c2.setTimeZone(TimeZone.getTimeZone("GMT"));
        try {
            testData.addRowFromValues("blah", 5, true, c1, c2, c2);
        }
        catch(TypeMismatchException e) {
            fail();
View Full Code Here


        break;
      case DATE:
        Date date = rs.getDate(column);
        // If date is null it is handled later.
        if (date != null) {
          GregorianCalendar gc =
              new GregorianCalendar(TimeZone.getTimeZone("GMT"));
          // Set the year, month and date in the gregorian calendar.
          // Use the 'set' method with those parameters, and not the 'setTime'
          // method with the date parameter, since the Date object contains the
          // current time zone and it's impossible to change it to 'GMT'.
          gc.setTime(date);
          value = new DateValue(gc);
        }
        break;
      case DATETIME:
        Timestamp timestamp = rs.getTimestamp(column);
        // If timestamp is null it is handled later.
        if (timestamp != null) {
          GregorianCalendar gc =
              new GregorianCalendar(TimeZone.getTimeZone("GMT"));
          gc.setTime(timestamp);
          // Set the milliseconds explicitly, as they are not saved in the
          // underlying date.
          gc.set(Calendar.MILLISECOND, timestamp.getNanos() / 1000000);
          value = new DateTimeValue(gc);
        }
        break;
      case TIMEOFDAY:
        Time time = rs.getTime(column);
        // If time is null it is handled later.
        if (time != null) {
          GregorianCalendar gc =
              new GregorianCalendar(TimeZone.getTimeZone("GMT"));
          gc.setTime(time);
          value = new TimeOfDayValue(gc);
        }
        break;
      default:
        String colValue = rs.getString(column);
View Full Code Here

     * @return A date time value based on the given string.
     * @throws ParseException If val cannot be parsed into a date.
     */
    private DateTimeValue parseDateTime(String val) throws ParseException {
        Date date = ((SimpleDateFormat) uFormat).parse(val);
        GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        gc.setTime(date);
        return new DateTimeValue(gc);
    }
View Full Code Here

     * @return A date value based on the given string.
     * @throws ParseException If val cannot be parsed into a date.
     */
    private DateValue parseDate(String val) throws ParseException {
        Date date = ((SimpleDateFormat) uFormat).parse(val);
        GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        gc.setTime(date);
        return new DateValue(gc);
    }
View Full Code Here

     * @return A time of day value based on the given string.
     * @throws ParseException If val cannot be parsed into a date.
     */
    private TimeOfDayValue parseTimeOfDay(String val) throws ParseException {
        Date date = ((SimpleDateFormat) uFormat).parse(val);
        GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        gc.setTime(date);
        return new TimeOfDayValue(gc);
    }
View Full Code Here

     * @return A date value with the appropriate date.
     */
    public Value evaluate(List<Value> values) {
        Value value = values.get(0);
        Date date;
        GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

        // If the given value is null, return a null date value.
        if(value.isNull()) {
            return DateValue.getNullValue();
        }
        DateValue dateValue;
        switch(value.getType()) {
            case DATE:
                dateValue = (DateValue) value;
                break;
            case DATETIME:
                dateValue = new DateValue((GregorianCalendar)
                        (((DateTimeValue) value).getObjectToFormat()));
                break;
            case NUMBER:
                date = new Date((long) ((NumberValue) value).getValue());
                gc.setTime(date);
                dateValue = new DateValue(gc);
                break;
            default:// Should never get here.
                throw new RuntimeException("Value type was not found: " + value.getType());
        }
View Full Code Here

     * @throws SQLException Thrown when the connection to the database failed.
     */
    public void testBuildDataTableRows() throws SQLException {
        // Build Timestamp, Date ant Time objects for the date February 8, 2008
        // 09:01:10. Set their values in the table.
        GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        gc.set(2008, 1, 8, 9, 1, 10);
        // Set the milliseconds explicitly, otherwise the milliseconds from the
        // time the gc was initialized are used.
        gc.set(GregorianCalendar.MILLISECOND, 0);

        Date date = new Date(gc.getTimeInMillis());
        Time time = new Time(gc.get(GregorianCalendar.HOUR), gc.get(GregorianCalendar.MINUTE),
                gc.get(GregorianCalendar.SECOND));
        Timestamp timestamp = new Timestamp(
                gc.get(GregorianCalendar.YEAR) - 1900, gc.get(GregorianCalendar.MONTH),
                gc.get(GregorianCalendar.DAY_OF_MONTH), gc.get(GregorianCalendar.HOUR),
                gc.get(GregorianCalendar.MINUTE), gc.get(GregorianCalendar.SECOND), 0);

        // Create the table rows.
        List<Object> row1 =
                Lists.<Object>newArrayList(100, "Yaron", null, 'M', 1000, false, date,
                        timestamp, time);
View Full Code Here

            // Do nothing, this is the expected behavior.
        }

        // Test creating a DateValue.
        try {
            GregorianCalendar calendar = new GregorianCalendar(2009, 2, 15);
            calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
            Value v = ValueType.DATE.createValue(calendar);
            assertTrue(v.getType() == ValueType.DATE);
            DateValue dv = (DateValue) v;
            assertEquals(dv.compareTo(new DateValue(calendar)), 0);
        }
        catch(TypeMismatchException e) {
            fail();
        }

        // Verify that an exception is thrown on type mismatch for DateValue.
        try {
            Value v = ValueType.DATE.createValue("abc");
            fail();
        }
        catch(TypeMismatchException e) {
            // Do nothing, this is the expected behavior.
        }

        // Test creating a null DateValue.
        try {
            Value v = ValueType.DATE.createValue(null);
            assertTrue(v.getType() == ValueType.DATE);
            DateValue dv = (DateValue) v;
            assertEquals(dv, DateValue.getNullValue());
        }
        catch(TypeMismatchException e) {
            // Do nothing, this is the expected behavior.
        }

        // Test creating a DateTimeValue.
        try {
            GregorianCalendar calendar = new GregorianCalendar(2009, 2, 15, 12, 30, 14);
            calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
            Value v = ValueType.DATETIME.createValue(calendar);
            assertTrue(v.getType() == ValueType.DATETIME);
            DateTimeValue dtv = (DateTimeValue) v;
            assertEquals(dtv.compareTo(new DateTimeValue(calendar)), 0);
        }
        catch(TypeMismatchException e) {
            fail();
        }

        // Verify that an exception is thrown on type mismatch for DateTimeValue.
        try {
            Value v = ValueType.DATETIME.createValue("abc");
            fail();
        }
        catch(TypeMismatchException e) {
            // Do nothing, this is the expected behavior.
        }

        // Test creating a null DateTimeValue.
        try {
            Value v = ValueType.DATETIME.createValue(null);
            assertTrue(v.getType() == ValueType.DATETIME);
            DateTimeValue dtv = (DateTimeValue) v;
            assertEquals(dtv, DateTimeValue.getNullValue());
        }
        catch(TypeMismatchException e) {
            // Do nothing, this is the expected behavior.
        }

        // Test creating a TimeOfDayValue.
        try {
            GregorianCalendar calendar = new GregorianCalendar(2009, 2, 15, 12, 30, 14);
            calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
            Value v = ValueType.TIMEOFDAY.createValue(calendar);
            assertTrue(v.getType() == ValueType.TIMEOFDAY);
            TimeOfDayValue todv = (TimeOfDayValue) v;
            assertEquals(todv.compareTo(new TimeOfDayValue(calendar)), 0);
        }
View Full Code Here

            assertFalse("An exception was not supposed to be thorwn", true);
        }
    }

    public void testCalendarConstructor() {
        GregorianCalendar calendar = new GregorianCalendar(2006, 1, 1, 21, 24, 25);
        calendar.set(GregorianCalendar.MILLISECONDS_IN_DAY, 222);
        DateTimeValue value = null;
        calendar.setTimeZone(TimeZone.getTimeZone("IST"));
        // Check exception thrown for non GMT time zone.
        try {
            value = new DateTimeValue(calendar);
            fail();
        }
        catch(IllegalArgumentException iae) {
            // do nothing
        }
        calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
        // Check exception not thrown for GMT time zone.
        try {
            value = new DateTimeValue(calendar);
        }
        catch(IllegalArgumentException iae) {
View Full Code Here

    public void testGetValueToFormat() {
        DateTimeValue val = new DateTimeValue(2020, 3, 12, 2, 31, 12, 111);
        DateTimeValue valNull = DateTimeValue.getNullValue();

        GregorianCalendar g = new GregorianCalendar(2020, 3, 12, 2, 31, 12);
        g.set(GregorianCalendar.MILLISECOND, 111);
        g.setTimeZone(TimeZone.getTimeZone("GMT"));

        assertNull(valNull.getObjectToFormat());
        assertEquals(g, val.getObjectToFormat());
    }
View Full Code Here

TOP

Related Classes of com.ibm.icu.util.GregorianCalendar

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.