summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Helbling2017-02-07 16:54:52 +0100
committerChristian Helbling2017-02-07 16:54:52 +0100
commite5aac2298465e3b78398af5b17198bc527ca3d33 (patch)
tree3961eab1e50cf44406a0ec9ec257c3fd51647fb3
parentf82923f96c15e957f4265f21597cd2cdc994482f (diff)
downloaditools-e5aac2298465e3b78398af5b17198bc527ca3d33.tar.gz
itools-e5aac2298465e3b78398af5b17198bc527ca3d33.tar.bz2
itools-e5aac2298465e3b78398af5b17198bc527ca3d33.zip
allow .time-1527 and .time-152715 as time formats for time debug parameter, add more tests for it::time()
-rw-r--r--it.class2
-rwxr-xr-xtests/it.t15
2 files changed, 14 insertions, 3 deletions
diff --git a/it.class b/it.class
index 34f0bf6..55d57db 100644
--- a/it.class
+++ b/it.class
@@ -901,7 +901,7 @@ static function gets()
*/
static function time()
{
- return ($t = EDC('time')) ? strtotime(rtrim(it::replace(array('(\d\d\d\d)-(\d\d)-(\d\d)-(\d\d)-(\d\d)(-(\d\d))?' => '$1-$2-$3 $4:$5:$7', '^(\d\d)-(\d\d)(-(\d\d))?' => 'today $1:$2:$4'), $t), ":")) : time();
+ return ($t = EDC('time')) ? strtotime(rtrim(it::replace(array('(\d\d\d\d)-(\d\d)-(\d\d)-(\d\d)-(\d\d)(-(\d\d))?' => '$1-$2-$3 $4:$5:$7', '^(\d\d)-?(\d\d)(-?(\d\d))?$' => 'today $1:$2:$4'), $t), ":")) : time();
}
/**
diff --git a/tests/it.t b/tests/it.t
index 88fbbb9..e028f27 100755
--- a/tests/it.t
+++ b/tests/it.t
@@ -344,8 +344,19 @@ is(
# it::date tests
-$GLOBALS['debug_time'] = "2014-01-01";
-is(it::date(), "2014-01-01 00:00:00");
+function _time($debug_time, $expected)
+{
+ $GLOBALS['debug_time'] = $debug_time;
+ is(it::date(), $expected, ".time-$debug_time");
+ $GLOBALS['debug_time'] = '';
+}
+_time("2014-01-01", "2014-01-01 00:00:00");
+_time("2014-01-01-15-27-15", "2014-01-01 15:27:15");
+_time("15-27", it::date('', '15:27'));
+_time("1527", it::date('', '15:27'));
+_time("15-27-15", it::date('', '15:27:15'));
+_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');