/// <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.PlusSmallNanoseconds(offset.Nanoseconds); if (asDuration.FloorDays < Instant.MinDays) { return(Instant.BeforeMinValue); } if (asDuration.FloorDays > Instant.MaxDays) { return(Instant.AfterMaxValue); } return(new Instant(asDuration)); }
internal LocalInstant Plus(Offset offset) => new LocalInstant(duration.PlusSmallNanoseconds(offset.Nanoseconds));