Exemplo n.º 1
0
 //-----------------------------------------------------------------------
 /// <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;
 }
Exemplo n.º 2
0
        /// <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));
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        /// <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));
        }