Пример #1
0
        /// <summary>
        /// 获取当天打卡区间最早与最晚时间
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static bool GetTargetDateClockRangesBorder(this PinhuaContext context, DateTime target, out DateTime earliest, out DateTime latest)
        {
            var now = DateTime.Now;

            earliest = DateTime.MaxValue;
            latest   = DateTime.MinValue;

            var ranges = context.GetCurrentClockRanges();

            if (ranges == null)
            {
                return(false);
            }

            foreach (var range in ranges)
            {
                var t1 = range.Beginning.Value.ConvertToTargetDate(target).AddMinutes(-range.MoveUp.Value);
                if (t1 < earliest)
                {
                    earliest = t1;
                }
                var t2 = range.Ending.Value.ConvertToTargetDate(target).AddMinutes(range.PutOff.Value);
                if (t2 > latest)
                {
                    latest = t2;
                }
            }

            return(true);
        }
Пример #2
0
        public static bool GetTargetMonthClockRangesBorder(this PinhuaContext context, int year, int month, out DateTime earliest, out DateTime latest)
        {
            var first = new DateTime(year, month, 1);
            var last  = first.AddMonths(1).AddDays(-1);

            earliest = DateTime.MaxValue;
            latest   = DateTime.MinValue;

            var ranges = context.GetCurrentClockRanges();

            if (ranges == null)
            {
                return(false);
            }

            foreach (var range in ranges)
            {
                var t1 = range.Beginning.Value.ConvertToTargetDate(first).AddMinutes(-range.MoveUp.Value);
                if (t1 < earliest)
                {
                    earliest = t1;
                }
                var t2 = range.Ending.Value.ConvertToTargetDate(last).AddMinutes(range.PutOff.Value);
                if (t2 > latest)
                {
                    latest = t2;
                }
            }

            return(true);
        }
Пример #3
0
        /// <summary>
        /// 获取当天打卡区间最早与最晚时间
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static bool GetCurrentClockRangesBorder(this PinhuaContext context, out DateTime earliest, out DateTime latest)
        {
            var now = DateTime.Now;

            earliest = DateTime.MaxValue;
            latest   = DateTime.MinValue;

            var ranges = context.GetCurrentClockRanges();

            if (ranges == null)
            {
                return(false);
            }

            foreach (var range in ranges)
            {
                var t1 = range.Beginning.Value.ConvertDateToToday().AddMinutes(-range.MoveUp.Value);
                if (t1 < earliest)
                {
                    earliest = t1;
                }
                var t2 = range.Ending.Value.ConvertDateToToday().AddMinutes(range.PutOff.Value);
                if (t2 > latest)
                {
                    latest = t2;
                }
            }
            if (now <= earliest)   // 比最早时间早,说明在第二天,那就要返回前一天的区间
            {
                earliest = earliest.AddDays(-1);
                latest   = latest.AddDays(-1);
            }

            return(true);
        }
Пример #4
0
        /// <summary>
        /// 获取当前班段信息
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static WeixinWorkPlanDetail GetCurrentClockRange(this PinhuaContext context)
        {
            var ranges = context.GetCurrentClockRanges();

            foreach (var p in ranges)
            {
                p.今天的打卡开始到结束区间(out var left, out var right);

                if (DateTime.Now.IsBetween(left, right))
                {
                    return(p);
                }
            }
            return(null);
        }