From fe6b056b52920d2a4e83d4ee98e63e0c10d95f28 Mon Sep 17 00:00:00 2001 From: Ehsan Sabet Date: Wed, 10 Nov 2021 12:11:00 +0330 Subject: [PATCH 1/3] add quarter format --- src/Lang/ar.php | 6 ++++++ src/Lang/az.php | 6 ++++++ src/Lang/en.php | 6 ++++++ src/Lang/fa.php | 6 ++++++ src/Lang/haz.php | 6 ++++++ src/Lang/ku.php | 6 ++++++ src/Lang/ps.php | 6 ++++++ src/Traits/Formatting.php | 7 ++++++- 8 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/Lang/ar.php b/src/Lang/ar.php index 0e96ab2..cb53bed 100644 --- a/src/Lang/ar.php +++ b/src/Lang/ar.php @@ -72,6 +72,12 @@ return [ 'jdate_before_equal' => 'يجب أن يكون :attribute تاريخ جلالي قبل :date أو يساوي.', 'jdatetime_before' => 'يجب أن يكون :attribute هو تاريخ جلالي قبل :date.', 'jdatetime_before_equal' => 'يجب أن يكون :attribute هو تاريخ جلالي قبل أو يساوي :date.', + ], + 'quarters' => [ + '1' => 'ربيع', + '2' => 'الصيف', + '3' => 'الخريف', + '4' => 'شتاء', ] ]; diff --git a/src/Lang/az.php b/src/Lang/az.php index cfe6519..83b069e 100644 --- a/src/Lang/az.php +++ b/src/Lang/az.php @@ -72,6 +72,12 @@ return [ 'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':date' . ' باشد.', 'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':date' . ' باشد.', 'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':date' . ' باشد.', + ], + 'quarters' => [ + '1' => 'بهار', + '2' => 'تابستان', + '3' => 'پاییز', + '4' => 'زمستان', ] ]; diff --git a/src/Lang/en.php b/src/Lang/en.php index 1220dbe..8d0e9b4 100644 --- a/src/Lang/en.php +++ b/src/Lang/en.php @@ -72,6 +72,12 @@ return [ 'jdate_before_equal' => 'The :attribute must be a Jalali date before or equal :date.', 'jdatetime_before' => 'The :attribute must be a Jalali datetime before :date.', 'jdatetime_before_equal' => 'The :attribute must be a Jalali datetime before or equal :date.', + ], + 'quarters' => [ + '1' => 'spring', + '2' => 'summer', + '3' => 'autumn', + '4' => 'winter', ] ]; diff --git a/src/Lang/fa.php b/src/Lang/fa.php index 9ad6e9d..15dcaad 100644 --- a/src/Lang/fa.php +++ b/src/Lang/fa.php @@ -72,6 +72,12 @@ return [ 'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':date' . ' باشد.', 'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':date' . ' باشد.', 'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':date' . ' باشد.', + ], + 'quarters' => [ + '1' => 'بهار', + '2' => 'تابستان', + '3' => 'پاییز', + '4' => 'زمستان', ] ]; diff --git a/src/Lang/haz.php b/src/Lang/haz.php index cc8d370..8d76699 100644 --- a/src/Lang/haz.php +++ b/src/Lang/haz.php @@ -72,6 +72,12 @@ return [ 'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':date' . ' باشد.', 'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':date' . ' باشد.', 'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':date' . ' باشد.', + ], + 'quarters' => [ + '1' => 'بهار', + '2' => 'تابستان', + '3' => 'پاییز', + '4' => 'زمستان', ] ]; diff --git a/src/Lang/ku.php b/src/Lang/ku.php index 87315a6..452c963 100644 --- a/src/Lang/ku.php +++ b/src/Lang/ku.php @@ -72,6 +72,12 @@ return [ 'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':date' . ' باشد.', 'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':date' . ' باشد.', 'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':date' . ' باشد.', + ], + 'quarters' => [ + '1' => 'بهار', + '2' => 'تابستان', + '3' => 'پاییز', + '4' => 'زمستان', ] ]; diff --git a/src/Lang/ps.php b/src/Lang/ps.php index 7e759f3..f5170a9 100644 --- a/src/Lang/ps.php +++ b/src/Lang/ps.php @@ -71,6 +71,12 @@ return [ 'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':date' . ' باشد.', 'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':date' . ' باشد.', 'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':date' . ' باشد.', + ], + 'quarters' => [ + '1' => 'بهار', + '2' => 'تابستان', + '3' => 'پاییز', + '4' => 'زمستان', ] ]; diff --git a/src/Traits/Formatting.php b/src/Traits/Formatting.php index 9fb6548..96840de 100644 --- a/src/Traits/Formatting.php +++ b/src/Traits/Formatting.php @@ -134,7 +134,10 @@ trait Formatting case 't': return static::isLeapYear( $pYear ) && ( $pMonth == 12 ) ? 30 : static::$daysMonthJalali[ intval( $pMonth ) - 1 ]; - + # Quarter + case 'Q': + case 'q': + return self::$messages['quarters'][$this->quarter]; # Years case 'L': return intval( $this->isLeapYear( $pYear ) ); @@ -291,6 +294,8 @@ trait Formatting "%n" => "\n", "%t" => "\t", "%%" => "%", + "%Q" => "q", + "%q" => "q" ); return str_replace(array_keys($strftime_date), array_values($strftime_date), $format); From 2b49c40adafca6ee9a6da2579ba73b92c7bdef9a Mon Sep 17 00:00:00 2001 From: Ehsan Sabet Date: Wed, 10 Nov 2021 12:11:35 +0330 Subject: [PATCH 2/3] test quarter format --- tests/FormatTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/FormatTest.php b/tests/FormatTest.php index 2d8e9e2..81ed3fd 100644 --- a/tests/FormatTest.php +++ b/tests/FormatTest.php @@ -120,4 +120,11 @@ class FormatTest extends TestCase $this->assertEquals('چهارشنبه یازده ام دی', $datetime); } + + public function testFormatQuarter() + { + $datetime = Verta::parse('1398-10-10 21:30:50')->formatWord('q'); + + $this->assertEquals('زمستان', $datetime); + } } From 1d8251ed4f093a0202c71a2111f3da0ba83ee10c Mon Sep 17 00:00:00 2001 From: Ehsan Sabet Date: Wed, 10 Nov 2021 13:09:48 +0330 Subject: [PATCH 3/3] update doc --- docs/en/index.html | 2 +- docs/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/index.html b/docs/en/index.html index d1cef0f..4c922bb 100644 --- a/docs/en/index.html +++ b/docs/en/index.html @@ -221,6 +221,7 @@ $v = $v->setTimeString('12:25:48'); $v = verta(); return $v->format('Y-n-j H:i'); // 1395-10-7 14:12 return $v->format('%B %d، %Y'); // دی 07، 1395 +return $v->format('%Q %Y'); // زمستان 1395 return $v; //1395-10-07 14:12:32

Read the PHP manual to create the format you want

@@ -390,7 +391,6 @@ return $v1->isNextYear(); // false return $v1->isLastYear(); // false return $v1->isFuture(); // false return $v1->isPast(); // false -return $v1->isPast(); // false return $v1->isCurrentYear(); // true return $v1->isSameAs('y', $v2); // true isSameYear() diff --git a/docs/index.html b/docs/index.html index 582e072..0df290e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -226,6 +226,7 @@ $v = $v->setTimeString('12:25:48'); $v = verta(); return $v->format('Y-n-j H:i'); // 1395-10-7 14:12 return $v->format('%B %d، %Y'); // دی 07، 1395 +return $v->format('%Q %Y'); // زمستان 1395 return $v; //1395-10-07 14:12:32

برای ساخت فرمت نمایش مورد نظر خود راهنمای پی اچ پی را مطالعه کنید

@@ -395,7 +396,6 @@ return $v1->isNextYear(); // false return $v1->isLastYear(); // false return $v1->isFuture(); // false return $v1->isPast(); // false -return $v1->isPast(); // false return $v1->isCurrentYear(); // true return $v1->isSameAs('y', $v2); // true isSameYear()