Skip to content
Browse files

Pretty date fix. 0000-00-00 is "never".

  • Loading branch information...
1 parent 592bc0b commit 6de929a3f12d152ad93c9960184a759346a3a8da @codefocus committed Jul 24, 2011
Showing with 12 additions and 13 deletions.
  1. +1 −1 plugins/durabledns/durabledns.php
  2. +11 −12 plugins/template/modifiers/date.php
View
2 plugins/durabledns/durabledns.php
@@ -1,4 +1,4 @@
-<?php
+TEST<?php
/**
* Durabledns plugin.
View
23 plugins/template/modifiers/date.php
@@ -16,10 +16,6 @@ class TemplateModifierDate extends TemplateModifier {
const YEAR = 31536000; // 365 days
-
-
-
-
/**
* run function.
*
@@ -66,6 +62,8 @@ public static function friendly($value, $language='en') {
static $i18n = array(
'en' => array(
'in the future' => 'in the future',
+ 'now' => 'now',
+ 'never' => 'never',
'yesterday' => 'yesterday',
'a' => 'a',
'an' => 'an',
@@ -88,6 +86,8 @@ public static function friendly($value, $language='en') {
),
'nl' => array(
'in the future' => 'in de toekomst',
+ 'now' => 'nu',
+ 'never' => 'nooit',
'yesterday' => 'gisteren',
'a' => 'een',
'an' => 'een',
@@ -110,15 +110,14 @@ public static function friendly($value, $language='en') {
),
);
-
-
+
// Format date if necessary
if (!is_numeric($value)) {
$value = strtotime($value);
}
if (false === $value) {
- throw new WhipPluginException('Unexpected date format: '.$value);
- return false;
+ // 0000-00-00 00:00:00 is Never
+ return $i18n[$language]['never'];
}
// Calculate the difference
$time_now = time();
@@ -127,6 +126,10 @@ public static function friendly($value, $language='en') {
// Future
return $i18n[$language]['in the future'];
}
+ elseif ($difference < 10*self::SECOND) {
+ // Now
+ return $i18n[$language]['now'];
+ }
elseif ($difference < self::MINUTE) {
// x seconds
if (1===$difference) {
@@ -176,9 +179,5 @@ public static function friendly($value, $language='en') {
return ceil($difference/self::YEAR).' '.$i18n[$language]['years'].' '.$i18n[$language]['ago'];
}
} // function friendly
-
-
} // Date
-
-

0 comments on commit 6de929a

Please sign in to comment.
Something went wrong with that request. Please try again.