Exemplo n.º 1
0
        /// <summary>
        /// Calcs the work at time.
        /// </summary>
        /// <param name="time">The time.</param>
        /// <returns></returns>
        public long CalcWorkAtTime(long time)
        {
            long retVal = 0;

            //Before
            if (time < 0)
            {
                return(GetDuration() - CalcWorkAtTime(time * -1));
            }
            if (time > 0)
            {
                //After
                for (int i = 0; i < WorkRanges.Length; i++)
                {
                    WorkRange range = WorkRanges[i];
                    if (range != null)
                    {
                        if (range.End > time)
                        {
                            retVal += (range.End - Math.Max(time, range.Start));
                        }
                    }
                }
            }

            return(retVal);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calcs the time remaining work.
        /// </summary>
        /// <param name="duration">The duration.</param>
        /// <returns></returns>
        public long CalcTimeRemainingWork(long duration)
        {
            long retVal = 0;
            long work   = 0;

            duration = duration < 0 ? duration * -1 : duration;

            for (int i = WorkRanges.Length - 1; i >= 0; i--)
            {
                WorkRange range = WorkRanges[i];
                if (range != null)
                {
                    work += range.GetDuration();
                    if (work > duration)
                    {
                        retVal = range.Start + (work - duration);
                        //if (retVal == range.Start && i != 0 && WorkRanges[i - 1] != null)
                        //{

                        // //   retVal = CalcTimeAtWork(duration);
                        //}
                        break;
                    }
                    else if (work == duration)
                    {
                        //retVal = CalcTimeAtWork(range.Start + (work - duration));
                        retVal = range.Start;
                        break;
                    }
                }
            }

            return(retVal);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calcs the time at work.
        /// </summary>
        /// <param name="duration">The duration.</param>
        /// <returns></returns>
        public long CalcTimeAtWork(long duration)
        {
            long retVal = 0;
            long work   = 0;

            duration = duration < 0 ? duration * -1 : duration;

            for (int i = 0; i < WorkRanges.Length; i++)
            {
                WorkRange range = WorkRanges[i];
                if (range != null)
                {
                    work += range.GetDuration();
                    if (work > duration)
                    {
                        retVal = range.End - (work - duration);
                        break;
                    }
                    else if (work == duration)
                    {
                        retVal = range.End;
                        break;
                    }
                }
            }

            return(retVal);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Overlapses the specified other.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns></returns>
        bool Overlaps(WorkRange other)
        {
            if (other == null)
                return false;

            return ((this.Start > other.Start && this.End > other.End)
                    || (other.Start > this.Start && other.End > this.End)) == false;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets the interval.
        /// </summary>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        public void AddInterval(int number, long start, long end)
        {
            //If end time is 0, it is treated as midnight the next day
            if (CalendarHelper.HourFromMilis(end) == 0 && CalendarHelper.MinuteFromMilis(end) == 0)
            {
                end = CalendarHelper.MilisPerHour() * 24 + end;
            }

            WorkRanges[number] = new WorkRange(start, end, false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Overlapses the specified other.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns></returns>
        bool Overlaps(WorkRange other)
        {
            if (other == null)
            {
                return(false);
            }

            return(((this.Start > other.Start && this.End > other.End) ||
                    (other.Start > this.Start && other.End > this.End)) == false);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Sets the interval.
        /// </summary>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        public void AddInterval(int number, long start, long end)
        {
            //If end time is 0, it is treated as midnight the next day
               if(CalendarHelper.HourFromMilis(end) == 0 && CalendarHelper.MinuteFromMilis(end) == 0)
               {
               end = CalendarHelper.MilisPerHour() * 24 + end;
               }

               WorkRanges[number] = new WorkRange(start, end, false);
        }
Exemplo n.º 8
0
        public object Clone()
        {
            WorkHours retVal = new WorkHours();

            for (int i = 0; i < WorkRanges.Length; i++)
            {
                if (WorkRanges[i] != null)
                {
                    WorkRange range = new WorkRange(WorkRanges[i].Start, WorkRanges[i].End, WorkRanges[i].OverTime);

                    retVal.WorkRanges[i] = range;
                }
            }

            return(retVal);
        }
Exemplo n.º 9
0
        public object Clone()
        {
            WorkHours retVal = new WorkHours();
            for(int i = 0; i < WorkRanges.Length; i++)
            {
                if(WorkRanges[i] != null)
                {
                    WorkRange range = new WorkRange(WorkRanges[i].Start, WorkRanges[i].End, WorkRanges[i].OverTime);

                    retVal.WorkRanges[i] = range;
                }
            }

            return retVal;
        }