public TimeBlockPeriodRelationTestData(DateTime start, TimeSpan duration, TimeSpan offset) { Guard.Assert(offset > TimeSpan.Zero, "offset은 양의 수여야 합니다."); var end = start.Add(duration); Reference = new TimeBlock(start, duration, true); var beforeEnd = start.Subtract(offset); var beforeStart = beforeEnd.Subtract(Reference.Duration); var insideStart = start.Add(offset); var insideEnd = end.Subtract(offset); var afterStart = end.Add(offset); var afterEnd = afterStart.Add(Reference.Duration); After = new TimeBlock(beforeStart, beforeEnd, true); StartTouching = new TimeBlock(beforeStart, start, true); StartInside = new TimeBlock(beforeStart, insideStart, true); InsideStartTouching = new TimeBlock(start, afterStart, true); EnclosingStartTouching = new TimeBlock(start, insideEnd, true); Enclosing = new TimeBlock(insideStart, insideEnd, true); EnclosingEndTouching = new TimeBlock(insideStart, end, true); ExactMatch = new TimeBlock(start, end, true); Inside = new TimeBlock(beforeStart, afterEnd, true); InsideEndTouching = new TimeBlock(beforeStart, end, true); EndInside = new TimeBlock(insideEnd, afterEnd, true); EndTouching = new TimeBlock(end, afterEnd, true); Before = new TimeBlock(afterStart, afterEnd, true); allPeriods.Add(Reference); allPeriods.Add(After); allPeriods.Add(StartTouching); allPeriods.Add(StartInside); allPeriods.Add(InsideStartTouching); allPeriods.Add(EnclosingStartTouching); allPeriods.Add(Enclosing); allPeriods.Add(EnclosingEndTouching); allPeriods.Add(ExactMatch); allPeriods.Add(Inside); allPeriods.Add(InsideEndTouching); allPeriods.Add(EndInside); allPeriods.Add(EndTouching); allPeriods.Add(Before); }
/// <summary> /// 지정된 Offset만큼 기간이 이후 시간으로 이동한 TimeBlock을 반환한다. /// </summary> /// <param name="offset"></param> /// <returns></returns> public virtual ITimeBlock GetNextBlock(TimeSpan offset) { var startOff = (offset > TimeSpan.Zero) ? offset : offset.Negate(); var result = new TimeBlock(End.Add(startOff), Duration, IsReadOnly); if(IsDebugEnabled) log.Debug("다음 Block을 구합니다. offset=[{0}], NextBlock=[{1}]", offset, result); return result; }
/// <summary> /// 지정된 Offset만큼 기간이 이전 시간으로 이동한 TimeBlock을 반환한다. /// </summary> /// <param name="offset"></param> /// <returns></returns> public virtual ITimeBlock GetPreviousBlock(TimeSpan offset) { var endOff = (offset > TimeSpan.Zero) ? offset.Negate() : offset; var result = new TimeBlock(Duration, Start.Add(endOff), IsReadOnly); if(IsDebugEnabled) log.Debug("이전 Block을 구합니다. offset=[{0}], PreviousBlock=[{1}]", offset, result); return result; }
/// <summary> /// 두 기간의 합집합 기간을 반환한다. /// </summary> /// <param name="period"></param> /// <param name="target"></param> /// <returns></returns> public static TimeBlock GetUnionBlock(this ITimePeriod period, ITimePeriod target) { target.ShouldNotBeNull("target"); TimeBlock unionBlock = null; if(period.HasPeriod && target.HasPeriod) { unionBlock = new TimeBlock(period.StartAsNullable < target.StartAsNullable ? period.StartAsNullable : target.StartAsNullable, period.EndAsNullable > target.EndAsNullable ? period.EndAsNullable : target.EndAsNullable, period.IsReadOnly); } else { var start = (period.StartAsNullable.HasValue && target.StartAsNullable.HasValue) ? Min(period.Start, target.Start) : (period.StartAsNullable ?? target.StartAsNullable); var end = (period.EndAsNullable.HasValue && target.EndAsNullable.HasValue) ? Max(period.End, target.End) : (period.EndAsNullable ?? target.EndAsNullable); unionBlock = new TimeBlock(start, end, period.IsReadOnly); } if(IsDebugEnabled) log.Debug("period[{0}]와 target[{1}] 의 합집합 TimeBlock [{2}]을 구했습니다!!!", period.AsString(), target.AsString(), unionBlock.AsString()); return unionBlock; }
/// <summary> /// 두 기간의 공통되는 기간을 반환한다. (교집합) /// </summary> /// <param name="period"></param> /// <param name="target"></param> /// <returns></returns> public static TimeBlock GetIntersectionBlock(this ITimePeriod period, ITimePeriod target) { target.ShouldNotBeNull("target"); TimeBlock intersectionBlock = null; if(IntersectsWith(period, target)) { var start = Max(period.Start, target.Start); var end = Min(period.End, target.End); intersectionBlock = new TimeBlock(start, end, period.IsReadOnly); } if(IsDebugEnabled) log.Debug("period[{0}]와 target[{1}] 의 교집합 TimeBlock [{2}]을 구했습니다!!!", period.AsString(), target.AsString(), intersectionBlock.AsString()); return intersectionBlock; }