//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public <R> R query(java.time.temporal.TemporalQuery<R> query) public override R query <R>(TemporalQuery <R> query) { if (query == TemporalQueries.ZoneId()) { return((R)Zone); } else if (query == TemporalQueries.Chronology()) { return((R)Chrono); } else if (query == TemporalQueries.LocalDate()) { return((R)(Date != java.time.temporal.TemporalAccessor_Fields.Null ? LocalDate.From(Date) : java.time.temporal.TemporalAccessor_Fields.Null)); } else if (query == TemporalQueries.LocalTime()) { return((R)Time); } else if (query == TemporalQueries.Zone() || query == TemporalQueries.Offset()) { return(query.QueryFrom(this)); } else if (query == TemporalQueries.Precision()) { return(java.time.temporal.TemporalAccessor_Fields.Null); // not a complete date/time } // inline TemporalAccessor.super.query(query) as an optimization // non-JDK classes are not permitted to make this optimization return(query.QueryFrom(this)); }
//----------------------------------------------------------------------- /// <summary> /// Queries this month-day using the specified query. /// <para> /// This queries this month-day using the specified query strategy object. /// The {@code TemporalQuery} object defines the logic to be used to /// obtain the result. Read the documentation of the query to understand /// what the result of this method will be. /// </para> /// <para> /// The result of this method is obtained by invoking the /// <seealso cref="TemporalQuery#queryFrom(TemporalAccessor)"/> method on the /// specified query passing {@code this} as the argument. /// /// </para> /// </summary> /// @param <R> the type of the result </param> /// <param name="query"> the query to invoke, not null </param> /// <returns> the query result, null may be returned (defined by the query) </returns> /// <exception cref="DateTimeException"> if unable to query (defined by the query) </exception> /// <exception cref="ArithmeticException"> if numeric overflow occurs (defined by the query) </exception> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public <R> R query(java.time.temporal.TemporalQuery<R> query) public override R query <R>(TemporalQuery <R> query) { if (query == TemporalQueries.Chronology()) { return((R)IsoChronology.INSTANCE); } return(TemporalAccessor.this.query(query)); }
/// <summary> /// Validates that the temporal has the correct chronology. /// </summary> private void ValidateChrono(TemporalAccessor temporal) { Objects.RequireNonNull(temporal, "temporal"); Chronology temporalChrono = temporal.query(TemporalQueries.Chronology()); if (temporalChrono != null && Chrono.Equals(temporalChrono) == ChronoPeriod_Fields.False) { throw new DateTimeException("Chronology mismatch, expected: " + Chrono.Id + ", actual: " + temporalChrono.Id); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public <R> R query(java.time.temporal.TemporalQuery<R> query) public override R query <R>(TemporalQuery <R> query) { if (query == TemporalQueries.Chronology()) { return((R)EffectiveChrono); } if (query == TemporalQueries.ZoneId()) { return((R)EffectiveZone); } if (query == TemporalQueries.Precision()) { return(Temporal.query(query)); } return(query.QueryFrom(this)); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET: //ORIGINAL LINE: private static java.time.temporal.TemporalAccessor adjust(final java.time.temporal.TemporalAccessor temporal, DateTimeFormatter formatter) private static TemporalAccessor Adjust(TemporalAccessor temporal, DateTimeFormatter formatter) { // normal case first (early return is an optimization) Chronology overrideChrono = formatter.Chronology; ZoneId overrideZone = formatter.Zone; if (overrideChrono == null && overrideZone == null) { return(temporal); } // ensure minimal change (early return is an optimization) Chronology temporalChrono = temporal.query(TemporalQueries.Chronology()); ZoneId temporalZone = temporal.query(TemporalQueries.ZoneId()); if (Objects.Equals(overrideChrono, temporalChrono)) { overrideChrono = null; } if (Objects.Equals(overrideZone, temporalZone)) { overrideZone = null; } if (overrideChrono == null && overrideZone == null) { return(temporal); } // make adjustment //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.time.chrono.Chronology effectiveChrono = (overrideChrono != null ? overrideChrono : temporalChrono); Chronology effectiveChrono = (overrideChrono != null ? overrideChrono : temporalChrono); if (overrideZone != null) { // if have zone and instant, calculation is simple, defaulting chrono if necessary if (temporal.IsSupported(INSTANT_SECONDS)) { Chronology chrono = (effectiveChrono != null ? effectiveChrono : IsoChronology.INSTANCE); return(chrono.zonedDateTime(Instant.From(temporal), overrideZone)); } // block changing zone on OffsetTime, and similar problem cases if (overrideZone.Normalized() is ZoneOffset && temporal.IsSupported(OFFSET_SECONDS) && temporal.get(OFFSET_SECONDS) != overrideZone.Rules.GetOffset(Instant.EPOCH).TotalSeconds) { throw new DateTimeException("Unable to apply override zone '" + overrideZone + "' because the temporal object being formatted has a different offset but" + " does not represent an instant: " + temporal); } } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.time.ZoneId effectiveZone = (overrideZone != null ? overrideZone : temporalZone); ZoneId effectiveZone = (overrideZone != null ? overrideZone : temporalZone); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.time.chrono.ChronoLocalDate effectiveDate; ChronoLocalDate effectiveDate; if (overrideChrono != null) { if (temporal.IsSupported(EPOCH_DAY)) { effectiveDate = effectiveChrono.Date(temporal); } else { // check for date fields other than epoch-day, ignoring case of converting null to ISO if (!(overrideChrono == IsoChronology.INSTANCE && temporalChrono == null)) { foreach (ChronoField f in ChronoField.values()) { if (f.DateBased && temporal.IsSupported(f)) { throw new DateTimeException("Unable to apply override chronology '" + overrideChrono + "' because the temporal object being formatted contains date fields but" + " does not represent a whole date: " + temporal); } } } effectiveDate = null; } } else { effectiveDate = null; } // combine available data // this is a non-standard temporal that is almost a pure delegate // this better handles map-like underlying temporal instances return(new TemporalAccessorAnonymousInnerClassHelper(temporal, effectiveChrono, effectiveZone, effectiveDate)); }