/// <summary> /// Adjusts the specified temporal object to have this month-day. /// <para> /// This returns a temporal object of the same observable type as the input /// with the month and day-of-month changed to be the same as this. /// </para> /// <para> /// The adjustment is equivalent to using <seealso cref="Temporal#with(TemporalField, long)"/> /// twice, passing <seealso cref="ChronoField#MONTH_OF_YEAR"/> and /// <seealso cref="ChronoField#DAY_OF_MONTH"/> as the fields. /// If the specified temporal object does not use the ISO calendar system then /// a {@code DateTimeException} is thrown. /// </para> /// <para> /// In most cases, it is clearer to reverse the calling pattern by using /// <seealso cref="Temporal#with(TemporalAdjuster)"/>: /// <pre> /// // these two lines are equivalent, but the second approach is recommended /// temporal = thisMonthDay.adjustInto(temporal); /// temporal = temporal.with(thisMonthDay); /// </pre> /// </para> /// <para> /// This instance is immutable and unaffected by this method call. /// /// </para> /// </summary> /// <param name="temporal"> the target object to be adjusted, not null </param> /// <returns> the adjusted object, not null </returns> /// <exception cref="DateTimeException"> if unable to make the adjustment </exception> /// <exception cref="ArithmeticException"> if numeric overflow occurs </exception> public Temporal AdjustInto(Temporal temporal) { if (Chronology.from(temporal).Equals(IsoChronology.INSTANCE) == false) { throw new DateTimeException("Adjustment only supported on ISO date-time"); } temporal = temporal.With(MONTH_OF_YEAR, Month_Renamed); return(temporal.With(DAY_OF_MONTH, System.Math.Min(temporal.range(DAY_OF_MONTH).Maximum, Day))); }
//----------------------------------------------------------------------- /// <summary> /// Obtains an instance of {@code MonthDay} from a temporal object. /// <para> /// This obtains a month-day based on the specified temporal. /// A {@code TemporalAccessor} represents an arbitrary set of date and time information, /// which this factory converts to an instance of {@code MonthDay}. /// </para> /// <para> /// The conversion extracts the <seealso cref="ChronoField#MONTH_OF_YEAR MONTH_OF_YEAR"/> and /// <seealso cref="ChronoField#DAY_OF_MONTH DAY_OF_MONTH"/> fields. /// The extraction is only permitted if the temporal object has an ISO /// chronology, or can be converted to a {@code LocalDate}. /// </para> /// <para> /// This method matches the signature of the functional interface <seealso cref="TemporalQuery"/> /// allowing it to be used as a query via method reference, {@code MonthDay::from}. /// /// </para> /// </summary> /// <param name="temporal"> the temporal object to convert, not null </param> /// <returns> the month-day, not null </returns> /// <exception cref="DateTimeException"> if unable to convert to a {@code MonthDay} </exception> public static MonthDay From(TemporalAccessor temporal) { if (temporal is MonthDay) { return((MonthDay)temporal); } try { if (IsoChronology.INSTANCE.Equals(Chronology.from(temporal)) == false) { temporal = LocalDate.From(temporal); } return(Of(temporal.get(MONTH_OF_YEAR), temporal.get(DAY_OF_MONTH))); } catch (DateTimeException ex) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: throw new DateTimeException("Unable to obtain MonthDay from TemporalAccessor: " + temporal + " of type " + temporal.GetType().FullName, ex); } }