Returns a crude time ago string.

@param int $time Origin timestamp

@return string
964410
protected function ago($time)
    {
        $time = time() - $time;

        if ($time < 60) {
            return 'a moment ago';
        }

        $secs = array(
            'year'   => 365.25 * 24 * 60 * 60,
            'month'  => 30 * 24 * 60 * 60,
            'week'   => 7 * 24 * 60 * 60,
            'day'    => 24 * 60 * 60,
            'hour'   => 60 * 60,
            'minute' => 60,
        );

        foreach ($secs as $str => $s) {
            $d = $time / $s;

            if ($d >= 1) {
                $r = round($d);
                return sprintf('%d %s%s ago', $r, $str, ($r > 1) ? 's' : '');
            }
        }
    }
1316966
public function expiresAfter($time)
    {
        if ($time instanceof \DateInterval) {
            $time = (int) $time->format("%r%s");
        }

        $this->expiration = time() + $time;

        return $this;
    }
601272
private static function translateToTimes(string $time) : string
	{
		static $translationMap = [
			'morning' => '06:00 - 11:59',
			'noon' => '12:00 - 12:29',
			'afternoon' => '12:30 - 16:59',
			'evening' => '17:00 - 21:59',
			'night' => '22:00 - 05:59',
			'midnight' => '00:00 - 00:29',
		];

		return array_key_exists($time, $translationMap) ? $translationMap[$time] : $time;
	}
678225
public static function timeToText($time)
    {
        $timeHour   = ceil($time * 60);
        $modMinutes = $timeHour % 60;
        $hour       = floor($time);

        return $hour . ' h ' . $modMinutes . ' m';
    }
287307
protected function resolveTime($time)
    {
        $timestamp = strtotime($time);

        if ($timestamp !== false) {
            return $timestamp;
        }

        if ($time === 'this' || $time === 'thisMonth') {
            return strtotime('first day of this month midnight');
        }

        if ($time === 'prev' || $time === 'prevMonth') {
            return strtotime('first day of last month midnight');
        }

        return time();
    }
432265
public static function _convert_time($time)
    {
        $reference = new DateTimeImmutable;
        $endTime = $reference->add(new DateInterval($time));

        return $endTime->getTimestamp() - $reference->getTimestamp();
    }
197107
public static function getTimestamp($dateTime = null)
    {
        return $dateTime ? is_numeric($dateTime) ? $dateTime : strtotime($dateTime) : time();
    }
292237
public static function relativeTime($time, array $options = array()) {
        $defaults = array(
            'seconds' => array('%ss', '%s second', '%s seconds'),
            'minutes' => array('%sm', '%s minute', '%s minutes'),
            'hours' => array('%sh', '%s hour', '%s hours'),
            'days' => array('%sd', '%s day', '%s days'),
            'weeks' => array('%sw', '%s week', '%s weeks'),
            'months' => array('%sm', '%s month', '%s months'),
            'years' => array('%sy', '%s year', '%s years'),
            'now' => 'just now',
            'in' => 'in %s',
            'ago' => '%s ago',
            'separator' => ', ',
            'verbose' => true,
            'depth' => 2,
            'time' => time()
        );

        $options = $options + $defaults;
        $diff = Time::difference($options['time'], Time::toUnix($time));
        $output = array();

        // Present tense
        if ($diff === 0) {
            return $options['now'];
        }

        // Past or future tense
        $seconds = abs($diff);
        $depth = $options['depth'];

        while ($seconds > 0 && $depth > 0) {
            if ($seconds >= Time::YEAR) {
                $key = 'years';
                $div = Time::YEAR;

            } else if ($seconds >= Time::MONTH) {
                $key = 'months';
                $div = Time::MONTH;

            } else if ($seconds >= Time::WEEK) {
                $key = 'weeks';
                $div = Time::WEEK;

            } else if ($seconds >= Time::DAY) {
                $key = 'days';
                $div = Time::DAY;

            } else if ($seconds >= Time::HOUR) {
                $key = 'hours';
                $div = Time::HOUR;

            } else if ($seconds >= Time::MINUTE) {
                $key = 'minutes';
                $div = Time::MINUTE;

            } else {
                $key = 'seconds';
                $div = Time::SECOND;
            }

            $count = round($seconds / $div);
            $seconds -= ($count * $div);

            if ($options['verbose']) {
                $index = ($count == 1) ? 1 : 2;
            } else {
                $index = 0;
            }

            $output[$key] = sprintf($options[$key][$index], $count);
            $depth--;
        }

        $output = implode($options['separator'], $output);

        // Past
        if ($diff > 0) {
            return sprintf($options['ago'], $output);
        }

        return sprintf($options['in'], $output);
    }
