public static int CalcSeconds(string time) { int h, m, s; WeekTimePair.ParseTime(time, out h, out m, out s); return(h * 3600 + m * 60 + s); }
public static int CalcMinutes(string time) { int h, m, s; WeekTimePair.ParseTime(time, out h, out m, out s); return(h * 60 + m); }
/// <summary> /// Количество секунд с воскресения /// </summary> /// <param name="dayOfWeek">день недели</param> /// <param name="time">время</param> /// <returns>количество секунд с воскресенья. Sunday 00:00:00 = 0</returns> public static int DateTimeToInt(DayOfWeek dayOfWeek, string time) { int hour, min, sec; WeekTimePair.ParseTime(time, out hour, out min, out sec); return(((int)dayOfWeek) * SecondsInDay + hour * 3600 + min * 60 + sec); }
public static bool IsTimeStringValid(string time, bool hourCanBeMoreThan23 = false) { if (string.IsNullOrEmpty(time)) { return(false); } try { var strs = time.Split(':'); if (strs.Length == 0) { return(false); } if (strs.Length > 3) { return(false); } int h, m, s; WeekTimePair.ParseTime(time, out h, out m, out s); if (h < 0) { return(false); } if (!hourCanBeMoreThan23) { if (h > 23) { return(false); } } if (m < 0 || m > 59) { return(false); } if (s < 0 || s > 59) { return(false); } return(true); } catch (Exception) { return(false); } }
public static IEnumerable <WeekTimePair> GeneratePairs(DayOfWeek dayOfWeekFrom, string timeFrom, int minutesDelta, int count) { WeekTimePair weekTimePair = null; for (var i = 0; i < count; i++) { weekTimePair = weekTimePair == null ? new WeekTimePair(dayOfWeekFrom, timeFrom) : weekTimePair.AddMinutes(minutesDelta); yield return(weekTimePair); } }