Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
phattarachai committed Jun 7, 2021
1 parent e276ce0 commit 4a75908
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Thaidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function date(string $format, int $timestamp, bool $buddhistEra): string

$format = $this->parseYear($format, $timestamp, $buddhistEra);


return date($format, $timestamp);
}

Expand Down Expand Up @@ -103,7 +104,9 @@ private function parseYear(string $format, $timestamp, bool $buddhistEra): strin
}

if (str_contains($format, 'y')) {
return str_replace('y', (date('y', $timestamp) + 43), $format);

$year = (date('y', $timestamp) + 43) % 100;
return str_replace('y', $year, $format);
}

return $format;
Expand Down
16 changes: 16 additions & 0 deletions tests/ThaidateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ public function convert_short_date_and_month()
$this->assertEquals('พฤ. 25 ก.พ. 64', $result);
}

/** @test */
public function convert_my_short_birth_date()
{
$result = thaidate('D j M y', strtotime('1987-11-28'));

$this->assertEquals('ส. 28 พ.ย. 30', $result);
}

/** @test */
public function convert_my_short_34_years_old()
{
$result = thaidate('D j M y', strtotime('2021-11-28'));

$this->assertEquals('อา. 28 พ.ย. 64', $result);
}

/** @test */
public function convert_from_timestampe()
{
Expand Down

0 comments on commit 4a75908

Please sign in to comment.