Given a timestamp, obtains corresponding field values.

@param int $time Timestamp
@return \stdClass Object with fields for year, month, day, hour, minute
161496
public static function get_fields_from_time($time) {
        $calendartype = \core_calendar\type_factory::get_calendar_instance();
        $wrongfields = $calendartype->timestamp_to_date_array($time);
        return array('day' => $wrongfields['mday'],
                'month' => $wrongfields['mon'], 'year' => $wrongfields['year'],
                'hour' => $wrongfields['hours'], 'minute' => $wrongfields['minutes']);
    }
151169
public static function createHighPrecision($time = null)
    {
        $dateTime = \DateTime::createFromFormat('U.u', $time ?: self::getMicrotime());
        
        $dateTime->setTimeZone(new \DateTimeZone(date_default_timezone_get()));
        
        return $dateTime;
    }
1195047
public function timeAgo($time = null, $format = null) {
		if (empty($time)) {
			$time = time();
		}
		if (empty($format)) {
			$format = '%x %X';
		}

		$result = $this->Html->tag(
			'time',
			$this->Time->i18nFormat($time, $format),
			[
				'data-toggle' => 'timeago',
				'datetime' => date('c', $this->Time->fromString($time)),
				'class' => 'help'
			]
		);

		return $result;
	}
479304
public static function formatMS($time): string
    {
        $time = round($time * 1000, 3);
        $dec = 3;

        if (!$time || $time >= 10 || $time >= 100) {
            $dec = 0;
        } elseif ($time < 10 && $time >= 0.1) {
            $dec = 1;
        } elseif ($time <= 0.01) {
            $dec = 3;
        }

        return number_format($time, $dec, '.', ' ') . ' ms';
    }
1245708
public function getValue($timestamp = null)
    {
        $values = $this->determine(is_int($timestamp) ? $timestamp : time());
        if (count($values) > 0 &&
            ($rate = max($values)) > 0
        ) {
            return $rate;
        }
        return $this->fallbackValue;
    }
712147
static public function nextSameWeekday($time) {
        $originalTime = strtotime($time);
        $nextWeekdayText = date("l");
        $nextWeekday = strtotime("next " . $nextWeekdayText);
        return strtotime(date("Y-m-d", $nextWeekday) . " " . date("H:i:s", $originalTime));
    }
850734
public function formatTime($time)
    {
        if ($this->timeFormat === null || $this->timeFormat === false) {
            return $time;
        }

        $dateTime = new \DateTime($time);

        if ($this->timeFormat === true) {
            return $dateTime;
        }

        return $dateTime->format($this->timeFormat);
    }
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;
    }
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);
    }
1065692
public function getTimestampDifference($time = null)
    {
        $time = (is_null($time)) ? $this->getCurrentTimestamp() : $time;

        return ($time - $this->initialTimestamp);
    }
48389
public static function timeStamp($time)
    {
        $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);

        //Second
        if ($seconds <= 60) {
            if ($seconds == 1) {
                return "$seconds second ago";
            } else {
                return "$seconds seconds ago";
            }
        }

        //Minutes
        elseif ($minutes <= 60) {
            if ($minutes == 1) {
                return "$minutes minute ago";
            } else {
                return "$minutes minutes ago";
            }
        }

        //Hours
        elseif ($hours <= 24) {
            if ($hours == 1) {
                return "$hours hour ago";
            } else {
                return "$hours hours ago";
            }
        }

        //Days
        elseif ($days <= 7) {
            if ($days = 1) {
                return "$days day ago";
            } else {
                return "$days days ago";
            }
        }

        //Weeks
        elseif ($weeks <= 4) {
            if ($weeks == 1) {
                return "$weeks week ago";
            } else {
                return "$weeks weeks ago";
            }
        }

        //Months
        elseif ($months <= 12) {
            if ($months == 1) {
                return "$months month ago";
            } else {
                return "$months months ago";
            }
        }

        //Years
        else {
            if ($years == 1) {
                return "$years year ago";
            } else {
                return "$years years ago";
            }
        }
    }
1205436
public static function factory($time = null, $timezone = null) {
        $timezone = static::timezone($timezone);

        if ($time instanceof DateTime) {
            return $time->setTimezone($timezone);
        }

        if (is_numeric($time)) {
            $time = '@' . $time;
        }

        $dt = new DateTime($time);
        $dt->setTimezone($timezone);

        return $dt;
    }
240157
protected function convertToDateTime( $time )
    {
        if ( $time instanceof DateTime )
        {
            return clone $time;
        }
        else if ( $time instanceof \DateTime )
        {
            return new DateTime( $time->format( \DateTime::ISO8601 ) );
        }
        else if ( is_numeric( $time ) )
        {
            return new DateTime( '@' . $time );
        }

        return new DateTime( (string) $time );
    }
419943
public static function getDate($time = null, $fmt = 'Y-m-d')
    {
        $times = $time?$time:time();
        return date($fmt, $times);
    }
1012389
public static function sql($time = null): string
    {
        return self::factory($time)->format(self::SQL_FORMAT);
    }
881611
protected function getFormatTime($time)
    {
        // Remaining times
        $hours = str_pad(floor($time / 60 / 60), 2, '0', STR_PAD_LEFT);
        $minutes = str_pad(floor(($time - ((int)$hours * 60 * 60)) / 60), 2, '0', STR_PAD_LEFT);
        $seconds = str_pad(floor(($time - ((int)$hours * 60 * 60) - ((int)$minutes * 60))), 2, '0', STR_PAD_LEFT);

        return "$hours:$minutes:$seconds";
    }
862423
public function setTime($time)
    {
        //argument 1 must be an integer or string
        Argument::i()->test(1, 'int', 'string');
        if (is_string($time)) {
            $time = strtotime($time);
        }

        $this->time = $time - $this->offset;
        return $this;
    }