summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2025-03-26 15:18:32 +0100
committerUrban Müller2025-03-26 15:18:41 +0100
commiteac020907afced2c33db53b564a80e4764dfe3b7 (patch)
treec51b6e77ae51cc27fae76466908966461f7a06c2
parent470fef0c3b772bf24ed161641ae9d2bd92fac4fa (diff)
downloaditools-master.tar.gz
itools-master.tar.bz2
itools-master.zip
allow 20241212 is second arg of it::dateHEADmaster
-rw-r--r--it.class4
-rwxr-xr-xtest/it.t4
2 files changed, 7 insertions, 1 deletions
diff --git a/it.class b/it.class
index b93d49a..a114e35 100644
--- a/it.class
+++ b/it.class
@@ -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());
diff --git a/test/it.t b/test/it.t
index 535f185..6ea1859 100755
--- a/test/it.t
+++ b/test/it.t
@@ -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');