Package com.ibm.icu.util

Examples of com.ibm.icu.util.GregorianCalendar


     *                                  parameters is illegal.
     */
    public DateValue(int year, int month, int dayOfMonth) {
        // Constructs a GregorianCalendar with the given date set in
        // the default time zone.
        GregorianCalendar calendar =
                new GregorianCalendar(year, month, dayOfMonth);

        // Input check. If the date is invalid the calendar object will output
        // different fields for year, month and/or dayOfMonth.
        // A RunTimeException is thrown here since it is very unusual for structured
        // data to be incorrect.
        if((calendar.get(GregorianCalendar.YEAR) != year)
                || (calendar.get(GregorianCalendar.MONTH) != month)
                || (calendar.get(GregorianCalendar.DAY_OF_MONTH) != dayOfMonth)) {
            throw new IllegalArgumentException("Invalid java date (yyyy-MM-dd): "
                    + year + '-' + month + '-' + dayOfMonth);
        }
        // Assign internal variables.
        this.year = year;
View Full Code Here


    @Override
    public Calendar getObjectToFormat() {
        if(isNull()) {
            return null;
        }
        GregorianCalendar cal = new GregorianCalendar(year, month, dayOfMonth);
        cal.setTimeZone(TimeZone.getTimeZone("GMT"));
        return cal;
    }
View Full Code Here

        if(isNull()) {
            return null;
        }

        // Set GMT TimeZone.
        Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        // Set to some predefined default. Don't change this default.
        cal.set(Calendar.YEAR, 1899);
        cal.set(Calendar.MONTH, Calendar.DECEMBER);
        cal.set(Calendar.DAY_OF_MONTH, 30);
        // Set the TimeOfDay based on this TimeOfDayValue.
        cal.set(Calendar.HOUR_OF_DAY, hours);
        cal.set(Calendar.MINUTE, minutes);
        cal.set(Calendar.SECOND, seconds);
        cal.set(Calendar.MILLISECOND, milliseconds);

        return cal;
    }
