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 - 26 May 2005 05:59 GMT
> 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

Signature
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 - 26 May 2005 07:59 GMT
> CalendarChooser objFromDate = new CalendarChooser () ;
> CalendarChooser objToDate = new CalendarChooser () ;
[quoted text clipped - 3 lines]
>
> 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 - 26 May 2005 23:02 GMT
>Date dtFrom = objFromDate.getDate () ;
>Date dtTo = objToDate.getDate () ;
[quoted text clipped - 10 lines]
>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