I realize this isnt strictly a JSF Problem, but it is in a backing bean that is called by my JSF App.
My problem is that when I compare :
if (dt == result)
dt has the value 2012-11-02 and result has Fri Nov 02 20:29:23 CET 2012 even though I formatted it with SimpleDateFormat.
the static variable ferienTage is an array of holidays that is supposed to be valid for any year. The function compares the parameter dt to the array and returns
true/false if it is a holiday.
Why is there a difference. Both Date objects have been instansiated and initialized.
The only thing more treacherous than dates when it comes to comparison are floating-point numbers. This is especially true when you read/write them from a database, where the granularity of the date/time objects doesn't correspond exactly to the granularity of the Java temporal objects.
A standard (not high-definition) java.util.Date or java.sql.Date is internally defined as the number of milliseconds since midnight Monday January 1, 1970. To determine whether two dates are the same day mathematically, extract the millisecond value from the date object as a long integer and slice off the fractional day part:
Or, if you prefer, don't multiply back and just count the actual days:
MS_PER_DAY is, of course 1000 (ms) * 60 (sec/minute) * 60 (min/hr) * 24 (hr/day), as a static long value. NOT an int!
In reality, there are somewhat arbitrary "leap seconds" so this isn't an astronomically precise way of doing things, but it's close enough for most business purposes.
Customer surveys are for companies who didn't pay proper attention to begin with.