Package com.ibm.icu.util

Examples of com.ibm.icu.util.GregorianCalendar


                    component = ((DateTimeValue) value).getMonth();
                }
                component = component / 3 + 1; // Add 1 to get 1-4 instead of 0-3.
                break;
            case DAY_OF_WEEK:
                GregorianCalendar calendar =
                        (GregorianCalendar) ((valueType == ValueType.DATE) ?
                                ((DateValue) value).getObjectToFormat() :
                                ((DateTimeValue) value).getObjectToFormat());
                component = calendar.get(GregorianCalendar.DAY_OF_WEEK);
                break;
            default:
                // should not get here since we assume that the given values are valid.
                throw new RuntimeException("An invalid time component.");
        }
View Full Code Here


            return NumberValue.getNullValue();
        }
        Date firstDate = getDateFromValue(firstValue);
        Date secondDate = getDateFromValue(secondValue);

        GregorianCalendar calendar =
                new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        calendar.setTime(secondDate);
        return new NumberValue(calendar.fieldDifference(firstDate, Calendar.DATE));
    }
View Full Code Here

     *
     * @param values Ignored.
     * @return A DateTime value with the current time.
     */
    public Value evaluate(List<Value> values) {
        return new DateTimeValue(new GregorianCalendar(
                TimeZone.getTimeZone("GMT")));
    }
