 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
maya Guest
|
Posted: Wed May 09, 2007 11:32 pm Post subject: Calendar: month problem.. |
|
|
remDate.set(Calendar.MONTH, iMonth);
returns '5' if choose "May" in drop-down (tested with an
'out.println' stmt..)
but:
getTime() method on this Calendar obj returns:
Wed Jun 27 14:20:21 EDT 2007
why June? when Month chosen is 5?
can see for yourself:
www.francesdelrio.com/domail/domail.jsp
only need to fill out date and month in form...
you will see discrepancies....
2nd line prints correct month chosen
but line afterwards shows one month more..
thank you.. |
|
| Back to top |
|
 |
Knute Johnson Guest
|
Posted: Thu May 10, 2007 3:16 am Post subject: Re: Calendar: month problem.. |
|
|
maya wrote:
| Quote: |
remDate.set(Calendar.MONTH, iMonth);
returns '5' if choose "May" in drop-down (tested with an 'out.println'
stmt..)
but:
getTime() method on this Calendar obj returns:
Wed Jun 27 14:20:21 EDT 2007
why June? when Month chosen is 5?
can see for yourself:
www.francesdelrio.com/domail/domail.jsp
only need to fill out date and month in form...
you will see discrepancies....
2nd line prints correct month chosen
but line afterwards shows one month more..
thank you..
|
Month is 0 based - from the docs:
Calendar
set
public final void set(int year,
int month,
int date)
Sets the values for the calendar fields YEAR, MONTH, and
DAY_OF_MONTH. Previous values of other calendar fields are retained. If
this is not desired, call clear() first.
Parameters:
year - the value used to set the YEAR calendar field.
month - the value used to set the MONTH calendar field. Month
value is 0-based. e.g., 0 for January.
date - the value used to set the DAY_OF_MONTH calendar field.
--
Knute Johnson
email s/nospam/knute/ |
|
| Back to top |
|
 |
Ian Wilson Guest
|
Posted: Tue May 15, 2007 2:13 pm Post subject: Re: Calendar: month problem.. |
|
|
Roedy Green wrote:
| Quote: | On Wed, 09 May 2007 14:32:57 -0400, maya <maya778899 (AT) yahoo (DOT) com
wrote, quoted or indirectly quoted someone who said :
why June? when Month chosen is 5?
This is one of many calendar and date gotchas . Sun numbers months
starting at 0 instead of 1 like everyone else.
|
Not everyone else, Perl does too. |
|
| Back to top |
|
 |
Lew Guest
|
Posted: Tue May 15, 2007 5:35 pm Post subject: Re: Calendar: month problem.. |
|
|
Ian Wilson wrote:
| Quote: | Roedy Green wrote:
On Wed, 09 May 2007 14:32:57 -0400, maya <maya778899 (AT) yahoo (DOT) com
wrote, quoted or indirectly quoted someone who said :
why June? when Month chosen is 5?
This is one of many calendar and date gotchas . Sun numbers months
starting at 0 instead of 1 like everyone else.
Not everyone else, Perl does too.
|
And Java array indices start at 0. Computer science is full of zero-based
concepts. It is what it is and that's why Sun publishes their Javadocs for
all to see.
--
Lew |
|
| Back to top |
|
 |
Nigel Wade Guest
|
Posted: Tue May 15, 2007 9:30 pm Post subject: Re: Calendar: month problem.. |
|
|
Ian Wilson wrote:
| Quote: | Roedy Green wrote:
On Wed, 09 May 2007 14:32:57 -0400, maya <maya778899 (AT) yahoo (DOT) com
wrote, quoted or indirectly quoted someone who said :
why June? when Month chosen is 5?
This is one of many calendar and date gotchas . Sun numbers months
starting at 0 instead of 1 like everyone else.
Not everyone else, Perl does too.
|
That statement of Roedy's is actually ambiguous without any commas in it. Does
he mean that Sun, like everyone else, numbers from 0. Or does he mean that
everyone else numbers from 1?
Perl date stuff is, I believe, based on POSIX date and C mktime/gmtime functions
(from which I presume much of Java date stuff also derives).
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw (AT) ion (DOT) le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555 |
|
| Back to top |
|
 |
Ian Wilson Guest
|
Posted: Tue May 15, 2007 9:56 pm Post subject: Re: Calendar: month problem.. |
|
|
Nigel Wade wrote:
| Quote: | Ian Wilson wrote:
Roedy Green wrote:
This is one of many calendar and date gotchas . Sun numbers months
starting at 0 instead of 1 like everyone else.
Not everyone else, Perl does too.
That statement of Roedy's is actually ambiguous without any commas in it. Does
he mean that Sun, like everyone else, numbers from 0. Or does he mean that
everyone else numbers from 1?
|
Ah yes, I see now.
Roedy thought
Sun numbers months starting at 0 instead of 1, like everyone else.
Roedy wrote
Sun numbers months starting at 0 instead of 1 like everyone else.
I thought I read
Sun numbers months starting at 0, instead of 1 like everyone else. |
|
| Back to top |
|
 |
