Пример #1
0
        }         // Difference

        // ----------------------------------------------------------------------
        public TimeSpan Difference(DateTime date1, DateTime date2)
        {
            if (date1.Equals(date2))
            {
                return(TimeSpan.Zero);
            }
            if (collectorFilter.WeekDays.Count == 0 && collectorFilter.CollectingHours.Count == 0 && collectorFilter.CollectingDayHours.Count == 0)
            {
                return(new DateDiff(date1, date2, calendar.Culture.Calendar, calendar.FirstDayOfWeek, calendar.YearBaseMonth).Difference);
            }

            TimeRange differenceRange = new TimeRange(date1, date2);

            CalendarPeriodCollector collector = new CalendarPeriodCollector(
                collectorFilter, new TimeRange(differenceRange.Start.Date, differenceRange.End.Date.AddDays(1)), SeekDirection.Forward, calendar);

            collector.CollectHours();

            // calculate gaps
            TimeGapCalculator <TimeRange> gapCalculator = new TimeGapCalculator <TimeRange>(calendar);
            ITimePeriodCollection         gaps          = gapCalculator.GetGaps(collector.Periods, differenceRange);

            // calculate difference (sum gap durations)
            TimeSpan difference = gaps.GetTotalDuration(durationProvider);

            return(date1 < date2 ? difference : difference.Negate());
        }         // Difference
Пример #2
0
        public static float?GetRoundedTotalDuration(this ITimePeriodCollection periods)
        {
            if (periods == null || periods.Count == 0)
            {
                return(null);
            }

            TimeSpan totalDuration = periods.GetTotalDuration(roundByQuarterHour);
            float    total         = totalDuration.Hours + (totalDuration.Minutes / 60f);

            return(total > 0 ? total : 24);
        }