Package com.ibm.icu.util

Examples of com.ibm.icu.util.GregorianCalendar


        final int kYear = 0// offset for dotNetDateTimeTicks[] field
        final int kMonth = 1;
        final int kDay = 2;
        final int kTicks = 3;
        final int kIncrement = 4;
        GregorianCalendar cal;
        long icuDate;
        long ticks, millis;
        int i;

        /* Open a proleptic Gregorian calendar. */
        long before0001AD = -1000000 * dayMillis;
        utc = new SimpleTimeZone(0, "UTC");
        cal = new GregorianCalendar(utc, Locale.ENGLISH);
        cal.setGregorianChange(new Date(before0001AD));
        for(i = 0; i < dotNetDateTimeTicks.length; i += kIncrement) {
            /* Test conversion from .Net/Universal time to ICU time. */
            millis = UniversalTimeScale.toLong(dotNetDateTimeTicks[i + kTicks], UniversalTimeScale.ICU4C_TIME);
            cal.clear();
            cal.set((int)dotNetDateTimeTicks[i + kYear],
                    (int)dotNetDateTimeTicks[i + kMonth] - 1, /* Java & ICU use January = month 0. */
                    (int)dotNetDateTimeTicks[i + kDay]);
            icuDate = cal.getTimeInMillis();
            if(millis != icuDate) {
                /* Print days not millis. */
                errln("UniversalTimeScale.toLong(ticks[" + i + "], ICU4C)=" +
                      (millis/dayMillis) + " != " + (icuDate/dayMillis) +
                      "=ucal_getMillis(" + dotNetDateTimeTicks[i + kYear] +
View Full Code Here


            }
        }
    }
    public boolean isDateAtLeast(int year, int month, int day){
        Date now = new Date();
        Calendar c = new GregorianCalendar(year, month, day);
        Date dt = c.getTime();
        if(now.compareTo(dt)>=0){
            return true;
        }
        return false;
    }
View Full Code Here

        }

        public long getTime(int year, int month, int dayOfMonth, int hour, int minute, int second) {
            long time;
            if (tzobj instanceof com.ibm.icu.util.TimeZone) {
                GregorianCalendar cal = new GregorianCalendar();
                cal.setTimeZone((com.ibm.icu.util.TimeZone)tzobj);
                cal.clear();
                cal.set(year, month, dayOfMonth, hour, minute, second);
                time = cal.getTimeInMillis();
            } else if (tzobj instanceof java.util.TimeZone) {
                java.util.GregorianCalendar cal = new java.util.GregorianCalendar();
                cal.setTimeZone((java.util.TimeZone)tzobj);
                cal.clear();
                cal.set(year, month, dayOfMonth, hour, minute, second);
                time = cal.getTimeInMillis();
            } else {
                throw new IllegalStateException("Unsupported TimeZone implementation");
            }
            return time;
        }
View Full Code Here

    /**
     * Check isLeapYear for BC years.
     */
    public void Test4125881() {
        GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance();
        DateFormat fmt = new SimpleDateFormat("MMMM d, yyyy G");
        cal.clear();
        for (int y=-20; y<=10; ++y) {
            cal.set(Calendar.ERA, y < 1 ? GregorianCalendar.BC : GregorianCalendar.AD);
            cal.set(Calendar.YEAR, y < 1 ? 1 - y : y);
            logln(y + " = " + fmt.format(cal.getTime()) + " " +
                               cal.isLeapYear(y));
            if (cal.isLeapYear(y) != ((y+40)%4 == 0))
                errln("Leap years broken");
        }
    }
