旗下导航:搜·么
当前位置:网站首页 > .Net教程 > 正文

C# 推断时间段是不是订交【C#.Net教程】,C#,时间段,相交

作者:搜教程发布时间:2019-11-27分类:.Net教程浏览:76评论:0


导读:1.推断两个起止时候是不是订交:publicstaticboolIsTimeBetween(TimeSpaninput,TimeSpanstart,Time...
1. 推断两个起止时候是不是订交:

public static bool IsTimeBetween(TimeSpan input, TimeSpan start, TimeSpan end, bool fromInclusice, bool toInclusive)
        {
            //http://www.ki4.cn/
            // see if start comes before end
            if (end < start)
            {
                return
                    ((toInclusive && (input <= end)) || (!toInclusive && (input < end)))
                    ||
                    ((fromInclusice && (input >= start)) || (!fromInclusice && (input > start)));
            }
            else
            {
                return
                    ((fromInclusice && (input >= start)) || (!fromInclusice && (input > start)))
                    &&
                    ((toInclusive && (input <= end)) || (!toInclusive && (input < end)));
            }


        }

2. 传入起止时候的表达式,推断与已知时候段的交集,生成Mongo查询:

public IMongoQuery GetMongoQueryIntersectWith<TCollection>(
            Expression<Func<TCollection, DateTime>> fromExp, 
            Expression<Func<TCollection, DateTime>> toExp)
        {
            var rangeTo = Query.And(Query<TCollection>.GTE(toExp, To), Query<TCollection>.LTE(fromExp, To));
            var rangeFrom = Query.And(Query<TCollection>.GTE(toExp, From), Query<TCollection>.LTE(fromExp, From));

            var rangeQuery = Query.Or(rangeTo, rangeFrom, 
                Query.And(Query<TCollection>.GTE(fromExp, From),Query<TCollection>.LTE(toExp, To)));
            return rangeQuery;
        }


个中From和To为两个时候属性

以上就是C# 推断时候段是不是订交的内容,更多相关内容请关注ki4网(www.ki4.cn)!

标签:C#时间段相交


欢迎 发表评论: