//----------------------------------------------------------------------- public ChronoLocalDateTimeImpl <D> Plus(long amountToAdd, TemporalUnit unit) { if (unit is ChronoUnit) { ChronoUnit f = (ChronoUnit)unit; switch (f) { case NANOS: return(PlusNanos(amountToAdd)); case MICROS: return(PlusDays(amountToAdd / MICROS_PER_DAY).PlusNanos((amountToAdd % MICROS_PER_DAY) * 1000)); case MILLIS: return(PlusDays(amountToAdd / MILLIS_PER_DAY).PlusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000)); case SECONDS: return(PlusSeconds(amountToAdd)); case MINUTES: return(PlusMinutes(amountToAdd)); case HOURS: return(PlusHours(amountToAdd)); case HALF_DAYS: // no overflow (256 is multiple of 2) return(PlusDays(amountToAdd / 256).PlusHours((amountToAdd % 256) * 12)); } return(With(Date.Plus(amountToAdd, unit), Time)); } return(ChronoLocalDateTimeImpl.EnsureValid(Date.Chronology, unit.AddTo(this, amountToAdd))); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static Object readInternal(byte type, java.io.ObjectInput in) throws java.io.IOException, ClassNotFoundException private static Object ReadInternal(sbyte type, ObjectInput @in) { switch (type) { case CHRONO_TYPE: return(AbstractChronology.ReadExternal(@in)); case CHRONO_LOCAL_DATE_TIME_TYPE: return(ChronoLocalDateTimeImpl.ReadExternal(@in)); case CHRONO_ZONE_DATE_TIME_TYPE: return(ChronoZonedDateTimeImpl.ReadExternal(@in)); case JAPANESE_DATE_TYPE: return(JapaneseDate.ReadExternal(@in)); case JAPANESE_ERA_TYPE: return(JapaneseEra.ReadExternal(@in)); case HIJRAH_DATE_TYPE: return(HijrahDate.ReadExternal(@in)); case MINGUO_DATE_TYPE: return(MinguoDate.ReadExternal(@in)); case THAIBUDDHIST_DATE_TYPE: return(ThaiBuddhistDate.ReadExternal(@in)); case CHRONO_PERIOD_TYPE: return(ChronoPeriodImpl.ReadExternal(@in)); default: throw new StreamCorruptedException("Unknown serialized type"); } }
/// <summary> /// Casts the {@code Temporal} to {@code ChronoLocalDateTime} ensuring it bas the specified chronology. /// </summary> /// <param name="chrono"> the chronology to check for, not null </param> /// <param name="temporal"> a date-time to cast, not null </param> /// <returns> the date-time checked and cast to {@code ChronoLocalDateTime}, not null </returns> /// <exception cref="ClassCastException"> if the date-time cannot be cast to ChronoLocalDateTimeImpl /// or the chronology is not equal this Chronology </exception> internal static ChronoLocalDateTimeImpl <R> ensureValid <R>(Chronology ChronoLocalDateTime_Fields, Temporal temporal) where R : ChronoLocalDate { //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") ChronoLocalDateTimeImpl<R> other = (ChronoLocalDateTimeImpl<R>) temporal; ChronoLocalDateTimeImpl <R> other = (ChronoLocalDateTimeImpl <R>)temporal; if (ChronoLocalDateTime_Fields.Chrono.Equals(other.Chronology) == false) { throw new ClassCastException("Chronology mismatch, required: " + ChronoLocalDateTime_Fields.Chrono.Id + ", actual: " + other.Chronology.Id); } return(other); }
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))); }
//----------------------------------------------------------------------- //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public ChronoLocalDateTimeImpl<D> with(java.time.temporal.TemporalAdjuster adjuster) public override ChronoLocalDateTimeImpl <D> With(TemporalAdjuster adjuster) { if (adjuster is ChronoLocalDate) { // The Chronology is checked in with(date,time) return(With((ChronoLocalDate)adjuster, Time)); } else if (adjuster is LocalTime) { return(With(Date, (LocalTime)adjuster)); } else if (adjuster is ChronoLocalDateTimeImpl) { //JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET: //ORIGINAL LINE: return ChronoLocalDateTimeImpl.ensureValid(date.getChronology(), (ChronoLocalDateTimeImpl<?>) adjuster); return(ChronoLocalDateTimeImpl.EnsureValid(Date.Chronology, (ChronoLocalDateTimeImpl <?>)adjuster)); } //JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET: //ORIGINAL LINE: return ChronoLocalDateTimeImpl.ensureValid(date.getChronology(), (ChronoLocalDateTimeImpl<?>) adjuster.adjustInto(this)); return(ChronoLocalDateTimeImpl.EnsureValid(Date.Chronology, (ChronoLocalDateTimeImpl <?>)adjuster.AdjustInto(this))); }
//----------------------------------------------------------------------- /// <summary> /// Obtains an instance from a local date-time using the preferred offset if possible. /// </summary> /// <param name="localDateTime"> the local date-time, not null </param> /// <param name="zone"> the zone identifier, not null </param> /// <param name="preferredOffset"> the zone offset, null if no preference </param> /// <returns> the zoned date-time, not null </returns> internal static ChronoZonedDateTime<R> ofBest<R>(ChronoLocalDateTimeImpl<R> localDateTime, ZoneId zone, ZoneOffset preferredOffset) where R : ChronoLocalDate { Objects.RequireNonNull(localDateTime, "localDateTime"); Objects.RequireNonNull(zone, "zone"); if (zone is ZoneOffset) { return new ChronoZonedDateTimeImpl<>(localDateTime, (ZoneOffset) zone, zone); } ZoneRules rules = zone.Rules; LocalDateTime isoLDT = LocalDateTime.From(localDateTime); IList<ZoneOffset> validOffsets = rules.GetValidOffsets(isoLDT); ZoneOffset offset; if (validOffsets.Count == 1) { offset = validOffsets[0]; } else if (validOffsets.Count == 0) { ZoneOffsetTransition trans = rules.GetTransition(isoLDT); localDateTime = localDateTime.PlusSeconds(trans.Duration.Seconds); offset = trans.OffsetAfter; } else { if (preferredOffset != null && validOffsets.Contains(preferredOffset)) { offset = preferredOffset; } else { offset = validOffsets[0]; } } Objects.RequireNonNull(offset, "offset"); // protect against bad ZoneRules return new ChronoZonedDateTimeImpl<>(localDateTime, offset, zone); }
//----------------------------------------------------------------------- /// <summary> /// Constructor. /// </summary> /// <param name="dateTime"> the date-time, not null </param> /// <param name="offset"> the zone offset, not null </param> /// <param name="zone"> the zone ID, not null </param> private ChronoZonedDateTimeImpl(ChronoLocalDateTimeImpl<D> dateTime, ZoneOffset offset, ZoneId zone) { this.DateTime = Objects.RequireNonNull(dateTime, "dateTime"); this.Offset_Renamed = Objects.RequireNonNull(offset, "offset"); this.Zone_Renamed = Objects.RequireNonNull(zone, "zone"); }