Format a into a relative timestring.

@param \DateTimeInterface $time The time instance to format.
@param array $options Array of options.
@return string Relative time string.
@see \Cake\I18n\Time::timeAgoInWords()
198550
public function timeAgoInWords(DateTimeInterface $time, array $options = [])
    {
        $options = $this->_options($options, FrozenTime::class);
        if ($options['timezone'] && $time instanceof ChronosInterface) {
            $time = $time->timezone($options['timezone']);
        }

        $now = $options['from']->format('U');
        $inSeconds = $time->format('U');
        $backwards = ($inSeconds > $now);

        $futureTime = $now;
        $pastTime = $inSeconds;
        if ($backwards) {
            $futureTime = $inSeconds;
            $pastTime = $now;
        }
        $diff = $futureTime - $pastTime;

        if (!$diff) {
            return __d('cake', 'just now', 'just now');
        }

        if ($diff > abs($now - (new FrozenTime($options['end']))->format('U'))) {
            return sprintf($options['absoluteString'], $time->i18nFormat($options['format']));
        }

        $diffData = $this->_diffData($futureTime, $pastTime, $backwards, $options);
        list($fNum, $fWord, $years, $months, $weeks, $days, $hours, $minutes, $seconds) = array_values($diffData);

        $relativeDate = [];
        if ($fNum >= 1 && $years > 0) {
            $relativeDate[] = __dn('cake', '{0} year', '{0} years', $years, $years);
        }
        if ($fNum >= 2 && $months > 0) {
            $relativeDate[] = __dn('cake', '{0} month', '{0} months', $months, $months);
        }
        if ($fNum >= 3 && $weeks > 0) {
            $relativeDate[] = __dn('cake', '{0} week', '{0} weeks', $weeks, $weeks);
        }
        if ($fNum >= 4 && $days > 0) {
            $relativeDate[] = __dn('cake', '{0} day', '{0} days', $days, $days);
        }
        if ($fNum >= 5 && $hours > 0) {
            $relativeDate[] = __dn('cake', '{0} hour', '{0} hours', $hours, $hours);
        }
        if ($fNum >= 6 && $minutes > 0) {
            $relativeDate[] = __dn('cake', '{0} minute', '{0} minutes', $minutes, $minutes);
        }
        if ($fNum >= 7 && $seconds > 0) {
            $relativeDate[] = __dn('cake', '{0} second', '{0} seconds', $seconds, $seconds);
        }
        $relativeDate = implode(', ', $relativeDate);

        // When time has passed
        if (!$backwards) {
            $aboutAgo = [
                'second' => __d('cake', 'about a second ago'),
                'minute' => __d('cake', 'about a minute ago'),
                'hour' => __d('cake', 'about an hour ago'),
                'day' => __d('cake', 'about a day ago'),
                'week' => __d('cake', 'about a week ago'),
                'month' => __d('cake', 'about a month ago'),
                'year' => __d('cake', 'about a year ago')
            ];

            return $relativeDate ? sprintf($options['relativeString'], $relativeDate) : $aboutAgo[$fWord];
        }

        // When time is to come
        if ($relativeDate) {
            return $relativeDate;
        }
        $aboutIn = [
            'second' => __d('cake', 'in about a second'),
            'minute' => __d('cake', 'in about a minute'),
            'hour' => __d('cake', 'in about an hour'),
            'day' => __d('cake', 'in about a day'),
            'week' => __d('cake', 'in about a week'),
            'month' => __d('cake', 'in about a month'),
            'year' => __d('cake', 'in about a year')
        ];

        return $aboutIn[$fWord];
    }
840499
public function timeTo(string $time): Date
    {
        $times = explode(':', $time);
        if (count($times) != 3) {
            throw new \InvalidArgumentException(
                    'Given time "' . $time . '" does not follow required format HH:MM:SS'
            );
        }

        list($hour, $minute, $second) = $times;
        if (!ctype_digit($hour) || 0 > $hour || 23 < $hour) {
            throw new \InvalidArgumentException(
                    'Given value ' . $hour . ' for hour not suitable for changing the time.'
            );
        }

        if (!ctype_digit($minute) || 0 > $minute || 59 < $minute) {
            throw new \InvalidArgumentException(
                    'Given value ' . $minute . ' for minute not suitable for changing the time.'
            );
        }

        if (!ctype_digit($second) || 0 > $second || 59 < $second) {
            throw new \InvalidArgumentException(
                    'Given value ' . $second . ' for second not suitable for changing the time.'
            );
        }

        return $this->createDateWithNewTime((int) $hour, (int) $minute, (int) $second);
    }
368296
private function formatTimeAsArray(\DateTimeInterface $dateTime, $ns)
    {
        if ($ns === null) {
            $ns = $dateTime->format('u');
        }
        return [
            'seconds' => (int) $dateTime->format('U'),
            'nanos' => (int) $ns
        ];
    }
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;
	}
1355467
public function format_datetime( $options, $js = false ) {

		$format = $this->format_date( $options, $js );

		$type = pods_v( static::$type . '_type', $options, 'format' );

		if ( 'format' !== $type || 'c' !== pods_v( static::$type . '_format', $options, '' ) ) {
			$format .= ' ' . $this->format_time( $options, $js );
		}

		return $format;
	}
