|
Rank: Newbie Groups: Member
Joined: 2/5/2009 Posts: 6
|
Hello,
I just went to discover your library an I may need it for my asp/c# application.
But I have one question about a feature. My need is to have a calendar with disabled days (week-end, holydays, ...) which is already implemented (great feature ;) ).
But is it possible to calculate easily the number of "enabled" days between two given dates from your Calendar ? I've checked the API documentation but I didn't find a method which do that.
Thanks in advance tomtom
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,200
|
Hi,
It should be quite easy for us to provide you a function to do that. Do you want the client side (JavaScript) version or server side (VB.NET/C#) version?
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 2/5/2009 Posts: 6
|
what an impressive promptness !!
I think it's better to have it in the server side version (i'm using c#)
Thanks a lot for your work !
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,200
|
tomtom wrote:what an impressive promptness !! We are known for our fast response. :) tomtom wrote: I think it's better to have it in the server side version (i'm using c#) Thanks a lot for your work !
You got it. We will post again when we have the code.
|
|
Rank: Newbie Groups: Member
Joined: 2/5/2009 Posts: 6
|
Thanks a lot !
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,200
|
Hi, Below is the code that you can use to count number of enabled days between two dates:
Code: C#
private bool IsDateEnabled(
EO.Web.Calendar calendar, DateTime date)
{
//Check against MinValidDate and MaxValidDate
if (date < calendar.MinValidDate)
return false;
if (date > calendar.MaxValidDate)
return false;
//Check against DisableWeekendDays
if (calendar.DisableWeekendDays &&
((date.DayOfWeek == DayOfWeek.Saturday) ||
(date.DayOfWeek == DayOfWeek.Sunday)))
return false;
//Check against DisabledDates
if (calendar.DisabledDates.Contains(date))
return false;
return true;
}
private int CountEnabledDays(
EO.Web.Calendar calendar, DateTime startDate, DateTime endDate)
{
int n = 0;
while (startDate <= endDate)
{
if (IsDateEnabled(calendar, startDate.Date))
n++;
startDate = startDate.AddDays(1);
}
return n;
}
You would call it like this:
Code: C#
int n = CountEnabledDays(
DatePicker1, //the DatePicker/Calendar control
new DateTime(2009, 2, 1), //Start date
new DateTime(2009, 2, 10)); //End date
Note the start date/end date are inclusive. The code also excludes disabled weekend days. If those are different than what you want, it should be fairly easy for you to modify it. Hope this helps. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 2/5/2009 Posts: 6
|
OK, thanks for all, I will use it !
|
|