Given a Date, calculate friendly how much time has passed

@param DateTime $releaseDate
@return string
353389
public function getTimeDiff(DateTime $releaseDate)
    {
        $now = new DateTime();

        /** @var DateInterval $diff */
        $diff = $now->diff($releaseDate);

        if ($diff->days > 7) {
            return '';
        }

        if ($diff->days == 7) {
            return 'a week ago';
        }

        if ($diff->days >= 1) {
            return sprintf('%d day(s) ago', $diff->days);
        }

        if ($diff->h >= 1) {
            return sprintf('%d hour(s) ago', $diff->h);
        }

        if ($diff->i >= 1) {
            return sprintf('%d minute(s) ago', $diff->i);
        }

        return 'just now';
    }
752329
public static function extractMinutes(\DateTime $datetime) : int {
		return (((int) $datetime->format('H')) * 60) + ((int) $datetime->format('i'));
	}
260473
public static function nice($dateString = null, $format = 'D, M jS Y, H:i') {

		$date = ($dateString == null) ? time() : strtotime($dateString);
		return date($format, $date);
	}
25466
public function getLastRead(): \DateTime
    {
        if ($this->caching == false) {
            return \DateTime::createFromFormat("F d Y H:i:s.", date("F d Y H:i:s.", fileatime($this->getAbsoluteFilePath())));
        }

        if ($this->lastRead == null) {
            $this->lastRead = \DateTime::createFromFormat("F d Y H:i:s.", date("F d Y H:i:s.", fileatime($this->getAbsoluteFilePath())));
        }

        return $this->lastRead;
    }
143062
private function convertFormat($time, $dateFormat)
    {
        if (!($time instanceof \DateTime)) {
            if (is_numeric($time)) {
                $transformer = new DateTimeToTimestampTransformer();
                $time = $transformer->reverseTransform($time);
            } else {
                $transformer = new DateTimeToStringTransformer(null, null, $dateFormat);
                $time = $transformer->reverseTransform($time);
            }
        }

        return $time;
    }
956253
public function findNotConfirmedAndNotRemindedParticipantsByExpireDate(\DateTime $expireDate)
    {
        $dql = '
            SELECT p, s
            FROM Phraseanet:ValidationParticipant p
            JOIN p.session s
            JOIN s.basket b
            WHERE p.is_confirmed = 0
            AND p.reminded IS NULL
            AND s.expires < :date AND s.expires > CURRENT_TIMESTAMP()';

        return $this->_em->createQuery($dql)
                ->setParameter('date', $expireDate, Type::DATETIME)
                ->getResult();
    }
860426
public function lastOnlineDate() : ?\DateTime
    {
        $isOnline = $this->info()->presences[0]->onlineStatus == "online";

        // They're online now, so just return the current DateTime.
        if ($isOnline) return new \DateTime();

        // If they don't have a DateTime, just return null.
        // This can happen if the User object was created using the onlineId string and not the profile data.
        // Sony only provides lastOnlineDate on the 'friends/profiles2' endpoint and not the individual userinfo endpoint.
        // This can be a TODO if in the future Sony decides to make that property available for that endpoint.
        // - Tustin 9/29/2018
        if (!isset($this->info()->presences[0]->lastOnlineDate)) return null;
        
        // I guess it's possible for lastOnlineDate to not exist, but that seems very unlikely.
        return new \DateTime($this->info()->presences[0]->lastOnlineDate);
    }
299720
private function getTimeDrift(string $date) :? int
    {
        $now = new \DateTime();
        $now->format(\DateTime::RFC1123);

        try {
            $realDate = new DateTime($date);
        } catch (\Exception $e) {
            return null;
        }

        return (int)\abs($now->getTimestamp() - $realDate->getTimestamp());
    }
1262469
public function getRoundedRequestDateDBFormatted($roundTo)
    {
        $timestamp = $this->getRequestTime();
        //round up x minutes so query cache can work
        $timestamp = ceil($timestamp / $roundTo) * $roundTo;

        //format date for sql query
        return $this->formatDBTimestamp($timestamp);
    }
