Retorna se a data passada é maior ou menor que a data instanciada
Retorno:
1 quando a data passada for maior
0 quando as datas forem iguais
-1 quando a data passada for menor

@param TDateTime $date

@return int
321237
public function compareDate($date = null)
    {
        $start    = $this->createDateUTC($this->toDateString());
        $end      = $this->createDateUTC($date ? $date->toDateString() : date(static::DATE_STR));
        $interval = $end->diff($start);

        return (int)($interval->format('%r') . (bool)$interval->format('%a'));
    }
1300689
public function average(Date $dt = null)
    {
        $dt = $dt ?: static::now($this->getTimezone());

        return $this->addSeconds((int) ($this->diffInSeconds($dt, false) / 2));
    }
143986
public static function fatorVencimento(\DateTime $data)
    {
        $dataBase = new \DateTime("1997-10-07");

        return (int)$data->diff($dataBase, true)->format('%r%a');
    }
1353977
public function getDate($date, string $pattern = "Y-m-d")
    {
        if (!$date) {
            $this->data['ano'] = date("Y");
            $this->data['mes'] = date("m");
            $this->data['dia'] = date("d");
        } else {
            $this->prepareDate($date);
        }

        if($this->erro) {
            return null;
        } else {
            $originalDate = $this->data['ano'] . '-' . $this->data['mes'] . '-' . $this->data['dia'];
            return date($pattern, strtotime($originalDate));
        }
    }
136814
public static function timeAgo($date)
    {
        $timeSince = false;
        if ( ! empty($date))
        {
            $ago = date('U') - $date;
            $periods = [__('second'), __('minute'), __('hour'), __('day'), __('week'), __('month'), __('year'), __('ten year')];
            $lengths = ['60', '60', '24', '7', '4.35', '12', '10'];
            for ($j = 0; $ago >= $lengths[$j]; $j++)
            {
                $ago /= $lengths[$j];
            }
            $ago = round($ago);

            if ($ago != 1)
            {
                $periods[$j] .= __('s');
            }
            $timeSince = $ago . ' ' . $periods[$j] . __(' ago');
        }

        return $timeSince;
    }
257801
public function max(Date $dt = null)
    {
        $dt = $dt ?: static::now($this->getTimezone());

        return $this->isAfter($dt) ? clone $this : clone $dt;
    }
1169083
private function parseRequestDate($date)
    {
        $timezone = new \DateTimeZone("UTC");
        $granularity = null;

        if (preg_match('#^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$#', $date)) {
            $parsedDate = date_create_from_format('Y-m-d\TH:i:s\Z', $date, $timezone);
            $granularity = Identity::GRANULARITY_YYYY_MM_DDTHH_MM_SSZ;
        } elseif (preg_match('#^\d{4}-\d{2}-\d{2}$#', $date)) {
            // Add ! to format to set time to 00:00:00
            $parsedDate = date_create_from_format('!Y-m-d', $date, $timezone);
            $granularity = Identity::GRANULARITY_YYYY_MM_DD;
        } else {
            throw new BadArgumentException("Expected a data in one of the following formats: " .
                Identity::GRANULARITY_YYYY_MM_DDTHH_MM_SSZ . " OR " .
                Identity::GRANULARITY_YYYY_MM_DD ." FOUND " . $date);
        }

        $parseResult = date_get_last_errors();
        if (!$parsedDate || ($parseResult['error_count'] > 0) || ($parseResult['warning_count'] > 0)) {
            throw new BadArgumentException("$date is not a valid date");
        }

        return [$parsedDate, $granularity];
    }
192411
protected function getFormatedDateTime( Date $date = null, Time $time = null ) {
		$timestamp = null;
		if($date && $time) {
			$timestamp = strtotime($date . ' ' . $time);
		}
		else {
			$timestamp = time();
		}
		return gmdate('Ymd\THis\Z', $timestamp);
	}
698130
public function diffInMicroseconds($date = null, $absolute = true)
    {
        $diff = $this->diff($this->resolveCarbon($date));
        $value = (int) round((((($diff->days * static::HOURS_PER_DAY) +
            $diff->h) * static::MINUTES_PER_HOUR +
            $diff->i) * static::SECONDS_PER_MINUTE +
            ($diff->f + $diff->s)) * static::MICROSECONDS_PER_SECOND);

        return $absolute || !$diff->invert ? $value : -$value;
    }