View Full Code Here

    /**
     * Prove that GregorianCalendar is proleptic (it used to cut off at 45 BC,
     * and not have leap years before then).
     */
    public void Test4125892() {
        GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance();
        //DateFormat fmt = new SimpleDateFormat("MMMM d, yyyy G");
        //fmt = null;
        cal.clear();
        cal.set(Calendar.ERA, GregorianCalendar.BC);
        cal.set(Calendar.YEAR, 81); // 81 BC is a leap year (proleptically)
        cal.set(Calendar.MONTH, Calendar.FEBRUARY);
        cal.set(Calendar.DATE, 28);
        cal.add(Calendar.DATE, 1);
        if (cal.get(Calendar.DATE) != 29 ||
            !cal.isLeapYear(-80)) // -80 == 81 BC
            errln("Calendar not proleptic");
    }
View Full Code Here

        if (a.getTimeZone()!= b.getTimeZone() && a.hashCode() == b.hashCode()) {
            errln("Calendar hash code ignores zone");
        }
        b.getTimeZone().setRawOffset(a.getTimeZone().getRawOffset());

        GregorianCalendar c = new GregorianCalendar();
        GregorianCalendar d = (GregorianCalendar)c.clone();
        if (c.hashCode() != d.hashCode()) {
            errln("GregorianCalendar hash code unequal for clones objects");
        }
        Date cutover = c.getGregorianChange();
        d.setGregorianChange(new Date(cutover.getTime() + 24*60*60*1000));
        if (c.hashCode() == d.hashCode()) {
            errln("GregorianCalendar hash code ignores cutover");
        }       
    }
View Full Code Here

    /**
     * GregorianCalendar.equals() ignores cutover date
     */
    public void Test4141665() {
        GregorianCalendar cal = new GregorianCalendar();
        GregorianCalendar cal2 = (GregorianCalendar)cal.clone();
        Date cut = cal.getGregorianChange();
        Date cut2 = new Date(cut.getTime() + 100*24*60*60*1000L); // 100 days
                                                                  // later
        if (!cal.equals(cal2)) {
            errln("Cloned GregorianCalendars not equal");
        }
        cal2.setGregorianChange(cut2);
        if (cal.equals(cal2)) {
            errln("GregorianCalendar.equals() ignores cutover");
        }
    }
View Full Code Here

    /**
     * Bug states that ArrayIndexOutOfBoundsException is thrown by
     * GregorianCalendar.roll() when IllegalArgumentException should be.
     */
    public void Test4142933() {
        GregorianCalendar calendar = new GregorianCalendar();
        try {
            calendar.roll(-1, true);
            errln("Test failed, no exception trown");
        }
        catch (IllegalArgumentException e) {
            // OK: Do nothing
            // logln("Test passed");
View Full Code Here

     * other of these will wrap. We've modified the test given in the bug report
     * to therefore only check the behavior of a calendar with a zero raw offset
     * zone.
     */
    public void Test4145158() {
        GregorianCalendar calendar = new GregorianCalendar();

        calendar.setTimeZone(TimeZone.getTimeZone("GMT"));

        calendar.setTime(new Date(Long.MIN_VALUE));
        int year1 = calendar.get(Calendar.YEAR);
        int era1 = calendar.get(Calendar.ERA);
       
        calendar.setTime(new Date(Long.MAX_VALUE));
        int year2 = calendar.get(Calendar.YEAR);
        int era2 = calendar.get(Calendar.ERA);
       
        if (year1 == year2 && era1 == era2) {
            errln("Fail: Long.MIN_VALUE or Long.MAX_VALUE wrapping around");
        }
    }
View Full Code Here

    /**
     * Maximum value for YEAR field wrong.
     */
    public void Test4145983() {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
        Date[] DATES = { new Date(Long.MAX_VALUE), new Date(Long.MIN_VALUE) };
        for (int i=0; i<DATES.length; ++i) {
            calendar.setTime(DATES[i]);
            int year = calendar.get(Calendar.YEAR);
            int maxYear = calendar.getMaximum(Calendar.YEAR);
            if (year > maxYear) {
                errln("Failed for "+DATES[i].getTime()+" ms: year=" +
                      year + ", maxYear=" + maxYear);
            }
        }
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.