summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it.class12
-rwxr-xr-xtests/it.t11
2 files changed, 17 insertions, 6 deletions
diff --git a/it.class b/it.class
index 64a2f51..f514537 100644
--- a/it.class
+++ b/it.class
@@ -859,6 +859,14 @@ static function gets()
}
/**
+ * Like time() but overridable via debug param
+ */
+function time()
+{
+ return ($t = EDC('time')) ? strtotime($t) : time();
+}
+
+/**
* Output formatted and localized date
* @param format optional format (default is 2007-01-02 03:04:05).
* Other formats are "date", "datetime", "time".
@@ -870,9 +878,9 @@ static function gets()
static function date($format = "", $stamp = null)
{
if (!isset($stamp))
- $stamp = EDC('time') ? strtotime(EDC('time')) : time();
+ $stamp = it::time();
else if (is_string($stamp) && !ctype_digit($stamp))
- $stamp = strtotime($stamp);
+ $stamp = strtotime($stamp, it::time());
list($name, $language) = explode(":", $format);
diff --git a/tests/it.t b/tests/it.t
index 3b69072..4cf61c1 100755
--- a/tests/it.t
+++ b/tests/it.t
@@ -333,12 +333,15 @@ is(
# it::date tests
+$GLOBALS['debug_time'] = "2014-01-01";
+is(it::date(), "2014-01-01 00:00:00");
+
is(it::date('date', '2011-10-25'), '25.10.2011', 'parse date string with strtotime');
is(it::date('date', '2011-10-25 + 3 days'), '28.10.2011', 'some date arithmetic');
-is(it::date('datetime', time()), it::date('datetime'), 'recognize int as timestamp');
-is(it::date('datetime', time()*1.0), it::date('datetime'), 'recognize float as timestamp');
-is(it::date('datetime', time() . ''), it::date('datetime'), 'recognize digit string as timestamp');
-is(it::date('datetime', '@' . time()), it::date('datetime'), 'recognize strtotime timestamp format');
+is(it::date('datetime', it::time()), it::date('datetime'), 'recognize int as timestamp');
+is(it::date('datetime', it::time()*1.0), it::date('datetime'), 'recognize float as timestamp');
+is(it::date('datetime', it::time() . ''), it::date('datetime'), 'recognize digit string as timestamp');
+is(it::date('datetime', '@' . it::time()), it::date('datetime'), 'recognize strtotime timestamp format');
is(it::date('datetime', 10), it::date('datetime', "10"), 'numeric and string give same result');
is(it::date('datetime', 10.0), it::date('datetime', "10"), '... as long as num is properly truncated');
is(it::date('datetime', 10.5), it::date('datetime', "10"), '... with one digit after point');