How to reduce the withdrawal date from a php script?

Help, there's a php script:

<?php
if( ! defined( 'DATALIFEENGINE' ) ) { die( "Hacking attempt!" ); }

function plural($n, $plurals) {
 $plural =
 ($n % 10 == 1 && $n % 100 != 11 ? 0 :
 ($n % 10 >= 2 && $n % 10 <= 4 &&
 ($n % 100 < 10 or $n % 100 >= 20) ? 1 : 2));
 return $plurals[$plural];
}

function relativeTime($dt, $precision = 2) {
 $times = array(
 365*24*60*60 => array("year", "year", "years"),
 30*24*60*60 => array("month", "month", "months"),
 7*24*60*60 => array("week", "weeks", "weeks"),
 24*60*60 => array("day", "day", "days"),
 60*60 => array("hour", "hour", "hours"),
 60 => array("minute", "minute", "minutes"),
);

 $diff = time() - $dt;

 if($diff < 60) $output='less than a minute';
 else {
 $output = array();
 $exit = 0;

 foreach($times as $period => $name) {

 if($exit >= $precision || ($exit > 0 && $period < 60)) break;
 $result = floor($diff / $period);

 if ($result > 0) {
 if($result == 1) $output[] = plural($result, $name);
 else $output[] = $result . '' . plural($result, $name);

 $diff -= $result * $period;
$exit++;
 } else if ($exit > 0) $exit++;
}
 if ($precision < 3) $sep = " and "; else $sep = ", ";

 $output = implode($sep, $output);
}
 return $output;
}

?>


It displays on the website a human understandable date.
For example:
day and 9 hours ago
a week and a day ago
3 weeks and 3 days ago
a month and a week ago
2 months and 3 weeks ago

How to reduce the script that you want to remove from the script to this:
Is day and 9 hours ago become day ago
Instead of a week and a day ago was a week ago
Instead of 3 weeks and 3 days ago was 3 weeks ago
Is a month and a week ago was a month ago
Is 2 months and 3 weeks ago was 2 months ago

Not enough knowledge to fix it as soon as did not try.
April 3rd 20 at 17:35
2 answers
April 3rd 20 at 17:37
Solution
It was easy.

Replace
function relativeTime($dt, $precision = 2) {
On
function relativeTime($dt, $precision = 1) {
April 3rd 20 at 17:39
In the morning I did not want to code to look - did the regular season https://regex101.com/r/xTZaho/1

Find more questions by tags PHP