EricF Guest
|
Posted: Wed May 16, 2007 7:11 am Post subject: Re: Calendar: month problem.. |
|
|
In article <76ydnZiyTvCNNNTbnZ2dnUVZ_r-onZ2d (AT) comcast (DOT) com>, Lew <lew (AT) nospam (DOT) lewscanon.com> wrote:
| Quote: | Ian Wilson wrote:
Roedy Green wrote:
On Wed, 09 May 2007 14:32:57 -0400, maya <maya778899 (AT) yahoo (DOT) com
wrote, quoted or indirectly quoted someone who said :
why June? when Month chosen is 5?
This is one of many calendar and date gotchas . Sun numbers months
starting at 0 instead of 1 like everyone else.
Not everyone else, Perl does too.
And Java array indices start at 0. Computer science is full of zero-based
concepts. It is what it is and that's why Sun publishes their Javadocs for
all to see.
I can't disagree but it's pretty lame. Month 1 in the real world is Jan. The |
Java domain model for dates/time is just a mess. JSR310 should clean it up.
Date and time are 2 separate (though related) concepts. If I create a Date
object at 10:00 am and at 11:00 am on the same day, I'd expect them to be
equal. Wrong.
Eric |
|
| Back to top |
|
 |
Patricia Shanahan Guest
|
Posted: Wed May 16, 2007 2:34 pm Post subject: Re: Calendar: month problem.. |
|
|
EricF wrote:
| Quote: | In article <76ydnZiyTvCNNNTbnZ2dnUVZ_r-onZ2d (AT) comcast (DOT) com>, Lew <lew (AT) nospam (DOT) lewscanon.com> wrote:
Ian Wilson wrote:
Roedy Green wrote:
On Wed, 09 May 2007 14:32:57 -0400, maya <maya778899 (AT) yahoo (DOT) com
wrote, quoted or indirectly quoted someone who said :
why June? when Month chosen is 5?
This is one of many calendar and date gotchas . Sun numbers months
starting at 0 instead of 1 like everyone else.
Not everyone else, Perl does too.
And Java array indices start at 0. Computer science is full of zero-based
concepts. It is what it is and that's why Sun publishes their Javadocs for
all to see.
I can't disagree but it's pretty lame. Month 1 in the real world is Jan. The
Java domain model for dates/time is just a mess. JSR310 should clean it up.
Date and time are 2 separate (though related) concepts. If I create a Date
object at 10:00 am and at 11:00 am on the same day, I'd expect them to be
equal. Wrong.
|
Ultimately, this is all a consequence of what I consider to be a basic
error in Java array design, the forced zero start.
If Java had allowed specification of a start index as well as a number
of elements for each array, Calendar could have used the month number,
rather than a zero-based month index, and still have been able to use it
as an array index.
In addition to the choice between 0 and 1 there are some cases where it
makes sense to have, for example, elements -1, 0, and 1.
Mapping from the most natural start index for a particular array to zero
based has to be done. The choice is between it being done by the
programmer, or by the programming language. Leaving it to the programmer
results in less natural code, and creates temptations to have things
start at zero whether or not it makes any sense.
Patricia |
|
| Back to top |
|
 |
