public static function compare(DateTime $date1, DateTime $date2)
    {
        // Not using getTimestamp() here because it is clamped to the 32-bit
        // signed integer range. Float compaison should be safe here as the
        // number are within the double-precision offered by floats and can
        // be represented exactly.
        $seconds1 = (float) $date1->format('U');
        $seconds2 = (float) $date2->format('U');

        if ($seconds1 > $seconds2) {
            return 1;
        }

        if ($seconds1 < $seconds2) {
            return -1;
        }

        return 0;
    }