public static double TimeOfDayToHours(object value) { if (value is System.TimeSpan) { return(((System.TimeSpan)value).TotalHours); } else if (value is System.DateTime) { return(((System.DateTime)value).TimeOfDay.TotalHours); } else { try { return(System.DateTime.Parse(ConvertUtil.ToString(value)).TimeOfDay.TotalHours); } catch { return(0); } } }
/// <summary> /// Returns number of seconds into the day a timeofday is. Acts similar to 'TimeToJulian' from old Dockmaster. /// </summary> /// <param name="value"></param> /// <returns></returns> /// <remarks></remarks> public static int TimeOfDayToSeconds(object value) { if (value is System.TimeSpan) { return((int)((System.TimeSpan)value).TotalSeconds); } else if (value is System.DateTime) { return((int)((System.DateTime)value).TimeOfDay.TotalSeconds); } else { try { return((int)System.DateTime.Parse(ConvertUtil.ToString(value)).TimeOfDay.TotalSeconds); } catch { return(0); } } }