Patricia Shanahan Guest
|
Posted: Thu May 17, 2007 5:42 pm Post subject: Re: Calendar: month problem.. |
|
|
Bjorn Abelli wrote:
| Quote: | "Patricia Shanahan" <pats (AT) acm (DOT) org> wrote...
....
Ultimately, this is all a consequence of what I consider to be a basic
error in Java array design, the forced zero start.
Even if you consider it to be an *error*, it's not.
It's a design *choice* made by Sun, which has a legacy logic, but still a
valid one.
If Java had allowed specification of a start index as well as a number
of elements for each array, Calendar could have used the month number,
rather than a zero-based month index, and still have been able to use it
as an array index.
Sure, it would be possible to include such a choice, but that in turn would
definitely result in *some* kind of unneccesary overhead, as that choice
need to be propagated to any place where the array could be used.
|
Fortran is probably the most extreme case of a language whose users care
about array indexing performance, yet the overheads of allowing
programmer-chosen index bases are considered acceptable in Fortran.
Indeed, the default origin is 1, so some level of index to offset
mapping is needed in even the default case. The expression in the
Fortran 77 standard for calculating the offset into a multi-dimensional
array from the bases and dimensions is positively scary, but I've only
had to deal with it when working on a Fortran compiler.
[http://www.fortran.com/fortran/F77_std/rjcnf0001-sh-5.html#sh-5.4.3]
In practice, the extra calculations tend to turn into loop invariant
common subexpressions, and even a very basic optimizer can get them out
of inner loops.
| Quote: | It would also make some *bad* things happen, as it also would lead to *some*
arrays starting with zero, some with one, which the programmer need to keep
in mind. It's much easier to use *one* type of indexing; less error-prone
that way.
|
I've programmed in both Fortran and C, and find being able to use the
natural indexing for the problem such a great simplification that it is
worth the effort of remembering that the base index is part of the array
definition. For example, a lot of mathematical formulas are written
using 1 as the first index. Those formulas can be converted really
directly to Fortran, but are awkward in C or Java.
| Quote: |
The reason behind the zero-base is that the "zero" isn't an index at all,
it's an "offset" from the start of the array. This is a legacy from C where
the address of the first element is the same as the address of the array
itself.
|
The JLS disagrees with you. The section "10.4 Array Access" uses "index"
and related words about six times, and has no mention of "offset" or any
related word.
[http://java.sun.com/docs/books/jls/third_edition/html/arrays.html#10.4]
However, in a sense you are right. The problem is that Java takes the
array offset, and pretends it is the array index. The offset should be
quietly calculated by the compiler from the array index expression and
the index origin, without ever coming to the programmer's intention.
Patricia |
|
| Back to top |
|
 |
beelzibub @ bawston schoo Guest
|
Posted: Thu May 17, 2007 9:50 pm Post subject: Re: Calendar: month problem.. |
|
|
Ian Wilson wrote:
| Quote: | Roedy Green wrote:
On Wed, 09 May 2007 14:32:57 -0400, maya <maya778899 (AT) yahoo (DOT) com
wrote, quoted or indirectly quoted someone who said :
why June? when Month chosen is 5?
This is one of many calendar and date gotchas . Sun numbers months
starting at 0 instead of 1 like everyone else.
Not everyone else, Perl does too
... hi i was wondering if you might want to take a look at my self assigned program and make a few pointers but write no code? [i want to say i did it myself]
k
--
Sometimes I'm in a good mood.
Sometimes I'm in a bad mood.
When all my moods have cum to pass
i hope they bury me upside down
so the world can kiss me porcelain,
white, Irish bottom.
|
--
Sometimes I'm in a good mood.
Sometimes I'm in a bad mood.
When all my moods have cum to pass
i hope they bury me upside down
so the world can kiss me porcelain,
white, Irish bottom. |
|
| Back to top |
|
 |
Bjorn Abelli Guest
|
Posted: Thu May 17, 2007 11:28 pm Post subject: Re: Calendar: month problem.. |
|
|
"Patricia Shanahan" <pats (AT) acm (DOT) org> wrote...
| Quote: | Bjorn Abelli wrote:
The reason behind the zero-base is that the "zero" isn't an index
at all, it's an "offset" from the start of the array. This is a
legacy from C where the address of the first element is the same
as the address of the array itself.
The JLS disagrees with you.
|
I don't think so.
| Quote: | The section "10.4 Array Access" uses "index" and related words
about six times, and has no mention of "offset" or any related word.
[http://java.sun.com/docs/books/jls/third_edition/html/arrays.html#10.4]
|
The JLS doesn't use the word "offset" as it doesn't explain the *reason*
behind using zero as base.
I did, by explaining where the zero-base comes from.
At the birth of Java, the legacy from C/C++ was a good thing, as it made the
transition from those languages easier in many cases.
Nowadays it might have become a liability?
;-)
/// Bjorn A |
|
| Back to top |
|
 |
John W. Kennedy Guest
|
Posted: Fri May 18, 2007 1:08 am Post subject: Re: Calendar: month problem.. |
|
|
Patricia Shanahan wrote:
| Quote: | Fortran is probably the most extreme case of a language whose users care
about array indexing performance, yet the overheads of allowing
programmer-chosen index bases are considered acceptable in Fortran.
|
Or you can do what PL/I compilers have historically done, and include as
part of the array object the address of the zero element, even if there
isn't one.
--
John W. Kennedy
"Never try to take over the international economy based on a radical
feminist agenda if you're not sure your leader isn't a transvestite."
-- David Misch: "She-Spies", "While You Were Out"
* TagZilla 0.066 * http://tagzilla.mozdev.org |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|