1. Determine if the two starting and ending times intersect:
public static bool Istimebetween (TimeSpan input, TimeSpan start, TimeSpan end, BOOL Frominclusice, bool toinclusive) { //http://www.php.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. The expression of incoming start and end time, and the intersection of the known time period, to generate MONGO query:
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; }
Where from and to are two time attributes
The above is the C # to determine whether the time period intersects the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!