//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static Object readInternal(byte type, java.io.ObjectInput in) throws java.io.IOException, ClassNotFoundException private static Object ReadInternal(sbyte type, ObjectInput @in) { switch (type) { case CHRONO_TYPE: return(AbstractChronology.ReadExternal(@in)); case CHRONO_LOCAL_DATE_TIME_TYPE: return(ChronoLocalDateTimeImpl.ReadExternal(@in)); case CHRONO_ZONE_DATE_TIME_TYPE: return(ChronoZonedDateTimeImpl.ReadExternal(@in)); case JAPANESE_DATE_TYPE: return(JapaneseDate.ReadExternal(@in)); case JAPANESE_ERA_TYPE: return(JapaneseEra.ReadExternal(@in)); case HIJRAH_DATE_TYPE: return(HijrahDate.ReadExternal(@in)); case MINGUO_DATE_TYPE: return(MinguoDate.ReadExternal(@in)); case THAIBUDDHIST_DATE_TYPE: return(ThaiBuddhistDate.ReadExternal(@in)); case CHRONO_PERIOD_TYPE: return(ChronoPeriodImpl.ReadExternal(@in)); default: throw new StreamCorruptedException("Unknown serialized type"); } }
/// <summary> /// Constructs a {@code JapaneseDate}. This constructor does NOT validate the given parameters, /// and {@code era} and {@code year} must agree with {@code isoDate}. /// </summary> /// <param name="era"> the era, validated not null </param> /// <param name="year"> the year-of-era, validated </param> /// <param name="isoDate"> the standard local date, validated not null </param> internal JapaneseDate(JapaneseEra era, int year, LocalDate isoDate) { if (isoDate.IsBefore(MEIJI_6_ISODATE)) { throw new DateTimeException("JapaneseDate before Meiji 6 is not supported"); } this.Era_Renamed = era; this.YearOfEra = year; this.IsoDate = isoDate; }
//----------------------------------------------------------------------- /// <summary> /// Creates an instance from an ISO date. /// </summary> /// <param name="isoDate"> the standard local date, validated not null </param> internal 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_Renamed = JapaneseEra.ToJapaneseEra(jdate.Era); this.YearOfEra = jdate.Year; this.IsoDate = isoDate; }
/// <summary> /// 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. /// <para> /// 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. /// </para> /// <para> /// 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> /// /// </para> /// </summary> /// <param name="era"> the Japanese era, not null </param> /// <param name="yearOfEra"> the Japanese year-of-era </param> /// <param name="month"> the Japanese month-of-year, from 1 to 12 </param> /// <param name="dayOfMonth"> the Japanese day-of-month, from 1 to 31 </param> /// <returns> the date in Japanese calendar system, not null </returns> /// <exception cref="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 </exception> public static JapaneseDate Of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) { Objects.RequireNonNull(era, "era"); LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(ChronoLocalDate_Fields.Null); jdate.setEra(era.PrivateEra).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.NormalizedYear, month, dayOfMonth); return(new JapaneseDate(era, yearOfEra, date)); }
/// <summary> /// Returns a {@code LocalGregorianCalendar.Date} converted from the given {@code isoDate}. /// </summary> /// <param name="isoDate"> the local date, not null </param> /// <returns> a {@code LocalGregorianCalendar.Date}, not null </returns> private static LocalGregorianCalendar.Date ToPrivateJapaneseDate(LocalDate isoDate) { LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(ChronoLocalDate_Fields.Null); sun.util.calendar.Era sunEra = JapaneseEra.PrivateEraFrom(isoDate); int year = isoDate.Year; if (sunEra != ChronoLocalDate_Fields.Null) { year -= sunEra.SinceDate.Year - 1; } jdate.setEra(sunEra).setYear(year).setMonth(isoDate.MonthValue).setDayOfMonth(isoDate.DayOfMonth); JapaneseChronology.JCAL.normalize(jdate); return(jdate); }
static JapaneseEra() { ERA_CONFIG = JapaneseChronology.JCAL.Eras; KNOWN_ERAS = new JapaneseEra[ERA_CONFIG.Length]; KNOWN_ERAS[0] = MEIJI; KNOWN_ERAS[1] = TAISHO; KNOWN_ERAS[2] = SHOWA; KNOWN_ERAS[3] = HEISEI; for (int i = N_ERA_CONSTANTS; i < ERA_CONFIG.Length; i++) { CalendarDate date = ERA_CONFIG[i].SinceDate; LocalDate isoDate = LocalDate.Of(date.Year, date.Month, date.DayOfMonth); KNOWN_ERAS[i] = new JapaneseEra(i - ERA_OFFSET + 1, isoDate); } };
//----------------------------------------------------------------------- public JapaneseDate With(TemporalField field, long newValue) { if (field is ChronoField) { ChronoField f = (ChronoField)field; if (GetLong(f) == newValue) // getLong() validates for supported fields { return(this); } switch (f) { case YEAR_OF_ERA: case YEAR: case ERA: { int nvalue = Chronology.Range(f).CheckValidIntValue(newValue, f); switch (f) { case YEAR_OF_ERA: return(this.WithYear(nvalue)); case YEAR: return(With(IsoDate.WithYear(nvalue))); case ERA: { return(this.WithYear(JapaneseEra.Of(nvalue), YearOfEra)); } } } break; } // YEAR, PROLEPTIC_MONTH and others are same as ISO return(With(IsoDate.With(field, newValue))); } return(base.With(field, newValue)); }
/// <summary> /// Obtains a {@code JapaneseDate} representing a date in the Japanese calendar /// system from the era, year-of-era and day-of-year fields. /// <para> /// This returns a {@code JapaneseDate} with the specified fields. /// The day must be valid for the year, otherwise an exception will be thrown. /// </para> /// <para> /// 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> /// /// </para> /// </summary> /// <param name="era"> the Japanese era, not null </param> /// <param name="yearOfEra"> the Japanese year-of-era </param> /// <param name="dayOfYear"> the chronology day-of-year, from 1 to 366 </param> /// <returns> the date in Japanese calendar system, not null </returns> /// <exception cref="DateTimeException"> if the value of any field is out of range, /// or if the day-of-year is invalid for the year </exception> internal static JapaneseDate OfYearDay(JapaneseEra era, int yearOfEra, int dayOfYear) { Objects.RequireNonNull(era, "era"); CalendarDate firstDay = era.PrivateEra.SinceDate; LocalGregorianCalendar.Date jdate = JapaneseChronology.JCAL.newCalendarDate(ChronoLocalDate_Fields.Null); jdate.Era = era.PrivateEra; if (yearOfEra == 1) { jdate.setDate(yearOfEra, firstDay.Month, firstDay.DayOfMonth + dayOfYear - 1); } else { jdate.setDate(yearOfEra, 1, dayOfYear); } JapaneseChronology.JCAL.normalize(jdate); if (era.PrivateEra != jdate.Era || yearOfEra != jdate.Year) { throw new DateTimeException("Invalid parameters"); } LocalDate localdate = LocalDate.Of(jdate.NormalizedYear, jdate.Month, jdate.DayOfMonth); return(new JapaneseDate(era, yearOfEra, localdate)); }
//----------------------------------------------------------------------- /// <summary> /// Returns a copy of this date with the year altered. /// <para> /// This method changes the year of the date. /// If the month-day is invalid for the year, then the previous valid day /// will be selected instead. /// </para> /// <para> /// This instance is immutable and unaffected by this method call. /// /// </para> /// </summary> /// <param name="era"> the era to set in the result, not null </param> /// <param name="yearOfEra"> the year-of-era to set in the returned date </param> /// <returns> a {@code JapaneseDate} based on this date with the requested year, never null </returns> /// <exception cref="DateTimeException"> if {@code year} is invalid </exception> private JapaneseDate WithYear(JapaneseEra era, int yearOfEra) { int year = JapaneseChronology.INSTANCE.ProlepticYear(era, yearOfEra); return(With(IsoDate.WithYear(year))); }