Esempio n. 1
0
        /// <summary>
        ///		Converts the value from one precision to another
        /// </summary>
        public static double ConvertValue(double value,
                                          WorktimePrecision fromPrecision,
                                          WorktimePrecision toPrecision)
        {
            var secounds = GetTimeInSeconds(value, fromPrecision);

            switch (toPrecision)
            {
            case WorktimePrecision.Seconds:
                return(secounds);

            case WorktimePrecision.Minutes:
                return(secounds / 60);

            case WorktimePrecision.Hours:
                return(secounds / 60 / 60);

            case WorktimePrecision.Days:
                return(secounds / 60 / 60 / 24);

            case WorktimePrecision.Weeks:
                return(secounds / 60 / 60 / 24 / 7);

            default:
                throw new ArgumentOutOfRangeException(nameof(toPrecision), toPrecision, null);
            }
        }
Esempio n. 2
0
        public void TestWorktimeCanAddAndFormatAsTime(double value, double toAdd, WorktimePrecision withPrecision, string expectedTime, string expectedDecimal)
        {
            var wt = new Worktime(value, WorktimePrecision.Minutes);

            wt = wt.Add(toAdd, withPrecision);
            Assert.That(wt.ToString(null, CultureInfo.InvariantCulture), Is.EqualTo(expectedTime));
            Assert.That(wt.ToString("d", CultureInfo.InvariantCulture), Is.EqualTo(expectedDecimal));
        }
Esempio n. 3
0
        private static double GetTimeInSeconds(double value, WorktimePrecision precision)
        {
            switch (precision)
            {
            case WorktimePrecision.Seconds:
                return(value);

            case WorktimePrecision.Minutes:
                return(value * 60);

            case WorktimePrecision.Hours:
                return(value * 60 * 60);

            case WorktimePrecision.Days:
                return(value * 60 * 60 * 24);

            case WorktimePrecision.Weeks:
                return(value * 60 * 60 * 24 * 7);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 4
0
        /// <summary>
        ///		Adds the value of time with the precision to a new Worktime
        /// </summary>
        /// <param name="time"></param>
        /// <param name="precision"></param>
        /// <returns></returns>
        public Worktime Add(double time, WorktimePrecision precision)
        {
            var newValueInSeconds = GetTimeInSeconds(TimeWorked, Precision) + GetTimeInSeconds(time, precision);

            return(new Worktime(ConvertValue(newValueInSeconds, WorktimePrecision.Seconds, Precision), Precision));
        }
Esempio n. 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="timeWorked"></param>
 /// <param name="precision"></param>
 public Worktime(double timeWorked, WorktimePrecision precision)
 {
     TimeWorked = timeWorked;
     Precision  = precision;
 }