Fix : date before 2000 throws an exception

This commit is contained in:
sparkyx 2021-10-21 23:46:52 +02:00
parent 6f8265689a
commit b0f58ab592
2 changed files with 52 additions and 2 deletions

View file

@ -240,7 +240,7 @@ function isDate($p_date)
{
if (strlen(trim($p_date)) == 0)
return null;
if (preg_match("/^[0-9]{1,2}\.[0-9]{1,2}\.20[0-9]{2}$/", $p_date) == 0)
if (preg_match("/^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4}$/", $p_date) == 0)
{
return null;

View file

@ -1,4 +1,4 @@
<?php
2<?php
use PHPUnit\Framework\TestCase;
@ -204,4 +204,54 @@ class Ac_CommonTest extends TestCase
$this->assertEquals($text,$text);
}
/**
* provides data to testIsDate
*/
function dataIsDate()
{
return array(
['01.01.1992',1],
['30.02.2001',0],
['15.07.01',0],
['21.08.2001',1]
);
}
/**
* @covers IsDate
* @testdox isDate
* @dataProvider dataIsDate
*/
function testIsDate($p_date,$expected)
{
$return=($expected==1)?$p_date:null;
$this->assertEquals(isDate($p_date),$return,"Test $p_date");
}
function dataCompareDate ()
{
return array(
['01.01.1992','05.02.2001',-1],
['01.01.2012','05.02.2001',1],
['05.02.2001','05.02.2001',0]);
}
/**
* @covers cmpDate
* @testDox test cmpDate
* @dataProvider dataCompareDate
*/
function testCompareDate($p_date,$p_date_2,$p_result)
{
$cmp=cmpDate($p_date,$p_date_2);
switch ( $p_result ) {
case 0:
$this->assertEquals($cmp,0);
break;
case 1:
$this->assertGreaterThan(0,$cmp);
break;
case -1:
$this->assertLessThan(0,$cmp);
break;
}
}
}