aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaZderMind2015-12-02 18:17:18 +0100
committerMaZderMind2015-12-02 18:17:18 +0100
commit9d434af7f2ce972a65043d5fa3c7f476b91c1fda (patch)
tree984d0a33e8b61a3b2b3c2bd847a551c5f8bc3a6e /lib
parent8a4fc337510ddaeb8ea3f27b7b5e807416c001ae (diff)
generate closed-page countdown on server-side
Diffstat (limited to 'lib')
-rw-r--r--lib/helper.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/helper.php b/lib/helper.php
index 0d4d868..6635fb1 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -61,3 +61,34 @@ function handle_lesscss_request($lessfile, $relative_path)
header('Content-Length: '.strlen($css));
print($css);
}
+
+function days_diff($date)
+{
+ $seconds = strtotime( $date ) - time();
+ $days = intval(ceil($seconds / 60 / 60 / 24));
+ return $days;
+}
+
+function days_diff_readable($date)
+{
+ $days = days_diff($date);
+ if($days == -1)
+ return 'yesterday';
+
+ if($days == 0)
+ return 'today';
+
+ if($days == 1)
+ return 'tomorrow';
+
+ if($days < -60)
+ return round(-$days / 30)." months ago";
+
+ if($days < 0)
+ return "$days days ago";
+
+ if($days > 60)
+ return 'in '.round($days / 30)." months";
+
+ return "in $days days";
+}