コード例 #1
0
ファイル: IsoFields.cs プロジェクト: ranganathsb/JavaSharp
                public ValueRange rangeRefinedBy(TemporalAccessor temporal)
                {
//JAVA TO C# CONVERTER TODO TASK: The following line could not be converted:
                    if (isSupportedBy(temporal) == false)
                    {
                        throw new UnsupportedTemporalTypeException("Unsupported field: DayOfQuarter");
                    }
                    long = QUARTER_OF_YEAR
//JAVA TO C# CONVERTER TODO TASK: The following line could not be converted:
                           if (qoy == 1)
                    {
                        long                   = YEAR
                                        return = java.time.chrono.IsoChronology.INSTANCE.isLeapYear(year) ? ValueRange.of(1, 91) : ValueRange.of(1, 90)
                    }
//JAVA TO C# CONVERTER TODO TASK: The following line could not be converted:
                    else if (qoy == 2)
                    {
                        return(ValueRange.of(1, 91));
                    }
//JAVA TO C# CONVERTER TODO TASK: The following line could not be converted:
                    else if (qoy == 3 || qoy == 4)
                    {
                        return(ValueRange.of(1, 92));
                    }                     // else value not from 1 to 4, so drop through
                    return =
                }
コード例 #2
0
 public TemporalAccessorAnonymousInnerClassHelper(TemporalAccessor temporal, Chronology effectiveChrono, ZoneId effectiveZone, ChronoLocalDate effectiveDate)
 {
     this.Temporal        = temporal;
     this.EffectiveChrono = effectiveChrono;
     this.EffectiveZone   = effectiveZone;
     this.EffectiveDate   = effectiveDate;
 }
コード例 #3
0
 private void CrossCheck(TemporalAccessor target)
 {
     for (IEnumerator <Map_Entry <TemporalField, Long> > it = FieldValues.GetEnumerator(); it.MoveNext();)
     {
         Map_Entry <TemporalField, Long> entry = it.Current;
         TemporalField field = entry.Key;
         if (target.IsSupported(field))
         {
             long val1;
             try
             {
                 val1 = target.GetLong(field);
             }
             catch (RuntimeException)
             {
                 continue;
             }
             long val2 = entry.Value;
             if (val1 != val2)
             {
                 throw new DateTimeException("Conflict found: Field " + field + " " + val1 + " differs from " + field + " " + val2 + " derived from " + target);
             }
             it.remove();
         }
     }
 }
コード例 #4
0
        /// <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);
            }
        }
コード例 #5
0
ファイル: ZoneId.cs プロジェクト: ranganathsb/JavaSharp
        //-----------------------------------------------------------------------
        /// <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);
        }
コード例 #6
0
        //-----------------------------------------------------------------------
        /// <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);
        }
コード例 #7
0
ファイル: IsoFields.cs プロジェクト: ranganathsb/JavaSharp
                public long getFrom(TemporalAccessor temporal)
                {
//JAVA TO C# CONVERTER TODO TASK: The following line could not be converted:
                    if (isSupportedBy(temporal) == false)
                    {
                        throw new UnsupportedTemporalTypeException("Unsupported field: DayOfQuarter");
                    }
                    int                                  = DAY_OF_YEAR
                                       int               = MONTH_OF_YEAR
                                                    long = YEAR
                                                           return doy - QUARTER_DAYS[((moy - 1) / 3) + (java.time.chrono.IsoChronology.INSTANCE.isLeapYear(year) ? 4 : 0)]
                }
コード例 #8
0
ファイル: IsoFields.cs プロジェクト: ranganathsb/JavaSharp
                public java.time.chrono.ChronoLocalDate resolve(java.util.Map <TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, java.time.format.ResolverStyle resolverStyle)
                {
                    Long               = YEAR
                                  Long = QUARTER_OF_YEAR
//JAVA TO C# CONVERTER TODO TASK: The following line could not be converted:
                                         if (yearLong == null || qoyLong == null)
                    {
                        return(null);
                    }
                    int                                                   = yearLong // always validate
                                             long                         = DAY_OF_QUARTER
                                                                ensureIso = partialTemporal
                                                                            java.time.LocalDate date;
//JAVA TO C# CONVERTER TODO TASK: The following line could not be converted:
                    if (resolverStyle == java.time.format.ResolverStyle.LENIENT)
                    {
                        date             = Math.multiplyExact(Math.subtractExact(qoyLong, 1), 3)
                                     doq = Math.subtractExact(doq, 1);
                    }
//JAVA TO C# CONVERTER TODO TASK: The following line could not be converted:
                    else
                    {
                        int qoy = QUARTER_OF_YEAR.range().checkValidIntValue(qoyLong, QUARTER_OF_YEAR);                         // validated
                        date = java.time.LocalDate.of(y, ((qoy - 1) * 3) + 1, 1);
//JAVA TO C# CONVERTER TODO TASK: The following line could not be converted:
                        if (doq < 1 || doq > 90)
                        {
//JAVA TO C# CONVERTER TODO TASK: The following line could not be converted:
                            if (resolverStyle == java.time.format.ResolverStyle.STRICT)
                            {
                                rangeRefinedBy(date).checkValidValue(doq, this); // only allow exact range
                            }                                                    // SMART
//JAVA TO C# CONVERTER TODO TASK: The following line could not be converted:
                            else
                            {
                                range().checkValidValue(doq, this);                                 // allow 1-92 rolling into next quarter
                            }
                        }
                        doq--;
                    }
                    fieldValues = this
                                  fieldValues = YEAR
                                                fieldValues                   = QUARTER_OF_YEAR
                                                                       return = doq
                }
