private static bool DoesOverlapExistOnTimeRanges( TimeAndDow givenClashExceptionTimeAndDow, TimeAndDow existingClashExceptionTimeAndDow, int offsetHours) { if (!existingClashExceptionTimeAndDow.StartTime.HasValue && !existingClashExceptionTimeAndDow.EndTime.HasValue) { return(true); } if (!givenClashExceptionTimeAndDow.StartTime.HasValue && !givenClashExceptionTimeAndDow.EndTime.HasValue) { return(true); } var existingClashExceptionRange = new DateTimeRange( RevertOffsetAndConvertToDateTime(existingClashExceptionTimeAndDow.StartTime.Value, offsetHours), RevertOffsetAndConvertToDateTime(existingClashExceptionTimeAndDow.EndTime.Value, offsetHours) ); var givenClashExceptionRange = new DateTimeRange( RevertOffsetAndConvertToDateTime(givenClashExceptionTimeAndDow.StartTime.Value, offsetHours), RevertOffsetAndConvertToDateTime(givenClashExceptionTimeAndDow.EndTime.Value, offsetHours) ); return(existingClashExceptionRange.Overlays(givenClashExceptionRange, DateTimeRange.CompareStrategy.IgnoreEdges)); }
private static bool DoesOverlapExistOnDaysOfWeek( TimeAndDow givenDifferenceTimeAndDow, ClashDifference existingDifference) { const char one = '1'; bool areDowsIntersect; var daysOfWeekOfGivenClashException = givenDifferenceTimeAndDow.DaysOfWeek.ParseDayOfWeekDayCode(); var daysOfWeekOfExistingClashException = existingDifference.TimeAndDow.DaysOfWeekBinary.ParseDayOfWeekDayCode(); var intersection = daysOfWeekOfExistingClashException.Intersect(daysOfWeekOfGivenClashException); areDowsIntersect = intersection.Any(); return(areDowsIntersect && DoesOverlapExistOnTimeRanges(givenDifferenceTimeAndDow, existingDifference.TimeAndDow?.ConvertToTimeAndDow())); }
private static bool DoesOverlapExistOnDaysOfWeek( TimeAndDow givenClashExceptionTimeAndDow, ClashException existingClashException, int offsetHours) { var daysOfWeekOfGivenClashException = givenClashExceptionTimeAndDow.DaysOfWeek.ParseDayOfWeekDayCode(); return(existingClashException.TimeAndDows.Any(existingClashExceptionTimeAndDow => { var daysOfWeekOfExistingClashException = existingClashExceptionTimeAndDow.DaysOfWeek.ParseDayOfWeekDayCode(); var intersection = daysOfWeekOfExistingClashException.Intersect(daysOfWeekOfGivenClashException); if (intersection.Any()) { return DoesOverlapExistOnTimeRanges(givenClashExceptionTimeAndDow, existingClashExceptionTimeAndDow, offsetHours); } return false; })); }
private static bool DoesOverlapExistOnTimeRanges( TimeAndDow givenDifferenceTimeAndDow, TimeAndDow existingDifferenceTimeAndDow) { const int offsetHours = 6; var startTime = new TimeSpan(6, 0, 0); var endTime = new TimeSpan(5, 59, 59); if (!existingDifferenceTimeAndDow.StartTime.HasValue && !existingDifferenceTimeAndDow.EndTime.HasValue) { return(true); } if (!givenDifferenceTimeAndDow.StartTime.HasValue && !givenDifferenceTimeAndDow.EndTime.HasValue) { return(true); } var existingDifferenceTimeAndDowStartTime = existingDifferenceTimeAndDow.StartTime ?? startTime; var existingDifferenceTimeAndDowEndTime = existingDifferenceTimeAndDow.EndTime ?? endTime; var existingClashRange = new DateTimeRange( RevertOffsetAndConvertToDateTime(existingDifferenceTimeAndDowStartTime, offsetHours), RevertOffsetAndConvertToDateTime(existingDifferenceTimeAndDowEndTime, offsetHours) ); var givenDifferenceTimeAndDowStartTime = givenDifferenceTimeAndDow.StartTime ?? startTime; var givenDifferenceTimeAndDowEndTime = givenDifferenceTimeAndDow.EndTime ?? endTime; var givenClashRange = new DateTimeRange( RevertOffsetAndConvertToDateTime(givenDifferenceTimeAndDowStartTime, offsetHours), RevertOffsetAndConvertToDateTime(givenDifferenceTimeAndDowEndTime, offsetHours) ); return(existingClashRange.Overlays(givenClashRange, DateTimeRange.CompareStrategy.IgnoreEdges)); }
public object Retrieve( KeyValuePair <string, string> keyValuePair, Type targetType, Type propertyType ) { string value = keyValuePair.Value; if (string.IsNullOrWhiteSpace(value)) { return(null); } var result = new TimeAndDow(); /* * The table column for a TimeAndDow field should contain either nothing or these * optional comma separated fields. Only one of each field will be considered. * * startTime=HH:MM:SS * endTime=HH:MM:SS * daysOfWeek=XXXXXXX * * For example, * startTime=HH:MM:SS * startTime=HH:MM:SS, endTime=HH:MM:SS * startTime=HH:MM:SS, endTime=HH:MM:SS, daysOfWeek=XXXXXXX * daysOfWeek=XXXXXXX * */ var timeAndDowPartSeparator = new[] { "," }; var fieldSeparator = new[] { '=' }; var timeAndDowParts = value.Split(timeAndDowPartSeparator, StringSplitOptions.RemoveEmptyEntries); foreach (string part in timeAndDowParts) { var cleanPart = part.Trim().ToUpperInvariant(); var field = cleanPart.Split(fieldSeparator, StringSplitOptions.RemoveEmptyEntries); if (field.Length != 2) { continue; } switch (field[0].Trim()) { case "STARTTIME": { string timeValue = field[1]?.Trim() ?? string.Empty; result.StartTime = TimeSpan.TryParse(timeValue, out TimeSpan time) ? time : (TimeSpan?)null; break; } case "ENDTIME": { string timeValue = field[1]?.Trim() ?? string.Empty; result.EndTime = TimeSpan.TryParse(timeValue, out TimeSpan time) ? time : (TimeSpan?)null; break; } case "DAYSOFWEEK": result.DaysOfWeek = field[1]?.Trim(); break; default: continue; } } return(result); }