1 /*
2 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
558 BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
559 gcal : (BaseCalendar) CalendarSystem.forName("julian");
560 BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
561 // Get the year in local time
562 cal.getCalendarDate(date + rawOffset, cdate);
563 int year = cdate.getNormalizedYear();
564 if (year >= startYear) {
565 // Clear time elements for the transition calculations
566 cdate.setTimeOfDay(0, 0, 0, 0);
567 offset = getOffset(cal, cdate, year, date);
568 }
569 }
570
571 if (offsets != null) {
572 offsets[0] = rawOffset;
573 offsets[1] = offset - rawOffset;
574 }
575 return offset;
576 }
577
578 /**
579 * Returns the difference in milliseconds between local time and
580 * UTC, taking into account both the raw offset and the effect of
581 * daylight saving, for the specified date and time. This method
582 * assumes that the start and end month are distinct. It also
583 * uses a default {@link GregorianCalendar} object as its
584 * underlying calendar, such as for determining leap years. Do
585 * not use the result of this method with a calendar other than a
586 * default {@code GregorianCalendar}.
587 *
588 * <p><em>Note: In general, clients should use
589 * {@code Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET)}
590 * instead of calling this method.</em>
591 *
592 * @param era The era of the given date.
593 * @param year The year in the given date.
594 * @param month The month in the given date. Month is 0-based. e.g.,
595 * 0 for January.
596 * @param day The day-in-month of the given date.
597 * @param dayOfWeek The day-of-week of the given date.
598 * @param millis The milliseconds in day in <em>standard</em> local time.
|
1 /*
2 * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
558 BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
559 gcal : (BaseCalendar) CalendarSystem.forName("julian");
560 BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
561 // Get the year in local time
562 cal.getCalendarDate(date + rawOffset, cdate);
563 int year = cdate.getNormalizedYear();
564 if (year >= startYear) {
565 // Clear time elements for the transition calculations
566 cdate.setTimeOfDay(0, 0, 0, 0);
567 offset = getOffset(cal, cdate, year, date);
568 }
569 }
570
571 if (offsets != null) {
572 offsets[0] = rawOffset;
573 offsets[1] = offset - rawOffset;
574 }
575 return offset;
576 }
577
578 /**
579 * Returns the difference in milliseconds between local time and
580 * UTC, taking into account both the raw offset and the effect of
581 * daylight saving, for the specified date and time. This method
582 * assumes that the start and end month are distinct. It also
583 * uses a default {@link GregorianCalendar} object as its
584 * underlying calendar, such as for determining leap years. Do
585 * not use the result of this method with a calendar other than a
586 * default {@code GregorianCalendar}.
587 *
588 * <p><em>Note: In general, clients should use
589 * {@code Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET)}
590 * instead of calling this method.</em>
591 *
592 * @param era The era of the given date.
593 * @param year The year in the given date.
594 * @param month The month in the given date. Month is 0-based. e.g.,
595 * 0 for January.
596 * @param day The day-in-month of the given date.
597 * @param dayOfWeek The day-of-week of the given date.
598 * @param millis The milliseconds in day in <em>standard</em> local time.
|