using System; namespace LCU.API.Internal.Operations.IncentiveApiLib.Persistence; public class DateTimeService : IDateTime { public DateTime Now => DateTime.Now; public DateTime UTCNow => DateTime.UtcNow; public DateTime ConvertDnaUnspecifiedTimeToUtc(DateTime dateTime) { var dnaAssumedTimeZone = TimeZoneConverter.TZConvert.GetTimeZoneInfo("America/Chicago"); return TimeZoneInfo.ConvertTime(dateTime, dnaAssumedTimeZone, TimeZoneInfo.Utc); } public DateTime? CSTWindowsNow { get { try { var centralTimeZone = TimeZoneConverter.TZConvert.GetTimeZoneInfo("Central Standard Time"); return TimeZoneInfo.ConvertTimeFromUtc(UTCNow, centralTimeZone); } catch (Exception) { return null; } } } public DateTime? CSTLinuxNow { get { try { var centralTimeZone = TimeZoneConverter.TZConvert.GetTimeZoneInfo("America/Chicago"); return TimeZoneInfo.ConvertTimeFromUtc(UTCNow, centralTimeZone); } catch (Exception) { return null; } } } public DateTime ConvertDateTimeFromCSTToUTCLinux(string dateTimeString) { var date = DateTime.Parse(dateTimeString); return TimeZoneInfo.ConvertTime(date, TimeZoneConverter.TZConvert.GetTimeZoneInfo("America/Chicago"), TimeZoneInfo.Utc); } public DateTime ConvertDateTimeFromCSTToUTCWindows(string dateTimeString) { var date = DateTime.Parse(dateTimeString); return TimeZoneInfo.ConvertTime(date, TimeZoneConverter.TZConvert.GetTimeZoneInfo("Central Standard Time"), TimeZoneInfo.Utc); } public DateTime getNextBonusPeriod(DateTime today) { var seedDate = new DateTime(2021, 10, 01); while (seedDate.Date <= today.Date || PayPeriodInMonth(seedDate) != 2) { seedDate = seedDate.AddDays(14); } return seedDate; } private int PayPeriodInMonth(DateTime input) { var period = 1; var previousPayDay = input.AddDays(-14); if (previousPayDay.Month == input.Month) { period = 2; } previousPayDay = previousPayDay.AddDays(-14); if (previousPayDay.Month == input.Month) { period = 3; } return period; } }