예제 #1
0
        //-----------------------------------------------------------------------
        public override ValueRange java.time.temporal.TemporalAccessor_Fields.range(TemporalField field)
        {
            if (field is ChronoField)
            {
                if (IsSupported(field))
                {
                    ChronoField f = (ChronoField)field;
                    switch (f)
                    {
                    case DAY_OF_MONTH:
                    case DAY_OF_YEAR:
                    case ALIGNED_WEEK_OF_MONTH:
                        return(IsoDate.Range(field));

                    case YEAR_OF_ERA:
                    {
                        ValueRange java.time.temporal.TemporalAccessor_Fields.Range = YEAR.range();
                        long max = (ProlepticYear <= 0 ? -java.time.temporal.TemporalAccessor_Fields.Range.Minimum + 1 + YEARS_DIFFERENCE : java.time.temporal.TemporalAccessor_Fields.Range.Maximum - YEARS_DIFFERENCE);
                        return(ValueRange.Of(1, max));
                    }
                    }
                    return(Chronology.Range(f));
                }
                throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
            }
            return(field.RangeRefinedBy(this));
        }
예제 #2
0
        public override ValueRange java.time.temporal.TemporalAccessor_Fields.range(TemporalField field)
        {
            if (field is ChronoField)
            {
                if (IsSupported(field))
                {
                    ChronoField f = (ChronoField)field;
                    switch (f)
                    {
                    case DAY_OF_MONTH:
                        return(ValueRange.Of(1, LengthOfMonth()));

                    case DAY_OF_YEAR:
                        return(ValueRange.Of(1, LengthOfYear()));

                    case YEAR_OF_ERA:
                    {
                        DateTime jcal = DateTime.GetInstance(JapaneseChronology.LOCALE);
                        jcal.set(DateTime.ERA, Era_Renamed.Value + JapaneseEra.ERA_OFFSET);
                        jcal = new DateTime(YearOfEra, IsoDate.MonthValue - 1, IsoDate.DayOfMonth);
                        return(ValueRange.Of(1, jcal.getActualMaximum(DateTime.YEAR)));
                    }
                    }
                    return(Chronology.Range(f));
                }
                throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
            }
            return(field.RangeRefinedBy(this));
        }
예제 #3
0
        //-----------------------------------------------------------------------
        public override ValueRange java.time.temporal.TemporalAccessor_Fields.range(TemporalField field)
        {
            if (field is ChronoField)
            {
                if (IsSupported(field))
                {
                    ChronoField f = (ChronoField)field;
                    switch (f)
                    {
                    case DAY_OF_MONTH:
                        return(ValueRange.Of(1, LengthOfMonth()));

                    case DAY_OF_YEAR:
                        return(ValueRange.Of(1, LengthOfYear()));

                    case ALIGNED_WEEK_OF_MONTH:                             // TODO
                        return(ValueRange.Of(1, 5));
                        // TODO does the limited range of valid years cause years to
                        // start/end part way through? that would affect range
                    }
                    return(Chronology.Range(f));
                }
                throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
            }
            return(field.RangeRefinedBy(this));
        }
예제 #4
0
 public long GetLong(TemporalField field)
 {
     if (field is ChronoField)
     {
         ChronoField f = (ChronoField)field;
         return(f.TimeBased ? Time.GetLong(field) : Date.GetLong(field));
     }
     return(field.GetFrom(this));
 }
예제 #5
0
 public override int Get(TemporalField field)
 {
     if (field is ChronoField)
     {
         ChronoField f = (ChronoField)field;
         return(f.TimeBased ? Time.Get(field) : Date.get(field));
     }
     return(java.time.temporal.TemporalAccessor_Fields.range(field).checkValidIntValue(GetLong(field), field));
 }
예제 #6
0
 public override ValueRange java.time.temporal.TemporalAccessor_Fields.range(TemporalField field)
 {
     if (field is ChronoField)
     {
         ChronoField f = (ChronoField)field;
         return(f.TimeBased ? Time.Range(field) : Date.range(field));
     }
     return(field.RangeRefinedBy(this));
 }
예제 #7
0
 //-----------------------------------------------------------------------
 public bool IsSupported(TemporalField field)
 {
     if (field is ChronoField)
     {
         ChronoField f = (ChronoField)field;
         return(f.DateBased || f.TimeBased);
     }
     return(field != ChronoLocalDateTime_Fields.Null && field.IsSupportedBy(this));
 }
예제 #8
0
        public HijrahDate With(TemporalField field, long newValue)
        {
            if (field is ChronoField)
            {
                ChronoField f = (ChronoField)field;
                // not using checkValidIntValue so EPOCH_DAY and PROLEPTIC_MONTH work
                ChronoLocalDate_Fields.Chrono.Range(f).CheckValidValue(newValue, f);                 // TODO: validate value
                int nvalue = (int)newValue;
                switch (f)
                {
                case DAY_OF_WEEK:
                    return(PlusDays(newValue - DayOfWeek));

                case ALIGNED_DAY_OF_WEEK_IN_MONTH:
                    return(PlusDays(newValue - GetLong(ALIGNED_DAY_OF_WEEK_IN_MONTH)));

                case ALIGNED_DAY_OF_WEEK_IN_YEAR:
                    return(PlusDays(newValue - GetLong(ALIGNED_DAY_OF_WEEK_IN_YEAR)));

                case DAY_OF_MONTH:
                    return(ResolvePreviousValid(ProlepticYear, MonthOfYear, nvalue));

                case DAY_OF_YEAR:
                    return(PlusDays(System.Math.Min(nvalue, LengthOfYear()) - DayOfYear));

                case EPOCH_DAY:
                    return(new HijrahDate(ChronoLocalDate_Fields.Chrono, newValue));

                case ALIGNED_WEEK_OF_MONTH:
                    return(PlusDays((newValue - GetLong(ALIGNED_WEEK_OF_MONTH)) * 7));

                case ALIGNED_WEEK_OF_YEAR:
                    return(PlusDays((newValue - GetLong(ALIGNED_WEEK_OF_YEAR)) * 7));

                case MONTH_OF_YEAR:
                    return(ResolvePreviousValid(ProlepticYear, nvalue, DayOfMonth));

                case PROLEPTIC_MONTH:
                    return(PlusMonths(newValue - ProlepticMonth));

                case YEAR_OF_ERA:
                    return(ResolvePreviousValid(ProlepticYear >= 1 ? nvalue : 1 - nvalue, MonthOfYear, DayOfMonth));

                case YEAR:
                    return(ResolvePreviousValid(nvalue, MonthOfYear, DayOfMonth));

                case ERA:
                    return(ResolvePreviousValid(1 - ProlepticYear, MonthOfYear, DayOfMonth));
                }
                throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
            }
            return(base.With(field, newValue));
        }
