Java Code Examples for sun.util.calendar.BaseCalendar#Date

The following examples show how to use sun.util.calendar.BaseCalendar#Date . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Date.java    From jdk8u60 with GNU General Public License v2.0 7 votes vote down vote up
/**
 * Sets the month of this date to the specified value. This
 * <tt>Date</tt> object is modified so that it represents a point
 * in time within the specified month, with the year, date, hour,
 * minute, and second the same as before, as interpreted in the
 * local time zone. If the date was October 31, for example, and
 * the month is set to June, then the new date will be treated as
 * if it were on July 1, because June has only 30 days.
 *
 * @param   month   the month value between 0-11.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(Calendar.MONTH, int month)</code>.
 */
@Deprecated
public void setMonth(int month) {
    int y = 0;
    if (month >= 12) {
        y = month / 12;
        month %= 12;
    } else if (month < 0) {
        y = CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar.Date d = getCalendarDate();
    if (y != 0) {
        d.setNormalizedYear(d.getNormalizedYear() + y);
    }
    d.setMonth(month + 1); // adjust 0-based to 1-based month numbering
}
 
Example 2
Source File: GregorianCalendar.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 7 votes vote down vote up
private int actualMonthLength() {
    int year = cdate.getNormalizedYear();
    if (year != gregorianCutoverYear && year != gregorianCutoverYearJulian) {
        return calsys.getMonthLength(cdate);
    }
    BaseCalendar.Date date = (BaseCalendar.Date) cdate.clone();
    long fd = calsys.getFixedDate(date);
    long month1 = getFixedDateMonth1(date, fd);
    long next1 = month1 + calsys.getMonthLength(date);
    if (next1 < gregorianCutoverDate) {
        return (int)(next1 - month1);
    }
    if (cdate != gdate) {
        date = (BaseCalendar.Date) gcal.newCalendarDate(TimeZone.NO_TIMEZONE);
    }
    gcal.getCalendarDateFromFixedDate(date, next1);
    next1 = getFixedDateMonth1(date, next1);
    return (int)(next1 - month1);
}
 
Example 3
Source File: Date.java    From dragonwell8_jdk with GNU General Public License v2.0 7 votes vote down vote up
/**
 * Sets the month of this date to the specified value. This
 * <tt>Date</tt> object is modified so that it represents a point
 * in time within the specified month, with the year, date, hour,
 * minute, and second the same as before, as interpreted in the
 * local time zone. If the date was October 31, for example, and
 * the month is set to June, then the new date will be treated as
 * if it were on July 1, because June has only 30 days.
 *
 * @param   month   the month value between 0-11.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(Calendar.MONTH, int month)</code>.
 */
@Deprecated
public void setMonth(int month) {
    int y = 0;
    if (month >= 12) {
        y = month / 12;
        month %= 12;
    } else if (month < 0) {
        y = CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar.Date d = getCalendarDate();
    if (y != 0) {
        d.setNormalizedYear(d.getNormalizedYear() + y);
    }
    d.setMonth(month + 1); // adjust 0-based to 1-based month numbering
}
 
Example 4
Source File: Date.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a copy of this object.
 */
public Object clone() {
    Date d = null;
    try {
        d = (Date)super.clone();
        if (cdate != null) {
            d.cdate = (BaseCalendar.Date) cdate.clone();
        }
    } catch (CloneNotSupportedException e) {} // Won't happen
    return d;
}
 
Example 5
Source File: Date.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the millisecond value of this <code>Date</code> object
 * without affecting its internal state.
 */
static final long getMillisOf(Date date) {
    if (date.cdate == null || date.cdate.isNormalized()) {
        return date.fastTime;
    }
    BaseCalendar.Date d = (BaseCalendar.Date) date.cdate.clone();
    return gcal.getTime(d);
}
 
Example 6
Source File: GregorianCalendar.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the fixed date of the first date of the month (usually
 * the 1st of the month) before the specified date.
 *
 * @param date the date for which the first day of the month is
 * calculated. The date has to be in the cut-over year (Gregorian
 * or Julian).
 * @param fixedDate the fixed date representation of the date
 */
private long getFixedDateMonth1(BaseCalendar.Date date, long fixedDate) {
    assert date.getNormalizedYear() == gregorianCutoverYear ||
        date.getNormalizedYear() == gregorianCutoverYearJulian;
    BaseCalendar.Date gCutover = getGregorianCutoverDate();
    if (gCutover.getMonth() == BaseCalendar.JANUARY
        && gCutover.getDayOfMonth() == 1) {
        // The cutover happened on January 1.
        return fixedDate - date.getDayOfMonth() + 1;
    }

    long fixedDateMonth1;
    // The cutover happened sometime during the year.
    if (date.getMonth() == gCutover.getMonth()) {
        // The cutover happened in the month.
        BaseCalendar.Date jLastDate = getLastJulianDate();
        if (gregorianCutoverYear == gregorianCutoverYearJulian
            && gCutover.getMonth() == jLastDate.getMonth()) {
            // The "gap" fits in the same month.
            fixedDateMonth1 = jcal.getFixedDate(date.getNormalizedYear(),
                                                date.getMonth(),
                                                1,
                                                null);
        } else {
            // Use the cutover date as the first day of the month.
            fixedDateMonth1 = gregorianCutoverDate;
        }
    } else {
        // The cutover happened before the month.
        fixedDateMonth1 = fixedDate - date.getDayOfMonth() + 1;
    }

    return fixedDateMonth1;
}
 
Example 7
Source File: GregorianCalendar.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates internal state.
 */
private void readObject(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    if (gdate == null) {
        gdate = (BaseCalendar.Date) gcal.newCalendarDate(getZone());
        cachedFixedDate = Long.MIN_VALUE;
    }
    setGregorianChange(gregorianCutover);
}
 
Example 8
Source File: GregorianCalendar.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a CalendarDate produced from the specified fixed date.
 *
 * @param fd the fixed date
 */
private BaseCalendar.Date getCalendarDate(long fd) {
    BaseCalendar cal = (fd >= gregorianCutoverDate) ? gcal : getJulianCalendarSystem();
    BaseCalendar.Date d = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
    cal.getCalendarDateFromFixedDate(d, fd);
    return d;
}
 
Example 9
Source File: Date.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private final BaseCalendar.Date getCalendarDate() {
    if (cdate == null) {
        BaseCalendar cal = getCalendarSystem(fastTime);
        cdate = (BaseCalendar.Date) cal.getCalendarDate(fastTime,
                                                        TimeZone.getDefaultRef());
    }
    return cdate;
}
 
Example 10
Source File: Date.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static final BaseCalendar getCalendarSystem(BaseCalendar.Date cdate) {
    if (jcal == null) {
        return gcal;
    }
    if (cdate.getEra() != null) {
        return jcal;
    }
    return gcal;
}
 
Example 11
Source File: Date.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Determines the date and time based on the arguments. The
 * arguments are interpreted as a year, month, day of the month,
 * hour of the day, minute within the hour, and second within the
 * minute, exactly as for the <tt>Date</tt> constructor with six
 * arguments, except that the arguments are interpreted relative
 * to UTC rather than to the local time zone. The time indicated is
 * returned represented as the distance, measured in milliseconds,
 * of that time from the epoch (00:00:00 GMT on January 1, 1970).
 *
 * @param   year    the year minus 1900.
 * @param   month   the month between 0-11.
 * @param   date    the day of the month between 1-31.
 * @param   hrs     the hours between 0-23.
 * @param   min     the minutes between 0-59.
 * @param   sec     the seconds between 0-59.
 * @return  the number of milliseconds since January 1, 1970, 00:00:00 GMT for
 *          the date and time specified by the arguments.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(year + 1900, month, date,
 * hrs, min, sec)</code> or <code>GregorianCalendar(year + 1900,
 * month, date, hrs, min, sec)</code>, using a UTC
 * <code>TimeZone</code>, followed by <code>Calendar.getTime().getTime()</code>.
 */
@Deprecated
public static long UTC(int year, int month, int date,
                       int hrs, int min, int sec) {
    int y = year + 1900;
    // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
    if (month >= 12) {
        y += month / 12;
        month %= 12;
    } else if (month < 0) {
        y += CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    int m = month + 1;
    BaseCalendar cal = getCalendarSystem(y);
    BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null);
    udate.setNormalizedDate(y, m, date).setTimeOfDay(hrs, min, sec, 0);

    // Use a Date instance to perform normalization. Its fastTime
    // is the UTC value after the normalization.
    Date d = new Date(0);
    d.normalize(udate);
    return d.fastTime;
}
 
Example 12
Source File: SimpleTimeZone.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private int getOffset(BaseCalendar cal, BaseCalendar.Date cdate, int year, long time) {
    synchronized (this) {
        if (cacheStart != 0) {
            if (time >= cacheStart && time < cacheEnd) {
                return rawOffset + dstSavings;
            }
            if (year == cacheYear) {
                return rawOffset;
            }
        }
    }

    long start = getStart(cal, cdate, year);
    long end = getEnd(cal, cdate, year);
    int offset = rawOffset;
    if (start <= end) {
        if (time >= start && time < end) {
            offset += dstSavings;
        }
        synchronized (this) {
            cacheYear = year;
            cacheStart = start;
            cacheEnd = end;
        }
    } else {
        if (time < end) {
            // TODO: support Gregorian cutover. The previous year
            // may be in the other calendar system.
            start = getStart(cal, cdate, year - 1);
            if (time >= start) {
                offset += dstSavings;
            }
        } else if (time >= start) {
            // TODO: support Gregorian cutover. The next year
            // may be in the other calendar system.
            end = getEnd(cal, cdate, year + 1);
            if (time < end) {
                offset += dstSavings;
            }
        }
        if (start <= end) {
            synchronized (this) {
                // The start and end transitions are in multiple years.
                cacheYear = (long) startYear - 1;
                cacheStart = start;
                cacheEnd = end;
            }
        }
    }
    return offset;
}
 
Example 13
Source File: Date.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Converts this <code>Date</code> object to a <code>String</code>
 * of the form:
 * <blockquote><pre>
 * dow mon dd hh:mm:ss zzz yyyy</pre></blockquote>
 * where:<ul>
 * <li><tt>dow</tt> is the day of the week (<tt>Sun, Mon, Tue, Wed,
 *     Thu, Fri, Sat</tt>).
 * <li><tt>mon</tt> is the month (<tt>Jan, Feb, Mar, Apr, May, Jun,
 *     Jul, Aug, Sep, Oct, Nov, Dec</tt>).
 * <li><tt>dd</tt> is the day of the month (<tt>01</tt> through
 *     <tt>31</tt>), as two decimal digits.
 * <li><tt>hh</tt> is the hour of the day (<tt>00</tt> through
 *     <tt>23</tt>), as two decimal digits.
 * <li><tt>mm</tt> is the minute within the hour (<tt>00</tt> through
 *     <tt>59</tt>), as two decimal digits.
 * <li><tt>ss</tt> is the second within the minute (<tt>00</tt> through
 *     <tt>61</tt>, as two decimal digits.
 * <li><tt>zzz</tt> is the time zone (and may reflect daylight saving
 *     time). Standard time zone abbreviations include those
 *     recognized by the method <tt>parse</tt>. If time zone
 *     information is not available, then <tt>zzz</tt> is empty -
 *     that is, it consists of no characters at all.
 * <li><tt>yyyy</tt> is the year, as four decimal digits.
 * </ul>
 *
 * @return  a string representation of this date.
 * @see     java.util.Date#toLocaleString()
 * @see     java.util.Date#toGMTString()
 */
public String toString() {
    // "EEE MMM dd HH:mm:ss zzz yyyy";
    BaseCalendar.Date date = normalize();
    StringBuilder sb = new StringBuilder(28);
    int index = date.getDayOfWeek();
    if (index == BaseCalendar.SUNDAY) {
        index = 8;
    }
    convertToAbbr(sb, wtb[index]).append(' ');                        // EEE
    convertToAbbr(sb, wtb[date.getMonth() - 1 + 2 + 7]).append(' ');  // MMM
    CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 2).append(' '); // dd

    CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(':');   // HH
    CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(':'); // mm
    CalendarUtils.sprintf0d(sb, date.getSeconds(), 2).append(' '); // ss
    TimeZone zi = date.getZone();
    if (zi != null) {
        sb.append(zi.getDisplayName(date.isDaylightTime(), TimeZone.SHORT, Locale.US)); // zzz
    } else {
        sb.append("GMT");
    }
    sb.append(' ').append(date.getYear());  // yyyy
    return sb.toString();
}
 
Example 14
Source File: Date.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Determines the date and time based on the arguments. The
 * arguments are interpreted as a year, month, day of the month,
 * hour of the day, minute within the hour, and second within the
 * minute, exactly as for the {@code Date} constructor with six
 * arguments, except that the arguments are interpreted relative
 * to UTC rather than to the local time zone. The time indicated is
 * returned represented as the distance, measured in milliseconds,
 * of that time from the epoch (00:00:00 GMT on January 1, 1970).
 *
 * @param   year    the year minus 1900.
 * @param   month   the month between 0-11.
 * @param   date    the day of the month between 1-31.
 * @param   hrs     the hours between 0-23.
 * @param   min     the minutes between 0-59.
 * @param   sec     the seconds between 0-59.
 * @return  the number of milliseconds since January 1, 1970, 00:00:00 GMT for
 *          the date and time specified by the arguments.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by {@code Calendar.set(year + 1900, month, date, hrs, min, sec)}
 * or {@code GregorianCalendar(year + 1900, month, date, hrs, min, sec)}, using a UTC
 * {@code TimeZone}, followed by {@code Calendar.getTime().getTime()}.
 */
@Deprecated
public static long UTC(int year, int month, int date,
                       int hrs, int min, int sec) {
    int y = year + 1900;
    // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
    if (month >= 12) {
        y += month / 12;
        month %= 12;
    } else if (month < 0) {
        y += CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    int m = month + 1;
    BaseCalendar cal = getCalendarSystem(y);
    BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null);
    udate.setNormalizedDate(y, m, date).setTimeOfDay(hrs, min, sec, 0);

    // Use a Date instance to perform normalization. Its fastTime
    // is the UTC value after the normalization.
    Date d = new Date(0);
    d.normalize(udate);
    return d.fastTime;
}
 
Example 15
Source File: Date.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Allocates a {@code Date} object and initializes it so that
 * it represents the instant at the start of the second specified
 * by the {@code year}, {@code month}, {@code date},
 * {@code hrs}, {@code min}, and {@code sec} arguments,
 * in the local time zone.
 *
 * @param   year    the year minus 1900.
 * @param   month   the month between 0-11.
 * @param   date    the day of the month between 1-31.
 * @param   hrs     the hours between 0-23.
 * @param   min     the minutes between 0-59.
 * @param   sec     the seconds between 0-59.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by {@code Calendar.set(year + 1900, month, date, hrs, min, sec)}
 * or {@code GregorianCalendar(year + 1900, month, date, hrs, min, sec)}.
 */
@Deprecated
public Date(int year, int month, int date, int hrs, int min, int sec) {
    int y = year + 1900;
    // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
    if (month >= 12) {
        y += month / 12;
        month %= 12;
    } else if (month < 0) {
        y += CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar cal = getCalendarSystem(y);
    cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
    cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0);
    getTimeImpl();
    cdate = null;
}
 
Example 16
Source File: GregorianCalendar.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the minimum value that this calendar field could have,
 * taking into consideration the given time value and the current
 * values of the
 * {@link Calendar#getFirstDayOfWeek() getFirstDayOfWeek},
 * {@link Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek},
 * {@link #getGregorianChange() getGregorianChange} and
 * {@link Calendar#getTimeZone() getTimeZone} methods.
 *
 * <p>For example, if the Gregorian change date is January 10,
 * 1970 and the date of this <code>GregorianCalendar</code> is
 * January 20, 1970, the actual minimum value of the
 * <code>DAY_OF_MONTH</code> field is 10 because the previous date
 * of January 10, 1970 is December 27, 1996 (in the Julian
 * calendar). Therefore, December 28, 1969 to January 9, 1970
 * don't exist.
 *
 * @param field the calendar field
 * @return the minimum of the given field for the time value of
 * this <code>GregorianCalendar</code>
 * @see #getMinimum(int)
 * @see #getMaximum(int)
 * @see #getGreatestMinimum(int)
 * @see #getLeastMaximum(int)
 * @see #getActualMaximum(int)
 * @since 1.2
 */
@Override
public int getActualMinimum(int field) {
    if (field == DAY_OF_MONTH) {
        GregorianCalendar gc = getNormalizedCalendar();
        int year = gc.cdate.getNormalizedYear();
        if (year == gregorianCutoverYear || year == gregorianCutoverYearJulian) {
            long month1 = getFixedDateMonth1(gc.cdate, gc.calsys.getFixedDate(gc.cdate));
            BaseCalendar.Date d = getCalendarDate(month1);
            return d.getDayOfMonth();
        }
    }
    return getMinimum(field);
}
 
Example 17
Source File: GregorianCalendar.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Returns the minimum value that this calendar field could have,
 * taking into consideration the given time value and the current
 * values of the
 * {@link Calendar#getFirstDayOfWeek() getFirstDayOfWeek},
 * {@link Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek},
 * {@link #getGregorianChange() getGregorianChange} and
 * {@link Calendar#getTimeZone() getTimeZone} methods.
 *
 * <p>For example, if the Gregorian change date is January 10,
 * 1970 and the date of this <code>GregorianCalendar</code> is
 * January 20, 1970, the actual minimum value of the
 * <code>DAY_OF_MONTH</code> field is 10 because the previous date
 * of January 10, 1970 is December 27, 1996 (in the Julian
 * calendar). Therefore, December 28, 1969 to January 9, 1970
 * don't exist.
 *
 * @param field the calendar field
 * @return the minimum of the given field for the time value of
 * this <code>GregorianCalendar</code>
 * @see #getMinimum(int)
 * @see #getMaximum(int)
 * @see #getGreatestMinimum(int)
 * @see #getLeastMaximum(int)
 * @see #getActualMaximum(int)
 * @since 1.2
 */
@Override
public int getActualMinimum(int field) {
    if (field == DAY_OF_MONTH) {
        GregorianCalendar gc = getNormalizedCalendar();
        int year = gc.cdate.getNormalizedYear();
        if (year == gregorianCutoverYear || year == gregorianCutoverYearJulian) {
            long month1 = getFixedDateMonth1(gc.cdate, gc.calsys.getFixedDate(gc.cdate));
            BaseCalendar.Date d = getCalendarDate(month1);
            return d.getDayOfMonth();
        }
    }
    return getMinimum(field);
}
 
Example 18
Source File: GregorianCalendar.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the day before the Gregorian cutover date as a
 * BaseCalendar.Date. The date is a Julian date.
 */
private BaseCalendar.Date getLastJulianDate() {
    return getCalendarDate(gregorianCutoverDate - 1);
}
 
Example 19
Source File: GregorianCalendar.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an empty GregorianCalendar.
 *
 * @param zone    the given time zone
 * @param aLocale the given locale
 * @param flag    the flag requesting an empty instance
 */
GregorianCalendar(TimeZone zone, Locale locale, boolean flag) {
    super(zone, locale);
    gdate = (BaseCalendar.Date) gcal.newCalendarDate(getZone());
}
 
Example 20
Source File: GregorianCalendar.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the day before the Gregorian cutover date as a
 * BaseCalendar.Date. The date is a Julian date.
 */
private BaseCalendar.Date getLastJulianDate() {
    return getCalendarDate(gregorianCutoverDate - 1);
}