コード例 #9
0
ファイル: MonthDay.cs プロジェクト: ranganathsb/JavaSharp
        //-----------------------------------------------------------------------
        /// <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);
            }
        }
コード例 #10
0
        //-----------------------------------------------------------------------
        private void ResolveFields()
        {
            // resolve ChronoField
            ResolveInstantFields();
            ResolveDateFields();
            ResolveTimeFields();

            // if any other fields, handle them
            // any lenient date resolution should return epoch-day
            if (FieldValues.Count > 0)
            {
                int changedCount = 0;
                while (changedCount < 50)
                {
                    foreach (Map_Entry <TemporalField, Long> entry in FieldValues)
                    {
                        TemporalField    targetField    = entry.Key;
                        TemporalAccessor resolvedObject = targetField.resolve(FieldValues, this, ResolverStyle);
                        if (resolvedObject != java.time.temporal.TemporalAccessor_Fields.Null)
                        {
                            if (resolvedObject is ChronoZonedDateTime)
                            {
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: java.time.chrono.ChronoZonedDateTime<?> czdt = (java.time.chrono.ChronoZonedDateTime<?>) resolvedObject;
                                ChronoZonedDateTime <?> czdt = (ChronoZonedDateTime <?>)resolvedObject;
                                if (Zone == java.time.temporal.TemporalAccessor_Fields.Null)
                                {
                                    Zone = czdt.Zone;
                                }
                                else if (Zone.Equals(czdt.Zone) == false)
                                {
                                    throw new DateTimeException("ChronoZonedDateTime must use the effective parsed zone: " + Zone);
                                }
                                resolvedObject = czdt.ToLocalDateTime();
                            }
                            if (resolvedObject is ChronoLocalDateTime)
                            {
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: java.time.chrono.ChronoLocalDateTime<?> cldt = (java.time.chrono.ChronoLocalDateTime<?>) resolvedObject;
                                ChronoLocalDateTime <?> cldt = (ChronoLocalDateTime <?>)resolvedObject;
                                UpdateCheckConflict(cldt.ToLocalTime(), Period.ZERO);
                                UpdateCheckConflict(cldt.ToLocalDate());
                                changedCount++;
                                goto outerContinue;                                 // have to restart to avoid concurrent modification
                            }
                            if (resolvedObject is ChronoLocalDate)
                            {
                                UpdateCheckConflict((ChronoLocalDate)resolvedObject);
                                changedCount++;
                                goto outerContinue;                                 // have to restart to avoid concurrent modification
                            }
                            if (resolvedObject is LocalTime)
                            {
                                UpdateCheckConflict((LocalTime)resolvedObject, Period.ZERO);
                                changedCount++;
                                goto outerContinue;                                 // have to restart to avoid concurrent modification
                            }
                            throw new DateTimeException("Method resolve() can only return ChronoZonedDateTime, " + "ChronoLocalDateTime, ChronoLocalDate or LocalTime");
                        }
                        else if (FieldValues.ContainsKey(targetField) == false)
                        {
                            changedCount++;
                            goto outerContinue;                             // have to restart to avoid concurrent modification
                        }
                    }
                    break;
                    outerContinue :;
                }
                outerBreak :
                if (changedCount == 50)                 // catch infinite loops
                {
                    throw new DateTimeException("One of the parsed fields has an incorrectly implemented resolve method");
                }
                // if something changed then have to redo ChronoField resolve
                if (changedCount > 0)
                {
                    ResolveInstantFields();
                    ResolveDateFields();
                    ResolveTimeFields();
                }
            }
        }
