summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it.class2
-rwxr-xr-xtest/it.t14
2 files changed, 14 insertions, 2 deletions
diff --git a/it.class b/it.class
index 8375b83..f302bce 100644
--- a/it.class
+++ b/it.class
@@ -1044,7 +1044,7 @@ static function date($format = "", $stamp = null)
if (!isset($stamp))
$stamp = it::time();
else if (is_string($stamp) && !ctype_digit($stamp))
- $stamp = strtotime($stamp, it::time());
+ $stamp = strtotime(it::replace(['\s(--|\+\+)\s*(\d)' => ' +\2', '\s(\+-|-\+)\s*(\d)' => ' -\2'], $stamp), it::time());
list($name, $language) = explode(":", $format);
diff --git a/test/it.t b/test/it.t
index 41758da..34279ce 100755
--- a/test/it.t
+++ b/test/it.t
@@ -388,7 +388,19 @@ _time("152715", it::date('', '15:27:15'));
_time("yesterday", it::date('', 'yesterday'));
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('date', '2011-10-25 + 3 days'), '28.10.2011', 'date arithmetic (add)');
+is(it::date('date', '2011-10-25 - 3 days'), '22.10.2011', 'date arithmetic (subtract)');
+is(it::date('date', '2011-10-25 +-3 days'), '22.10.2011', 'date arithmetic (negative value)');
+is(it::date('date', '2011-10-25 --3 days'), '28.10.2011', 'date arithmetic (double negative)');
+is(it::date('date', '2011-10-25 ++ 3 days'), '28.10.2011', 'date arithmetic (double positive with space)');
+is(it::date('date', '2011-10-25 -+ 3 days'), '22.10.2011', 'date arithmetic (negative positive with space)');
+is(it::date('datetime', '2011-10-25 +12 hours +30 minutes'), '25.10.2011 12:30', 'datetime arithmetic (hours minutes)');
+is(it::date('datetime', '2011-10-25 +24 hours +30 minutes'), '26.10.2011 00:30', 'datetime arithmetic (hours minutes over midnight)');
+is(it::date('datetime', '2011-10-25 8:00 +10 minutes'), '25.10.2011 08:10', 'time arithmetic (add)');
+is(it::date('datetime', '2011-10-25 8:00 -10 minutes'), '25.10.2011 07:50', 'time arithmetic (subtract)');
+is(it::date('datetime', '2011-10-25 8:00 +-10 minutes'), '25.10.2011 07:50', 'time arithmetic (negative value)');
+is(it::date('datetime', '2011-10-25 8:00 --10 minutes'), '25.10.2011 08:10', 'time arithmetic (double negative)');
+is(it::date('datetime', '2011-10-25 --1 month --3 days 8:00 +- 4 hours +-10 minutes'), '28.11.2011 03:50', 'date and time arithmetic (multiple signs)');
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');