1166834
public static function dataPascoa($date)
    {
        $date = static::prepareDate($date);

        $ano = @$date->year;
        if (static::$pascoa) {
            if ($ano == static::$pascoa->getYear()) {
                return static::$pascoa;
            }
        }
        $c = floor($ano / 100);
        $n = $ano - (19 * floor($ano / 19));
        $k = floor(($c - 17) / 25);
        $i = $c - floor($c / 4) - floor(($c - $k) / 3) + (19 * $n) + 15;
        $i = $i - (30 * floor($i / 30));
        $i = $i - (floor($i / 28) * (1 - floor($i / 28)) * floor(29 / ($i + 1)) * floor((21 - $n) / 11));
        $j = $ano + floor($ano / 4) + $i + 2 -$c + floor($c / 4);
        $j = $j - (7 * floor($j / 7));
        $L = $i - $j;
        $mes = 3 + floor(($L + 40) / 44);
        $dia = $L + 28 - (31 * floor($mes / 4));
        static::$pascoa = DateTimeBr::createFromDate($ano, $mes, $dia);

        return static::$pascoa;
    }
830805
function timeAgo($date)
    {

        if (empty($date)) {

            return "No date provided";
        }

        $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");

        $lengths = array("60", "60", "24", "7", "4.35", "12", "10");

        $now = time();

        $unix_date = strtotime($date);

        // check validity of date

        if (empty($unix_date)) {

            return "Bad date";
        }

        // is it future date or past date

        if ($now > $unix_date) {

            $difference = $now - $unix_date;

            $tense = "ago";
        } else {

            $difference = $unix_date - $now;
            $tense = "from now";
        }

        for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths) - 1; $j++) {

            $difference /= $lengths[$j];
        }

        $difference = round($difference);

        if ($difference != 1) {

            $periods[$j] .= "s";
        }

        return "$difference $periods[$j] {$tense}";
    }
511980
private function normalizeDateValue($date)
    {
        if (is_string($date)) {
            $date = strtotime($date);
        } elseif ($date instanceof \DateTime) {
            $date = $date->format('U');
        } elseif (!is_int($date)) {
            throw new \InvalidArgumentException('Date values must be a '
                . 'string, an int, or a DateTime object.');
        }

        return $date;
    }
84156
public function parse($date) {
        if (is_string($date)) {
            if (($date == "") || strtotime($date) == -1) {
                //为空默认取得当前时间戳
                $tmpdate = time();
            } else {
                //把字符串转换成UNIX时间戳
                $tmpdate = strtotime($date);
            }
        } elseif (is_null($date))  {
            //为空默认取得当前时间戳
            $tmpdate = time();

        } elseif (is_numeric($date)) {
            //数字格式直接转换为时间戳
            $tmpdate = $date;

        } else {
            if (get_class($date) == "Date") {
                //如果是Date对象
                $tmpdate = $date->date;
            } else {
                //默认取当前时间戳
                $tmpdate = time();
            }
        }
        return $tmpdate;
    }
680803
public function dateTo(string $date): Date
    {
        $dates = explode('-', $date);
        if (count($dates) != 3) {
            throw new \InvalidArgumentException(
                    'Given date "' . $date . '" does not follow required format YYYY-MM-DD'
            );
        }

        list($year, $month, $day) = $dates;
        if (!ctype_digit($year)) {
            throw new \InvalidArgumentException(
                    'Given value ' . $year . ' for year not suitable for changing the date.'
            );
        }

        if (!ctype_digit($month) || 1 > $month || 12 < $month) {
            throw new \InvalidArgumentException(
                    'Given value ' . $month . ' for month not suitable for changing the date.'
            );
        }

        if (!ctype_digit($day) || 1 > $day || 31 < $day) {
            throw new \InvalidArgumentException(
                    'Given value ' . $day . ' for day not suitable for changing the date.'
            );
        }

        return $this->createNewDateWithExistingTime((int) $year, (int) $month, (int) $day);
    }
919170
public function floatDiffInSeconds($date = null, $absolute = true)
    {
        return $this->diffInMicroseconds($date, $absolute) / static::MICROSECONDS_PER_SECOND;
    }
1342484
public function toDateTime($date)
    {
        if ($date instanceof \DateTimeInterface) {
            return $date;
        }

        if (preg_match('/^(\d{4})-(\d{1,2})-(\d{1,2})$/', $date)) {
            return \DateTime::createFromFormat('Y-m-d', $date);
        }

        return \DateTime::createFromFormat($this->db->getQuery(true)->getDateFormat(), $date);
    }
419155
protected static function strBrToUs($date)
    {
        if (is_string($date)) {
            $expreg = '/^(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/(\d{4})(T| ){0,1}(([0-1][0-9]|[2][0-3]):([0-5][0-9]):([0-5][0-9])){0,1}$/';
            if (preg_match($expreg, $date, $datebit)) {
                @list($tudo, $dia, $mes, $ano, $tz, $time, $hora, $min, $seg) = $datebit;

                return "$ano-$mes-$dia" . ($hora | $min | $seg ? "$hora:$min:$seg" : "");
            }
        }
        return null;
    }