diff options
-rw-r--r-- | it.class | 4 | ||||
-rwxr-xr-x | test/it.t | 4 |
2 files changed, 7 insertions, 1 deletions
@@ -1054,12 +1054,14 @@ static function time() * Formats can be qualified with language, e.g. "date:en" * Special formats without language support are "icsdate", "icsdatetime". * @param stamp optional unix timestamp (default is now). - * If it contains nondigits, it is fed to strtotime + * If it contains nondigits or is a plausible 8 digit date YYYYMMDD, it is fed to strtotime */ static function date($format = "", $stamp = null) { if (!isset($stamp)) $stamp = it::time(); + else if (ctype_digit((string)$stamp) && 19000000 < $stamp && $stamp < 21000000) + $stamp = strtotime($stamp); else if (is_string($stamp) && !ctype_digit($stamp)) $stamp = strtotime(it::replace(['\s(--|\+\+)\s*(\d)' => ' +\2', '\s(\+-|-\+)\s*(\d)' => ' -\2'], $stamp), it::time()); @@ -420,6 +420,10 @@ is(it::date('datetime', 1000000), it::date('datetime', "1000000"), '... large nu is(it::date('datetime', 1000000.543), it::date('datetime', "1000000"), '... large nummer and point'); is(it::date('time', "10.5"), "10:05", 'interpret string with points with strtotime'); is(it::date('time', "10.05"), "10:05", 'interpret string with points with strtotime'); +is(it::date('Y-m-d', "20000101"), '2000-01-01', 'interpret 8 digit strings as dates'); +is(it::date('Y-m-d', 20000101), '2000-01-01', 'interpret 8 numbers strings as dates'); +is(it::date('Y-m-d', "20990101"), '2099-01-01', 'interpret 8 digit strings as dates'); +is(it::date('Y-m-d', strtotime("1980-01-01")), '1980-01-01', 'interpret typical time stamps correctly'); # it::uc* is(it::ucfirst('foo bär über'), 'Foo bär über'); |