Skip to content

Commit ebfb53e

Browse files
authored
Merge pull request #40 from victorgso001/feature/ptDate2IsoDate-adjusts
Adjusts and tests for ptDate2IsoDate function
2 parents bd13777 + 743cbbd commit ebfb53e

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public static function ptDate2IsoDate($date)
171171
$fDate = explode('/', $date);
172172

173173
if (count($fDate) < 3) {
174-
$fDate = $date;
174+
return null;
175175
} else {
176176
if (strlen($fDate[2])<4) {
177177
if (intval($fDate[2])>30) {

tests/HelpersTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,19 @@ public function testMaskCnpj()
174174
$this->assertEquals(Helpers::maskCnpj($right), '11.222.333/4444-55');
175175
$this->assertNull(Helpers::maskCnpj($wrong));
176176
}
177+
178+
public function testPtDate2IsoDate()
179+
{
180+
$date = '01/02/2003';
181+
$other_date = '01/02/03';
182+
$incomplete_date = '01/02';
183+
$another_incomplete_date = '01/2002';
184+
$wrong_input = 'string';
185+
186+
$this->assertEquals(Helpers::ptDate2IsoDate($date), '2003-02-01');
187+
$this->assertEquals(Helpers::ptDate2IsoDate($other_date), '2003-02-01');
188+
$this->assertNull(Helpers::ptDate2IsoDate($incomplete_date));
189+
$this->assertNull(Helpers::ptDate2IsoDate($another_incomplete_date));
190+
$this->assertNull(Helpers::ptDate2IsoDate($wrong_input));
191+
}
177192
}

0 commit comments

Comments
 (0)