internal OffsetDateTimeField(DateTimeField field, int offset) // If the field is null, we want to let the // base constructor throw the exception, rather than // fail to dereference it properly here. : this(Preconditions.CheckNotNull(field, "field"), field.FieldType, offset, int.MinValue, int.MaxValue) { }
internal ZeroIsMaxDateTimeField(DateTimeField wrappedField, DateTimeFieldType fieldType) : base(wrappedField, fieldType) { if (wrappedField.GetMinimumValue() != 0) { throw new ArgumentException("Wrapped field's minumum value must be zero"); } }
/// <summary> /// Verifies the input value against the valid range of the calendar field. /// </summary> /// <param name="field">The calendar field definition.</param> /// <param name="name">The name of the field for the error message.</param> /// <param name="value">The value to check.</param> /// <param name="allowNegated">if set to <c>true</c> all the range of value to be the negative as well.</param> /// <exception cref="ArgumentOutOfRangeException">If the given value is not in the valid range of the given calendar field.</exception> internal static void VerifyFieldValue(DateTimeField field, string name, long value, Boolean allowNegated) { bool failed = false; string range = ""; long minimum = field.GetMinimumValue(); long maximum = field.GetMaximumValue(); if (allowNegated) { range = "[" + minimum + ", " + maximum + "] or [" + -maximum + ", " + -minimum + "]"; } else { range = "[" + minimum + ", " + maximum + "]"; } if (allowNegated && value < 0) { if (value < -maximum || -minimum < value) { failed = true; } } else { if (value < minimum || maximum < value) { failed = true; } } if (failed) { throw new ArgumentOutOfRangeException(name, value, name + " is not in the valid range: " + range); } }
internal static void VerifyValueBounds(DateTimeField field, long value, long lowerBound, long upperBound) { // TODO: i18n or decide whether we want our own custom type with lower and upper bounds if ((value < lowerBound) || (value > upperBound)) { throw new ArgumentOutOfRangeException("value", value, "Value should be in range [" + lowerBound + "-" + upperBound + "]"); } }
internal RemainderDateTimeField(DateTimeField field, DateTimeFieldType fieldType, int divisor) : base(field, fieldType) { if (divisor < 2) { throw new ArgumentOutOfRangeException("divisor", "The divisor must be at least 2"); } remainderRangeField = new ScaledDurationField(field.DurationField, fieldType.RangeDurationFieldType.Value, divisor); this.divisor = divisor; }
protected DecoratedDateTimeField(DateTimeField wrappedField, DateTimeFieldType fieldType, DurationField durationField) : base(fieldType, durationField, Preconditions.CheckNotNull(wrappedField, "wrappedField").IsLenient, true) { // Already checked for nullity by now if (!wrappedField.IsSupported) { throw new ArgumentException("The wrapped field must be supported"); } this.wrappedField = wrappedField; }
private OffsetDateTimeField(DateTimeField field, DateTimeFieldType fieldType, int offset, int minValue, int maxValue) : base(field, fieldType) { if (offset == 0) { throw new ArgumentOutOfRangeException("offset", "The offset cannot be zero"); } this.offset = offset; // This field is only really used for weeks etc - not ticks - // so casting the min and max to int should be fine. min = Math.Max(minValue, (int)field.GetMinimumValue() + offset); max = Math.Min(maxValue, (int)field.GetMaximumValue() + offset); }
internal DividedDateTimeField(DateTimeField field, DateTimeFieldType fieldType, int divisor) : base(field, fieldType, new ScaledDurationField(field.DurationField, fieldType.DurationFieldType, divisor)) { if (divisor < 2) { throw new ArgumentOutOfRangeException("divisor", "The divisor must be at least 2"); } this.divisor = divisor; long fieldMin = field.GetMinimumValue(); min = fieldMin >= 0 ? fieldMin / divisor : ((fieldMin + 1) / divisor - 1); long fieldMax = field.GetMinimumValue(); max = fieldMax >= 0 ? fieldMax / divisor : ((fieldMax + 1) / divisor - 1); }
internal OffsetDateTimeField(DateTimeField field, DateTimeFieldType fieldType, int offset) : this(field, fieldType, offset, int.MinValue, int.MaxValue) { }
/// <summary> /// Verifies the input value against the valid range of the calendar field. /// </summary> /// <param name="field">The calendar field definition.</param> /// <param name="name">The name of the field for the error message.</param> /// <param name="value">The value to check.</param> /// <exception cref="ArgumentOutOfRangeException">If the given value is not in the valid range of the given calendar field.</exception> internal static void VerifyFieldValue(DateTimeField field, string name, long value) { VerifyFieldValue(field, name, value, false); }
private static LocalDateTime WithField(LocalDateTime ldt, DateTimeField field, long value) { return new LocalDateTime(field.SetValue(ldt.LocalInstant, value), ldt.Calendar); }
protected DecoratedDateTimeField(DateTimeField wrappedField, DateTimeFieldType fieldType) : this(Preconditions.CheckNotNull(wrappedField, "wrappedField"), fieldType, wrappedField.DurationField) { }
internal GJYearOfEraDateTimeField(DateTimeField yearField, BasicCalendarSystem calendarSystem) : base(yearField, DateTimeFieldType.YearOfEra) { this.calendarSystem = calendarSystem; }
/// <summary> /// Copies just the supported fields from the specified set into this builder, /// and returns this builder again (for fluent building). /// </summary> /// <param name="other">The set of fields to copy.</param> internal Builder WithSupportedFieldsFrom(FieldSet other) { if (other == null) { throw new ArgumentNullException("other"); } Ticks = other.Ticks.IsSupported ? other.Ticks : Ticks; Milliseconds = other.Milliseconds.IsSupported ? other.Milliseconds : Milliseconds; Seconds = other.Seconds.IsSupported ? other.Seconds : Seconds; Minutes = other.Minutes.IsSupported ? other.Minutes : Minutes; Hours = other.Hours.IsSupported ? other.Hours : Hours; HalfDays = other.HalfDays.IsSupported ? other.HalfDays : HalfDays; Days = other.Days.IsSupported ? other.Days : Days; Weeks = other.Weeks.IsSupported ? other.Weeks : Weeks; WeekYears = other.WeekYears.IsSupported ? other.WeekYears : WeekYears; Months = other.Months.IsSupported ? other.Months : Months; Years = other.Years.IsSupported ? other.Years : Years; Centuries = other.Centuries.IsSupported ? other.Centuries : Centuries; Eras = other.Eras.IsSupported ? other.Eras : Eras; TickOfSecond = other.TickOfSecond.IsSupported ? other.TickOfSecond : TickOfSecond; TickOfMillisecond = other.TickOfMillisecond.IsSupported ? other.TickOfMillisecond : TickOfMillisecond; TickOfDay = other.TickOfDay.IsSupported ? other.TickOfDay : TickOfDay; MillisecondOfSecond = other.MillisecondOfSecond.IsSupported ? other.MillisecondOfSecond : MillisecondOfSecond; MillisecondOfDay = other.MillisecondOfDay.IsSupported ? other.MillisecondOfDay : MillisecondOfDay; SecondOfMinute = other.SecondOfMinute.IsSupported ? other.SecondOfMinute : SecondOfMinute; SecondOfDay = other.SecondOfDay.IsSupported ? other.SecondOfDay : SecondOfDay; MinuteOfHour = other.MinuteOfHour.IsSupported ? other.MinuteOfHour : MinuteOfHour; MinuteOfDay = other.MinuteOfDay.IsSupported ? other.MinuteOfDay : MinuteOfDay; HourOfDay = other.HourOfDay.IsSupported ? other.HourOfDay : HourOfDay; ClockHourOfDay = other.ClockHourOfDay.IsSupported ? other.ClockHourOfDay : ClockHourOfDay; HourOfHalfDay = other.HourOfHalfDay.IsSupported ? other.HourOfHalfDay : HourOfHalfDay; ClockHourOfHalfDay = other.ClockHourOfHalfDay.IsSupported ? other.ClockHourOfHalfDay : ClockHourOfHalfDay; HalfDayOfDay = other.HalfDayOfDay.IsSupported ? other.HalfDayOfDay : HalfDayOfDay; DayOfWeek = other.DayOfWeek.IsSupported ? other.DayOfWeek : DayOfWeek; DayOfMonth = other.DayOfMonth.IsSupported ? other.DayOfMonth : DayOfMonth; DayOfYear = other.DayOfYear.IsSupported ? other.DayOfYear : DayOfYear; WeekOfWeekYear = other.WeekOfWeekYear.IsSupported ? other.WeekOfWeekYear : WeekOfWeekYear; WeekYear = other.WeekYear.IsSupported ? other.WeekYear : WeekYear; WeekYearOfCentury = other.WeekYearOfCentury.IsSupported ? other.WeekYearOfCentury : WeekYearOfCentury; MonthOfYear = other.MonthOfYear.IsSupported ? other.MonthOfYear : MonthOfYear; Year = other.Year.IsSupported ? other.Year : Year; YearOfCentury = other.YearOfCentury.IsSupported ? other.YearOfCentury : YearOfCentury; YearOfEra = other.YearOfEra.IsSupported ? other.YearOfEra : YearOfEra; CenturyOfEra = other.CenturyOfEra.IsSupported ? other.CenturyOfEra : CenturyOfEra; Era = other.Era.IsSupported ? other.Era : Era; return this; }
internal Builder(FieldSet baseSet) { if (baseSet == null) { throw new ArgumentNullException("baseSet"); } Ticks = baseSet.Ticks; Milliseconds = baseSet.Milliseconds; Seconds = baseSet.Seconds; Minutes = baseSet.Minutes; Hours = baseSet.Hours; HalfDays = baseSet.HalfDays; Days = baseSet.Days; Weeks = baseSet.Weeks; WeekYears = baseSet.WeekYears; Months = baseSet.Months; Years = baseSet.Years; Centuries = baseSet.Centuries; Eras = baseSet.Eras; TickOfSecond = baseSet.TickOfSecond; TickOfMillisecond = baseSet.TickOfMillisecond; TickOfDay = baseSet.TickOfDay; MillisecondOfSecond = baseSet.MillisecondOfSecond; MillisecondOfDay = baseSet.MillisecondOfDay; SecondOfMinute = baseSet.SecondOfMinute; SecondOfDay = baseSet.SecondOfDay; MinuteOfHour = baseSet.MinuteOfHour; MinuteOfDay = baseSet.MinuteOfDay; HourOfDay = baseSet.HourOfDay; ClockHourOfDay = baseSet.ClockHourOfDay; HourOfHalfDay = baseSet.HourOfHalfDay; ClockHourOfHalfDay = baseSet.ClockHourOfHalfDay; HalfDayOfDay = baseSet.HalfDayOfDay; DayOfWeek = baseSet.DayOfWeek; DayOfMonth = baseSet.DayOfMonth; DayOfYear = baseSet.DayOfYear; WeekOfWeekYear = baseSet.WeekOfWeekYear; WeekYear = baseSet.WeekYear; WeekYearOfCentury = baseSet.WeekYearOfCentury; MonthOfYear = baseSet.MonthOfYear; Year = baseSet.Year; YearOfCentury = baseSet.YearOfCentury; YearOfEra = baseSet.YearOfEra; CenturyOfEra = baseSet.CenturyOfEra; Era = baseSet.Era; }
private FieldSet(Builder builder) { ticks = builder.Ticks ?? UnsupportedDurationField.Ticks; milliseconds = builder.Milliseconds ?? UnsupportedDurationField.Milliseconds; seconds = builder.Seconds ?? UnsupportedDurationField.Seconds; minutes = builder.Minutes ?? UnsupportedDurationField.Minutes; hours = builder.Hours ?? UnsupportedDurationField.Hours; halfDays = builder.HalfDays ?? UnsupportedDurationField.HalfDays; days = builder.Days ?? UnsupportedDurationField.Days; weeks = builder.Weeks ?? UnsupportedDurationField.Weeks; weekYears = builder.WeekYears ?? UnsupportedDurationField.WeekYears; months = builder.Months ?? UnsupportedDurationField.Months; years = builder.Years ?? UnsupportedDurationField.Years; centuries = builder.Centuries ?? UnsupportedDurationField.Centuries; eras = builder.Eras ?? UnsupportedDurationField.Eras; tickOfSecond = builder.TickOfSecond ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.TickOfSecond, ticks); tickOfMillisecond = builder.TickOfMillisecond ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.TickOfMillisecond, ticks); tickOfDay = builder.TickOfDay ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.TickOfDay, ticks); millisecondOfSecond = builder.MillisecondOfSecond ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.MillisecondOfSecond, milliseconds); millisecondOfDay = builder.MillisecondOfDay ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.MillisecondOfDay, milliseconds); secondOfMinute = builder.SecondOfMinute ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.SecondOfMinute, seconds); secondOfDay = builder.SecondOfDay ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.SecondOfDay, seconds); minuteOfHour = builder.MinuteOfHour ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.MinuteOfHour, minutes); minuteOfDay = builder.MinuteOfDay ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.MinuteOfDay, minutes); hourOfDay = builder.HourOfDay ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.HourOfDay, hours); clockHourOfDay = builder.ClockHourOfDay ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.ClockHourOfDay, hours); hourOfHalfDay = builder.HourOfHalfDay ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.HourOfHalfDay, hours); clockHourOfHalfDay = builder.ClockHourOfHalfDay ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.ClockHourOfHalfDay, hours); halfDayOfDay = builder.HalfDayOfDay ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.HalfDayOfDay, halfDays); dayOfWeek = builder.DayOfWeek ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.DayOfWeek, days); dayOfMonth = builder.DayOfMonth ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.DayOfMonth, days); dayOfYear = builder.DayOfYear ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.DayOfYear, days); weekOfWeekYear = builder.WeekOfWeekYear ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.WeekOfWeekYear, weeks); weekYear = builder.WeekYear ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.WeekYear, years); weekYearOfCentury = builder.WeekYearOfCentury ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.WeekYearOfCentury, weekYears); monthOfYear = builder.MonthOfYear ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.MonthOfYear, months); year = builder.Year ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.Year, years); yearOfCentury = builder.YearOfCentury ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.YearOfCentury, years); yearOfEra = builder.YearOfEra ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.YearOfEra, years); centruryOfEra = builder.CenturyOfEra ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.CenturyOfEra, centuries); era = builder.Era ?? UnsupportedDateTimeField.GetInstance(DateTimeFieldType.Era, eras); }