public void checkIfTimeFormat(string s) { int indexOfAM = s.IndexOf("am"); int indexOfam = s.IndexOf("AM"); int indexOfPM = s.IndexOf("pm"); int indexOfpm = s.IndexOf("PM"); Conversions objectConversions = new Conversions(); if (indexOfam != -1 || indexOfAM != -1 || indexOfpm != -1 || indexOfPM != -1) { TimeSpan startimeProperFormat = objectConversions.Convert12HourFormatTo24HourFormat(s); errorMessage = STARTTIME; } }
public void setStartTime(string s) { try { if (s.CompareTo("null") == 0) { startime = s; return; } //if (!(s.ElementAt(2) == ':' && s.ElementAt(5) == ':')) ErrorHandling objectErrorHandling = new ErrorHandling(); string MessageOrDate = objectErrorHandling.checkTime(s); if (MessageOrDate.CompareTo("date value has been entered") == 0) { setStartDate(s); startime = "null"; return; } else if (MessageOrDate.CompareTo("invalid time value") == 0 || MessageOrDate.CompareTo("") == 0) { startime = MessageOrDate; return; } else { s = MessageOrDate; } Conversions objectConversions = new Conversions(); TimeSpan startimeProperFormat = objectConversions.Convert12HourFormatTo24HourFormat(s); startime = startimeProperFormat.ToString(); } catch (Exception e) { StreamWriter loggingWriter = new StreamWriter("Logging.txt"); loggingWriter.WriteLine(System.DateTime.Now + e.Message + "\n"); loggingWriter.Close(); } }
public void checkIfTimeFormat(string s) { try { int indexOfAM = s.IndexOf("am"); int indexOfam = s.IndexOf("AM"); int indexOfPM = s.IndexOf("pm"); int indexOfpm = s.IndexOf("PM"); Conversions objectConversions = new Conversions(); if (indexOfam != -1 || indexOfAM != -1 || indexOfpm != -1 || indexOfPM != -1) { TimeSpan startimeProperFormat = objectConversions.Convert12HourFormatTo24HourFormat(s); errorMessage = STARTTIME; } } catch (Exception e) { StreamWriter loggingWriter = new StreamWriter("Logging.txt"); loggingWriter.WriteLine(System.DateTime.Now + e.Message + "\n"); loggingWriter.Close(); } }
public void setEndTime(string s) { try { Conversions objectConversions = new Conversions(); if (s.CompareTo("null") == 0) { endtime = s; return; } { ErrorHandling objectErrorHandling = new ErrorHandling(); string MessageOrDate = objectErrorHandling.checkTime(s); if (MessageOrDate.CompareTo("date value has been entered") == 0) { setEndDate(s); endtime = "null"; return; } else if (MessageOrDate.CompareTo("invalid time value") == 0 || MessageOrDate.CompareTo("") == 0) { endtime = "invalid time value"; return; } else { s = MessageOrDate; } TimeSpan endtimeProperFormat = objectConversions.Convert12HourFormatTo24HourFormat(s); if (getStartTime() != "null") { DateTime d1; DateTime d2; try { bool startDateCheck = DateTime.TryParse(startDate, out d1); bool endDateCheck = DateTime.TryParse(endDate, out d2); if (startDateCheck && endDateCheck) { if ((objectConversions.ConvertStringToDate(startDate)).CompareTo(objectConversions.ConvertStringToDate(endDate)) == 0) { if (TimeSpan.Parse(startime).CompareTo(endtimeProperFormat) < 0) { endtime = endtimeProperFormat.ToString(); } } } } catch (FormatException f) { StreamWriter loggingWriter = new StreamWriter("Logging.txt"); loggingWriter.WriteLine(System.DateTime.Now + f.Message + "\n"); loggingWriter.Close(); } } endtimeProperFormat = objectConversions.Convert12HourFormatTo24HourFormat(s); endtime = endtimeProperFormat.ToString(); } } catch (System.Exception e) { StreamWriter loggingWriter = new StreamWriter("Logging.txt"); loggingWriter.WriteLine(System.DateTime.Now + e.Message + "\n"); loggingWriter.Close(); } }