/// <summary> /// Gets a value using a query. /// </summary> /// <param name="query"> the query to use, not null </param> /// <returns> the result, null if not found and optional is true </returns> /// <exception cref="DateTimeException"> if the type is not available and the section is not optional </exception> internal R getValue <R>(TemporalQuery <R> query) { R result = Temporal_Renamed.query(query); if (result == null && Optional == 0) { throw new DateTimeException("Unable to extract value: " + Temporal_Renamed.GetType()); } return(result); }
//----------------------------------------------------------------------- /// <summary> /// Obtains an instance of {@code ZoneOffset} from a temporal object. /// <para> /// This obtains an offset 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 ZoneOffset}. /// </para> /// <para> /// A {@code TemporalAccessor} represents some form of date and time information. /// This factory converts the arbitrary temporal object to an instance of {@code ZoneOffset}. /// </para> /// <para> /// The conversion uses the <seealso cref="TemporalQueries#offset()"/> query, which relies /// on extracting the <seealso cref="ChronoField#OFFSET_SECONDS OFFSET_SECONDS"/> field. /// </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 ZoneOffset::from}. /// /// </para> /// </summary> /// <param name="temporal"> the temporal object to convert, not null </param> /// <returns> the zone-offset, not null </returns> /// <exception cref="DateTimeException"> if unable to convert to an {@code ZoneOffset} </exception> public static ZoneOffset From(TemporalAccessor temporal) { Objects.RequireNonNull(temporal, "temporal"); ZoneOffset offset = temporal.query(TemporalQueries.Offset()); if (offset == temporal.TemporalAccessor_Fields.Null) { //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 ZoneOffset from TemporalAccessor: " + temporal + " of type " + temporal.GetType().FullName); } return(offset); }
//----------------------------------------------------------------------- /// <summary> /// Obtains an instance of {@code ZoneId} from a temporal object. /// <para> /// This obtains a zone 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 ZoneId}. /// </para> /// <para> /// A {@code TemporalAccessor} represents some form of date and time information. /// This factory converts the arbitrary temporal object to an instance of {@code ZoneId}. /// </para> /// <para> /// The conversion will try to obtain the zone in a way that favours region-based /// zones over offset-based zones using <seealso cref="TemporalQueries#zone()"/>. /// </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 ZoneId::from}. /// /// </para> /// </summary> /// <param name="temporal"> the temporal object to convert, not null </param> /// <returns> the zone ID, not null </returns> /// <exception cref="DateTimeException"> if unable to convert to a {@code ZoneId} </exception> public static ZoneId From(TemporalAccessor temporal) { ZoneId obj = temporal.query(TemporalQueries.Zone()); if (obj == null) { //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 ZoneId from TemporalAccessor: " + temporal + " of type " + temporal.GetType().FullName); } return(obj); }
//----------------------------------------------------------------------- /// <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); } }