1222049
public static function formatDate(\DateTimeInterface $dateTime, $format)
    {
        $phpFormats = array(
            self::DATE => "Y-m-d",
            self::DATE_AND_TIME => 'Y-m-d\TH:i:s\Z',
        );
        $phpFormat = $phpFormats[$format];

        return $dateTime->format($phpFormat);
    }
716438
public function timeAgo($start)
    {
        $end = new \DateTime("now");
        $translator = $this->container->get('translator');
        $interval = $start->diff($end);
        $formats = array("%Y", "%m", "%W", "%d", "%H", "%i", "%s");

        $translation["singular"] = array(
            "%Y" => $translator->trans("year", array(), 'platform'),
            "%m" => $translator->trans("month", array(), 'platform'),
            "%W" => $translator->trans("week", array(), 'platform'),
            "%d" => $translator->trans("day", array(), 'platform'),
            "%H" => $translator->trans("hour", array(), 'platform'),
            "%i" => $translator->trans("minute", array(), 'platform'),
            "%s" => $translator->trans("second", array(), 'platform')
        );

        $translation["plural"] = array(
            "%Y" => $translator->trans("years", array(), 'platform'),
            "%m" => $translator->trans("months", array(), 'platform'),
            "%W" => $translator->trans("weeks", array(), 'platform'),
            "%d" => $translator->trans("days", array(), 'platform'),
            "%H" => $translator->trans("hours", array(), 'platform'),
            "%i" => $translator->trans("minutes", array(), 'platform'),
            "%s" => $translator->trans("seconds", array(), 'platform')
        );

        foreach ($formats as $format) {
            if ($format == "%W") {
                $i = round($interval->format("%d") / 8); //fix for week that does not exist in DataInterval obj
            } else {
                $i = ltrim($interval->format($format), "0");
            }

            if ($i > 0) {
                $unit = (int) $i === 1 ? $translation["singular"][$format]: $translation["plural"][$format];

                return $this->container->get("translator")->transChoice(
                    'time_ago',
                    $i,
                    array('%count%' => $i, '%unit%' => $unit),
                    "platform"
                );
            }
        }

        //?? why seconds ago
        return $this->container->get("translator")->transChoice(
            "seconds_ago",
            1,
            array('%count%' => 1),
            "home"
        );
    }
958024
public function toSqlTimeWithTimeZone(DateTimeInterface $time, Provider $provider = null) : string
    {
        $this->setParameterProvider($provider);

        return $time->format($provider->getTimeWithTimeZoneFormat());
    }
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;

	}
546418
static protected function regex($time)
    {
      if(!preg_match('/^' . self::PATTERN . '$/', $time, $matches))
        throw new InvalidArgumentException(__METHOD__ . '; Invalid time, no match with pattern (' . $time . ')');
        
      return $matches;
    }
938712
public static function timestampToGmt($time = null)
    {
        $time = $time ?? time();
        $dateTime = new \DateTime();
        $dateTime->setTimestamp($time)->modify('+2 hours');

        return $dateTime->format('d/m/Y H:i:s');
    }
1074312
private function formatDate(\DateTime $dateTime)
    {
        return $dateTime->format(\Magento\Framework\DB\Adapter\Pdo\Mysql::DATE_FORMAT);
    }
1352327
public function time(array $time = null)
    {
        if (is_null($time)) {
            return $this->time;
        }

        $validKeys = (count(array_diff(['hour', 'minute', 'second'], array_keys($time))) === 0);

        if (false === $validKeys) {
            throw new \InvalidArgumentException('Invalid arguments provided: '.implode($time));
        }

        $this->time = $time;

        return $this;
    }
425565
private function parseDateTime($time)
    {
        if (is_string($time)) {
            try {
                $time = new DateTimeImmutable($time);
            } catch (Exception $e) {
                throw new InvalidArgumentException(sprintf(
                    'Invalid date/time value: %s',
                    $e->getMessage()
                ), $e->getCode(), $e);
            }
        }

        if ($time instanceof DateTime) {
            try {
                $time = DateTimeImmutable::createFromMutable($time);
            } catch (Exception $e) {
                throw new InvalidArgumentException(sprintf(
                    'Invalid date/time value: %s',
                    $e->getMessage()
                ), $e->getCode(), $e);
            }
        }

        if ($time instanceof DateTimeImmutable) {
            $time = $time->setTimezone(static::$now->getTimezone());
        } else {
            throw new InvalidArgumentException('Invalid date/time for the presenter.');
        }

        return $time;
    }
1120273
public function getDateString(DateTime $time)
	{
		if ($this->getOption('type') === 'date')
		{
			return $time->format('Y-m-d');
		}
		else if ($this->getOption('type') === 'datetime')
		{
			return $time->format('Y-m-d H:i:s');
		}
		else
		{
			return $time->format('H:i:s');
		}
	}
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);
    }
47769
protected function dateFormatter($dateTime, $format)
    {
        if (is_numeric($dateTime)) {
            return gmdate($format, (int) $dateTime);
        }

        if (is_string($dateTime)) {
            $dateTime = new \DateTime($dateTime);
        }

        if ($dateTime instanceof \DateTimeInterface) {
            static $utc;
            if (!$utc) {
                $utc = new \DateTimeZone('UTC');
            }
            return $dateTime->setTimezone($utc)->format($format);
        }

        throw new \InvalidArgumentException('Date/Time values must be either '
            . 'be a string, integer, or DateTime object');
    }