Beispiel #1
0
        public static DateTime GetFivePmYesterday(ITimeProvider timeProvider = null)
        {
            if (timeProvider == null)
            {
                timeProvider = new SystemTimeProvider();
            }

            DateTime today = timeProvider.Today().ToUniversalTime();

            DateTime fivePm = new DateTime(today.Year, today.Month, today.Day, 17, 0, 0);

            TimeZoneInfo estTz  = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
            TimeSpan     offset = estTz.GetUtcOffset(fivePm);

            DateTimeOffset dto = new DateTimeOffset(fivePm, offset);

            if (dto.UtcDateTime > timeProvider.Now().UtcDateTime)
            {
                dto = dto.AddDays(-1);
            }

            return(dto.LocalDateTime);
        }