Ejemplo n.º 1
0
 /// <summary>
 /// 添加工作单元
 /// </summary>
 /// <param name="businessDay"></param>
 public void AddBusinessDay(BusinessDay businessDay)
 {
     if (InstanceName == nameof(Default))
     {
         throw new InvalidOperationException($"Operation is forbidden as the default instance.");
     }
     if (businessDay != null)
     {
         BusinessDays.Add(businessDay);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 判断指定时刻开始是否存在下一个工作区间,并通过out返回开始时刻和所在的单个工作单元
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="nextDate"></param>
        /// <param name="businessDay"></param>
        /// <returns></returns>
        internal bool NextBusinessDay(DateTime startDate, out DateTime nextDate, out BusinessDay businessDay)
        {
            nextDate    = startDate;
            businessDay = null;
            var tree = GetDayTree();

            for (int i = 0; i < 7; i++)
            {
                var dayOfWeek = nextDate.DayOfWeek;
                if (!tree.ContainsKey(dayOfWeek))
                {
                    nextDate = nextDate.AddDays(1).Date;
                    continue;
                }
                var businessDays = tree[dayOfWeek];
                if (businessDays == null)
                {
                    continue;
                }
                foreach (var day in businessDays)
                {
                    if (day == null)
                    {
                        continue;
                    }
                    var timeOfDay = nextDate.TimeOfDay;

                    if (timeOfDay >= day.StartTime && timeOfDay < day.EndTime)
                    {
                        businessDay = day;
                        return(true);
                    }
                    if (timeOfDay >= day.StartTime)
                    {
                        continue;
                    }
                    businessDay = day;
                    nextDate    = nextDate.Date.SafeAdd(day.StartTime);
                    return(true);
                }
                nextDate = nextDate.AddDays(1).Date;
            }
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 判断指定时刻开始是否存在下一个工作单元,并通过out返回开始时刻和所在的单个工作单元
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="nextDate"></param>
        /// <param name="businessDay"></param>
        /// <returns></returns>
        internal bool NextBusinessDay(DateTimeOffset startDate, out DateTimeOffset nextDate, out BusinessDay businessDay)
        {
            var result = NextBusinessDay(startDate.DateTime, out DateTime nDate, out businessDay);

            nextDate = new DateTimeOffset(nDate);
            return(result);
        }