コード例 #11
0
 /// <summary>
 /// Obtains a {@code MinguoDate} from a temporal object.
 /// <para>
 /// This obtains a date in the Minguo calendar system 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 MinguoDate}.
 /// </para>
 /// <para>
 /// The conversion typically uses the <seealso cref="ChronoField#EPOCH_DAY EPOCH_DAY"/>
 /// field, which is standardized across calendar systems.
 /// </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 MinguoDate::from}.
 ///
 /// </para>
 /// </summary>
 /// <param name="temporal">  the temporal object to convert, not null </param>
 /// <returns> the date in Minguo calendar system, not null </returns>
 /// <exception cref="DateTimeException"> if unable to convert to a {@code MinguoDate} </exception>
 public static MinguoDate From(TemporalAccessor temporal)
 {
     return(MinguoChronology.INSTANCE.Date(temporal));
 }
コード例 #12
0
 /// <summary>
 /// Creates a new instance of the context.
 /// </summary>
 /// <param name="temporal">  the temporal object being output, not null </param>
 /// <param name="formatter">  the formatter controlling the format, not null </param>
 internal DateTimePrintContext(TemporalAccessor temporal, DateTimeFormatter formatter) : base()
 {
     this.Temporal_Renamed = Adjust(temporal, formatter);
     this.Formatter        = formatter;
 }
コード例 #13
0
ファイル: HijrahDate.cs プロジェクト: ranganathsb/JavaSharp
 /// <summary>
 /// Obtains a {@code HijrahDate} of the Islamic Umm Al-Qura calendar from a temporal object.
 /// <para>
 /// This obtains a date in the Hijrah calendar system 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 HijrahDate}.
 /// </para>
 /// <para>
 /// The conversion typically uses the <seealso cref="ChronoField#EPOCH_DAY EPOCH_DAY"/>
 /// field, which is standardized across calendar systems.
 /// </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 HijrahDate::from}.
 ///
 /// </para>
 /// </summary>
 /// <param name="temporal">  the temporal object to convert, not null </param>
 /// <returns> the date in Hijrah calendar system, not null </returns>
 /// <exception cref="DateTimeException"> if unable to convert to a {@code HijrahDate} </exception>
 public static HijrahDate From(TemporalAccessor temporal)
 {
     return(HijrahChronology.INSTANCE.Date(temporal));
 }
コード例 #14
0
ファイル: IsoFields.cs プロジェクト: ranganathsb/JavaSharp
 public boolean isSupportedBy(TemporalAccessor temporal)
 {
     return = temporal
 }
コード例 #15
0
 /// <summary>
 /// Obtains a {@code JapaneseDate} from a temporal object.
 /// <para>
 /// This obtains a date in the Japanese calendar system 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 JapaneseDate}.
 /// </para>
 /// <para>
 /// The conversion typically uses the <seealso cref="ChronoField#EPOCH_DAY EPOCH_DAY"/>
 /// field, which is standardized across calendar systems.
 /// </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 JapaneseDate::from}.
 ///
 /// </para>
 /// </summary>
 /// <param name="temporal">  the temporal object to convert, not null </param>
 /// <returns> the date in Japanese calendar system, not null </returns>
 /// <exception cref="DateTimeException"> if unable to convert to a {@code JapaneseDate} </exception>
 public static JapaneseDate From(TemporalAccessor temporal)
 {
     return(JapaneseChronology.INSTANCE.Date(temporal));
 }
コード例 #16
0
 /// <summary>
 /// Obtains a {@code ThaiBuddhistDate} from a temporal object.
 /// <para>
 /// This obtains a date in the Thai Buddhist calendar system 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 ThaiBuddhistDate}.
 /// </para>
 /// <para>
 /// The conversion typically uses the <seealso cref="ChronoField#EPOCH_DAY EPOCH_DAY"/>
 /// field, which is standardized across calendar systems.
 /// </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 ThaiBuddhistDate::from}.
 ///
 /// </para>
 /// </summary>
 /// <param name="temporal">  the temporal object to convert, not null </param>
 /// <returns> the date in Thai Buddhist calendar system, not null </returns>
 /// <exception cref="DateTimeException"> if unable to convert to a {@code ThaiBuddhistDate} </exception>
 public static ThaiBuddhistDate From(TemporalAccessor temporal)
 {
     return(ThaiBuddhistChronology.INSTANCE.Date(temporal));
 }
コード例 #17
0
 public static FakeClock FakeClock(TemporalAccessor initialTime)
 {
     return((new FakeClock(initialTime.getLong(ChronoField.INSTANT_SECONDS), TimeUnit.SECONDS)).forward(initialTime.getLong(ChronoField.NANO_OF_SECOND), TimeUnit.NANOSECONDS));
 }
コード例 #18
0
//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));
        }