Advertisements

On 14 May 2004 09:47:06 -0700, (tdd) wrote or
quoted :
>I am trying to calculate the weekStartDate. When I set the date to
>05/15/2004 it returns 05/17/2004 as the beginning date. It should
>return 05/10/2004. What am I doing wrong?

tdd wrote:
> I am trying to calculate the weekStartDate. When I set the date to
> 05/15/2004 it returns 05/17/2004 as the beginning date. It should
> return 05/10/2004. What am I doing wrong?

You're assuming that setting DAY_OF_WEEK will cause the Calendar to move
backward instead of forward. That's not clear in the documentation I'm
reading. In any case, you can ensure this works by using looping doing
a Calendar.add(Calendar.DATE, -1) and comparing DAY_OF_WEEK each time.

Incidentally, Monday as the first day of the week? That's a new one to
me. Must be a cultural/local thing. Calendar's documentation mentions
that this is set according to the current Locale automatically, so I'd
assume that unless you have a reason to do otherwise, you should leave
it as is.

On 14 May 2004 09:47:06 -0700, (tdd) wrote or
quoted :
>I am trying to calculate the weekStartDate. When I set the date to
>05/15/2004 it returns 05/17/2004 as the beginning date. It should
>return 05/10/2004. What am I doing wrong?

On Fri, 14 May 2004 11:27:39 -0600, Chris Smith <>
wrote or quoted :
>Incidentally, Monday as the first day of the week? That's a new one to
>me. Must be a cultural/local thing. Calendar's documentation mentions
>that this is set according to the current Locale automatically, so I'd
>assume that unless you have a reason to do otherwise, you should leave
>it as is.
in France, it is Monday = 2. In the US, it is Sunday=1 so much for
0-based.

The USA uses the term weekEND to refer to Saturday and Sunday, yet
they say the week starts with Sunday, yet they say God rested on the
7th day, and celebrate that on Sunday. Christians therefore should
reject 0-based indexing on religious grounds. But then nothing about
dates make any sense. Read the notes inhttp://mindprod.com/jglossl/bigdate.html andhttp://mindprod.com/jgloss/leap.html

Roedy Green wrote:
> The USA uses the term weekEND to refer to Saturday and Sunday, yet
> they say the week starts with Sunday, yet they say God rested on the
> 7th day, and celebrate that on Sunday.

Just in terms of interesting history, throughout the history of the
Judeo-Christian world (and thus most of Western civilization) Sunday has
always been considered the beginning of the week. The decision of the
early Christian Church to celebrate the risen Christ on Sunday was a
change from earlier Jewish practice, and Christians fully realized that
it was not the seventh day. Jewish Christians definitely observed the
Sabbath, in addition to celebrating eucharist on Sunday. Only after
centuries of forgetting do modern Christians tend to think of Sunday as
being the Sabbath because it's a convenient way to interpret more of
Jewish scripture as applying to them.

The term "weekend", on the other hand, I don't know about. I'd assume
it comes from the 5-day work week, and the idea that you get that time
off after the long week of work. As such, it would be a rather new
innovation -- post Industrial Revolution, anyway.

Chris you beat me to the post. Roedy you've got to be careful with
statements about all X, it shows a bias and usually can't be supported.
In this case shows a lack of knowledge of the underlying 1700+ year
history of Sunday ceremony/rest day.

The term that drifted is "Sabbath", the practice that changed was
when to rest and do religious ceremonies, the move was explicitly done. Which
day is the 1st day of the week in the 7 day cycle hasn't actually moved.
If you think it did I might ask how you
would define such a move? Some prescriptive declaration from a historic
document? Some common usage? "Weekend" comes close, but it seems to be in
struggle with Sunday as the first day of the week. For example, some parts of
the world put Monday in the far left column, but Sunday on the far left is much
more common.

Roedy, the following is equivalent:
>in France, it is Monday = 2. In the US, it is Sunday=1 so much for
>0-based.

Did you mean Monday = 1?

The point for Java Programmers is that Sunday = 1 and Saturday = 7,
it is not uncommon to find DOW week calculations where a 0 works as well
as a 7 when expecting to end up on Saturday. This is not always the case, so
everyone should be careful.

Curiously if we move the SetFirstDayOfWeek up, so that it you
are left with pushing a date in, moving to a MONDAY and getting
the resulting date, the result is the Monday of the current week.

The simplist way to demonstrate that is to just move the line
up in the getWeekStartDate routine.
> public String getWeekStartDate(){
c.setFirstDayOfWeek(Calendar.MONDAY);
> c.setTime(target);
> c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
> return dateFormatter.format(c.getTime());
> }

Running the class with just the one-line change results in
LAST Monday.
05/15/2004
Start Date:05/10/2004

Starting with last Monday results in last Monday.
05/10/2004
Start Date:05/10/2004

Starting with next Monday results in next Monday.
05/17/2004
Start Date:05/17/2004

Apparently there is some unanticipated interaction between
SetFirstDayOfWeek and the other sets.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!