Java Code Examples for sun.util.calendar.LocalGregorianCalendar#Date
The following examples show how to use
sun.util.calendar.LocalGregorianCalendar#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: JapaneseImperialCalendar.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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 must be in the era transition year. * @param fixedDate the fixed date representation of the date */ private long getFixedDateMonth1(LocalGregorianCalendar.Date date, long fixedDate) { int eraIndex = getTransitionEraIndex(date); if (eraIndex != -1) { long transition = sinceFixedDates[eraIndex]; // If the given date is on or after the transition date, then // return the transition date. if (transition <= fixedDate) { return transition; } } // Otherwise, we can use the 1st day of the month. return fixedDate - date.getDayOfMonth() + 1; }
Example 2
Source File: JapaneseImperialCalendar.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Returns the index to the new era if the given date is in a * transition month. For example, if the give date is Heisei 1 * (1989) January 20, then the era index for Heisei is * returned. Likewise, if the given date is Showa 64 (1989) * January 3, then the era index for Heisei is returned. If the * given date is not in any transition month, then -1 is returned. */ private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) { int eraIndex = getEraIndex(date); CalendarDate transitionDate = eras[eraIndex].getSinceDate(); if (transitionDate.getYear() == date.getNormalizedYear() && transitionDate.getMonth() == date.getMonth()) { return eraIndex; } if (eraIndex < eras.length - 1) { transitionDate = eras[++eraIndex].getSinceDate(); if (transitionDate.getYear() == date.getNormalizedYear() && transitionDate.getMonth() == date.getMonth()) { return eraIndex; } } return -1; }
Example 3
Source File: JapaneseChronology.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public int prolepticYear(Era era, int yearOfEra) { if (era instanceof JapaneseEra == false) { throw new ClassCastException("Era must be JapaneseEra"); } JapaneseEra jera = (JapaneseEra) era; int gregorianYear = jera.getPrivateEra().getSinceDate().getYear() + yearOfEra - 1; if (yearOfEra == 1) { return gregorianYear; } if (gregorianYear >= Year.MIN_VALUE && gregorianYear <= Year.MAX_VALUE) { LocalGregorianCalendar.Date jdate = JCAL.newCalendarDate(null); jdate.setEra(jera.getPrivateEra()).setDate(yearOfEra, 1, 1); if (JapaneseChronology.JCAL.validate(jdate)) { return gregorianYear; } } throw new DateTimeException("Invalid yearOfEra value"); }
Example 4
Source File: JapaneseChronology.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public int prolepticYear(Era era, int yearOfEra) { if (era instanceof JapaneseEra == false) { throw new ClassCastException("Era must be JapaneseEra"); } JapaneseEra jera = (JapaneseEra) era; int gregorianYear = jera.getPrivateEra().getSinceDate().getYear() + yearOfEra - 1; if (yearOfEra == 1) { return gregorianYear; } if (gregorianYear >= Year.MIN_VALUE && gregorianYear <= Year.MAX_VALUE) { LocalGregorianCalendar.Date jdate = JCAL.newCalendarDate(null); jdate.setEra(jera.getPrivateEra()).setDate(yearOfEra, 1, 1); if (JapaneseChronology.JCAL.validate(jdate)) { return gregorianYear; } } throw new DateTimeException("Invalid yearOfEra value"); }
Example 5
Source File: JapaneseImperialCalendar.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** * 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 must be in the era transition year. * @param fixedDate the fixed date representation of the date */ private long getFixedDateMonth1(LocalGregorianCalendar.Date date, long fixedDate) { int eraIndex = getTransitionEraIndex(date); if (eraIndex != -1) { long transition = sinceFixedDates[eraIndex]; // If the given date is on or after the transition date, then // return the transition date. if (transition <= fixedDate) { return transition; } } // Otherwise, we can use the 1st day of the month. return fixedDate - date.getDayOfMonth() + 1; }
Example 6
Source File: JapaneseImperialCalendar.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** * Returns the index to the new era if the given date is in a * transition month. For example, if the give date is Heisei 1 * (1989) January 20, then the era index for Heisei is * returned. Likewise, if the given date is Showa 64 (1989) * January 3, then the era index for Heisei is returned. If the * given date is not in any transition month, then -1 is returned. */ private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) { int eraIndex = getEraIndex(date); CalendarDate transitionDate = eras[eraIndex].getSinceDate(); if (transitionDate.getYear() == date.getNormalizedYear() && transitionDate.getMonth() == date.getMonth()) { return eraIndex; } if (eraIndex < eras.length - 1) { transitionDate = eras[++eraIndex].getSinceDate(); if (transitionDate.getYear() == date.getNormalizedYear() && transitionDate.getMonth() == date.getMonth()) { return eraIndex; } } return -1; }
Example 7
Source File: JapaneseDate.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Creates an instance from an ISO date. * * @param isoDate the standard local date, validated not null */ JapaneseDate(LocalDate isoDate) { if (isoDate.isBefore(MEIJI_6_ISODATE)) { throw new DateTimeException("JapaneseDate before Meiji 6 is not supported"); } LocalGregorianCalendar.Date jdate = toPrivateJapaneseDate(isoDate); this.era = JapaneseEra.toJapaneseEra(jdate.getEra()); this.yearOfEra = jdate.getYear(); this.isoDate = isoDate; }
Example 8
Source File: JapaneseImperialCalendar.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static int getEraIndex(LocalGregorianCalendar.Date date) { Era era = date.getEra(); for (int i = eras.length - 1; i > 0; i--) { if (eras[i] == era) { return i; } } return 0; }
Example 9
Source File: JapaneseImperialCalendar.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
public Object clone() { JapaneseImperialCalendar other = (JapaneseImperialCalendar) super.clone(); other.jdate = (LocalGregorianCalendar.Date) jdate.clone(); other.originalFields = null; other.zoneOffsets = null; return other; }
Example 10
Source File: JapaneseDate.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Creates an instance from an ISO date. * * @param isoDate the standard local date, validated not null */ JapaneseDate(LocalDate isoDate) { if (isoDate.isBefore(MEIJI_6_ISODATE)) { throw new DateTimeException("JapaneseDate before Meiji 6 is not supported"); } LocalGregorianCalendar.Date jdate = toPrivateJapaneseDate(isoDate); this.era = JapaneseEra.toJapaneseEra(jdate.getEra()); this.yearOfEra = jdate.getYear(); this.isoDate = isoDate; }
Example 11
Source File: JapaneseDate.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Returns a {@code LocalGregorianCalendar.Date} converted from the given {@code isoDate}. * * @param isoDate the local date, not null * @return a {@code LocalGregorianCalendar.Date}, not null */ private static LocalGregorianCalendar.Date toPrivateJapaneseDate(LocalDate isoDate) { LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(null); sun.util.calendar.Era sunEra = JapaneseEra.privateEraFrom(isoDate); int year = isoDate.getYear(); if (sunEra != null) { year -= sunEra.getSinceDate().getYear() - 1; } jdate.setEra(sunEra).setYear(year).setMonth(isoDate.getMonthValue()).setDayOfMonth(isoDate.getDayOfMonth()); JapaneseChronology.JCAL.normalize(jdate); return jdate; }
Example 12
Source File: JapaneseImperialCalendar.java From Bytecoder with Apache License 2.0 | 5 votes |
private static int getEraIndex(LocalGregorianCalendar.Date date) { Era era = date.getEra(); for (int i = eras.length - 1; i > 0; i--) { if (eras[i] == era) { return i; } } return 0; }
Example 13
Source File: JapaneseImperialCalendar.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Returns a LocalGregorianCalendar.Date produced from the specified fixed date. * * @param fd the fixed date */ private static LocalGregorianCalendar.Date getCalendarDate(long fd) { LocalGregorianCalendar.Date d = jcal.newCalendarDate(TimeZone.NO_TIMEZONE); jcal.getCalendarDateFromFixedDate(d, fd); return d; }
Example 14
Source File: JapaneseDate.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Obtains a {@code JapaneseDate} representing a date in the Japanese calendar * system from the era, year-of-era and day-of-year fields. * <p> * This returns a {@code JapaneseDate} with the specified fields. * The day must be valid for the year, otherwise an exception will be thrown. * <p> * The day-of-year in this factory is expressed relative to the start of the year-of-era. * This definition changes the normal meaning of day-of-year only in those years * where the year-of-era is reset to one due to a change in the era. * For example: * <pre> * 6th Jan Showa 64 = day-of-year 6 * 7th Jan Showa 64 = day-of-year 7 * 8th Jan Heisei 1 = day-of-year 1 * 9th Jan Heisei 1 = day-of-year 2 * </pre> * * @param era the Japanese era, not null * @param yearOfEra the Japanese year-of-era * @param dayOfYear the chronology day-of-year, from 1 to 366 * @return the date in Japanese calendar system, not null * @throws DateTimeException if the value of any field is out of range, * or if the day-of-year is invalid for the year */ static JapaneseDate ofYearDay(JapaneseEra era, int yearOfEra, int dayOfYear) { Objects.requireNonNull(era, "era"); CalendarDate firstDay = era.getPrivateEra().getSinceDate(); LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(null); jdate.setEra(era.getPrivateEra()); if (yearOfEra == 1) { jdate.setDate(yearOfEra, firstDay.getMonth(), firstDay.getDayOfMonth() + dayOfYear - 1); } else { jdate.setDate(yearOfEra, 1, dayOfYear); } JapaneseChronology.JCAL.normalize(jdate); if (era.getPrivateEra() != jdate.getEra() || yearOfEra != jdate.getYear()) { throw new DateTimeException("Invalid parameters"); } LocalDate localdate = LocalDate.of(jdate.getNormalizedYear(), jdate.getMonth(), jdate.getDayOfMonth()); return new JapaneseDate(era, yearOfEra, localdate); }
Example 15
Source File: JapaneseDate.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Obtains a {@code JapaneseDate} representing a date in the Japanese calendar * system from the era, year-of-era and day-of-year fields. * <p> * This returns a {@code JapaneseDate} with the specified fields. * The day must be valid for the year, otherwise an exception will be thrown. * <p> * The day-of-year in this factory is expressed relative to the start of the year-of-era. * This definition changes the normal meaning of day-of-year only in those years * where the year-of-era is reset to one due to a change in the era. * For example: * <pre> * 6th Jan Showa 64 = day-of-year 6 * 7th Jan Showa 64 = day-of-year 7 * 8th Jan Heisei 1 = day-of-year 1 * 9th Jan Heisei 1 = day-of-year 2 * </pre> * * @param era the Japanese era, not null * @param yearOfEra the Japanese year-of-era * @param dayOfYear the chronology day-of-year, from 1 to 366 * @return the date in Japanese calendar system, not null * @throws DateTimeException if the value of any field is out of range, * or if the day-of-year is invalid for the year */ static JapaneseDate ofYearDay(JapaneseEra era, int yearOfEra, int dayOfYear) { Objects.requireNonNull(era, "era"); CalendarDate firstDay = era.getPrivateEra().getSinceDate(); LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(null); jdate.setEra(era.getPrivateEra()); if (yearOfEra == 1) { jdate.setDate(yearOfEra, firstDay.getMonth(), firstDay.getDayOfMonth() + dayOfYear - 1); } else { jdate.setDate(yearOfEra, 1, dayOfYear); } JapaneseChronology.JCAL.normalize(jdate); if (era.getPrivateEra() != jdate.getEra() || yearOfEra != jdate.getYear()) { throw new DateTimeException("Invalid parameters"); } LocalDate localdate = LocalDate.of(jdate.getNormalizedYear(), jdate.getMonth(), jdate.getDayOfMonth()); return new JapaneseDate(era, yearOfEra, localdate); }
Example 16
Source File: JapaneseDate.java From Bytecoder with Apache License 2.0 | 3 votes |
/** * Obtains a {@code JapaneseDate} representing a date in the Japanese calendar * system from the era, year-of-era, month-of-year and day-of-month fields. * <p> * This returns a {@code JapaneseDate} with the specified fields. * The day must be valid for the year and month, otherwise an exception will be thrown. * <p> * The Japanese month and day-of-month are the same as those in the * ISO calendar system. They are not reset when the era changes. * For example: * <pre> * 6th Jan Showa 64 = ISO 1989-01-06 * 7th Jan Showa 64 = ISO 1989-01-07 * 8th Jan Heisei 1 = ISO 1989-01-08 * 9th Jan Heisei 1 = ISO 1989-01-09 * </pre> * * @param era the Japanese era, not null * @param yearOfEra the Japanese year-of-era * @param month the Japanese month-of-year, from 1 to 12 * @param dayOfMonth the Japanese day-of-month, from 1 to 31 * @return the date in Japanese calendar system, not null * @throws DateTimeException if the value of any field is out of range, * or if the day-of-month is invalid for the month-year, * or if the date is not a Japanese era */ public static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) { Objects.requireNonNull(era, "era"); LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(null); jdate.setEra(era.getPrivateEra()).setDate(yearOfEra, month, dayOfMonth); if (!JapaneseChronology.JCAL.validate(jdate)) { throw new DateTimeException("year, month, and day not valid for Era"); } LocalDate date = LocalDate.of(jdate.getNormalizedYear(), month, dayOfMonth); return new JapaneseDate(era, yearOfEra, date); }
Example 17
Source File: JapaneseImperialCalendar.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Returns the maximum value for the given calendar field of this * {@code GregorianCalendar} instance. The maximum value is * defined as the largest value returned by the * {@link Calendar#get(int) get} method for any possible time value, * taking into consideration the current values of the * {@link Calendar#getFirstDayOfWeek() getFirstDayOfWeek}, * {@link Calendar#getMinimalDaysInFirstWeek() getMinimalDaysInFirstWeek}, * and {@link Calendar#getTimeZone() getTimeZone} methods. * * @param field the calendar field. * @return the maximum value for the given calendar field. * @see #getMinimum(int) * @see #getGreatestMinimum(int) * @see #getLeastMaximum(int) * @see #getActualMinimum(int) * @see #getActualMaximum(int) */ public int getMaximum(int field) { switch (field) { case YEAR: { // The value should depend on the time zone of this calendar. LocalGregorianCalendar.Date d = jcal.getCalendarDate(Long.MAX_VALUE, getZone()); return Math.max(LEAST_MAX_VALUES[YEAR], d.getYear()); } } return MAX_VALUES[field]; }
Example 18
Source File: JapaneseDate.java From jdk8u60 with GNU General Public License v2.0 | 3 votes |
/** * Obtains a {@code JapaneseDate} representing a date in the Japanese calendar * system from the era, year-of-era, month-of-year and day-of-month fields. * <p> * This returns a {@code JapaneseDate} with the specified fields. * The day must be valid for the year and month, otherwise an exception will be thrown. * <p> * The Japanese month and day-of-month are the same as those in the * ISO calendar system. They are not reset when the era changes. * For example: * <pre> * 6th Jan Showa 64 = ISO 1989-01-06 * 7th Jan Showa 64 = ISO 1989-01-07 * 8th Jan Heisei 1 = ISO 1989-01-08 * 9th Jan Heisei 1 = ISO 1989-01-09 * </pre> * * @param era the Japanese era, not null * @param yearOfEra the Japanese year-of-era * @param month the Japanese month-of-year, from 1 to 12 * @param dayOfMonth the Japanese day-of-month, from 1 to 31 * @return the date in Japanese calendar system, not null * @throws DateTimeException if the value of any field is out of range, * or if the day-of-month is invalid for the month-year, * or if the date is not a Japanese era */ public static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) { Objects.requireNonNull(era, "era"); LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(null); jdate.setEra(era.getPrivateEra()).setDate(yearOfEra, month, dayOfMonth); if (!JapaneseChronology.JCAL.validate(jdate)) { throw new DateTimeException("year, month, and day not valid for Era"); } LocalDate date = LocalDate.of(jdate.getNormalizedYear(), month, dayOfMonth); return new JapaneseDate(era, yearOfEra, date); }
Example 19
Source File: JapaneseDate.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Obtains a {@code JapaneseDate} representing a date in the Japanese calendar * system from the era, year-of-era, month-of-year and day-of-month fields. * <p> * This returns a {@code JapaneseDate} with the specified fields. * The day must be valid for the year and month, otherwise an exception will be thrown. * <p> * The Japanese month and day-of-month are the same as those in the * ISO calendar system. They are not reset when the era changes. * For example: * <pre> * 6th Jan Showa 64 = ISO 1989-01-06 * 7th Jan Showa 64 = ISO 1989-01-07 * 8th Jan Heisei 1 = ISO 1989-01-08 * 9th Jan Heisei 1 = ISO 1989-01-09 * </pre> * * @param era the Japanese era, not null * @param yearOfEra the Japanese year-of-era * @param month the Japanese month-of-year, from 1 to 12 * @param dayOfMonth the Japanese day-of-month, from 1 to 31 * @return the date in Japanese calendar system, not null * @throws DateTimeException if the value of any field is out of range, * or if the day-of-month is invalid for the month-year, * or if the date is not a Japanese era */ public static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) { Objects.requireNonNull(era, "era"); LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(null); jdate.setEra(era.getPrivateEra()).setDate(yearOfEra, month, dayOfMonth); if (!JapaneseChronology.JCAL.validate(jdate)) { throw new DateTimeException("year, month, and day not valid for Era"); } LocalDate date = LocalDate.of(jdate.getNormalizedYear(), month, dayOfMonth); return new JapaneseDate(era, yearOfEra, date); }
Example 20
Source File: JapaneseDate.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Obtains a {@code JapaneseDate} representing a date in the Japanese calendar * system from the era, year-of-era, month-of-year and day-of-month fields. * <p> * This returns a {@code JapaneseDate} with the specified fields. * The day must be valid for the year and month, otherwise an exception will be thrown. * <p> * The Japanese month and day-of-month are the same as those in the * ISO calendar system. They are not reset when the era changes. * For example: * <pre> * 6th Jan Showa 64 = ISO 1989-01-06 * 7th Jan Showa 64 = ISO 1989-01-07 * 8th Jan Heisei 1 = ISO 1989-01-08 * 9th Jan Heisei 1 = ISO 1989-01-09 * </pre> * * @param era the Japanese era, not null * @param yearOfEra the Japanese year-of-era * @param month the Japanese month-of-year, from 1 to 12 * @param dayOfMonth the Japanese day-of-month, from 1 to 31 * @return the date in Japanese calendar system, not null * @throws DateTimeException if the value of any field is out of range, * or if the day-of-month is invalid for the month-year, * or if the date is not a Japanese era */ public static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) { Objects.requireNonNull(era, "era"); LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(null); jdate.setEra(era.getPrivateEra()).setDate(yearOfEra, month, dayOfMonth); if (!JapaneseChronology.JCAL.validate(jdate)) { throw new DateTimeException("year, month, and day not valid for Era"); } LocalDate date = LocalDate.of(jdate.getNormalizedYear(), month, dayOfMonth); return new JapaneseDate(era, yearOfEra, date); }