check whether given day is present in a given week of month.
Hi,
I am trying to find whether a particular day(sunday,Monday...) is there in a given week of a month using Gregorian Calendar.
thanks.
Hi,
I am trying to find whether a particular day(sunday,Monday...) is there in a given week of a month using Gregorian Calendar.
thanks.
Okay. So get the week number from the GregorianCalendar. If it's the number you were thinking of, then it is. Otherwise it isn't.
public boolean isDayInWeek(int day, int week) {
return day >= Calendar.SUNDAY && day <= Calendar.SATURDAY;
}
> What is the week parameter for?
The requirement was to find whether a particular day was there in a given week. I'm not one to shy away from requirements, even when they are superfluous.
> return day >= Calendar.SUNDAY && day <= Calendar.SATURDAY;
I think we discussed the sequence problem before. This code relies on the constants to be sequential numbers from SUN to SAT. Which isn't guaranteed at all.
My suggestion according to the requirements:
public boolean isDayInWeek(int day, int week) {
return true;
}
Don't I wish there were weeks without Mondays...
> > return day >= Calendar.SUNDAY && day <=
> Calendar.SATURDAY;
>
> I think we discussed the sequence problem before.
> This code relies on the constants to be sequential
> numbers from SUN to SAT. Which isn't guaranteed at
> all.
>
> My suggestion according to the requirements:
> [code]public boolean isDayInWeek(int day, int week)
> {
>return true;
> /code]
Agreed.
> Don't I wish there were weeks without Mondays...
Doesn't everybody.
I have all the days(Sunday, Monday,Tuesday,Wednesday,Thursday,Friday,Saturday) check boxes.I have start date and end date.For example:
Start date is 07/01/2007 (mm/dd/yyyy)
End Date is 07/20/2007 (mm/dd/yyyy)
I have weeks( week1,week2 ,week3,week4,week5) check boxes.I am storing week field in the database.
when the I give start date and end date, my code enables only those days and weeks that are contained in start date and end date.
But the first and last week may not contain all the days.
So I dont want to insert that week into the database even if it is selected.
I want to find out whether all the days are contained in week (given week,date,day)
Can any body assist...
Thanks.