public static Time GetRemainingTime(CountdownSchedule schedule, DateTime now) { var finished = schedule.NextCycle; if (finished < now) { return(CalculateTime(finished, now)); } return(CalculateTime(now, finished)); }
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)); }
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 }); }