Skip to content

Commit

Permalink
♻️ lint: Code Format with Pint.
Browse files Browse the repository at this point in the history
  • Loading branch information
anuzpandey committed May 11, 2024
1 parent b5d4070 commit 5d15d29
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 33 deletions.
18 changes: 10 additions & 8 deletions src/Helper/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
if (! function_exists('toNepaliDate')) {
/**
* The function converts a given date to the Nepali date format
* @param string|Carbon $date <p>The date parameter is a string that represents the date in the English calendar format.</p>
* @param string|null $format <p>The format parameter is used to specify the desired format of the Nepali date.</p>
* @param string $locale <p>The "locale" parameter is used to specify the language and region. Supported languages are <i>en</i> and <i>np</i></p>
*
* @param string|Carbon $date <p>The date parameter is a string that represents the date in the English calendar format.</p>
* @param string|null $format <p>The format parameter is used to specify the desired format of the Nepali date.</p>
* @param string $locale <p>The "locale" parameter is used to specify the language and region. Supported languages are <i>en</i> and <i>np</i></p>
* @return string <p>Nepali date converted from the given English Date.</p>
*/
function toNepaliDate(string|Carbon $date, string $format = null, string $locale = null): string
function toNepaliDate(string|Carbon $date, ?string $format = null, ?string $locale = null): string
{
return LaravelNepaliDate::from($date)
->toNepaliDate(
Expand All @@ -24,12 +25,13 @@ function toNepaliDate(string|Carbon $date, string $format = null, string $locale
if (! function_exists('toEnglishDate')) {
/**
* The function converts a given date to the English date format
* @param $date <p>The date parameter is a string that represents the date in the Nepali calendar format.</p>
* @param string $format <p>The format parameter is used to specify the desired format of the English date.</p>
* @param string $locale <p>The "locale" parameter is used to specify the language and region. Supported languages are <i>en</i> and <i>np</i></p>
*
* @param $date <p>The date parameter is a string that represents the date in the Nepali calendar format.</p>
* @param string $format <p>The format parameter is used to specify the desired format of the English date.</p>
* @param string $locale <p>The "locale" parameter is used to specify the language and region. Supported languages are <i>en</i> and <i>np</i></p>
* @return string <p>English date converted from the given Nepali Date.</p>
*/
function toEnglishDate(string|Carbon $date, string $format = null, string $locale = null): string
function toEnglishDate(string|Carbon $date, ?string $format = null, ?string $locale = null): string
{
return LaravelNepaliDate::from($date)
->toEnglishDate(
Expand Down
4 changes: 1 addition & 3 deletions src/LaravelNepaliDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ class LaravelNepaliDate

public function __construct(
public string|Carbon $date,
)
{
) {
}


public static function from(string|Carbon $date): LaravelNepaliDate
{
$parsedDate = ($date instanceof Carbon)
Expand Down
3 changes: 0 additions & 3 deletions src/Mixin/NepaliDateMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
class NepaliDateMixin
{

public function toNepaliDate(): Closure
{
return function (?string $format = 'Y-m-d', ?string $locale = 'np') {
Expand All @@ -21,7 +20,6 @@ public function toNepaliDate(): Closure
};
}


public function toEnglishDate(): Closure
{
return function (?string $format = 'Y-m-d', ?string $locale = 'en') {
Expand All @@ -30,5 +28,4 @@ public function toEnglishDate(): Closure
return LaravelNepaliDate::from($date)->toEnglishDate($format, $locale);
};
}

}
6 changes: 3 additions & 3 deletions src/Traits/EnglishDateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ trait EnglishDateTrait
9 => '9',
];

public function toEnglishDate(string $format = null, string $locale = null): string
public function toEnglishDate(?string $format = null, ?string $locale = null): string
{
$checkIfIsInRange = $this->isInNepaliDateRange($this->date);

Expand Down Expand Up @@ -169,8 +169,8 @@ public function performCalculationBasedOnNepaliDays(string|int $totalNepaliDays)
}

$this->englishYear = $_year;
$this->englishMonth = $_month > 9 ? $_month : '0' . $_month;
$this->englishDay = $totalEnglishDays > 9 ? $totalEnglishDays : '0' . $totalEnglishDays;
$this->englishMonth = $_month > 9 ? $_month : '0'.$_month;
$this->englishDay = $totalEnglishDays > 9 ? $totalEnglishDays : '0'.$totalEnglishDays;
$this->dayOfWeek = $_day;
}

Expand Down
11 changes: 4 additions & 7 deletions src/Traits/HelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function convertEnToNpNumber($number): array|string
return str_replace($en_number, $np_number, $number);
}


public function convertEnToNpWord($word): array|string
{
$en_word = [
Expand Down Expand Up @@ -82,7 +81,6 @@ public function convertEnToNpWord($word): array|string
return str_replace($en_word, $np_word, $word);
}


public function getFormattedString(string $format, array $formatData, string $locale): string
{
$formattedString = '';
Expand All @@ -92,7 +90,9 @@ public function getFormattedString(string $format, array $formatData, string $lo

if (array_key_exists($char, $formatData)) {
if ($locale === 'np') {
if ($char === 'S') continue;
if ($char === 'S') {
continue;
}
$formattedString .= $formatData[$char];
} else {
if ($char === 'S') {
Expand All @@ -105,10 +105,10 @@ public function getFormattedString(string $format, array $formatData, string $lo
$formattedString .= $char;
}
}

return $formattedString;
}


public function getOrdinalSuffix(int $number): string
{
if ($number % 100 >= 11 && $number % 100 <= 13) {
Expand All @@ -123,7 +123,6 @@ public function getOrdinalSuffix(int $number): string
};
}


private function getNepaliLocaleFormattingCharacters(NepaliDateArrayData $nepaliDateArray): array
{
return [
Expand All @@ -139,7 +138,6 @@ private function getNepaliLocaleFormattingCharacters(NepaliDateArrayData $nepali
];
}


private function getEnglishLocaleFormattingCharacters(NepaliDateArrayData $nepaliDateArray): array
{
return [
Expand All @@ -155,7 +153,6 @@ private function getEnglishLocaleFormattingCharacters(NepaliDateArrayData $nepal
];
}


private function formatDateString(string $format, string $locale, $dateArray): string
{
$formattedArray = ($locale === 'en')
Expand Down
7 changes: 3 additions & 4 deletions src/Traits/NepaliDateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ trait NepaliDateTrait
9 => '',
];

public function toNepaliDate(string $format = null, string $locale = null): string
public function toNepaliDate(?string $format = null, ?string $locale = null): string
{
$this->performCalculationOnEnglishDate();

Expand All @@ -80,8 +80,8 @@ public function toFormattedNepaliDate(string $format, string $locale): string

public function toNepaliDateArray(): NepaliDateArrayData
{
$nepaliMonth = $this->nepaliMonth > 9 ? $this->nepaliMonth : '0' . $this->nepaliMonth;
$nepaliDay = $this->nepaliDay > 9 ? $this->nepaliDay : '0' . $this->nepaliDay;
$nepaliMonth = $this->nepaliMonth > 9 ? $this->nepaliMonth : '0'.$this->nepaliMonth;
$nepaliDay = $this->nepaliDay > 9 ? $this->nepaliDay : '0'.$this->nepaliDay;

return NepaliDateArrayData::from([
'year' => $this->nepaliYear,
Expand Down Expand Up @@ -231,5 +231,4 @@ private function isInEnglishDateRange(Carbon $date): string|bool

return true;
}

}
4 changes: 1 addition & 3 deletions tests/ConvertToEnglishDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
['2022-12-20', '1966-04-02'],
]);


it('can convert to nepali formatted result', function (string $format, string $locale, string $expectedResult) {
$date = '2053-01-10';

Expand All @@ -40,9 +39,8 @@
['2022-12-20', '1966-04-02'],
]);


it('can convert to nepali formatted result to english date with helper function', function (string $format, string $locale, string $expectedResult) {
expect(toEnglishDate("2053-01-10", $format, $locale))
expect(toEnglishDate('2053-01-10', $format, $locale))
->toBe($expectedResult);
})->with([
['d F Y, l', 'np', '२२ अप्रिल १९९६, सोमबार'],
Expand Down
3 changes: 1 addition & 2 deletions tests/ConvertToNepaliDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
['Y/m/d', 'np', '२०५३/०१/१०'],
]);


it('can convert to basic nepali date with helper function toNepaliDate', function (string $date, string $expectedResult) {
expect(toNepaliDate($date))
->toBe($expectedResult);
Expand All @@ -41,7 +40,7 @@
]);

it('can convert to nepali formatted result with helper function toNepaliDate', function (string $format, string $locale, string $expectedResult) {
expect(toNepaliDate("1996-04-22", $format, $locale))
expect(toNepaliDate('1996-04-22', $format, $locale))
->toBe($expectedResult);
})->with([
['d F Y, l', 'np', '१० वैशाख २०५३, सोमबार'],
Expand Down

0 comments on commit 5d15d29

Please sign in to comment.