Skip to content

Commit

Permalink
Merge pull request #40 from victorgso001/feature/ptDate2IsoDate-adjusts
Browse files Browse the repository at this point in the history
Adjusts and tests for ptDate2IsoDate function
  • Loading branch information
esron authored Oct 7, 2020
2 parents bd13777 + 743cbbd commit ebfb53e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static function ptDate2IsoDate($date)
$fDate = explode('/', $date);

if (count($fDate) < 3) {
$fDate = $date;
return null;
} else {
if (strlen($fDate[2])<4) {
if (intval($fDate[2])>30) {
Expand Down
15 changes: 15 additions & 0 deletions tests/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,19 @@ public function testMaskCnpj()
$this->assertEquals(Helpers::maskCnpj($right), '11.222.333/4444-55');
$this->assertNull(Helpers::maskCnpj($wrong));
}

public function testPtDate2IsoDate()
{
$date = '01/02/2003';
$other_date = '01/02/03';
$incomplete_date = '01/02';
$another_incomplete_date = '01/2002';
$wrong_input = 'string';

$this->assertEquals(Helpers::ptDate2IsoDate($date), '2003-02-01');
$this->assertEquals(Helpers::ptDate2IsoDate($other_date), '2003-02-01');
$this->assertNull(Helpers::ptDate2IsoDate($incomplete_date));
$this->assertNull(Helpers::ptDate2IsoDate($another_incomplete_date));
$this->assertNull(Helpers::ptDate2IsoDate($wrong_input));
}
}

0 comments on commit ebfb53e

Please sign in to comment.