Exemplo n.º 1
0
        /// <summary>
        /// Equivalent to <see cref="Instant.SafePlus"/>, but in the opposite direction.
        /// </summary>
        internal Instant SafeMinus(Offset offset)
        {
            int days = duration.FloorDays;

            // If we can do the arithmetic safely, do so.
            if (days > Instant.MinDays && days < Instant.MaxDays)
            {
                return(Minus(offset));
            }
            // Handle BeforeMinValue and BeforeMaxValue simply.
            if (days < Instant.MinDays)
            {
                return(Instant.BeforeMinValue);
            }
            if (days > Instant.MaxDays)
            {
                return(Instant.AfterMaxValue);
            }
            // Okay, do the arithmetic as a Duration, then check the result for overflow, effectively.
            var asDuration = duration.MinusSmallNanoseconds(offset.Nanoseconds);

            if (asDuration.FloorDays < Instant.MinDays)
            {
                return(Instant.BeforeMinValue);
            }
            if (asDuration.FloorDays > Instant.MaxDays)
            {
                return(Instant.AfterMaxValue);
            }
            // And now we don't need any more checks.
            return(Instant.FromTrustedDuration(asDuration));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns a new instant based on this local instant, as if we'd applied a zero offset.
 /// This is just a slight optimization over calling <c>localInstant.Minus(Offset.Zero)</c>.
 /// </summary>
 internal Instant MinusZeroOffset() => Instant.FromTrustedDuration(duration);