Skip to content

Commit

Permalink
Update PHP version requirement to support PHP 8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
MoamenEltouny committed Jul 7, 2024
1 parent d9265bd commit d7d5adc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.2']
php-versions: ['8.0', '8.1', '8.2', '8.3']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}

steps:
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
"license": "MIT",
"authors": [
{
"name": "Moamen Eltouny",
"email": "support@raggitech.com"
"name": "Moamen Eltouny (Raggi)",
"email": "raggigroup@gmail.com"
}
],
"require": {
"php": "^8.2",
"nesbot/carbon": "^3.0"
"php": ">=8.0",
"nesbot/carbon": ">=2.20.0"
},
"require-dev": {
"phpunit/phpunit": ">=5.0"
"orchestra/testbench": "^7.0"
},
"config": {
"sort-packages": true
Expand Down
File renamed without changes.
59 changes: 36 additions & 23 deletions src/Hijri.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
namespace Pharaonic\Hijri;

use Carbon\Carbon;
use Carbon\Month;
use Carbon\Translator;
use Carbon\WeekDay;
use DateTimeInterface;
use DateTimeZone;

Expand Down Expand Up @@ -65,8 +63,6 @@ class Hijri extends Carbon
*/
protected $CURRENT_DAY = null;



/**
* Getting an instance of Hijri class.
*
Expand Down Expand Up @@ -142,11 +138,16 @@ private function convertToHijri()
* as it allows you to do Carbon::parse('Monday next week')->fn() rather
* than (new Carbon('Monday next week'))->fn().
*
* @param string|DateTimeInterface|null $time
* @param DateTimeZone|string|null $tz
*
* @throws InvalidFormatException
*
* @return static
*/
public static function parse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null): static
public static function parse($time = null, $tz = null)
{
return self::$HIJRI_INSTANCE->prepare(parent::parse($time, $timezone));
return self::$HIJRI_INSTANCE->prepare(parent::parse($time, $tz));
}

/**
Expand All @@ -157,7 +158,7 @@ public static function parse(DateTimeInterface|WeekDay|Month|string|int|float|nu
*
* @return $this|string
*/
public function locale(?string $locale = null, string ...$fallbackLocales): static|string
public function locale(string $locale = null, ...$fallbackLocales)
{
if ($locale === null) {
return $this->getTranslatorLocale();
Expand Down Expand Up @@ -197,8 +198,10 @@ public function locale(?string $locale = null, string ...$fallbackLocales): stat
* @param string|null $context whole format string
* @param string $keySuffix "", "_short" or "_min"
* @param string|null $defaultValue default value if translation missing
*
* @return string
*/
public function getTranslatedDayName(?string $context = null, string $keySuffix = '', ?string $defaultValue = null): string
public function getTranslatedDayName($context = null, $keySuffix = '', $defaultValue = null)
{
return $this->getTranslatedFormByRegExp('weekdays', $keySuffix, $context, $this->CURRENT_DAY, $defaultValue ?: $this->englishDayOfWeek);
}
Expand Down Expand Up @@ -229,8 +232,10 @@ protected function getTranslatedFormByRegExp($baseKey, $keySuffix, $context, $su
* @param string|null $context whole format string
* @param string $keySuffix "" or "_short"
* @param string|null $defaultValue default value if translation missing
*
* @return string
*/
public function getTranslatedMonthName(?string $context = null, string $keySuffix = '', ?string $defaultValue = null): string
public function getTranslatedMonthName($context = null, $keySuffix = '', $defaultValue = null)
{
return $this->getTranslatedFormByRegExp('months', $keySuffix, $context, $this->month - 1, $defaultValue ?: $this->englishMonth);
}
Expand All @@ -239,21 +244,29 @@ public function getTranslatedMonthName(?string $context = null, string $keySuffi
* Returns the formatted date string on success or FALSE on failure.
*
* @see https://php.net/manual/en/datetime.format.php
*
* @param string $format
*
* @return string
*/
public function format(string $format): string
public function format($format): string
{
return str_replace([
$this->englishDayOfWeek,
$this->englishMonth,

$this->shortEnglishDayOfWeek,
$this->shortEnglishMonth
], [
$this->dayName,
$this->monthName,

$this->shortDayName,
$this->monthName,
], parent::format($format));
return str_replace(
[
$this->englishDayOfWeek,
$this->englishMonth,

$this->shortEnglishDayOfWeek,
$this->shortEnglishMonth
],
[
$this->dayName,
$this->monthName,

$this->shortDayName,
$this->monthName,
],
parent::format($format)
);
}
}
10 changes: 8 additions & 2 deletions tests/HijriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ protected function setUp(): void

public function testHijri()
{
$this->assertEquals('Monday, Sha\'aban 8, 1413 7:00 PM', $this->dt->toHijri()->isoFormat('LLLL'));
$this->assertEquals(
'Monday, Sha\'aban 8, 1413 7:00 PM',
$this->dt->toHijri()->isoFormat('LLLL')
);
}

public function testLocalizaedHijri()
{
$this->assertEquals('الاثنين 8 شَعبان 1413 19:00', $this->dt->toHijri()->locale('ar')->isoFormat('LLLL'));
$this->assertEquals(
'الاثنين 8 شَعبان 1413 19:00',
$this->dt->toHijri()->locale('ar')->isoFormat('LLLL')
);
}
}

0 comments on commit d7d5adc

Please sign in to comment.