Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calendar chooser problem

1 view
Skip to first unread message

bilari...@yahoo.com

unread,
May 26, 2005, 12:47:35 AM5/26/05
to
Hi,
I am using a Date selector component that allows the user to visually
select a date (day-month-year). But there is a slight problem I am
facing:

CalendarChooser objFromDate = new CalendarChooser () ;

CalendarChooser objToDate = new CalendarChooser () ;
.
.
.
Date dtFrom = objFromDate.getDate () ;
Date dtTo = objToDate.getDate () ;

return dtFrom.compareTo ( dtTo ) ;

The last line does not return 0 even if identical dates were selected.
This is probably because of the very slight time difference between
creation of the two CalendarChooser objects. If I see the Date values
in the debugger, they are identical, but if I see the 'long' value of
the dates, they differ in the last three digits.
How do I get around this problem? I cannot set the time component to 0
entirely since at some places, the time is also required. Setting the
millis and nanos component of the date also seems pretty patchy at
best.

Thanks in advance.

Best regards.

Andrew Thompson

unread,
May 26, 2005, 12:59:09 AM5/26/05
to
On 25 May 2005 21:47:35 -0700, bilari...@yahoo.com wrote:

> Hi,
> I am using a Date selector component that allows the user to visually
> select a date (day-month-year).

No, you are using two of them.

>..But there is a slight problem I am facing:


>
> CalendarChooser objFromDate = new CalendarChooser () ;
>
> CalendarChooser objToDate = new CalendarChooser () ;

// replace the above with
CalendarChooser chooser = new CalendarChooser();
> .
> .
> .

What does '...' mean, specifically?

Do you initialise the choosers, display them, then block till
a date is selected?

If so, do that once, then..

> Date dtFrom = objFromDate.getDate () ;

Date dtFrom = chooser.getDate();

[ repeat the chooser initialise/display/block from above ]

> Date dtTo = objToDate.getDate () ;

Date dtTo = chooser.getDate();

> How do I get around this problem?

Perhaps another group would be better suited to your
needs at the moment..
<http://www.physci.org/codes/javafaq.jsp#cljh>

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane

Niels Dybdahl

unread,
May 26, 2005, 2:59:02 AM5/26/05
to
> CalendarChooser objFromDate = new CalendarChooser () ;
> CalendarChooser objToDate = new CalendarChooser () ;
> Date dtFrom = objFromDate.getDate () ;
> Date dtTo = objToDate.getDate () ;
> return dtFrom.compareTo ( dtTo ) ;
>
> The last line does not return 0 even if identical dates were selected.

Date does also include the time. So if you really only want to compare the
dates, then create new dates like:

Date dtFromDateOnly = new Date(dtFrom.getYear(), dtFrom.getMonth(),
dtFrom.getDate(), 0, 0, 0);

Or you might use similar functions from Calendar as most of the functions
above are deprecated.

Niels Dybdahl


Lee Weiner

unread,
May 26, 2005, 6:02:13 PM5/26/05
to
In article <1117082855.0...@g43g2000cwa.googlegroups.com>, bilari...@yahoo.com wrote:
>Date dtFrom = objFromDate.getDate () ;
>Date dtTo = objToDate.getDate () ;
>
>return dtFrom.compareTo ( dtTo ) ;
>
>The last line does not return 0 even if identical dates were selected.
>This is probably because of the very slight time difference between
>creation of the two CalendarChooser objects. If I see the Date values
>in the debugger, they are identical, but if I see the 'long' value of
>the dates, they differ in the last three digits.
>How do I get around this problem? I cannot set the time component to 0
>entirely since at some places, the time is also required. Setting the
>millis and nanos component of the date also seems pretty patchy at
>best.

So, if the time component is significant, what is your definition of equality?
When do you want compareTo() to return 0?

Lee Weiner
lee AT leeweiner DOT org

0 new messages