-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
46 lines (43 loc) · 1.46 KB
/
api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
//funció per calcular temps passat des d'una data
//format: "yyyy-mm-dd hh:MM:ss"
function time_ago($time) {
$time_ago = strtotime($time);
$cur_time = time();
$time_elapsed = $cur_time - $time_ago;
$seconds = $time_elapsed ;
$minutes = round($time_elapsed / 60 );
$hours = round($time_elapsed / 3600);
$days = round($time_elapsed / 86400 );
$weeks = round($time_elapsed / 604800);
$months = round($time_elapsed / 2600640 );
$years = round($time_elapsed / 31207680 );
if($seconds<0){
return "future";
}else if($seconds <= 60){
return "less than a minute ago";
}else if($minutes <=60){
if($minutes==1){ return "a minute ago"; }
else{ return "$minutes minutes ago"; }
}else if($hours <=24){
if($hours==1){ return "an hour ago"; }
else{ return "$hours hours ago"; }
}else if($days <= 7){
if($days==1){ return "yesterday"; }
else{ return "$days days ago";}
}else if($weeks <= 4.3){
if($weeks==1){ return "a week ago"; }
else{ return "$weeks weeks ago"; }
}else if($months <=12){
if($months==1){ return "a month ago"; }
else{ return "$months months ago"; }
}else{
if($years==1){ return "one year ago"; }
else{ return "$years years ago"; }
}
}
$t = filemtime("index.html"); //numero
$ts = strftime("%Y-%m-%d %H:%M:%S",$t); //string
$ta = time_ago($ts); //string
echo "$ts ($ta)";
?>