public bool SetArchiveStrategy(ArchiveStrategy newArchiveStrategy) { bool strategyChanged = false; // if it's not set or if the current value is lower // than the new value, then set it. Otherwise, leave it alone. if ((int)archiveStrategy < (int)newArchiveStrategy) { archiveStrategy = newArchiveStrategy; strategyChanged = true; } return(strategyChanged); }
private (DateTime, DateTime) GetNextFileDate(DateTime dateTime, ArchiveStrategy archiveStrategy, DayOfWeek firstDayOfWeek) { DateTime startDateTime; DateTime endDateTime; _logger.Debug($"Calculating date using {archiveStrategy} strategy..."); switch (archiveStrategy) { // Get files older than a day case ArchiveStrategy.Daily: endDateTime = dateTime.AddDays(-1); startDateTime = endDateTime; break; // Get files older than a week case ArchiveStrategy.Weekly: endDateTime = dateTime.AddDays(Utils.GetPreviousDayOfWeekDifference(firstDayOfWeek, dateTime) - 1); startDateTime = endDateTime.AddDays(-6); break; // Get files older than a month case ArchiveStrategy.Monthly: endDateTime = dateTime.AddMonths(-1); endDateTime = new DateTime(endDateTime.Year, endDateTime.Month, DateTime.DaysInMonth(endDateTime.Year, endDateTime.Month)); startDateTime = new DateTime(endDateTime.Year, endDateTime.Month, 1); break; // Get files older than a year case ArchiveStrategy.Yearly: endDateTime = dateTime.AddYears(-1); endDateTime = new DateTime(endDateTime.Year - 1, 12, 31); startDateTime = new DateTime(endDateTime.Year, 1, 1); break; default: throw new ApplicationException($"Archive strategy '{archiveStrategy}' is not a valid value."); } // Set the end of the calculated day startDateTime = new DateTime(startDateTime.Year, startDateTime.Month, startDateTime.Day, 0, 0, 0, 0); endDateTime = new DateTime(endDateTime.Year, endDateTime.Month, endDateTime.Day, 23, 59, 59, 999); _logger.Debug($"Date calculated: {startDateTime.ToString(System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat)} - {endDateTime.ToString(System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat)}."); // Return calculated date return(startDateTime, endDateTime); }