Skip to content

Commit

Permalink
🔨 fix: codestyle with pint | remove config and support for php < 8.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
anuzpandey committed Oct 24, 2023
1 parent 41cc40e commit fd692cb
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 113 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"php": "^7.4|^8.0",
"php": "^8.1",
"spatie/laravel-package-tools": "^1.14.0",
"illuminate/contracts": "^10.0"
},
Expand Down
6 changes: 0 additions & 6 deletions config/nepali-date.php

This file was deleted.

7 changes: 1 addition & 6 deletions src/DataTransferObject/NepaliDateArrayData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class NepaliDateArrayData
{

public function __construct(
public readonly string $year,
public readonly string $month,
Expand All @@ -16,11 +15,9 @@ public function __construct(
public readonly string $monthName,
public readonly string $npDayName,
public readonly string $npMonthName,
)
{
) {
}


public static function from(array $data): self
{
return new self(
Expand All @@ -37,7 +34,6 @@ public static function from(array $data): self
);
}


public function toArray(): array
{
return [
Expand All @@ -53,5 +49,4 @@ public function toArray(): array
'npMonthName' => $this->npMonthName,
];
}

}
14 changes: 4 additions & 10 deletions src/LaravelNepaliDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,28 @@

namespace Anuzpandey\LaravelNepaliDate;

use Anuzpandey\LaravelNepaliDate\DataTransferObject\NepaliDateArrayData;
use Anuzpandey\LaravelNepaliDate\Traits\CalendarDateDataTrait;
use Anuzpandey\LaravelNepaliDate\Traits\DiffForHumsTrait;
use Anuzpandey\LaravelNepaliDate\Traits\EnglishDateTrait;
use Anuzpandey\LaravelNepaliDate\Traits\HelperTrait;
use Anuzpandey\LaravelNepaliDate\Traits\IsLeapYearTrait;
use Anuzpandey\LaravelNepaliDate\Traits\NepaliDateTrait;
use Carbon\Carbon;
use RuntimeException;

class LaravelNepaliDate
{
use CalendarDateDataTrait;
use NepaliDateTrait;
use EnglishDateTrait;
use IsLeapYearTrait;
use DiffForHumsTrait;
use EnglishDateTrait;
use HelperTrait;

use IsLeapYearTrait;
use NepaliDateTrait;

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


public static function from(string|Carbon $date): LaravelNepaliDate
{
$parsedDate = ($date instanceof Carbon)
Expand All @@ -37,5 +32,4 @@ public static function from(string|Carbon $date): LaravelNepaliDate

return new static($parsedDate);
}

}
6 changes: 1 addition & 5 deletions src/LaravelNepaliDateServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

namespace Anuzpandey\LaravelNepaliDate;

use Anuzpandey\LaravelNepaliDate\Commands\LaravelNepaliDateCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Anuzpandey\LaravelNepaliDate\Commands\LaravelNepaliDateCommand;

class LaravelNepaliDateServiceProvider extends PackageServiceProvider
{
public function configurePackage(Package $package): void
{
$package
->name('laravel-nepali-date');
// ->hasConfigFile()
// ->hasViews()
// ->hasMigration('create_laravel-nepali-date_table')
// ->hasCommand(LaravelNepaliDateCommand::class);
}
}
10 changes: 7 additions & 3 deletions src/Traits/CalendarDateDataTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

trait CalendarDateDataTrait
{

private array $calendarData = [
0 => [2000, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
1 => [2001, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
Expand Down Expand Up @@ -100,20 +99,25 @@ trait CalendarDateDataTrait
];

private array $normalMonths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

private array $leapMonths = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

private array $englishNormalMonths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
private array $englishLeapMonths = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

private array $englishLeapMonths = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

/* These are initial values for nepali date. */
private string|int $nepaliYear = 2000;

private string|int $nepaliMonth = 9;

private string|int $nepaliDay = 16; // 17 - 1

private string|int $dayOfWeek = 6; // 7 - 1, 0 for sunday, 6 for saturday

private string|int $englishYear = 1943;

private string|int $englishMonth = 4;
private string|int $englishDay = 13; // 14 - 1

private string|int $englishDay = 13; // 14 - 1
}
7 changes: 3 additions & 4 deletions src/Traits/DiffForHumsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Anuzpandey\LaravelNepaliDate\Traits;

trait DiffForHumsTrait {

trait DiffForHumsTrait
{
public function nepaliDiffForHumans($diffInHuman): string
{
$expData = explode(' ', $diffInHuman);
Expand All @@ -13,7 +13,6 @@ public function nepaliDiffForHumans($diffInHuman): string
$index = strpos($diffInHuman, $expData[0]) + strlen($expData[0]);
$remainingData = substr($diffInHuman, $index);

return $this->convertEnToNpNumber($numberData) . $this->convertEnToNpWord($remainingData);
return $this->convertEnToNpNumber($numberData).$this->convertEnToNpWord($remainingData);
}

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


public function toEnglishDate(): string
{
$checkIfIsInRange = $this->isInNepaliDateRange($this->date);

if (!$checkIfIsInRange) {
if (! $checkIfIsInRange) {
throw new RuntimeException($checkIfIsInRange);
}

$totalNepaliDays = $this->calculateTotalNepaliDays();

$this->performCalculationBasedonNepaliDays($totalNepaliDays);

return $this->englishYear . '-' . $this->englishMonth . '-' . $this->englishDay;
return $this->englishYear.'-'.$this->englishMonth.'-'.$this->englishDay;
}


public function toEnglishDateArray(): NepaliDateArrayData
{
$this->toEnglishDate();
Expand All @@ -96,7 +94,6 @@ public function toEnglishDateArray(): NepaliDateArrayData
]);
}


public function isInNepaliDateRange(Carbon $date): string|bool
{
if ($date->year < 2000 || $date->year > 2089) {
Expand All @@ -111,10 +108,9 @@ public function isInNepaliDateRange(Carbon $date): string|bool
return 'Day is out of range. Please provide day between 1-32';
}

return TRUE;
return true;
}


public function calculateTotalNepaliDays()
{
$totalNepaliDays = 0;
Expand All @@ -138,7 +134,6 @@ public function calculateTotalNepaliDays()
return $totalNepaliDays;
}


public function performCalculationBasedOnNepaliDays(string|int $totalNepaliDays)
{
$_day = 4 - 1;
Expand Down Expand Up @@ -173,17 +168,15 @@ 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;
}


public function toFormattedEnglishDate(
string $format = 'd F Y, l',
string $locale = 'en'
): string
{
): string {
$englishDateArray = $this->toEnglishDateArray();

$formattedArray = ($locale === 'en')
Expand All @@ -201,5 +194,4 @@ public function toFormattedEnglishDate(
default => $this->invalidDateFormatException(),
};
}

}
44 changes: 21 additions & 23 deletions src/Traits/HelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,34 @@ trait HelperTrait
public function convertEnToNpNumber($number): array|string
{
$en_number = [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
];

$np_number = [
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
];

return str_replace($en_number, $np_number, $number);
}


public function convertEnToNpWord($word): array|string
{
$en_word = [
Expand Down Expand Up @@ -73,13 +72,12 @@ public function convertEnToNpWord($word): array|string
'घण्टा',
'घण्टा',
'मिनेट',
'मिनेट'
'मिनेट',
];

return str_replace($en_word, $np_word, $word);
}


private function invalidDateFormatException(): void
{
throw new \RuntimeException('Invalid date format provided. Valid formats are: "d F Y, l" - "l, d F Y" - "d F Y" - "d-m-Y" - "Y-m-d" - "d/m/Y" - "Y/m/d"');
Expand Down
5 changes: 2 additions & 3 deletions src/Traits/IsLeapYearTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace Anuzpandey\LaravelNepaliDate\Traits;

trait IsLeapYearTrait {

trait IsLeapYearTrait
{
public function isLeapYear($year): bool
{
return ($year % 100 == 0)
? ($year % 400 == 0)
: ($year % 4 == 0);
}

}
Loading

0 comments on commit fd692cb

Please sign in to comment.