Added comments

This commit is contained in:
Lars van Hijfte
2017-02-03 12:12:16 +01:00
parent 1fd984cc02
commit 3aae884bb5
6 changed files with 211 additions and 8 deletions

View File

@@ -1,9 +1,16 @@
<?php
/**
* Return a relative dutch and readable text when given a datetime.
* @param $date
* @return string
*/
function nicetime($date) {
if(empty($date)) {
return "No date provided";
}
// Create dutch arrays so it has dutch words.
$single_periods = array("seconde", "minuut", "uur", "dag", "week", "maand", "jaar", "decennium");
$multiple_periods = array("seconden", "minuten", "uur", "dagen", "weken", "maanden", "jaar", "decennia");
$lengths = array("60", "60", "24", "7", "4.35", "12", "10", "0");
@@ -15,7 +22,8 @@ function nicetime($date) {
return "Bad date";
}
if($now > $unix_date) {
// Check if it is in the future or not.
if($now >= $unix_date) {
$difference = $now - $unix_date;
$tense = "geleden";
} else {
@@ -23,6 +31,7 @@ function nicetime($date) {
$tense = "vanaf nu";
}
// Get the nice time.
for($i = 0; $difference >= $lengths[$i] && $i < count($lengths) - 1; $i++) {
$difference /= $lengths[$i];
}