예제 #9
0
 public long GetField(ChronoField field)
 {
     return(field switch {
         ChronoField.MILLI_OF_SECOND => Millisecond,
         ChronoField.SECOND_OF_MINUTE => Second,
         ChronoField.MINUTE_OF_HOUR => Minute,
         ChronoField.HOUR_OF_DAY => Hour,
         ChronoField.DAY_OF_MONTH => Day,
         ChronoField.MONTH_OF_YEAR => Month,
         ChronoField.ALIGNED_WEEK_OF_YEAR => WeekOfYear,
         ChronoField.YEAR => Year,
         ChronoField.DAY_OF_WEEK => (long)DateTime.DayOfWeek,
         _ => throw new ArgumentOutOfRangeException(nameof(field), field, null)
     });
예제 #10
0
 public ChronoLocalDateTimeImpl <D> With(TemporalField field, long newValue)
 {
     if (field is ChronoField)
     {
         ChronoField f = (ChronoField)field;
         if (f.TimeBased)
         {
             return(With(Date, Time.With(field, newValue)));
         }
         else
         {
             return(With(Date.With(field, newValue), Time));
         }
     }
     return(ChronoLocalDateTimeImpl.EnsureValid(Date.Chronology, field.AdjustInto(this, newValue)));
 }
		//-----------------------------------------------------------------------
		public override ChronoZonedDateTime<D> With(TemporalField field, long newValue)
		{
			if (field is ChronoField)
			{
				ChronoField f = (ChronoField) field;
				switch (f)
				{
					case INSTANT_SECONDS:
						return Plus(newValue - toEpochSecond(), SECONDS);
					case OFFSET_SECONDS:
					{
						ZoneOffset offset = ZoneOffset.OfTotalSeconds(f.checkValidIntValue(newValue));
						return Create(DateTime.toInstant(offset), Zone_Renamed);
					}
				}
				return OfBest(DateTime.With(field, newValue), Zone_Renamed, Offset_Renamed);
			}
			return ChronoZonedDateTimeImpl.EnsureValid(Chronology, field.AdjustInto(this, newValue));
		}
예제 #12
0
        //-----------------------------------------------------------------------
        public MinguoDate With(TemporalField field, long newValue)
        {
            if (field is ChronoField)
            {
                ChronoField f = (ChronoField)field;
                if (GetLong(f) == newValue)
                {
                    return(this);
                }
                switch (f)
                {
                case PROLEPTIC_MONTH:
                    Chronology.Range(f).CheckValidValue(newValue, f);
                    return(PlusMonths(newValue - ProlepticMonth));

                case YEAR_OF_ERA:
                case YEAR:
                case ERA:
                {
                    int nvalue = Chronology.Range(f).CheckValidIntValue(newValue, f);
                    switch (f)
                    {
                    case YEAR_OF_ERA:
                        return(With(IsoDate.WithYear(ProlepticYear >= 1 ? nvalue + YEARS_DIFFERENCE : (1 - nvalue) + YEARS_DIFFERENCE)));

                    case YEAR:
                        return(With(IsoDate.WithYear(nvalue + YEARS_DIFFERENCE)));

                    case ERA:
                        return(With(IsoDate.WithYear((1 - ProlepticYear) + YEARS_DIFFERENCE)));
                    }
                }
                break;
                }
                return(With(IsoDate.With(field, newValue)));
            }
            return(base.With(field, newValue));
        }
예제 #13
0
        //-----------------------------------------------------------------------
        public JapaneseDate With(TemporalField field, long newValue)
        {
            if (field is ChronoField)
            {
                ChronoField f = (ChronoField)field;
                if (GetLong(f) == newValue)                 // getLong() validates for supported fields
                {
                    return(this);
                }
                switch (f)
                {
                case YEAR_OF_ERA:
                case YEAR:
                case ERA:
                {
                    int nvalue = Chronology.Range(f).CheckValidIntValue(newValue, f);
                    switch (f)
                    {
                    case YEAR_OF_ERA:
                        return(this.WithYear(nvalue));

                    case YEAR:
                        return(With(IsoDate.WithYear(nvalue)));

                    case ERA:
                    {
                        return(this.WithYear(JapaneseEra.Of(nvalue), YearOfEra));
                    }
                    }
                }
                break;
                }
                // YEAR, PROLEPTIC_MONTH and others are same as ISO
                return(With(IsoDate.With(field, newValue)));
            }
            return(base.With(field, newValue));
        }
예제 #14
0
 public abstract ValueRange Range(ChronoField field);
예제 #15
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));
        }