Skip to content

Commit

Permalink
Added persian numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadRasoul Fekri committed Feb 18, 2020
1 parent c89ea43 commit 299a905
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Date
/* allowed numbers values */
const ARABIC_NUMBERS = 0;
const INDIAN_NUMBERS = 1;
const PERSIAN_NUMBERS = 2;

/**
* @var string
Expand Down Expand Up @@ -175,6 +176,13 @@ class Date
*/
protected $arabicNumbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

/**
* Persian numbers
*
* @var array
*/
protected $persianNumbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];

/**
* @var Carbon
*/
Expand Down Expand Up @@ -350,6 +358,10 @@ public function format(string $format = null, int $numbers = null)
{
$dateString = str_replace($this->arabicNumbers, $this->indianNumbers, $dateString);
}
elseif ($numbers === static::PERSIAN_NUMBERS)
{
$dateString = str_replace($this->arabicNumbers, $this->persianNumbers, $dateString);
}

return $dateString;
}
Expand Down

0 comments on commit 299a905

Please sign in to comment.