title: Using Groovy comparison operators with Date objects
body: <p>I'm investigating an issue and ran across some suspicious code involving comparison of Date instances using comparison operators. e.g.</p>
  
  <pre><code>    def stamp = ... //Date
      def offset = ... //Integer
      def d = new Date(stamp.time + offset)
      if (d &lt; new Date()) {
          ...
      }
  </code></pre>
  
  <p><a href="http://www.ibm.com/developerworks/java/library/j-pg10255.html" rel="noreferrer">This</a> resource indicates the above is equivalent to the following</p>
  
  <pre><code>    def stamp = ... //Date
      def offset = ... //Integer
      def d = new Date(stamp.time + offset)
      if (d.compareTo(new Date()) &lt; 0) {
          ...
      }
  </code></pre>
  
  <p>However, the <a href="http://groovy.codehaus.org/JN0545-Dates" rel="noreferrer">GDK documentation on Dates</a> only has examples comparing dates using <code>compareTo</code>, <code>before</code>, and <code>after</code> and I seem to recall specifically avoiding using the comparison operators on Dates due to an experience with unexpected results.  Are the above two code examples indeed equivalent (that is, can I safely use comparison operators on Dates in Groovy, or should I only use <code>compareTo</code>, <code>before</code>, and <code>after</code>)?</p>
  
  <p>Thanks!</p>