private static bool AreDOWsNeighboring(string dow0, string dow1) { int convered = BinaryGenerator.getDayOfWeekPos(dow0.Trim()) - BinaryGenerator.getDayOfWeekPos(dow1.Trim()); if (convered == 1 || convered == -1) { return(true); } else { return(false); } }
public static byte ConvertDaysString(string entry_days) { entry_days = entry_days.Trim(); byte converted_entry_days = 0; while (true) { if (entry_days.IndexOf('-') == -1 && entry_days.IndexOf(':') == -1) { converted_entry_days |= BinaryGenerator.dayOfWeekToBytePos(entry_days.Trim()); break; //done :) } else { if (entry_days.IndexOf('-') > -1 && entry_days.IndexOf(':') > -1) { if (entry_days.IndexOf('-') > entry_days.IndexOf(':')) { //so... looks like the colon is closer converted_entry_days |= BinaryGenerator.dayOfWeekToBytePos(entry_days.Substring(0, entry_days.IndexOf(':')).Trim()); entry_days = entry_days.Substring(entry_days.IndexOf(':') + 1).Trim(); } else { //it seems like the dash is closer int first_day, second_day; first_day = BinaryGenerator.getDayOfWeekPos(entry_days.Substring(0, entry_days.IndexOf('-')).Trim()); entry_days = entry_days.Substring(entry_days.IndexOf('-') + 1).Trim(); //there must be a colon coming up so we can use that second_day = BinaryGenerator.getDayOfWeekPos(entry_days.Substring(0, entry_days.IndexOf(':')).Trim()); entry_days = entry_days.Substring(entry_days.IndexOf(':') + 1).Trim(); for (; first_day <= second_day; first_day++) { converted_entry_days |= BinaryGenerator.dayOfWeekToBytePos(days_of_the_week[first_day]); } } } else if (entry_days.IndexOf('-') > -1) { //there's a dash but no colon int first_day, second_day; first_day = BinaryGenerator.getDayOfWeekPos(entry_days.Substring(0, entry_days.IndexOf('-')).Trim()); entry_days = entry_days.Substring(entry_days.IndexOf('-') + 1).Trim(); //you shouldn't have another dash after this one and there is no colon second_day = BinaryGenerator.getDayOfWeekPos(entry_days.Trim()); for (; first_day <= second_day; first_day++) { converted_entry_days |= BinaryGenerator.dayOfWeekToBytePos(days_of_the_week[first_day]); } } else { //so if we're here there's a colon but no dash while (entry_days.IndexOf(':') > -1) { converted_entry_days |= BinaryGenerator.dayOfWeekToBytePos(entry_days.Substring(0, entry_days.IndexOf(':')).Trim()); entry_days = entry_days.Substring(entry_days.IndexOf(':') + 1).Trim(); } } } } return(converted_entry_days); }