예제 #1
0
        public static TimeSpan Without(this TimeSpan time, TimeUnit unit)
        {
            var timeCopy = new TimeSpan(time.Ticks);

            if (unit.Has(TimeUnit.Milliseconds))
            {
                timeCopy = timeCopy.Subtract(new TimeSpan(0, 0, 0, 0, time.Milliseconds));
            }
            if (unit.Has(TimeUnit.Seconds))
            {
                timeCopy = timeCopy.Subtract(new TimeSpan(0, 0, 0, time.Seconds));
            }
            if (unit.Has(TimeUnit.Minutes))
            {
                timeCopy = timeCopy.Subtract(new TimeSpan(0, time.Minutes, 0));
            }
            if (unit.Has(TimeUnit.Hours))
            {
                timeCopy = timeCopy.Subtract(new TimeSpan(time.Hours, 0, 0));
            }
            if (unit.Has(TimeUnit.Days))
            {
                timeCopy = timeCopy.Subtract(new TimeSpan(time.Days, 0, 0, 0));
            }
            return(timeCopy);
        }