Esempio n. 1
0
 /// <summary>
 /// Convert a TimeSpace to a fractional hours value.
 /// </summary>
 /// <param name="timeSpan">The TimeSpan to convert</param>
 /// <param name="roundTo">The increment to round the fraction to.</param>
 /// <returns>The original TimeSpace value as a fractional hours value, but rounded to the specified increment.</returns>
 public static decimal?ToDecimalHours(this TimeSpan?timeSpan, RoundingIncrements roundTo = RoundingIncrements.Tenth)
 {
     if (!timeSpan.HasValue)
     {
         return(null);
     }
     return(timeSpan.Value.ToDecimalHours(roundTo));
 }
Esempio n. 2
0
 /// <summary>
 /// Round a decimal hours value to the specified increment.
 /// </summary>
 /// <param name="hours">The fractional hours value to round.</param>
 /// <param name="roundTo">The increment to round the fraction to.</param>
 /// <returns>The original fractional hours value, but rounded to the specified increment.</returns>
 public static decimal?RoundFractionalHour(this decimal?hours, RoundingIncrements roundTo = RoundingIncrements.Tenth)
 {
     if (!hours.HasValue)
     {
         return(null);
     }
     return(hours.Value.RoundFractionalHour(roundTo));
 }
Esempio n. 3
0
        /// <summary>
        /// Convert a TimeSpace to a fractional hours value.
        /// </summary>
        /// <param name="timeSpan">The TimeSpan to convert</param>
        /// <param name="roundTo">The increment to round the fraction to.</param>
        /// <returns>The original TimeSpace value as a fractional hours value, but rounded to the specified increment.</returns>
        public static decimal ToDecimalHours(this TimeSpan timeSpan, RoundingIncrements roundTo = RoundingIncrements.Tenth)
        {
            TimeSpan temp = timeSpan.RoundMinutes(roundTo);

            return(temp.Days * 24 +
                   temp.Hours +
                   (decimal)temp.Minutes / 60);
        }
Esempio n. 4
0
 /// <summary>
 /// Round a TimeSpan to the specified increment.
 /// </summary>
 /// <param name="timeSpan">The TimeSpan value to round.</param>
 /// <param name="roundTo">The increment to round the minutes to.</param>
 /// <returns>The original TimeSpan value, but rounded to the specified increment.</returns>
 public static TimeSpan?RoundMinutes(this TimeSpan?timeSpan, RoundingIncrements roundTo = RoundingIncrements.Tenth)
 {
     if (!timeSpan.HasValue)
     {
         return(null);
     }
     return(timeSpan.Value.RoundMinutes(roundTo));
 }
Esempio n. 5
0
 /// <summary>
 /// Round a DateTime value to the specified increment.
 /// </summary>
 /// <param name="dateTime">The DateTime value to round.</param>
 /// <param name="roundTo">The increment to round the minutes to.</param>
 /// <returns>The original DateTime value, but rounded to the specified increment.</returns>
 public static DateTime?RoundMinutes(this DateTime?dateTime, RoundingIncrements roundTo = RoundingIncrements.Tenth)
 {
     if (!dateTime.HasValue)
     {
         return(null);
     }
     return(dateTime.Value.RoundMinutes(roundTo));
 }
Esempio n. 6
0
        /// <summary>
        /// Round a TimeSpan to the specified increment.
        /// </summary>
        /// <param name="timeSpan">The TimeSpan value to round.</param>
        /// <param name="roundTo">The increment to round the minutes to.</param>
        /// <returns>The original TimeSpan value, but rounded to the specified increment.</returns>
        public static TimeSpan RoundMinutes(this TimeSpan timeSpan, RoundingIncrements roundTo = RoundingIncrements.Tenth)
        {
            byte minutes = (byte)timeSpan.Minutes;

            switch (roundTo)
            {
            case RoundingIncrements.Quarter:
                minutes = minutes.roundTo15Minutes();
                break;

            case RoundingIncrements.Tenth:
                minutes = minutes.roundTo6Minutes();
                break;

            default:
                break;
            }
            return(new TimeSpan(timeSpan.Days, timeSpan.Hours, minutes, 0));
        }
Esempio n. 7
0
        /// <summary>
        /// Round a DateTime value to the specified increment.
        /// </summary>
        /// <param name="dateTime">The DateTime value to round.</param>
        /// <param name="roundTo">The increment to round the minutes to.</param>
        /// <returns>The original DateTime value, but rounded to the specified increment.</returns>
        public static DateTime RoundMinutes(this DateTime dateTime, RoundingIncrements roundTo = RoundingIncrements.Tenth)
        {
            byte minutes = (byte)dateTime.Minute;

            switch (roundTo)
            {
            case RoundingIncrements.Quarter:
                minutes = minutes.roundTo15Minutes();
                break;

            case RoundingIncrements.Tenth:
                minutes = minutes.roundTo6Minutes();
                break;

            default:
                break;
            }
            return(new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, minutes, 0, dateTime.Kind));
        }
Esempio n. 8
0
        /// <summary>
        /// Round a decimal hours value to the specified increment.
        /// </summary>
        /// <param name="hours">The fractional hours value to round.</param>
        /// <param name="roundTo">The increment to round the fraction to.</param>
        /// <returns>The original fractional hours value, but rounded to the specified increment.</returns>
        public static decimal RoundFractionalHour(this decimal hours, RoundingIncrements roundTo = RoundingIncrements.Tenth)
        {
            int  hr      = (int)hours;
            byte minutes = hours.validMinutes();

            switch (roundTo)
            {
            case RoundingIncrements.Quarter:
                minutes = minutes.roundTo15Minutes();
                break;

            case RoundingIncrements.Tenth:
                minutes = minutes.roundTo6Minutes();
                break;

            default:
                break;
            }
            return(hr + ((decimal)minutes / 60));
        }