/// <summary> /// Warning: bug found. dt.Offset may be incorrect as offsets could be different if range crosses daylight saving switch, i.e. October - December, or month of November in the EST USA. /// </summary> /// <param name="unit"></param> /// <param name="referenceMoment"></param> /// <returns></returns> public static TimeMomentRange ToDate(this TimeUnits unit, DateTimeOffset?referenceMoment = null) { var span = new RelativeTimeSpan(Timeline.ToDateOrTillSpecified, unit); TimeMomentRange range = span.GetTimeMomentRange(referenceMoment); return(range); }
/// <summary> /// Warning: bug found. dt.Offset may be incorrect as offsets could be different if range crosses daylight saving switch, i.e. October - December, or month of November in the EST USA. /// </summary> /// <param name="unit"></param> /// <param name="unitCount"></param> /// <param name="referenceMoment"></param> /// <returns></returns> public static TimeMomentRange Next(this TimeUnits unit, ulong unitCount = 1, DateTimeOffset?referenceMoment = null) { var span = new RelativeTimeSpan(Timeline.NextExcludingCurrent, unit, unitCount); TimeMomentRange range = span.GetTimeMomentRange(referenceMoment); return(range); }
/// <summary> /// Warning: bug found. dt.Offset may be incorrect as offsets could be different if range crosses daylight saving switch, i.e. October - December, or month of November in the EST USA. /// </summary> /// <param name="referenceMoment"></param> /// <returns></returns> public TimeMomentRange GetTimeMomentRange(DateTimeOffset?referenceMoment = null) { DateTime?refMoment = referenceMoment == null ? (DateTime?)null : new DateTime(referenceMoment.Value.UtcDateTime.Ticks); #pragma warning disable 618 DateRange derange = this.GetDateTimeRange(refMoment); #pragma warning restore 618 DateTimeOffset?starto, endo; if (referenceMoment == null) { starto = derange.HasStart ? derange.Start.Value : (DateTimeOffset?)null; endo = derange.HasEnd ? derange.End.Value : (DateTimeOffset?)null; } else { TimeSpan utcOffset = referenceMoment.Value.Offset; starto = derange.HasStart ? new DateTimeOffset(derange.Start.Value, utcOffset) : (DateTimeOffset?)null; endo = derange.HasEnd ? new DateTimeOffset(derange.End.Value, utcOffset) : (DateTimeOffset?)null; } TimeMomentRange range = new TimeMomentRange(starto, endo); return(range); }