c# - Define a Custom Weekend Starting and Ending Day & Time and finding its occurrences over date range -


i having tough time in calculating number of custom defined weekends , later finding them on specified date range, have apply different rates based on days (weekends, season days & normal days).

for example, trip starting @ 16/08/2017 09:00:00 , ending @ 29/08/2017 09:00:00 weekend start @ fri 15:00:00 till mon 09:00:00 every week. need calculate how many weekends occur in given trip start , end time , how many regular days, both charged @ different rates. appreciated.

please note date , times dynamic , can changed, looking generic solution

if range small enough can try:

public class datetimerange {     private datetime start { get; set; }     private datetime end { get; set; }      public datetimerange(datetime start, datetime end)     {         start = start;         end = end;     }      public int dayoffscount()     {         var current = start;         var dayoffscount = 0;         while (current < end)         {             if (isdayoff(current))             {                 dayoffscount++;             }             current = current.adddays(1);         }         return dayoffscount;     }   }   public bool isdayoff(datetime dt)     {         if (dt.dayofweek == dayofweek.saturday || dt.dayofweek == dayofweek.sunday)             return true;         return isholiday(dt);     } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -