"\'()]+)~i', function($matches) use ($link_attrs) { global $config; $escaped_url = rtrim($matches[1], '.,!?;:)]}>'); $clean_url = html_entity_decode($escaped_url, ENT_QUOTES, 'UTF-8'); $tabIndex = $config->strictAccessibility ? ' tabindex="0" ' : ' '; return '' . $escaped_url . ''; }, $text ); } // For relative time display, compare the stored time to the current time // and display it as "X seconds/minutes/hours/days etc." ago // // TODO: Convert to either accepting a DateTime or use DateTime->fromFormat() public static function relative_time(string $tickTime): string { $datetime = new DateTime($tickTime); $now = new DateTime('now', $datetime->getTimezone()); $diff = $now->diff($datetime); if ($diff->y > 0) { return $diff->y . ' year' . ($diff->y > 1 ? 's' : '') . ' ago'; } if ($diff->m > 0) { return $diff->m . ' month' . ($diff->m > 1 ? 's' : '') . ' ago'; } if ($diff->d > 0) { return $diff->d . ' day' . ($diff->d > 1 ? 's' : '') . ' ago'; } if ($diff->h > 0) { return $diff->h . ' hour' . ($diff->h > 1 ? 's' : '') . ' ago'; } if ($diff->i > 0) { return $diff->i . ' minute' . ($diff->i > 1 ? 's' : '') . ' ago'; } return $diff->s . ' second' . ($diff->s != 1 ? 's' : '') . ' ago'; } }