SIPSorcery.SimpleWizardInRuleControl.GetTimePattern C# (CSharp) Method

GetTimePattern() private method

Extracts the time pattern from the UI controls that represent a rule that's being applied for a specific time.
private GetTimePattern ( SimpleWizardRule rule ) : string
rule SIPSorcery.Entities.SimpleWizardRule
return string
        private string GetTimePattern(SimpleWizardRule rule)
        {
            if (!m_ruleWhenSpecificTimes.IsChecked.GetValueOrDefault())
            {
                rule.TimePattern = null;
                return null;
            }
            else
            {
                string timePattern = null;
                timePattern += (m_monCheckbox.IsChecked.GetValueOrDefault()) ? "M" : null;
                timePattern += (m_tueCheckbox.IsChecked.GetValueOrDefault()) ? "Tu" : null;
                timePattern += (m_wedCheckbox.IsChecked.GetValueOrDefault()) ? "W" : null;
                timePattern += (m_thuCheckbox.IsChecked.GetValueOrDefault()) ? "Th" : null;
                timePattern += (m_friCheckbox.IsChecked.GetValueOrDefault()) ? "F" : null;
                timePattern += (m_satCheckbox.IsChecked.GetValueOrDefault()) ? "Sa" : null;
                timePattern += (m_sunCheckbox.IsChecked.GetValueOrDefault()) ? "Su" : null;

                if (timePattern == null)
                {
                    return "At least one day must be checked for a rule using a specific time.";
                }
                else
                {
                    int startTimeHour = 0;
                    int startTimeMin = 0;
                    int endTimeHour = 0;
                    int endTimeMin = 0;

                    if (!Int32.TryParse(m_startTimeHour.Text, out startTimeHour))
                    {
                        return "The start time hour was invalid. Please make sure it contains only numbers.";
                    }
                    if (!Int32.TryParse(m_startTimeMin.Text, out startTimeMin))
                    {
                        return "The start time minute was invalid. Please make sure it contains only numbers.";
                    }
                    if (!Int32.TryParse(m_endTimeHour.Text, out endTimeHour))
                    {
                        return "The end time hour was invalid. Please make sure it contains only numbers.";
                    }
                    if (!Int32.TryParse(m_endTimeMin.Text, out endTimeMin))
                    {
                        return "The end time minute was invalid. Please make sure it contains only numbers.";
                    }

                    if (startTimeHour < 0 || startTimeHour > 23)
                    {
                        return "The start time hour was invalid. Please make sure it is between 0 and 23.";
                    }
                    else if (startTimeMin < 0 || startTimeMin > 59)
                    {
                        return "The start time minute was invalid. Please make sure it is between 0 and 59.";
                    }
                    if (endTimeHour < 0 || endTimeHour > 23)
                    {
                        return "The end time hour was invalid. Please make sure it is between 0 and 23.";
                    }
                    else if (endTimeMin < 0 || endTimeMin > 59)
                    {
                        return "The end time minute was invalid. Please make sure it is between 0 and 59.";
                    }
                    else if ((startTimeHour * 60 + startTimeMin) >= (endTimeHour * 60 + endTimeMin))
                    {
                        return "The start time must be less than the end time.";
                    }

                    rule.TimePattern = timePattern + ";" + startTimeHour.ToString("D2") + ":" + startTimeMin.ToString("D2") + "-" + endTimeHour.ToString("D2") + ":" + endTimeMin.ToString("D2");

                    return null;
                }
            }
        }