View Full Code Here

        if (gmtfmtCache[cacheIdx] != null) {
            fmt = (MessageFormat)gmtfmtCache[cacheIdx].get();
        }
        if (fmt == null) {
            fmt = new MessageFormat(formatData.gmtFormat);
            GregorianCalendar gcal = new GregorianCalendar(TimeZone.getTimeZone("Etc/UTC"));
            SimpleDateFormat sdf = (SimpleDateFormat)this.clone();
            sdf.setCalendar(gcal);
            sdf.applyPattern(formatData.getGmtHourFormat(sign, width));
            fmt.setFormat(0, sdf);
            gmtfmtCache[cacheIdx] = new WeakReference(fmt);
View Full Code Here

            // require the host zone to be set; it can be set in Java.
            String[] ids = TimeZone.getAvailableIDs();
            boolean bad = false;
            for (int i=0; i<ids.length; ++i) {
                TimeZone zone = TimeZone.getTimeZone(ids[i]);
                GregorianCalendar cal = new GregorianCalendar(zone);
                cal.clear();
                cal.set(1900, 15, 5, 5, 8, 13);
                if (cal.get(Calendar.HOUR) != 5) {
                    logln("Fail: " + zone.getID() + " " +
                          zone.useDaylightTime() + "; DST_OFFSET = " +
                          cal.get(Calendar.DST_OFFSET) / (60*60*1000.0) + "; ZONE_OFFSET = " +
                          cal.get(Calendar.ZONE_OFFSET) / (60*60*1000.0) + "; getRawOffset() = " +
                          zone.getRawOffset() / (60*60*1000.0) +
                          "; HOUR = " + cal.get(Calendar.HOUR));
                    cal.clear();
                    cal.set(1900, 15, 5, 5, 8, 13);
                    if (cal.get(Calendar.HOUR) != 5) {
                        logln("Fail: " + zone.getID() + " " +
                              zone.useDaylightTime() + "; DST_OFFSET = " +
                              cal.get(Calendar.DST_OFFSET) / (60*60*1000.0) + "; ZONE_OFFSET = " +
                              cal.get(Calendar.ZONE_OFFSET) / (60*60*1000.0) + "; getRawOffset() = " +
                              zone.getRawOffset() / (60*60*1000.0) +
                              "; HOUR = " + cal.get(Calendar.HOUR));
                        cal.clear();
                        cal.set(1900, 15, 5, 5, 8, 13);
                        logln("ms = " + cal.getTime() + " (" + cal.getTime().getTime() + ")");
                        cal.get(Calendar.HOUR);
                        java.util.GregorianCalendar cal2 = new java.util.GregorianCalendar(java.util.TimeZone.getTimeZone(ids[i]));
                        cal2.clear();
                        cal2.set(1900, 15, 5, 5, 8, 13);
                        cal2.get(Calendar.HOUR);
                        logln("java.util.GC: " + zone.getID() + " " +
                            zone.useDaylightTime() + "; DST_OFFSET = " +
                            cal2.get(Calendar.DST_OFFSET) / (60*60*1000.0) + "; ZONE_OFFSET = " +
                            cal2.get(Calendar.ZONE_OFFSET) / (60*60*1000.0) + "; getRawOffset() = " +
                            zone.getRawOffset() / (60*60*1000.0) +
                            "; HOUR = " + cal.get(Calendar.HOUR));
                        logln("ms = " + cal2.getTime() + " (" + cal2.getTime().getTime() + ")");
                        bad = true;
                    } else if (false) { // Change to true to debug
                        logln("OK: " + zone.getID() + " " +
                              zone.useDaylightTime() + " " +
                              cal.get(Calendar.DST_OFFSET) / (60*60*1000) + " " +
                              zone.getRawOffset() / (60*60*1000) +
                              ": HOUR = " + cal.get(Calendar.HOUR));
                    }
                }
                if (bad) errln("TimeZone problems with GC");
            }
        } catch (MissingResourceException e) {
View Full Code Here

    }

    public void Test4035301() {
       
        try {
            GregorianCalendar c = new GregorianCalendar(98, 8, 7);
            GregorianCalendar d = new GregorianCalendar(98, 8, 7);
            if (c.after(d) ||
                c.after(c) ||
                c.before(d) ||
                c.before(c) ||
                !c.equals(c) ||
View Full Code Here

        try {
            String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
            SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
            pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
            pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
            Calendar calendar = new GregorianCalendar(pdt);

            calendar.set(Calendar.MONTH,3);
            calendar.set(Calendar.DAY_OF_MONTH,18);
            calendar.set(Calendar.SECOND, 30);

            logln("MONTH: " + calendar.get(Calendar.MONTH));
            logln("DAY_OF_MONTH: " +
                               calendar.get(Calendar.DAY_OF_MONTH));
            logln("MINUTE: " + calendar.get(Calendar.MINUTE));
            logln("SECOND: " + calendar.get(Calendar.SECOND));

            calendar.add(Calendar.SECOND,6);
            //This will print out todays date for MONTH and DAY_OF_MONTH
            //instead of the date it was set to.
            //This happens when adding MILLISECOND or MINUTE also
            logln("MONTH: " + calendar.get(Calendar.MONTH));
            logln("DAY_OF_MONTH: " +
                               calendar.get(Calendar.DAY_OF_MONTH));
            logln("MINUTE: " + calendar.get(Calendar.MINUTE));
            logln("SECOND: " + calendar.get(Calendar.SECOND));
            if (calendar.get(Calendar.MONTH) != 3 ||
                calendar.get(Calendar.DAY_OF_MONTH) != 18 ||
                calendar.get(Calendar.SECOND) != 36)
                errln("Fail: Calendar.add misbehaves");
        } catch (Exception e) {
            warnln("Could not load data. "+ e.getMessage());
        }
    }
View Full Code Here

            // jdk1.4.1 will drop support for 2.6 so we should be ok when it
            // comes out
            java.util.TimeZone javazone = java.util.TimeZone.getTimeZone("GMT");
            TimeZone icuzone = TimeZone.getTimeZone("GMT");

            GregorianCalendar gc = new GregorianCalendar(icuzone);
           
            gc.set(1997, 3, 1, 15, 16, 17); // April 1, 1997

            gc.set(Calendar.HOUR, 0);
            gc.set(Calendar.AM_PM, Calendar.AM);
            gc.set(Calendar.MINUTE, 0);
            gc.set(Calendar.SECOND, 0);
            gc.set(Calendar.MILLISECOND, 0);

            Date cd = gc.getTime();
            java.util.Calendar cal = java.util.Calendar.getInstance(javazone);
            cal.clear();
            cal.set(1997, 3, 1, 0, 0, 0);
            Date exp = cal.getTime();
            if (!cd.equals(exp))
View Full Code Here

    public void Test4070502() {
        java.util.Calendar tempcal = java.util.Calendar.getInstance();
        tempcal.clear();
        tempcal.set(1998, 0, 30);
        Date d = getAssociatedDate(tempcal.getTime());
        Calendar cal = new GregorianCalendar();
        cal.setTime(d);
        if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY ||
            cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
            errln("Fail: Want weekday Got " + d);
    }
View Full Code Here

     *
     * @param d
     *            The date to start from
     */
    public static Date getAssociatedDate(Date d) {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(d);
        //cal.add(field, amount); //<-- PROBLEM SEEN WITH field = DATE,MONTH
        // cal.getTime(); // <--- REMOVE THIS TO SEE BUG
        while (true) {
            int wd = cal.get(Calendar.DAY_OF_WEEK);
            if (wd == Calendar.SATURDAY || wd == Calendar.SUNDAY) {
                cal.add(Calendar.DATE, 1);
                // cal.getTime();
            }
            else
                break;
        }
        return cal.getTime();
    }
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.