869334
protected function getAvailableAt($delay)
    {
        $availableAt = ($delay instanceof DateTime) ? $delay : Carbon::now()->addSeconds($delay);

        return $availableAt->getTimestamp();
    }
1040255
public function getSecond($timestamp = false)
    {
        if (!$timestamp) {
            $timestamp = $this->dateTime->getTimestamp();
        }

        return (int) date('s', $timestamp);
    }
372696
public function getReleasedAt() : ?string 
    {
        if ( ! $this->hasReleasedAt()) {
            $this->setReleasedAt($this->getDefaultReleasedAt());
        }
        return $this->releasedAt;
    }
533883
public static function getRelTime($datetime, $datetimeFrom = null)
    {
        $ret = '';
        $dateTime = self::getDateTime($datetime);
        $dateTimeFrom = self::getDateTime($datetimeFrom);
        $dateTimeSameDay = clone $dateTimeFrom;
        $dateTimeSameDay->setTime(0, 0, 0);
        $diffSec = $dateTimeFrom->getTimestamp() - $dateTime->getTimestamp();
        if ($dateTime > $dateTimeFrom) {
            // Future
            $dateTimeTest = clone $dateTimeSameDay;
            if ($dateTime < $dateTimeTest->modify('tomorrow')) {
                $ret = 'Today at '.$dateTime->format('g:ia');
            } elseif ($dateTime < $dateTimeTest->modify('+2 days')) {
                $ret = 'Tomorrow at '.$dateTime->format('g:ia');
            } else {
                $ret = $dateTime->format('F jS');
            }
        } elseif ($diffSec < 60) {
            // within a min
            $ret = 'Just now';
        } elseif ($diffSec < 3600) {
            // within an hour
            $ret = \round(($diffSec)/60) .' min ago';
        } elseif ($diffSec < 3600*6) {
            // within 6 hours
            $hrs = \round(($diffSec)/3600);
            $ret = $hrs.' '.Str::plural($hrs, 'hour').' ago';
        } elseif ($dateTime > $dateTimeSameDay) {             // since midnight so it's today
            $ret = 'Today at '.$dateTime->format('g:ia');
        } elseif ($dateTime->getTimestamp() >= $dateTimeSameDay->getTimestamp() - 86400) {
            $ret = 'Yesterday at '.$dateTime->format('g:ia');
        } elseif ($dateTime->getTimestamp() >= $dateTimeSameDay->getTimestamp() - 86400*7) {
            $ret = $dateTime->format('l \a\t g:ia');
        } elseif ($dateTime->getTimestamp() > \mktime(0, 0, 0, 1, 1)) {// since 1st Jan so it's this year
            $ret = $dateTime->format('F jS');
        } else {                                // last year..
            $ret = $dateTime->format('F jS, Y');
        }
        $ret = \str_replace(' at 12:00am', '', $ret);
        return $ret;
    }
556284
public static function flexiDateToDateTime($flexidate)
    {
        return \DateTime::createFromFormat(strstr($flexidate, '+') ? self::$DateFormat.'O'
                    : self::$DateFormat, $flexidate)->setTime(0, 0);
    }
1163557
public static function timestamp($time = null): int
    {
        if ($time instanceof \DateTime) {
            return $time->format('U');
        }

        $time = time();

        if ($time !== null) {
            $time = is_numeric($time) ? (int) $time : strtotime($time);
        }

        return $time;
    }
982201
static function isValidISODateString( $sDate )
	{
		if ( ! CLib::IsExistingString( $sDate ) )
		{
			return false;
		}

		$nTime	= strtotime( $sDate );
		return ( false !== $nTime &&
			0 == strcasecmp( $sDate, date( "Y-m-d", $nTime ) ) );
	}
1217990
public static function getMinutesCount($beginDate, $endDate)
    {
        // Get date diff
        $diff = $endDate->diff($beginDate);

        // Calculate all minutes
        $minutes = $diff->days * 24 * 60;
        $minutes += $diff->h * 60;
        $minutes += $diff->i;

        return $minutes;
    }