Ejemplo n.º 1
0
 internal ZeroIsMaxDateTimeField(DateTimeField wrappedField, DateTimeFieldType fieldType) : base(wrappedField, fieldType)
 {
     if (wrappedField.GetMinimumValue() != 0)
     {
         throw new ArgumentException("Wrapped field's minumum value must be zero");
     }
 }
Ejemplo n.º 2
0
 protected DateTimeField(DateTimeFieldType fieldType, DurationField durationField,
     bool isLenient, bool isSupported)
 {
     this.fieldType = Preconditions.CheckNotNull(fieldType, "fieldType");
     this.durationField = Preconditions.CheckNotNull(durationField, "durationField");
     this.isLenient = isLenient;
     this.isSupported = isSupported;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Verifies the input value against the specified range, for the given field type.
 /// </summary>
 /// <param name="fieldType">The field type</param>
 /// <param name="value">The value to verify</param>
 /// <param name="lowerBound">The minimum valid value</param>
 /// <param name="upperBound">The maximum valid value</param>
 internal static void VerifyValueBounds(DateTimeFieldType fieldType, 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 of type " + fieldType + " should be in range [" + lowerBound + "-" + upperBound + "]");
     }
 }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
        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);
        }
        protected PreciseDurationDateTimeField(DateTimeFieldType fieldType, DurationField unitField)
            : base(fieldType, unitField)
        {
            if (!unitField.IsPrecise)
            {
                throw new ArgumentException("Unit duration field must be precise");
            }

            unitTicks = unitField.UnitTicks;
            if (unitTicks < 1)
            {
                throw new ArgumentException("The unit ticks must be at least one");
            }
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
 internal PreciseDateTimeField(DateTimeFieldType type, DurationField unit, DurationField rangeField) : base(type, unit)
 {
     if (rangeField == null)
     {
         throw new ArgumentNullException("rangeField");
     }
     if (!rangeField.IsPrecise)
     {
         throw new ArgumentException("Range duration field must be precise");
     }
     effectiveRange = rangeField.UnitTicks / unit.UnitTicks;
     if (effectiveRange < 2)
     {
         throw new ArgumentException("The effective range must be at least 2.");
     }
     this.rangeField = rangeField;
 }
 /// <summary>
 /// Returns an instance for the specified field type and duration field.
 /// The returned value is cached.
 /// TODO: Potentially use ReaderWriterLockSlim? Assess performance of caching in the first place...
 /// </summary>
 public static UnsupportedDateTimeField GetInstance(DateTimeFieldType fieldType, DurationField durationField)
 {
     if (fieldType == null)
     {
         throw new ArgumentNullException("fieldType");
     }
     if (durationField == null)
     {
         throw new ArgumentNullException("durationField");
     }
     lock (cacheLock)
     {
         UnsupportedDateTimeField cached = cache[fieldType.Ordinal];
         if (cached == null || !ReferenceEquals(cached.DurationField, durationField))
         {
             cached = new UnsupportedDateTimeField(fieldType, durationField);
             cache[fieldType.Ordinal] = cached;
         }
         return cached;
     }
 }
Ejemplo n.º 11
0
 internal OffsetDateTimeField(DateTimeField field, DateTimeFieldType fieldType, int offset) : this(field, fieldType, offset, int.MinValue, int.MaxValue)
 {
 }
Ejemplo n.º 12
0
 internal RemainderDateTimeField(DividedDateTimeField dividedField, DateTimeFieldType fieldType) : base(dividedField.WrappedField, fieldType)
 {
     divisor = dividedField.Divisor;
     remainderRangeField = dividedField.DurationField;
 }
 private UnsupportedDateTimeField(DateTimeFieldType fieldType, DurationField durationField) : base(fieldType, durationField, false, false)
 {
 }
Ejemplo n.º 14
0
 internal StubDateTimeField(DateTimeFieldType type) : base(type, new MockCountingDurationField(DurationFieldType.Seconds))
 {
 }
Ejemplo n.º 15
0
 protected DecoratedDateTimeField(DateTimeField wrappedField, DateTimeFieldType fieldType)
     : this(Preconditions.CheckNotNull(wrappedField, "wrappedField"), fieldType, wrappedField.DurationField)
 {
 }
Ejemplo n.º 16
0
 protected DateTimeField(DateTimeFieldType fieldType, DurationField durationField)
     : this(fieldType, durationField, false, true)
 {
 }