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.

[155 byte] By [tutikashilpaa] at [2007-11-27 10:51:56]
# 1

Yes it is

tjacobs01a at 2007-7-29 11:34:26 > top of Java-index,Java Essentials,Java Programming...
# 2

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.

DrClapa at 2007-7-29 11:34:26 > top of Java-index,Java Essentials,Java Programming...
# 3

public boolean isDayInWeek(int day, int week) {

return day >= Calendar.SUNDAY && day <= Calendar.SATURDAY;

}

dwga at 2007-7-29 11:34:26 > top of Java-index,Java Essentials,Java Programming...
# 4

What is the week parameter for?

floundera at 2007-7-29 11:34:26 > top of Java-index,Java Essentials,Java Programming...
# 5

> 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.

dwga at 2007-7-29 11:34:26 > top of Java-index,Java Essentials,Java Programming...
# 6

> 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...

CeciNEstPasUnProgrammeura at 2007-7-29 11:34:26 > top of Java-index,Java Essentials,Java Programming...
# 7

> > 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.

dwga at 2007-7-29 11:34:26 > top of Java-index,Java Essentials,Java Programming...
# 8

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.

tutikashilpaa at 2007-7-29 11:34:26 > top of Java-index,Java Essentials,Java Programming...