code: public static int compare(Date d1, Date d2)
     {
        int result;
        if (d1 == null || d2 == null)
        {
           result = (d1 == d2 ? 0 : (d1 == null ? 1 : -1));
        }
        else
        {
           long diff = d1.getTime() - d2.getTime();
           result = ((diff == 0) ? 0 : ((diff > 0) ? 1 : -1));
        }
        return (result);
     }
docs: Compare two dates, handling null values.
  TODO: correct the comparison order to align with Date.compareTo
  
  @param d1 Date instance
  @param d2 Date instance
  @return int comparison result