using System; using System.Collections.Generic; using System.Linq; namespace Sony.Filtr.Utility.Extensions { public static class DateTimeExtensions { public static IEnumerable GetDateRangeTo(this DateTime start, DateTime endDate) { for (var dt = start; dt <= endDate; dt = dt.AddDays(1)) { yield return dt.Date; } } public static IEnumerable GetDateRangeToNow(this DateTime startDate) { if (startDate > DateTime.UtcNow) { return Enumerable.Empty(); } return startDate.GetDateRangeTo(DateTime.UtcNow); } public static string ToNeutralShortDateString(this DateTime dateTime) { return dateTime.ToString("yyyy-MM-dd"); } public static string ToNeutralShortDateString(this DateTime? dateTime) { return dateTime?.ToString("yyyy-MM-dd"); } public static bool IsYesterday(this DateTime dt) { return dt.Date == DateTime.Now.AddDays(-1).Date; } public static DateTime FromVendorTimestamp(this double vendorTimestamp) { // Unix timestamp is seconds past epoch System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); dtDateTime = dtDateTime.AddSeconds(vendorTimestamp / 100).ToLocalTime(); return dtDateTime; } } }