internal ZeroIsMaxDateTimeField(DateTimeField wrappedField, DateTimeFieldType fieldType) : base(wrappedField, fieldType)
 {
     if (wrappedField.GetMinimumValue() != 0)
     {
         throw new ArgumentException("Wrapped field's minumum value must be zero");
     }
 }
Esempio n. 2
0
 /// <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 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);
        }
        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);
        }