550010
public static function timeTense($datetime)
    {
        $datetime = self::makeCarbon($datetime);
        $yesterday = $datetime->subDays(1);
        $tomorrow = $datetime->addDays(1);
        $time = $datetime->format('H:i');
        $date = $datetime->format('j M Y');

        if ($datetime->isToday()) {
            $date = 'Today';
        }
        elseif ($datetime->isYesterday()) {
            $date = 'Yesterday';
        }
        elseif ($datetime->isTomorrow()) {
            $date = 'Tomorrow';
        }

        return $date.' at '.$time;
    }
278371
public static function wasLastMonth($time) {
        $start = static::factory('first day of last month 00:00:00');

        $end = clone $start;
        $end->modify('next month -1 second');

        $time = static::factory($time);

        return ($time >= $start && $time <= $end);
    }
499840
protected function normalizeDateValue($time)
	{
		if(is_string($time))
		{
			if(ctype_digit($time) || ($time{0}=='-' && ctype_digit(substr($time, 1))))
				return (int)$time;
			else
				return strtotime($time);
		}
		elseif (class_exists('DateTime', false) && $time instanceof DateTime)
			return $time->getTimestamp();
		else
			return (int)$time;
	}
734888
public function humanTimeDiff($time, $chunk = false)
    {
        if (!is_integer($time)) {
            $time = strtotime($time);
        }
        if ($chunk) {
            $different = time() - $time;

            $seconds = $different;
            $minutes = round($different / 60);
            $hours = round($different / 3600);
            $days = round($different / 86400);
            $weeks = round($different / 604800);
            $months = round($different / 2419200);
            $years = round($different / 29030400);

            if ($seconds <= 60) {
                if ($seconds == 1) {
                    return "$seconds second ago";
                } else {
                    return "$seconds seconds ago";
                }
            } elseif ($minutes <= 60) {
                if ($minutes == 1) {
                    return "$minutes minute ago";
                } else {
                    return "$minutes minutes ago";
                }
            } elseif ($hours <= 24) {
                if ($hours == 1) {
                    return "$hours hour ago";
                } else {
                    return "$hours hours ago";
                }
            } elseif ($days <= 7) {
                if ($days = 1) {
                    return "$days day ago";
                } else {
                    return "$days days ago";
                }
            } elseif ($weeks <= 4) {
                if ($weeks == 1) {
                    return "$weeks week ago";
                } else {
                    return "$weeks weeks ago";
                }
            } elseif ($months <= 12) {
                if ($months == 1) {
                    return "$months month ago";
                } else {
                    return "$months months ago";
                }
            } else {
                if ($years == 1) {
                    return "$years year ago";
                } else {
                    return "$years years ago";
                }
            }
        } else {
            $dtF = new \DateTime('@0');
            $dtT = new \DateTime("@$time");
            return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');
        }
    }
1239364
public static function windowsFileTimeToUnix($time)
    {
        $magicnum = '116444735995904000';

        $time = bcsub($time, $magicnum);
        $time = bcdiv($time, '10000000', 0);

        return apply_filters('AdApi/Format/WindowsTime', $time);
    }
623209
public function dateString(string $time): string
    {
        return date($this->dateFormat, ctype_digit($time) ? $time : strtotime($time));
    }
1162376
public static function makeTimestamp( $time ) {

		if( is_numeric($time) )
			return (int) $time;

		elseif( $time instanceof \DateTime )
			return $time->getTimestamp();

		$ts = strtotime($time);

		if( $ts === false )
			throw new \LogicException("Unable convert {$time} to a valid timestamp");

		return $ts;

	}
900726
public static function fromString($time)
    {
        try {
            $date = new \DateTime($time);
        } catch (\Exception $e) {
            throw new \InvalidArgumentException(sprintf('Invalid time "%s".', $time));
        }

        return self::fromDate($date);
    }
476106
public static function niceTime($time) {
		if (($pos = strpos($time, ' ')) !== false) {
			$time = substr($time, $pos + 1);
		}
		return substr($time, 0, 5);
	}