Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 16866 invoked from network); 16 Feb 2004 22:11:37 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 16 Feb 2004 22:11:37 -0000 Received: (qmail 75265 invoked by uid 500); 16 Feb 2004 22:11:21 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 75180 invoked by uid 500); 16 Feb 2004 22:11:20 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 75156 invoked from network); 16 Feb 2004 22:11:20 -0000 Received: from unknown (HELO atlanta.seagullsw.com) (12.6.96.143) by daedalus.apache.org with SMTP; 16 Feb 2004 22:11:20 -0000 Received: by atlanta.seagullsw.com with Internet Mail Service (5.5.2656.59) id ; Mon, 16 Feb 2004 17:13:07 -0500 Message-ID: <245A7290F0E0D311BF6E009027E7908B0934B0EE@atlanta.seagullsw.com> From: Gary Gregory To: 'Jakarta Commons Developers List' Subject: RE: DateUtils.equals(d1, d2) Date: Mon, 16 Feb 2004 17:13:06 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2656.59) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C3F4DA.0017F9C8" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N ------_=_NextPart_001_01C3F4DA.0017F9C8 Content-Type: text/plain See alse the bug report for an example of this not working... gg > -----Original Message----- > From: Todd V. Jonker [mailto:todd@consciouscode.com] > Sent: Monday, February 16, 2004 13:21 > To: Jakarta Commons Developers List > Subject: Re: DateUtils.equals(d1, d2) > > Serge, I'm not sure that your proposed method will do what you want. > > You can't compare the results of java.util.Date.getTime() and > java.sql.Timestamp.getTime() because the latter is only precise to the > second, not the millisecond. Likewise, java.sql.Date.getTime() is only > precise to the second. > > Unless you do rather snarly logic, it may not be meaningful to compare > any util.Date with any of the sql types. Quoting from the Timestamp API: > > "Due to the differences between the Timestamp class and the > java.util.Date class mentioned above, it is recommended that code not > view Timestamp values generically as an instance of java.util.Date. The > inheritance relationship between Timestamp and java.util.Date really > denotes implementation inheritance, and not type inheritance." > > To compare a until.Date with a sql.Timestamp you'll have to rebuild the > latter's time to millisecond precision by call getNanos(), rounding the > result to the millisecond, and adding it to getTime(). And if you want > "true" equality you'll have to fail if the submillisecond nanos aren't > zero. Doing all of that is of debatable usefulness, because the use of > such a somewhat-generic equality method probably indicates that the > programmer doesn't understand the subtleties here and he's probably > writing a bug. :-) > > Just my two cents from painful experience... > > .T. > > > > On Fri, 13 Feb 2004 18:12:37 -0500, "Serge Knystautas" > said: > > There was a bugzilla issue opened about this, and a brief discussion > > about such, but I wanted to move it to the list for better visibility. > > > > Basically if you have 2 date objects (e.g., java.util.Date and > > java.sql.Timestamp), ObjectUtils.equals() will return that they are not > > equal even if they represent the same point in time. > > > > Unless someone objects, I was going to add DateUtils.equals(Date d1, > > Date d2) and the equality check will be what's returned from each date's > > getTime(). Just as an example: > > > > long now = System.currentTimeMillis(); > > Date date = new java.util.Date(now); > > Date ts = new java.sql.Timestamp(now); > > > > ObjectUtils.equals(date, ts) = false; (as of 2.1) > > DateUtils.equals(date, ts) = true; > > > > Anyone have a different idea or think this is a bad idea? > > > > -- > > Serge Knystautas > > President > > Lokitech >>> software . strategy . design >> http://www.lokitech.com > > p. 301.656.5501 > > e. sergek@lokitech.com > > -- > Todd V. Jonker > > Conscious Code Ltd > The Practice of Programming > www.consciouscode.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-dev-help@jakarta.apache.org ------_=_NextPart_001_01C3F4DA.0017F9C8--