View Full Code Here

    protected StringBuilder appendCellJson(TableCell cell,
                                           StringBuilder sb, boolean includeFormatting, boolean isLastColumn) {
        Value value = cell.getValue();
        ValueType type = cell.getType();
        StringBuilder valueJson = new StringBuilder();
        GregorianCalendar calendar;
        String escapedFormattedString = "";
        boolean isJsonNull = false;

        // Prepare a Json string representing the current value.
        DateValue dateValue;
        TimeOfDayValue timeOfDayValue;
        if((value == null) || (value.isNull())) {
            valueJson.append("null");
            isJsonNull = true;
        }
        else {
            switch(type) {
                case BOOLEAN:
                    valueJson.append(((BooleanValue) value).getValue());
                    break;
                case DATE:
                    valueJson.append("Date(");
                    dateValue = (DateValue) value;
                    valueJson.append(dateValue.getYear()).append(",");
                    valueJson.append(dateValue.getMonth()).append(",");
                    valueJson.append(dateValue.getDayOfMonth());
                    valueJson.append(")");
                    this.appendDate(valueJson);
                    break;
                case NUMBER:
                    valueJson.append(((NumberValue) value).getValue());
                    break;
                case TEXT:
                    valueJson.append("\"");
                    valueJson.append(EscapeUtil.jsonEscape(value.toString()));
                    valueJson.append("\"");
                    break;
                case TIMEOFDAY:
                    valueJson.append("[");
                    timeOfDayValue = (TimeOfDayValue) value;
                    valueJson.append(timeOfDayValue.getHours()).append(",");
                    valueJson.append(timeOfDayValue.getMinutes()).append(",");
                    valueJson.append(timeOfDayValue.getSeconds()).append(",");
                    valueJson.append(timeOfDayValue.getMilliseconds());
                    valueJson.append("]");
                    break;
                case DATETIME:
                    calendar = ((DateTimeValue) value).getCalendar();
                    valueJson.append("Date(");
                    valueJson.append(calendar.get(GregorianCalendar.YEAR)).append(",");
                    valueJson.append(calendar.get(GregorianCalendar.MONTH)).append(",");
                    valueJson.append(calendar.get(GregorianCalendar.DAY_OF_MONTH));
                    valueJson.append(",");
                    valueJson.append(calendar.get(GregorianCalendar.HOUR_OF_DAY));
                    valueJson.append(",");
                    valueJson.append(calendar.get(GregorianCalendar.MINUTE)).append(",");
                    valueJson.append(calendar.get(GregorianCalendar.SECOND));
                    valueJson.append(")");
                    this.appendDate(valueJson);
                    break;
                default:
                    throw new IllegalArgumentException("Illegal value Type " + type);
View Full Code Here

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

    public void testCalendarConstructor() {
        GregorianCalendar calendar = new GregorianCalendar(2006, 1, 3);
        DateValue value = null;
        calendar.setTimeZone(TimeZone.getTimeZone("IST"));
        // Check exception thrown for non GMT time zone.
        try {
            value = new DateValue(calendar);
            fail();
        }
        catch(IllegalArgumentException iae) {
            // Expected behavior.
        }
        calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
        // Check that an exception is not thrown for GMT time zone.
        try {
            value = new DateValue(calendar);
        }
        catch(IllegalArgumentException iae) {
View Full Code Here

    public void testGetValueToFormat() {
        DateValue val = new DateValue(500, 2, 30);
        DateValue valNull = DateValue.getNullValue();

        assertNull(valNull.getObjectToFormat());
        GregorianCalendar g = new GregorianCalendar(500, 2, 30);
        g.setTimeZone(TimeZone.getTimeZone("GMT"));
        assertEquals(g, val.getObjectToFormat());

    }
View Full Code Here

    }

    public void testCalendarConstructor() {
        // All fields are set in the calendar although only hour, minute and seconds
        // are requried.
        GregorianCalendar calendar = new GregorianCalendar(2006, 1, 1, 21, 24, 25);
        TimeOfDayValue value = null;
        calendar.setTimeZone(TimeZone.getTimeZone("IST"));
        // Check exception thrown for non GMT time zone.
        try {
            value = new TimeOfDayValue(calendar);
            fail();
        }
        catch(IllegalArgumentException iae) {
            // do nothing
        }
        calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
        // Check exception not thrown for GMT time zone.
        try {
            value = new TimeOfDayValue(calendar);
        }
        catch(IllegalArgumentException iae) {
            fail();
        }
        // Verify values - default milliseconds.
        assertEquals(21, value.getHours());
        assertEquals(24, value.getMinutes());
        assertEquals(25, value.getSeconds());
        assertEquals(0, value.getMilliseconds());

        // Non default milliseconds.
        calendar.set(GregorianCalendar.MILLISECOND, 123);
        value = new TimeOfDayValue(calendar);
        assertEquals(123, value.getMilliseconds());
    }
View Full Code Here

    public void testGetValueToFormat() {
        TimeOfDayValue val1 = new TimeOfDayValue(12, 23, 12, 111);
        TimeOfDayValue nullVal = TimeOfDayValue.getNullValue();

        assertNull(nullVal.getObjectToFormat());
        GregorianCalendar cal = new GregorianCalendar(1899, 11, 30, 12, 23, 12);
        cal.set(Calendar.MILLISECOND, 111);
        cal.setTimeZone(TimeZone.getTimeZone("GMT"));
        assertEquals(cal, val1.getObjectToFormat());
    }
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.set(date.getYear() + 1900, date.getMonth(), date.getDate());
                    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"));
                    // Set the year, month, date, hours, minutes and seconds in the
                    // gregorian calendar. Use the 'set' method with those parameters,
                    // and not the 'setTime' method with the timestamp parameter, since
                    // the Timestamp object contains the current time zone and it's
                    // impossible to change it to 'GMT'.
                    gc.set(timestamp.getYear() + 1900, timestamp.getMonth(),
                            timestamp.getDate(), timestamp.getHours(), timestamp.getMinutes(),
                            timestamp.getSeconds());
                    // 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"));
                    // Set the hours, minutes and seconds of the time in the gregorian
                    // calendar. Set the year, month and date to be January 1 1970 like
                    // in the Time object.
                    // Use the 'set' method with those parameters,
                    // and not the 'setTime' method with the time parameter, since
                    // the Time object contains the current time zone and it's
                    // impossible to change it to 'GMT'.
                    gc.set(1970, Calendar.JANUARY, 1, time.getHours(), time.getMinutes(),
                            time.getSeconds());
                    // Set the milliseconds explicitly, otherwise the milliseconds from
                    // the time the gc was initialized are used.
                    gc.set(GregorianCalendar.MILLISECOND, 0);
                    value = new TimeOfDayValue(gc);
                }
                break;
            default:
                String colValue = rs.getString(column);
View Full Code Here

     *                                  parameters is illegal.
     */
    public DateTimeValue(int year, int month, int dayOfMonth, int hours,
                         int minutes, int seconds, int milliseconds) {
        // Constructs a GregorianCalendar with the given date and time.
        calendar = new GregorianCalendar(year, month, dayOfMonth, hours,
                minutes, seconds);
        calendar.set(GregorianCalendar.MILLISECOND, milliseconds);
        calendar.setTimeZone(TimeZone.getTimeZone("GMT"));

        // Check input.
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.