Пример #1
0
        public static Time GetRemainingTime(CountdownSchedule schedule, DateTime now)
        {
            var finished = schedule.NextCycle;

            if (finished < now)
            {
                return(CalculateTime(finished, now));
            }

            return(CalculateTime(now, finished));
        }
Пример #2
0
        public static Time GetElapsedTime(CountdownSchedule schedule, DateTime now)
        {
            var finished = schedule.NextCycle;

            if (finished < now)
            {
                return(CalculateTime(finished, now));
            }

            var started = schedule.Started;

            return(CalculateTime(started, now));
        }
Пример #3
0
        public static CountdownProgress GetProgress(CountdownSchedule schedule, DateTime now)
        {
            var finished = schedule.NextCycle;
            var previous = schedule.PreviousCycle;

            var remainingDays = (finished - now).TotalDays;
            var totalDays     = (finished - previous).TotalDays;
            var progress      = totalDays > 0d ? (1 - remainingDays / totalDays) : 1;

            var remainingDaysRounded = finished.TimeOfDay < now.TimeOfDay
        ? (int)Math.Ceiling(remainingDays)
        : (int)Math.Floor(remainingDays);

            var totalDaysRounded = finished.TimeOfDay < previous.TimeOfDay
        ? (int)Math.Ceiling(totalDays)
        : (int)Math.Floor(totalDays);

            return(new CountdownProgress
            {
                DaysRemaining = remainingDaysRounded,
                DaysTotal = totalDaysRounded,
                ProgressPercentage = progress
            });
        }