예제 #1
0
        public static CalendarDateTime Add(CalendarDateTime x, Duration y)
        {
            if (y is CalendarDateTimeDuration)
            {
                return Add(x, (CalendarDateTimeDuration)y);
            }

            if (y is OrdinalDateTimeDuration)
            {
                return Add(x, ((OrdinalDateTimeDuration)y).ToCalendarDateTimeDuration());
            }

            if (y is CalendarDateDuration)
            {
                return Add(x, (CalendarDateDuration)y);
            }

            if (y is OrdinalDateDuration)
            {
                return Add(x, ((OrdinalDateDuration)y).ToCalendarDateDuration());
            }

            if (y is TimeDuration)
            {
                return Add(x, (TimeDuration)y);
            }

            if (y is DesignatedDuration)
            {
                return Add(x, (DesignatedDuration)y);
            }

            throw new InvalidOperationException($"A {y.GetType()} cannot be added to a {x.GetType()}.");
        }
예제 #2
0
        internal static TimeSpan Subtract(CalendarDateTime later, TimePoint earlier)
        {
            if (earlier is CalendarDateTime)
            {
                return later - (CalendarDateTime)earlier;
            }

            if (earlier is OrdinalDateTime)
            {
                return later - ((OrdinalDateTime)earlier).ToCalendarDateTime();
            }

            if (earlier is WeekDateTime)
            {
                return later - ((WeekDateTime)earlier).ToCalendarDateTime();
            }

            if (earlier is CalendarDate)
            {
                return later - (CalendarDate)earlier;
            }

            if (earlier is OrdinalDate)
            {
                return later - ((OrdinalDate)earlier).ToCalendarDate();
            }

            if (earlier is WeekDate)
            {
                return later - ((WeekDate)earlier).ToCalendarDate();
            }

            if (earlier is Time)
            {
                return later - (Time)earlier;
            }

            throw new InvalidOperationException($"A {earlier.GetType()} cannot be subtracted from a {later.GetType()}");
        }