/// <summary> /// Initializes a new instance of the <see cref="TimeSpan"/> structure to a specified number of /// days, hours, minutes, seconds, and milliseconds. /// </summary> /// <param name="days">Number of days.</param> /// <param name="hours">Number of hours.</param> /// <param name="minutes">Number of minutes.</param> /// <param name="seconds">Number of seconds.</param> /// <param name="milliseconds">Number of milliseconds.</param> /// <param name="microseconds">Number of microseconds.</param> /// <remarks> /// The specified <paramref name="days"/>, <paramref name="hours"/>, <paramref name="minutes"/>, <paramref name="seconds"/> /// <paramref name="milliseconds"/> and <paramref name="microseconds"/> are converted to ticks, and that value initializes this instance. /// </remarks> /// <exception cref="ArgumentOutOfRangeException"> /// The parameters specify a <see cref="TimeSpan"/> value less than <see cref="MinValue"/> or greater than <see cref="MaxValue"/> /// </exception> public TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds, int microseconds) { long totalMicroseconds = (((long)days * 3600 * 24 + (long)hours * 3600 + (long)minutes * 60 + seconds) * 1000 + milliseconds) * 1000 + microseconds; if (totalMicroseconds > MaxMicroSeconds || totalMicroseconds < MinMicroSeconds) { ThrowHelper.ThrowArgumentOutOfRange_TimeSpanTooLong(); } _ticks = totalMicroseconds * TicksPerMicrosecond; }
internal static long TimeToTicks(int hour, int minute, int second) { // totalSeconds is bounded by 2^31 * 2^12 + 2^31 * 2^8 + 2^31, // which is less than 2^44, meaning we won't overflow totalSeconds. long totalSeconds = (long)hour * 3600 + (long)minute * 60 + (long)second; if (totalSeconds > MaxSeconds || totalSeconds < MinSeconds) { ThrowHelper.ThrowArgumentOutOfRange_TimeSpanTooLong(); } return(totalSeconds * TicksPerSecond); }