diff --git a/composer.json b/composer.json index 1a7f9e6..94b6c5c 100755 --- a/composer.json +++ b/composer.json @@ -17,10 +17,10 @@ "Verta" ], "require": { - "php": "^7.3|^8.0", - "illuminate/support": "^6.0|^7.0|^8.0|^9.0", - "illuminate/validation": "^6.0|^7.0|^8.0|^9.0", - "hekmatinasser/notowo": "^1.0" + "php": "^8.0", + "illuminate/support": "^^8.0|^9.0", + "illuminate/validation": "^^8.0|^9.0", + "hekmatinasser/jalali": "^8.0" }, "require-dev": { "orchestra/testbench": "^4.18|^5.20|^6.24|^7.0" diff --git a/docs/assert/logo.png b/docs/assert/logo.png deleted file mode 100644 index a583b01..0000000 Binary files a/docs/assert/logo.png and /dev/null differ diff --git a/docs/css/style.css b/docs/css/style.css deleted file mode 100644 index 69db951..0000000 --- a/docs/css/style.css +++ /dev/null @@ -1,214 +0,0 @@ -* { - box-sizing: border-box; - outline: 0 -} - -*, -::after, -::before, -:after, -:before { - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale -} - -article, -footer, -header { - display: block -} - -html { - font-size: 100%; - -ms-text-size-adjust: 100%; - -webkit-text-size-adjust: 100%; -} - -body { - margin: 0; - font-family: 'Markazi Text', sans-serif; - font-size: 15px; - line-height: 27px; - color: #000 -} - -a:focus { - outline: thin dotted -} - -a:active, -a:hover { - outline: 0 -} - -p { - font-size: 20px; -} - -pre { - margin: 1em 0; - font-family: monospace, serif; - font-size: 1em; - white-space: pre-wrap; - word-wrap: break-word; - padding: 10px; - direction: ltr; - text-align: left; - color: #090910;; - background: #fbfbfd; -} - -ul { - padding: 0; - font-size: 20px; - margin: 1em 0; - list-style: none; - list-style-image: none -} - -a, -a:visited { - color: #666; - text-decoration: none -} - -h1 { - font-size: 30px; - text-transform: uppercase; - text-align: center; - margin-bottom: 25px; - position: relative; - padding: 0 0 20px 0 -} - -h2 { - font-size: 26px; - margin-bottom: 20px -} - -h3 { - font-size: 24px -} - -header#header { - background: #fbfbfd; - text-align: center; - line-height: 60px; - padding: 50px 30px; - margin: 0 0 30px 0; - border-bottom: 2px solid #ff6f6f; -} - -header#header h1 { - color: #ff6f6f; - font-family: sans; - font-weight: 700; - font-size: 70px; - line-height: 90px; -} - -header#header h1::after { - background: white; -} - -header#header h2 { - color: lightgray; -} - -.sidebar { - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; -} - -.sticky { - position: -webkit-sticky; - position: sticky; - top: 10px; - padding: 0 15px; -} - -footer#footer { - background: #ddd; - color: #888; - padding: 30px 0; - margin-top: 30px -} - -@media (max-width:480px) { - header#header { - padding: 30px 15px - } - header#header h1 { - font-size: 44px; - line-height: 70px; - padding-bottom: 15px; - margin-bottom: 15px - } - header#header h2 { - font-size: 20px - } -} - -.container { - width: 100%; - padding-left: 15px; - padding-right: 15px; - margin-left: auto; - margin-right: auto; -} - -@media (min-width: 576px) { - .container { - max-width: 540px; - } -} - -@media (min-width: 768px) { - .container { - max-width: 720px; - } -} - -@media (min-width: 992px) { - .container { - max-width: 960px; - } -} - -@media (min-width: 1200px) { - .container { - max-width: 1140px; - } -} - -.row { - display: -ms-flexbox; - display: flex; - -ms-flex-wrap: wrap; - flex-wrap: wrap; - margin-left: -15px; - margin-right: -15px; -} - -.col-sm-3, .col-sm-6 { - position: relative; - width: 100%; - padding-left: 15px; - padding-right: 15px; -} - -@media (min-width: 576px) { - .col-sm-3 { - -ms-flex: 0 0 25%; - flex: 0 0 25%; - max-width: 25%; - } - .col-sm-9 { - -ms-flex: 0 0 75%; - flex: 0 0 75%; - max-width: 75%; - } -} \ No newline at end of file diff --git a/docs/en/index.html b/docs/en/index.html deleted file mode 100644 index 17de816..0000000 --- a/docs/en/index.html +++ /dev/null @@ -1,633 +0,0 @@ - - - - - Verta — Laravel plugin Jalali datetime - - - - - - - - - - Fork me on GitHub - - -
-
-
- -
-
-
-

Installation

-

Enter the following command to install Verta

-
$ composer require hekmatinasser/verta
-

You can add the package to your project by entering the following command

- -
// config/app.php
-'providers' => [
-    ...
-    Hekmatinasser\Verta\Laravel\VertaServiceProvider::class,
-],
-
-'alias' => [
-    ...
-    'Verta' => Hekmatinasser\Verta\Verta::class,
-]
-

Usage

-

Use the following command at the top of each file of the use Verta class

-
-use Verta;
-// or
-use Hekmatinasser\Verta\Verta;
-
-

Creator

-

To get the current datetime, use the following command

-
-$v = new Verta(); //1396-02-02 15:32:08
-$v = verta(); //1396-02-02 15:32:08
-
-

To get the current date and time, use the following command

-
-$v = Verta::now(); //1396-02-02 15:32:08
-$v = Verta::today(); //1396-03-02 00:00:00
-$v = Verta::tomorrow(); // 1396-03-03 00:00:00
-$v = Verta::yesterday(); // 1396-03-01 00:00:00
-
-

To get the current date and time similar datetime string, use the following command

-
-$v = new Verta('now'); // 1399-06-18 15:32:08
-$v = new Verta('-1 day'); //1399-06-17 15:07:04
-$v = new Verta('+1 month'); //1399-07-17 16:51:09
-$v = new Verta('next friday'); //1399-06-21 00:00:00
-$v = new Verta('last sunday'); //1399-06-16 00:00:00
-
- -

To convert your Gregorian datetime, use the following command

-
-$v = new Verta('2016-12-27 14:12:32');
-$v = Verta::instance('2016-12-25 11:12:36');
-$v = Facades\Verta::instance('2016-12-25 11:12:36');
-
-

To use the timestamp number, use the following command

-
-$v = new Verta(1333857600);
-
-

To use the Datetime class PHP, use the following command

-
-$dt = new \Datetime();
-return new Verta($dt); // 1395-12-09 15:05:56
-
-

To use the Carbon class, use the following command

-
-$c = \Carbon::now();
-return verta($c); // 1395-12-09 15:05:56
-// or
-\Illuminate\Support\Carbon::now()->toJalali(); // 1395-12-09 15:05:56
-// or with laravel helper
-now()->toJalali(); // 1395-12-09 15:05:56
-// or in models
-return $model->created_at->toJalali();
-
-

To use the jalali datetime as a string, use the following command

-
-$v = Verta::parse('1395-10-07 14:12:32');
-$v = Verta::parse('1396 مهر 17');
-$v =  Verta::parseFormat('Y n j','1396 مهر 17');
-
- -

If the date values are separate, use the following commands

-
-return Verta::create();  // 1395-12-14 11:17:01 equal now()
-return Verta::create(2016,12,25,15,20,15);  // 1395-10-05 15:20:15
-return Verta::createDate(2016,12,25); // 1395-10-05 21:35:49 set time now
-return Verta::createTime(15,51,5); // 1396-02-31 15:51:05 set date now
-
-// alias create functions
-return Verta::createGregorian(2016,12,25,15,20,15);  // 1395-10-05 15:20:15
-return Verta::createGregorianDate(2016,12,25); // 1395-10-05 21:35:49 set time now
-return Verta::createGregorianTime(15,51,5); // 1396-02-31 15:51:05 set date now
-
-

To use the timestamp numeric, use the following command

-
-return Verta::createTimestamp(1488614023); // 1395-12-14 11:23:43
-
-

If the date jalali values are separate, use the following commands

-
-// get Jalali datetime
-return Verta::createJalali(1394,12,29,15,51,5);  // 1394-12-29 15:51:05
-return Verta::createJalaliDate(1394,12,29); // 1394-12-29 11:18:29 set time now
-return Verta::createJalaliTime(15,51,5); // 1395-12-14 15:51:05 set date now
-
-

Transformations

-

Gregorian to Jalali date, use the following command

-
-return Verta::getJalali(2015,12,25); // [1394,10,4]
-
-

Jalali to Gregorian date, use the following command

-
-return Verta::getGregorian(1394,10,4); // [2015,12,25]
-
-

Verta to Datatime PHP, use the following command

-
-$dt = verta()->datetime();
-
-

Verta to Carbon, use the following command

-
-$c = Carbon::instance($v->datetime());
-// or
-$c = $v->toCarbon();
-
-

Property

-

To get property, use the following command

-
-$v = verta(); // 1396-03-14 14:18:23
-return $v->year; // 1396
-return $v->quarter // 1
-return $v->month; // 3
-return $v->day; // 14
-return $v->hour; // 14
-return $v->minute; // 18
-return $v->second; // 23
-return $v->micro; // 0
-return $v->dayOfWeek; // 1
-return $v->dayOfYear; // 107
-return $v->weekOfYear; // 16
-return $v->daysInMonth; // 31
-return $v->timestamp; // 1496557661
-return $v->timezone; // Asia/Tehran
-
-

To set property, use the following command

-
-$v = verta();
-$v->year = 1395;
-$v->month = 4; // set 13 for next year first month
-$v->day = 25;
-$v->hour = 16;
-$v->minute = 50;
-$v->second = 42;
-$v->timestamp = 1496557661;
-$v->timezone = 'Asia/Baku';
-
-

To set property with method, use the following command

-
-$v = $v->year(1395);
-$v = $v->month(4); // set 13 for next year first month
-$v = $v->day(25);
-$v = $v->hour(16);
-$v = $v->minute(50);
-$v = $v->second(42);
-$v = $v->timestamp(1496557661);
-$v = $v->timezone('Asia/Baku');
-
-

To set property together, use the following command

-
-$v = $v->setDateTime(1395, 4, 25, 16, 50, 42);
-$v = $v->setDateTime(1395, 4, 25, 16, 50, 42, 1569856);
-$v = $v->setDateJalali(1395, 4, 25);
-$v = $v->setTimeString('12:25:48');
-
-

Format

-

To output format, use the following command

-
-$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

-

- strftime - date -

-

To default output format, use the following command

-
-Verta::setStringformat('Y/n/j H:i:s');
-return verta(); // 1395/12/12 00:11:35
-
-

To reset output format, use the following command

-
-Verta::resetStringFormat();
-return verta(); // 1395-12-12 00:18:04
-
-

To display the datetime in standard formats, use the following command

-
-return $v->formatDatetime(); // 1395-12-10 23:37:26
-return $v->formatDate(); // 1395-12-10
-return $v->formatTime(); // 23:26:35
-return $v->formatJalaliDatetime(); // 1395/12/10 23:46:09
-return $v->formatJalaliDate(); // 1395/12/10
-
-

To output format Gregorian, use the following command

-
-return $v->formatGregorian('Y-m-d H:i:s'); // 2017-05-23 23:21:02
-
-

To display the date difference as a unit of time, use the following command

-

If you do set parameter, the difference is calculated with the current time

-
-return $v1->formatDifference($v2); // 12 ماه بعد
-return $v1->formatDifference($v3); // 1 سال قبل
-return $v1->addDays(25)->formatDifference(); // 4 هفته بعد
-return $v1->subDays(6)->formatDifference(); // 6 روز قبل
-return verta()->formatDifference(); // الان
-
-

To display numbers in alphabetical order, use the following command

-
-return $v->formatWord('Y'); // یک هزار و سیصد و نود و شش
-return $v->formatWord('l dS F'); // چهارشنبه بیست و نه ام شهریور
-return $v->formatWord('d F Y'); // بیست و نه شهریور یک هزار و سیصد و نود و شش
-return $v->formatWord('r'); // چهارشنبه یک هزار و سیصد و نود و شش, شش, بیست و نه, بیست و دو:چهل و نه:سی و هشت +04:30
-return $v->formatWord('d F ') . $v->year; // بیست و نه شهریور 1396
-
-

Modification

-

To add or sub datetime, use the following command

-
-$v = verta();
-return $v->addYear(); // 1396-10-07 14:12:32
-return $v->addYears(4); // 1399-10-07 14:12:32
-return $v->subYear(); // 1394-10-07 14:12:32
-return $v->subYears(2); // 1393-10-07 14:12:32
-
-
-return $v->addMonth(); // 1395-11-07 14:12:32
-return $v->addMonths(5); // 1396-03-07 14:12:32
-return $v->subMonth(); // 1395-09-07 14:12:32
-return $v->subMonths(2); // 1395-08-07 14:12:32
-
-
-return $v->addWeek(); // 1395-10-12 14:12:32
-return $v->addWeeks(3); // 1395-10-26 14:12:32
-return $v->subWeek(); // 1395-09-30 14:12:32
-return $v->subWeeks(2); // 1395-09-27 14:12:32
-
-
-return $v->addDay(); // 1395-10-08 14:12:32
-return $v->addDays(3); // 1395-10-11 14:12:32
-return $v->subDay(); // 1395-10-06 14:12:32
-return $v->subDays(2); // 1395-09-05 14:12:32
-
-
-return $v->addHour(); // 1395-10-07 15:12:32
-return $v->addHours(5); // 1395-10-07 19:12:32
-return $v->subHour(); // 1395-10-07 13:12:32
-return $v->subHours(2); // 1395-10-07 12:12:32
-
-
-return $v->addMinute(); // 1395-10-07 14:13:32
-return $v->addMinutes(3); // 1395-10-07 14:15:32
-return $v->subMinute(); // 1395-10-07 14:11:32
-return $v->subMinutes(2); // 1395-10-07 14:10:32
-
-
-return $v->addSecond(); // 1395-10-07 14:12:33
-return $v->addSeconds(3); // 1395-10-07 14:12:35
-return $v->subSecond(); // 1395-10-07 14:12:31
-return $v->subSeconds(2); // 1395-10-07 14:12:30
-
-

To get start or end datetime period, use the following command

-
-$v = verta(); // 1396-04-29 14:25:48
-return $v->startDay(); // 1396-04-29 00:00:00
-return $v->endDay(); // 1396-04-29 23:59:59
-
-
-return $v->startWeek(); // 1396 1396-04-24 00:00:00
-return $v->endWeek(); // 1396-04-30 23:59:59
-
-
-return $v->startMonth(); // 1396-04-01 00:00:00
-return $v->endMonth(); // 1396-04-31 00:00:00
-
-
-return $v->startQuarter(); // 1396-04-01 00:00:00
-return $v->endQuarter(); // 1396-06-31 23:59:59
-
-
-return $v->startYear(); // 1396-01-01 00:00:00
-return $v->endYear(); // 1396-12-29 23:59:59
-
-
-return $v->startHour(); // 1396-04-29 14:00:00
-return $v->endHour(); // 1396-04-29 14:59:59
-
-
-return $v->startMinute(); // 1396-04-29 14:25:00
-return $v->endMinute(); // 1396-04-29 14:25:59
-
-

Comparison

-

To validate datetime, use the following command

-
-return Verta::isLeapYear(1394); // false
-return Verta::isValidDate(1394, 12, 30); // false
-return Verta::isValidTime(15, 12, 30); // true
-
-

To difference datetime together, use the following command

-
-// diff objects together
-$v1 = verta(); // 1396-03-31 22:21:40
-$v2 = verta('2017-06-21 01:21:40'); // 1396-03-31 01:21:40
-$v3 = verta('2017-06-20'); // 1396-03-30 15:24:53
-
-return $v1->diffYears($v3); // -1
-return $v1->diffMonths($v2); // 11
-return $v2->diffMonths(); // -11 compare with now
-return $v1->diffWeeks($v2); // 51
-return $v1->diffDays($v3); // -372
-return $v3->diffMinutes(); // 536548
-return $v3->diffSeconds(); // 12261931
-
-

To compere datetime together, use the following command

-
-return $v1->eq(); // ture alias equalTo()
-return $v1->ne($v2); // true alias notEqualTo()
-return $v1->gt($v2); // true alias greaterThan()
-return $v1->gte($v2); // true alias greaterThanOrEqualTo()
-return $v1->lt($v2); // false alias lessThan()
-return $v1->lte($v2); // false alias lessThanOrEqualTo()
-return $v1->between($v2, $v3); // false
-
-

To compere datetime for closest, farthest, min or max together, use the following command

-
-return $v1->closest($v2, $v3); // return $v2 object
-return $v1->farthest($v2, $v3); // return $v3 object
-return $v1->minimum($v2); // return $v2
-return $v1->min($v2); // return $v2
-return $v1->maximum($v2); // return $v1
-return $v1->max($v2); // return $v1
-
-

To compere datetime now, use the following command

-
-return $v1->isWeekday(); // true
-return $v1->isWeekend(); // false
-return $v1->isYesterday(); // false
-return $v1->isToday(); // true
-return $v1->isTomorrow(); // false
-return $v1->isNextWeek(); // false
-return $v1->isLastWeek(); // false
-return $v1->isNextMonth(); // false
-return $v1->isLastMonth(); // false
-return $v1->isNextYear(); // false
-return $v1->isLastYear(); // false
-return $v1->isFuture(); // false
-return $v1->isPast(); // false
-
-return $v1->isCurrentYear(); // true
-return $v1->isSameAs('y', $v2); // true isSameYear()
-return $v1->isCurrentMonth(); // true
-return $v1->isSameMonth($v2); // true
-return $v1->isSameDay($v2); // true
-return $v1->isBirthday(); // true compare with today
-return $v1->isBirthday($v2); // true
-
-return $v1->isSaturday(); // false
-return $v1->isSunday(); // false
-return $v1->isMonday(); // false
-return $v1->isTuesday(); // false
-return $v1->isWednesday(); // false
-return $v1->isThursday(); // true
-return $v1->isFriday(); // false
-
-

Laravel Validator

-

You can validate form with Validator Laravel

-

You need to define error messages for jdate, ... rules in validation.php in lang folders.

-
-'jdate' => 'The :attribute is not valid Jalali date',
-'jdate_equal' => 'The :attribute is not equal Jalali date  :date',
-'jdate_not_equal' => 'The :attribute is\'nt not equal Jalali date  :date',
-'jdatetime' => 'The :attribute is not valid Jalali datetime',
-'jdatetime_equal' => 'The :attribute is not equal Jalali datetime :date',
-'jdatetime_not_equal' => 'The :attribute is\'nt not equal Jalali datetime :date',
-'jdate_after' => 'The :attribute must be a Jalali date after :date.',
-'jdate_after_equal' => 'The :attribute must be a Jalali date after or equal :date.',
-'jdatetime_after' => 'The :attribute must be a Jalali datetime after :date.',
-'jdatetime_after_equal' => 'The :attribute must be a Jalali datetime after or equal :date.',
-'jdate_before' => 'The :attribute must be a Jalali date before :date.',
-'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.',
-
-'attributes' => [
-    'start_date' => 'start date',
-    'expire_datetime' => 'expire datetime',
-],
-
-

Validation Rules

-

Determines if an input is a valid Jalali date with the specified format

-

The default format is Y/m/d

-
-'start_date' => 'jdate'
-'start_date' => 'jdate:Y/m/d'
-
-

Determines if an input is a valid Jalali date with the specified format and it is equal a given - date

-

The default format is Y/m/d

- -
-'start_date' => 'jdate_equal'
-'start_date' => 'jdate_equal:1388/01/01'
-'start_date' => 'jdate_equal:1388/01/01,Y/m/d'
-
- -

Determines if an input is a valid Jalali date with the specified format and it is not equal a - given date

-

The default format is Y/m/d

- -
-'start_date' => 'jdate_not_equal'
-'start_date' => 'jdate_not_equal:1388/01/01'
-'start_date' => 'jdate_not_equal:1388/01/01,Y/m/d'
-
-

Determines if an input is a valid Jalali datetime with the specified format

-

The default format is Y/m/d H:i:s

-
-'start_date' => 'jdatetime'
-'start_date' => 'jdatetime:Y/m/d H:i:s'
-
-

Determines if an input is a valid Jalali datetime with the specified format and it is equal a - given datetime

-

The default format is Y/m/d H:i:s

-
-'start_date' => 'jdatetime_equal'
-'start_date' => 'jdatetime_equal:1388/01/01 12:56:28'
-'start_date' => 'jdatetime_equal:1388/01/01 12:56:28,Y/m/d H:i:s'
-
-

Determines if an input is a valid Jalali datetime with the specified format and it is not equal a - given datetime

-

The default format is Y/m/d H:i:s

-
-'start_date' => 'jdatetime_not_equal'
-'start_date' => 'jdatetime_not_equal:1388/01/01 12:56:28'
-'start_date' => 'jdatetime_not_equal:1388/01/01 12:56:28,Y/m/d H:i:s'
-
- -

Determines if an input is a valid Jalali date with the specified format and it is after a given - date

-

The default date is now

-

The default format is Y/m/d

-
-'start_date' => 'jdate_after'
-'start_date' => 'jdate_after:1388/01/01'
-'start_date' => 'jdate_after:1388/01/01,Y/m/d'
-
-

Determines if an input is a valid Jalali datetime with the specified format and it is after or - equal a given datetime

-

The default date is now

-

The default format is Y/m/d

-
-'start_date' => 'jdate_after_equal'
-'start_date' => 'jdate_after_equal:1388/01/01'
-'start_date' => 'jdate_after_equal:1388/01/01,Y/m/d'
-
-

Determines if an input is a valid Jalali datetime with the specified format and it is after a - given datetime

-

The default date is now

-

The default format is Y/m/d H:i:s

-
-'start_date' => 'jdatetime_after'
-'start_date' => 'jdatetime_after:1388/01/01'
-'start_date' => 'jdatetime_after:1388/01/01,Y/m/d'
-
-

Determines if an input is a valid Jalali datetime with the specified format and it is after or - equal a given datetime

-

The default date is now

-

The default format is Y/m/d H:i:s

-
-'start_date' => 'jdatetime_after_equal'
-'start_date' => 'jdatetime_after_equal:1388/01/01'
-'start_date' => 'jdatetime_after_equal:1388/01/01,Y/m/d'
-
- -

Determines if an input is a valid Jalali date with the specified format and it is before a given - date

-

The default date is now

-

The default format is Y/m/d

-
-'start_date' => 'jdate_before'
-'start_date' => 'jdate_before:1388/01/01'
-'start_date' => 'jdate_before:1388/01/01,Y/m/d'
-
-

Determines if an input is a valid Jalali date with the specified format and it is before or equal - a given date

-

The default date is now

-

The default format is Y/m/d

-
-'start_date' => 'jdate_before_equal'
-'start_date' => 'jdate_before_equal:1388/01/01'
-'start_date' => 'jdate_before_equal:1388/01/01,Y/m/d'
-
-

Determines if an input is a valid Jalali datetime with the specified format and it is before a - given date-time

-

The default date is now

-

The default format is Y/m/d H:i:s

-
-'start_date' => 'jdatetime_before'
-'start_date' => 'jdatetime_before:1388/01/01'
-'start_date' => 'jdatetime_before:1388/01/01,Y/m/d'
-
-

Determines if an input is a valid Jalali datetime with the specified format and it is before or - equal a given datetime

-

The default date is now

-

The default format is Y/m/d H:i:s

-
-'start_date' => 'jdatetime_before_equal'
-'start_date' => 'jdatetime_before_equal:1388/01/01'
-'start_date' => 'jdatetime_before_equal:1388/01/01,Y/m/d'
-
-

Can combine the rules of the between the two boundaries

-
-$validate = Validator::make([
-    'start_date' => '1389/01/31',
-    'expire_datetime' => '1397/02/16 12:10:00',
-],
-[
-    'start_date' => 'required|jdate:Y/m/d|jdate_after:1388/01/01,Y/m/d|jdate_before:1390/01/01',
-    'expire_datetime' => 'required|jdatetime|jdatetime_after:1397/02/16 12:09:50,Y/m/d H:i:s|jdatetime_before:1397/02/16 12:11:00',
-]);
-
-if ($validate->fails()) {
-    dd($validate->messages()->toArray());
-}
-
-    //output
-array:2 [
-  "start_date" => array:1 [
-    0 => "The start date must be a Jalali date before 1390/01/01."
-  ]
-  "expire_datetime" => array:1 [
-    0 => "The expire datetime must be a Jalali datetime before 1397/02/16 12:10:00."
-  ]
-]
-
- - -

Traslation

-

You can show weekdays, months , messages in the languages available in Verta To view supported - languages, go to the folder langs

-

To set locale, use the following command

-
-Verta::setLocale('fa');
-
-

To get current locale, use the following command

-
-Verta::getLocale(); // fa
-
-

To reset locale to fa, use the following command

-
-Verta::resetLocale();
-
-
-
-
-
- - - - - diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index 138f60d..0000000 --- a/docs/index.html +++ /dev/null @@ -1,635 +0,0 @@ - - - - - Verta — پکیج تاریخ شمسی در لاراول - - - - - - - - - - - Fork me on GitHub - - -
-
- -
-
-

نصب

-

برای نصب دستور زیر را وارد کنید

-
$ composer require hekmatinasser/verta
-

می توانید پکیج را درون پروژه خود اضافه کنید برای این کار دستور زیر را وارد کنید

- -
// config/app.php
-'providers' => [
-    ...
-    Hekmatinasser\Verta\Laravel\VertaServiceProvider::class,
-],
-
-'alias' => [
-    ...
-    'Verta' => Hekmatinasser\Verta\Verta::class,
-]
-

نحوه استفاده

-

در بالای هر فایل خود از کلاس ورتا استفاده میکند، از دستور زیر استفاده کنید

-
-use Verta;
-// or
-use Hekmatinasser\Verta\Verta;
-
-

ایجاد کردن

-

برای بدست آوردن تاریخ و زمان کنونی شمسی، از دستور زیر استفاده کنید

-
-$v = new Verta(); //1396-02-02 15:32:08
-$v = verta(); //1396-02-02 15:32:08
-
-

برای بدست آوردن تاریخ و زمان به نسبت اکنون، از دستور زیر استفاده کنید

-
-$v = Verta::now(); //1396-02-02 15:32:08
-$v = Verta::today(); //1396-03-02 00:00:00
-$v = Verta::tomorrow(); // 1396-03-03 00:00:00
-$v = Verta::yesterday(); // 1396-03-01 00:00:00
-
-

برای بدست آوردن تاریخ و زمان به نسبت اکنون مانند تاریخ زمان پی اچ پی به صورت رشته ، از دستور زیر - استفاده کنید

-
-$v = new Verta('now'); // 1399-06-18 15:32:08
-$v = new Verta('-1 day'); //1399-06-17 15:07:04
-$v = new Verta('+1 month'); //1399-07-17 16:51:09
-$v = new Verta('next friday'); //1399-06-21 00:00:00
-$v = new Verta('last sunday'); //1399-06-16 00:00:00
-
- -

برای تبدیل تاریخ میلادی خود به شمسی، از دستور زیر استفاده کنید

-
-$v = new Verta('2016-12-27 14:12:32');
-$v = Verta::instance('2016-12-25 11:12:36');
-$v = Facades\Verta::instance('2016-12-25 11:12:36');
-
-

برای استفاده از عدد تایم استمپ به شمسی، از دستور زیر استفاده کنید

-
-$v = new Verta(1333857600);
-
-

برای استفاده از کلاس تاریخ و زمان پی اچ پی به شمسی، از دستور زیر استفاده کنید

-
-$dt = new \Datetime();
-return new Verta($dt); // 1395-12-09 15:05:56
-
-

برای استفاده از کلاس کربن به شمسی، از دستور زیر استفاده کنید

-
-$c = \Carbon::now();
-return verta($c); // 1395-12-09 15:05:56
-// or
-\Illuminate\Support\Carbon::now()->toJalali(); // 1395-12-09 15:05:56
-// or with laravel helper
-now()->toJalali(); // 1395-12-09 15:05:56
-// or in models
-return $model->created_at->toJalali();
-
-

برای استفاده از تاریخ شمسی به صورت رشته، از دستور زیر استفاده کنید

-
-$v = Verta::parse('1395-10-07 14:12:32');
-$v = Verta::parse('1396 مهر 17');
-$v =  Verta::parseFormat('Y n j','1396 مهر 17');
-
- -

در صورتی مقادیر تاریخ میلادی به صورت جداگانه باشد، از دستورات زیر استفاده کنید

-
-return Verta::create();  // 1395-12-14 11:17:01 equal now()
-return Verta::create(2016,12,25,15,20,15);  // 1395-10-05 15:20:15
-return Verta::createDate(2016,12,25); // 1395-10-05 21:35:49 set time now
-return Verta::createTime(15,51,5); // 1396-02-31 15:51:05 set date now
-
-// alias create functions
-return Verta::createGregorian(2016,12,25,15,20,15);  // 1395-10-05 15:20:15
-return Verta::createGregorianDate(2016,12,25); // 1395-10-05 21:35:49 set time now
-return Verta::createGregorianTime(15,51,5); // 1396-02-31 15:51:05 set date now
-
-

برای استفاده از عدد تایم استمپ به شمسی، از دستور زیر استفاده کنید

-
-return Verta::createTimestamp(1488614023); // 1395-12-14 11:23:43
-
-

در صورتی مقادیر تاریخ شمسی به صورت جداگانه باشد، از دستورات زیر استفاده کنید

-
-// get Jalali datetime
-return Verta::createJalali(1394,12,29,15,51,5);  // 1394-12-29 15:51:05
-return Verta::createJalaliDate(1394,12,29); // 1394-12-29 11:18:29 set time now
-return Verta::createJalaliTime(15,51,5); // 1395-12-14 15:51:05 set date now
-
-

تبدیل تاریخ

-

برای تبدیل از میلادی به شمسی به صورت ساده، از دستور زیر استفاده کنید

-
-return Verta::getJalali(2015,12,25); // [1394,10,4]
-
-

برای تبدیل از شمسی به میلادی به صورت ساده، از دستور زیر استفاده کنید

-
-return Verta::getGregorian(1394,10,4); // [2015,12,25]
-
-

برای تبدیل تاریخ از ورتا به تاریخ و زمان پی اچ پی، از دستور زیر استفاده کنید

-
-$dt = verta()->datetime();
-
-

برای تبدیل تاریخ از ورتا به کربن، از دستور زیر استفاده کنید

-
-$c = Carbon::instance($v->datetime());
-// or
-$c = $v->toCarbon();
-
-

خصوصیات

-

برای دریافت مقادیر خصوصیات، از دستورات زیر استفاده کنید

-
-$v = verta(); // 1396-03-14 14:18:23
-return $v->year; // 1396
-return $v->quarter // 1
-return $v->month; // 3
-return $v->day; // 14
-return $v->hour; // 14
-return $v->minute; // 18
-return $v->second; // 23
-return $v->micro; // 0
-return $v->dayOfWeek; // 1
-return $v->dayOfYear; // 107
-return $v->weekOfYear; // 16
-return $v->daysInMonth; // 31
-return $v->timestamp; // 1496557661
-return $v->timezone; // Asia/Tehran
-
-

برای مقدار دهی خصوصیات، از دستورات زیر استفاده کنید

-
-$v = verta();
-$v->year = 1395;
-$v->month = 4; // عدد 13 برای ثبت سال آینده اولین ماه
-$v->day = 25;
-$v->hour = 16;
-$v->minute = 50;
-$v->second = 42;
-$v->timestamp = 1496557661;
-$v->timezone = 'Asia/Baku';
-
-

برای مقدار دهی خصوصیات با استفاده از تابع، از دستورات زیر استفاده کنید

-
-$v = $v->year(1395);
-$v = $v->month(4); // set 13 for next year first month
-$v = $v->day(25);
-$v = $v->hour(16);
-$v = $v->minute(50);
-$v = $v->second(42);
-$v = $v->timestamp(1496557661);
-$v = $v->timezone('Asia/Baku');
-
-

برای مقدار دهی خصوصیات با یکدیگر، از دستورات زیر استفاده کنید

-
-$v = $v->setDateTime(1395, 4, 25, 16, 50, 42);
-$v = $v->setDateTime(1395, 4, 25, 16, 50, 42, 1569856);
-$v = $v->setDateJalali(1395, 4, 25);
-$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
-
-

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

-

- strftime - date -

-

برای تعیین فرمت خروجی پیش فرض، از دستور زیر استفاده کنید

-
-Verta::setStringformat('Y/n/j H:i:s');
-return verta(); // 1395/12/12 00:11:35
-
-

برای تنظیم مجددفرمت خروجی به حالت اولیه، از دستور زیر استفاده کنید

-
-Verta::resetStringFormat();
-return verta(); // 1395-12-12 00:18:04
-
-

برای نمایش تاریخ با فرمت های متعارف، از دستور زیر استفاده کنید

-
-return $v->formatDatetime(); // 1395-12-10 23:37:26
-return $v->formatDate(); // 1395-12-10
-return $v->formatTime(); // 23:26:35
-return $v->formatJalaliDatetime(); // 1395/12/10 23:46:09
-return $v->formatJalaliDate(); // 1395/12/10
-
-

برای نمایش تاریخ به صورت میلادی، از دستور زیر استفاده کنید

-
-return $v->formatGregorian('Y-m-d H:i:s'); // 2017-05-23 23:21:02
-
-

برای نمایش اختلاف تاریخ به صورت واحد زمانی، از دستور زیر استفاده کنید

-

درصورتی که تاریخ را وارد نکنید، اختلاف با زمان کنونی محاسبه می شود.

-
-return $v1->formatDifference($v2); // 12 ماه بعد
-return $v1->formatDifference($v3); // 1 سال قبل
-return $v1->addDays(25)->formatDifference(); // 4 هفته بعد
-return $v1->subDays(6)->formatDifference(); // 6 روز قبل
-return verta()->formatDifference(); // الان
-
-

برای نمایش اعداد به صورت حروف، از دستور زیر استفاده کنید

-
-return $v->formatWord('Y'); // یک هزار و سیصد و نود و شش
-return $v->formatWord('l dS F'); // چهارشنبه بیست و نه ام شهریور
-return $v->formatWord('d F Y'); // بیست و نه شهریور یک هزار و سیصد و نود و شش
-return $v->formatWord('r'); // چهارشنبه یک هزار و سیصد و نود و شش, شش, بیست و نه, بیست و دو:چهل و نه:سی و هشت +04:30
-return $v->formatWord('d F ') . $v->year; // بیست و نه شهریور 1396
-
-

تغییر دادن

-

برای اضافه یا کم کردن از تاریخ خود، از دستور زیر استفاده کنید

-
-$v = verta();
-return $v->addYear(); // 1396-10-07 14:12:32
-return $v->addYears(4); // 1399-10-07 14:12:32
-return $v->subYear(); // 1394-10-07 14:12:32
-return $v->subYears(2); // 1393-10-07 14:12:32
-
-
-return $v->addMonth(); // 1395-11-07 14:12:32
-return $v->addMonths(5); // 1396-03-07 14:12:32
-return $v->subMonth(); // 1395-09-07 14:12:32
-return $v->subMonths(2); // 1395-08-07 14:12:32
-
-
-return $v->addWeek(); // 1395-10-12 14:12:32
-return $v->addWeeks(3); // 1395-10-26 14:12:32
-return $v->subWeek(); // 1395-09-30 14:12:32
-return $v->subWeeks(2); // 1395-09-27 14:12:32
-
-
-return $v->addDay(); // 1395-10-08 14:12:32
-return $v->addDays(3); // 1395-10-11 14:12:32
-return $v->subDay(); // 1395-10-06 14:12:32
-return $v->subDays(2); // 1395-09-05 14:12:32
-
-
-return $v->addHour(); // 1395-10-07 15:12:32
-return $v->addHours(5); // 1395-10-07 19:12:32
-return $v->subHour(); // 1395-10-07 13:12:32
-return $v->subHours(2); // 1395-10-07 12:12:32
-
-
-return $v->addMinute(); // 1395-10-07 14:13:32
-return $v->addMinutes(3); // 1395-10-07 14:15:32
-return $v->subMinute(); // 1395-10-07 14:11:32
-return $v->subMinutes(2); // 1395-10-07 14:10:32
-
-
-return $v->addSecond(); // 1395-10-07 14:12:33
-return $v->addSeconds(3); // 1395-10-07 14:12:35
-return $v->subSecond(); // 1395-10-07 14:12:31
-return $v->subSeconds(2); // 1395-10-07 14:12:30
-
-

برای بدست آوردن تاریخ شروع و پایان هر بازه زمانی، از دستور زیر استفاده کنید

-
-$v = verta(); // 1396-04-29 14:25:48
-return $v->startDay(); // 1396-04-29 00:00:00
-return $v->endDay(); // 1396-04-29 23:59:59
-
-
-return $v->startWeek(); // 1396 1396-04-24 00:00:00
-return $v->endWeek(); // 1396-04-30 23:59:59
-
-
-return $v->startMonth(); // 1396-04-01 00:00:00
-return $v->endMonth(); // 1396-04-31 00:00:00
-
-
-return $v->startQuarter(); // 1396-04-01 00:00:00
-return $v->endQuarter(); // 1396-06-31 23:59:59
-
-
-return $v->startYear(); // 1396-01-01 00:00:00
-return $v->endYear(); // 1396-12-29 23:59:59
-
-
-return $v->startHour(); // 1396-04-29 14:00:00
-return $v->endHour(); // 1396-04-29 14:59:59
-
-
-return $v->startMinute(); // 1396-04-29 14:25:00
-return $v->endMinute(); // 1396-04-29 14:25:59
-
-

بررسی و مقایسه

-

برای اعتبار سنجی تاریخ، از دستور زیر استفاده کنید

-
-return Verta::isLeapYear(1394); // false
-return Verta::isValidDate(1394, 12, 30); // false
-return Verta::isValidTime(15, 12, 30); // true
-
-

برای محاسبه اختلاف تاریخ ها با یکدیگر، از دستور زیر استفاده کنید

-
-// diff objects together
-$v1 = verta(); // 1396-03-31 22:21:40
-$v2 = verta('2017-06-21 01:21:40'); // 1396-03-31 01:21:40
-$v3 = verta('2017-06-20'); // 1396-03-30 15:24:53
-
-return $v1->diffYears($v3); // -1
-return $v1->diffMonths($v2); // 11
-return $v2->diffMonths(); // -11 مقایسه با زمان کنونی
-return $v1->diffWeeks($v2); // 51
-return $v1->diffDays($v3); // -372
-return $v3->diffMinutes(); // 536548
-return $v3->diffSeconds(); // 12261931
-
-

برای مقایسه تاریخ ها با یکدیگر، از دستور زیر استفاده کنید

-
-return $v1->eq(); // ture alias equalTo()
-return $v1->ne($v2); // true alias notEqualTo()
-return $v1->gt($v2); // true alias greaterThan()
-return $v1->gte($v2); // true alias greaterThanOrEqualTo()
-return $v1->lt($v2); // false alias lessThan()
-return $v1->lte($v2); // false alias lessThanOrEqualTo()
-return $v1->between($v2, $v3); // false
-
-

برای بررسی تاریخ از لحاظ نزدیکتر یا دورتر بودن و یا کوچکتر و بزرگتر بودن، از دستور زیر استفاده - کنید

-
-return $v1->closest($v2, $v3); // return $v2 object
-return $v1->farthest($v2, $v3); // return $v3 object
-return $v1->minimum($v2); // return $v2
-return $v1->min($v2); // return $v2
-return $v1->maximum($v2); // return $v1
-return $v1->max($v2); // return $v1
-
-

برای بررسی تاریخ فعلی، از دستورات زیر استفاده کنید

-
-return $v1->isWeekday(); // true
-return $v1->isWeekend(); // false
-return $v1->isYesterday(); // false
-return $v1->isToday(); // true
-return $v1->isTomorrow(); // false
-return $v1->isNextWeek(); // false
-return $v1->isLastWeek(); // false
-return $v1->isNextMonth(); // false
-return $v1->isLastMonth(); // false
-return $v1->isNextYear(); // false
-return $v1->isLastYear(); // false
-return $v1->isFuture(); // false
-return $v1->isPast(); // false
-
-return $v1->isCurrentYear(); // true
-return $v1->isSameAs('y', $v2); // true isSameYear()
-return $v1->isCurrentMonth(); // true
-return $v1->isSameMonth($v2); // true
-return $v1->isSameDay($v2); // true
-return $v1->isBirthday(); // true compare with today
-return $v1->isBirthday($v2); // true
-
-return $v1->isSaturday(); // false
-return $v1->isSunday(); // false
-return $v1->isMonday(); // false
-return $v1->isTuesday(); // false
-return $v1->isWednesday(); // false
-return $v1->isThursday(); // true
-return $v1->isFriday(); // false
-
-

اعتبار سنجی

-

شما می توانید با اعتبار سنجی لاراول تاریخ های شمسی درون فرم های خود استفاده کنید

-

شما باید پیام های خطا برای اعتبار سنجی خود در در مسیر فایل های ترجمه خود اضافه کنید ارور های - ترجمه شده برای زبان های قابل پشتیبانی در زبان ها مراجعه کنید - قرار دارد .برای نمونه کد هایی که درون پکیج برای پیام خطا وجود دارد در فایل ترجمه خود قرار - دهیدبرای مثال در فایل ترجمه پیام خطا به آرایه عبارات زیر را اضافه کنید

-
-'jdate' => ':attribute تاریخ شمسی معتبر نمی باشد.',
-'jdate_equal' => ':attribute تاریخ شمسی برابر :date نمی باشد.',
-'jdate_not_equal' => ':attribute تاریخ شمسی نامساوی :date نمی باشد.',
-'jdatetime' => ':attribute تاریخ و زمان شمسی معتبر نمی باشد.',
-'jdatetime_equal' => ':attribute تاریخ و زمان شمسی مساوی :date نمی باشد.',
-'jdatetime_not_equal' => ':attribute تاریخ و زمان شمسی نامساوی :date نمی باشد.',
-'jdate_after' => ':attribute تاریخ شمسی باید بعد از :date باشد.',
-'jdate_after_equal' => ':attribute تاریخ شمسی باید بعد یا برابر از :date باشد.',
-'jdatetime_after' => ':attribute تاریخ و زمان شمسی باید بعد از :date باشد.',
-'jdatetime_after_equal' => ':attribute تاریخ و زمان شمسی باید بعد یا برابر از :date باشد.',
-'jdate_before' => ':attribute تاریخ شمسی باید قبل از :date باشد.',
-'jdate_before_equal' => ':attribute تاریخ شمسی باید قبل یا برابر از :date باشد.',
-'jdatetime_before' => ':attribute تاریخ و زمان شمسی باید قبل از :date باشد.',
-'jdatetime_before_equal' => ':attribute تاریخ و زمان شمسی باید قبل یا برابر از :date باشد.',
-
-'attributes' => [
-    'start_date' => 'تاریخ شروع',
-    'expire_datetime' => 'تاریخ انقضا',
-],
-
-

قوانین اعتبار سنجی

-

اگر تاریخ شمسی با فرمت معین درست باشد

-

فرمت پیش فرض Y/m/d می باشد

-
-'start_date' => 'jdate'
-'start_date' => 'jdate:Y/m/d'
-
-

اگر تاریخ شمسی با فرمت تعیین شده مساوی باشد

-

فرمت پیش فرض Y/m/d می باشد

- -
-'start_date' => 'jdate_equal'
-'start_date' => 'jdate_equal:1388/01/01'
-'start_date' => 'jdate_equal:1388/01/01,Y/m/d'
-
- -

اگر تاریخ شمسی با فرمت تعیین شده نامساوی باشد

-

فرمت پیش فرض Y/m/d می باشد

- -
-'start_date' => 'jdate_not_equal'
-'start_date' => 'jdate_not_equal:1388/01/01'
-'start_date' => 'jdate_not_equal:1388/01/01,Y/m/d'
-
-

اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد

-

فرمت پیش فرض Y/m/d H:i:s می باشد

-
-'start_date' => 'jdatetime'
-'start_date' => 'jdatetime:Y/m/d H:i:s'
-
-

اگر تاریخ و زمان شمسی با فرمت تعیین شده مساوی باشد

-

فرمت پیش فرض Y/m/d H:i:s می باشد

-
-'start_date' => 'jdatetime_equal'
-'start_date' => 'jdatetime_equal:1388/01/01 12:56:28'
-'start_date' => 'jdatetime_equal:1388/01/01 12:56:28,Y/m/d H:i:s'
-
-

اگر تاریخ و زمان شمسی با فرمت تعیین شده نامساوی باشد

-

فرمت پیش فرض Y/m/d H:i:s می باشد

-
-'start_date' => 'jdatetime_not_equal'
-'start_date' => 'jdatetime_not_equal:1388/01/01 12:56:28'
-'start_date' => 'jdatetime_not_equal:1388/01/01 12:56:28,Y/m/d H:i:s'
-
- -

اگر تاریخ شمسی با فرمت تعیین شده درست باشد و بعد از تاریخ تعیین شده باشد

-

درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد

-

فرمت پیش فرض Y/m/d می باشد

-
-'start_date' => 'jdate_after'
-'start_date' => 'jdate_after:1388/01/01'
-'start_date' => 'jdate_after:1388/01/01,Y/m/d'
-
-

اگر تاریخ شمسی با فرمت تعیین شده درست باشد و بعد یا مساوی از تاریخ تعیین شده باشد

-

درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد

-

فرمت پیش فرض Y/m/d می باشد

-
-'start_date' => 'jdate_after_equal'
-'start_date' => 'jdate_after_equal:1388/01/01'
-'start_date' => 'jdate_after_equal:1388/01/01,Y/m/d'
-
-

اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و بعد از تاریخ تعیین شده باشد

-

درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد

-

فرمت پیش فرض Y/m/d H:i:s می باشد

-
-'start_date' => 'jdatetime_after'
-'start_date' => 'jdatetime_after:1388/01/01'
-'start_date' => 'jdatetime_after:1388/01/01,Y/m/d'
-
-

اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و بعد یا مساوی از تاریخ تعیین شده باشد

-

درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد

-

فرمت پیش فرض Y/m/d H:i:s می باشد

-
-'start_date' => 'jdatetime_after_equal'
-'start_date' => 'jdatetime_after_equal:1388/01/01'
-'start_date' => 'jdatetime_after_equal:1388/01/01,Y/m/d'
-
- -

اگر تاریخ شمسی با فرمت تعیین شده درست باشد و قبل از تاریخ تعیین شده باشد

-

درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد

-

فرمت پیش فرض Y/m/d می باشد

-
-'start_date' => 'jdate_before'
-'start_date' => 'jdate_before:1388/01/01'
-'start_date' => 'jdate_before:1388/01/01,Y/m/d'
-
-

اگر تاریخ شمسی با فرمت تعیین شده درست باشد و قبل یا مساوی از تاریخ تعیین شده باشد

-

درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد

-

فرمت پیش فرض Y/m/d می باشد

-
-'start_date' => 'jdate_before_equal'
-'start_date' => 'jdate_before_equal:1388/01/01'
-'start_date' => 'jdate_before_equal:1388/01/01,Y/m/d'
-
-

اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و قبل از تاریخ تعیین شده باشد

-

درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد

-

فرمت پیش فرض Y/m/d H:i:s می باشد

-
-'start_date' => 'jdatetime_before'
-'start_date' => 'jdatetime_before:1388/01/01'
-'start_date' => 'jdatetime_before:1388/01/01,Y/m/d'
-
-

اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و قبل یا مساوی از تاریخ تعیین شده باشد

-

درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد

-

فرمت پیش فرض Y/m/d H:i:s می باشد

-
-'start_date' => 'jdatetime_before_equal'
-'start_date' => 'jdatetime_before_equal:1388/01/01'
-'start_date' => 'jdatetime_before_equal:1388/01/01,Y/m/d'
-
-

میتوانید با ترکیب قوانین تاریخ را بین دو محدوده بررسی کنید

-
-$validate = Validator::make([
-    'start_date' => '1389/01/31',
-    'expire_datetime' => '1397/02/16 12:10:00',
-],
-[
-    'start_date' => 'required|jdate:Y/m/d|jdate_after:1388/01/01,Y/m/d|jdate_before:1390/01/01',
-    'expire_datetime' => 'required|jdatetime|jdatetime_after:1397/02/16 12:09:50,Y/m/d H:i:s|jdatetime_before:1397/02/16 12:11:00',
-]);
-
-if ($validate->fails()) {
-dd($validate->messages()->toArray());
-}
-
-//output
-array:2 [
-    "start_date" => array:1 [
-        0 => "تاریخ شروع تاریخ شمسی باید قبل از ۱۳۹۰/۰۱/۰۱ باشد."
-    ]
-    "expire_datetime" => array:1 [
-        0 => "تاریخ انقضا تاریخ و زمان شمسی باید قبل از ۱۳۹۷/۰۲/۱۶ ۱۲:۱۰:۰۰ باشد."
-    ]
-]
-
- -

زبان ها

-

شما میتوانید ایام و ماه ها و پیام را به زبان های موجود در ورتا نمایش دهید برای مشاهده زبان ها - پشتیبانی می شود به پوشه زیر مشاهده - زبان ها مراجعه کنید -

-

برای تعیین زبان پیام های از دستور زیر استفاده کنید

-
-Verta::setLocale('fa');
-
-

برای دریافت زبان جاری پیام های از دستور زیر استفاده کنید

-
-Verta::getLocale(); // fa
-
-

برای ریست کردن زبان به فارسی از دستور زیر استفاده کنید

-
-Verta::resetLocale();
-
-

برای افزودن زبان های دیگر نمونه فایل های موجود را برای ادغام با پروژه ارسال کنید

- -
-
-
-
- - - - - diff --git a/src/Lang/ar.php b/src/Lang/ar.php deleted file mode 100644 index 07cb1d7..0000000 --- a/src/Lang/ar.php +++ /dev/null @@ -1,82 +0,0 @@ - [ - '0' => '۰', - '1' => '۱', - '2' => '۲', - '3' => '۳', - '4' => '٤', - '5' => '٥', - '6' => '٦', - '7' => '۷', - '8' => '۸', - '9' => '۹', - ], - 'year_months' => [ - '1' => 'حَمَل', - '2' => 'ثَور', - '3' => 'جَوزا', - '4' => 'سَرَطان', - '5' => 'اَسَد', - '6' => 'سُنبُله', - '7' => 'میزان', - '8' => 'عَقرَب', - '9' => 'قَوس', - '10' => 'جَدْی', - '11' => 'دَلو', - '12' => 'حوت', - ], - 'weekdays' => [ - '1' => 'السبت', - '2' => 'الأحد', - '3' => 'الاثنين', - '4' => 'يوم الثلاثاء', - '5' => 'الأربعاء', - '6' => 'يوم الخميس', - '7' => 'جمعة', - ], - 'date_units' => [ - 'second' => 'ثواني', - 'mintue' => 'الدقائق', - 'hour' => 'الساعة', - 'day' => 'يوم', - 'week' => 'أسبوع', - 'month' => 'شهر', - 'yaer' => 'سنة', - 'decade' => 'عشر سنوات', - 'century' => 'مئة عام', - ], - 'phrase' => [ - 'am' => 'ق ظ', - 'pm' => 'ب ظ', - 'ante_meridiem' => 'صباحي', - 'post_meridiem' => 'بعد الظهر', - 'th' => '', - 'ago' => 'قبل', - 'now' => 'الآن', - 'later' => 'التالي', - ], - 'validation' => [ - 'jdate' => ':attribute x ليس تاريخ جلالي صالحًا', - 'jdate_equal' => ':attribute لا يساوي تاريخ جلالي :date', - 'jdate_not_equal' => 'ال :attribute لا يساوي تاريخ جلالي :date', - 'jdatetime' => ':attribute غير صالح لتاريخ جلالي', - 'jdatetime_equal' => ':attribute ليس مساويًا لـ تاريخ جلالي :date', - 'jdatetime_not_equal' => ':attribute لا يساوي تاريخ جلالي :date', - 'jdate_after' => 'يجب أن يكون :attribute تاريخ جلالي بعد :date.', - 'jdate_after_equal' => 'يجب أن يكون :attribute هو تاريخ جلالي بعد :date أو يساوي.', - 'jdatetime_after' => 'يجب أن يكون :attribute عبارة عن تاريخ جلالي بعد :date.', - 'jdatetime_after_equal' => 'يجب أن يكون :attribute عبارة عن تاريخ جلالي بعد :date أو يساوي.', - 'jdate_before' => 'يجب أن يكون :attribute تاريخ جلالي قبل :date.', - '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 deleted file mode 100644 index 9050577..0000000 --- a/src/Lang/az.php +++ /dev/null @@ -1,82 +0,0 @@ - [ - '0' => '۰', - '1' => '۱', - '2' => '۲', - '3' => '۳', - '4' => '۴', - '5' => '۵', - '6' => '۶', - '7' => '۷', - '8' => '۸', - '9' => '۹', - ], - 'year_months' => [ - '1' => 'آغلارگولر', - '2' => 'گولن', - '3' => 'قیزاران', - '4' => 'قورا پیشیرن', - '5' => 'قویروق دوغان', - '6' => 'زومار', - '7' => 'خزل', - '8' => 'قیروو', - '9' => 'آذر', - '10' => 'چیلله', - '11' => 'دوندوران', - '12' => 'بایرام', - ], - 'weekdays' => [ - '1' => 'شنبه', - '2' => 'یکشنبه', - '3' => 'دوشنبه', - '4' => 'سه شنبه', - '5' => 'چهارشنبه', - '6' => 'پنج شنبه', - '7' => 'جمعه', - ], - 'date_units' => [ - 'second' => 'ثانیه', - 'mintue' => 'دقیقه', - 'hour' => 'ساعت', - 'day' => 'روز', - 'week' => 'هفته', - 'month' => 'ماه', - 'yaer' => 'سال', - 'decade' => 'دهه', - 'century' => 'قرن', - ], - 'phrase' => [ - 'am' => 'ق ظ', - 'pm' => 'ب ظ', - 'ante_meridiem' => 'قبل از ظهر', - 'post_meridiem' => 'بعد از ظهر', - 'th' => 'ام', - 'ago' => 'قبل', - 'now' => 'الان', - 'later' => 'بعد', - ], - 'validation' => [ - 'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.', - 'jdate_equal' => ':attribute' . ' تاریخ شمسی برابر ' . ':date' . ' نمی باشد.', - 'jdate_not_equal' => ':attribute' . ' تاریخ شمسی نامساوی ' . ':date' . ' نمی باشد.', - 'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.', - 'jdatetime_equal' => ':attribute' . ' تاریخ و زمان شمسی مساوی ' . ':date' . ' نمی باشد.', - 'jdatetime_not_equal' => ':attribute' . ' تاریخ و زمان شمسی نامساوی ' . ':date' . ' نمی باشد.', - 'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':date' . ' باشد.', - 'jdate_after_equal' => ':attribute' . ' تاریخ شمسی باید بعد یا برابر از ' . ':date' . ' باشد.', - 'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':date' . ' باشد.', - 'jdatetime_after_equal' => ':attribute' . ' تاریخ و زمان شمسی باید بعد یا برابر از ' . ':date' . ' باشد.', - 'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':date' . ' باشد.', - '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 deleted file mode 100644 index 8066c8c..0000000 --- a/src/Lang/en.php +++ /dev/null @@ -1,82 +0,0 @@ - [ - '0' => '0', - '1' => '1', - '2' => '2', - '3' => '3', - '4' => '4', - '5' => '5', - '6' => '6', - '7' => '7', - '8' => '8', - '9' => '9', - ], - 'year_months' => [ - '1' => 'farvardin', - '2' => 'ordibehesht', - '3' => 'khordad', - '4' => 'tir', - '5' => 'mordad', - '6' => 'shahrivar', - '7' => 'mehr', - '8' => 'aban', - '9' => 'azar', - '10' => 'dey', - '11' => 'bahman', - '12' => 'esfand', - ], - 'weekdays' => [ - '1' => 'saturday', - '2' => 'sunday', - '3' => 'monday', - '4' => 'tuesday', - '5' => 'wednesday', - '6' => 'thursday', - '7' => 'friday', - ], - 'date_units' => [ - 'second' => 'second', - 'mintue' => 'mintue', - 'hour' => 'hour', - 'day' => 'day', - 'week' => 'week', - 'month' => 'month', - 'yaer' => 'yaer', - 'decade' => 'decade', - 'century' => 'century', - ], - 'phrase' => [ - 'am' => 'am', - 'pm' => 'pm', - 'ante_meridiem' => 'ante meridiem', - 'post_meridiem' => 'post meridiem', - 'th' => 'th', - 'ago' => 'ago', - 'now' => 'now', - 'later' => 'later', - ], - 'validation' => [ - 'jdate' => 'The :attribute is not valid Jalali date', - 'jdate_equal' => 'The :attribute is not equal Jalali date :date', - 'jdate_not_equal' => 'The :attribute is\'nt not equal Jalali date :date', - 'jdatetime' => 'The :attribute is not valid Jalali datetime', - 'jdatetime_equal' => 'The :attribute is not equal Jalali datetime :date', - 'jdatetime_not_equal' => 'The :attribute is\'nt not equal Jalali datetime :date', - 'jdate_after' => 'The :attribute must be a Jalali date after :date.', - 'jdate_after_equal' => 'The :attribute must be a Jalali date after or equal :date.', - 'jdatetime_after' => 'The :attribute must be a Jalali datetime after :date.', - 'jdatetime_after_equal' => 'The :attribute must be a Jalali datetime after or equal :date.', - 'jdate_before' => 'The :attribute must be a Jalali date before :date.', - '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 deleted file mode 100644 index 31a92da..0000000 --- a/src/Lang/fa.php +++ /dev/null @@ -1,82 +0,0 @@ - [ - '0' => '۰', - '1' => '۱', - '2' => '۲', - '3' => '۳', - '4' => '۴', - '5' => '۵', - '6' => '۶', - '7' => '۷', - '8' => '۸', - '9' => '۹', - ], - 'year_months' => [ - '1' => 'فروردین', - '2' => 'اردیبهشت', - '3' => 'خرداد', - '4' => 'تیر', - '5' => 'مرداد', - '6' => 'شهریور', - '7' => 'مهر', - '8' => 'آبان', - '9' => 'آذر', - '10' => 'دی', - '11' => 'بهمن', - '12' => 'اسفند', - ], - 'weekdays' => [ - '1' => 'شنبه', - '2' => 'یکشنبه', - '3' => 'دوشنبه', - '4' => 'سه شنبه', - '5' => 'چهارشنبه', - '6' => 'پنج شنبه', - '7' => 'جمعه', - ], - 'date_units' => [ - 'second' => 'ثانیه', - 'mintue' => 'دقیقه', - 'hour' => 'ساعت', - 'day' => 'روز', - 'week' => 'هفته', - 'month' => 'ماه', - 'yaer' => 'سال', - 'decade' => 'دهه', - 'century' => 'قرن', - ], - 'phrase' => [ - 'am' => 'ق ظ', - 'pm' => 'ب ظ', - 'ante_meridiem' => 'قبل از ظهر', - 'post_meridiem' => 'بعد از ظهر', - 'th' => 'ام', - 'ago' => 'قبل', - 'now' => 'الان', - 'later' => 'بعد', - ], - 'validation' => [ - 'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.', - 'jdate_equal' => ':attribute' . ' تاریخ شمسی برابر ' . ':date' . ' نمی باشد.', - 'jdate_not_equal' => ':attribute' . ' تاریخ شمسی نامساوی ' . ':date' . ' نمی باشد.', - 'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.', - 'jdatetime_equal' => ':attribute' . ' تاریخ و زمان شمسی مساوی ' . ':date' . ' نمی باشد.', - 'jdatetime_not_equal' => ':attribute' . ' تاریخ و زمان شمسی نامساوی ' . ':date' . ' نمی باشد.', - 'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':date' . ' باشد.', - 'jdate_after_equal' => ':attribute' . ' تاریخ شمسی باید بعد یا برابر از ' . ':date' . ' باشد.', - 'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':date' . ' باشد.', - 'jdatetime_after_equal' => ':attribute' . ' تاریخ و زمان شمسی باید بعد یا برابر از ' . ':date' . ' باشد.', - 'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':date' . ' باشد.', - '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 deleted file mode 100644 index b6c015d..0000000 --- a/src/Lang/haz.php +++ /dev/null @@ -1,82 +0,0 @@ - [ - '0' => '۰', - '1' => '۱', - '2' => '۲', - '3' => '۳', - '4' => '۴', - '5' => '۵', - '6' => '۶', - '7' => '۷', - '8' => '۸', - '9' => '۹', - ], - 'year_months' => [ - '1' => 'اورال', - '2' => 'اید', - '3' => 'بررید', - '4' => 'سرتایستو', - '5' => 'چیله تایستو', - '6' => 'آخیر تایستو', - '7' => 'تخم ریز', - '8' => 'برگ ریز', - '9' => 'چیله زمستو', - '10' => 'بامو', - '11' => 'سیاه بار', - '12' => 'نجیر', - ], - 'weekdays' => [ - '1' => 'شنبه', - '2' => 'یکشنبه', - '3' => 'دوشنبه', - '4' => 'سه شنبه', - '5' => 'چهارشنبه', - '6' => 'پنج شنبه', - '7' => 'جمعه', - ], - 'date_units' => [ - 'second' => 'ثانیه', - 'mintue' => 'دقیقه', - 'hour' => 'ساعت', - 'day' => 'روز', - 'week' => 'هفته', - 'month' => 'ماه', - 'yaer' => 'سال', - 'decade' => 'دهه', - 'century' => 'قرن', - ], - 'phrase' => [ - 'am' => 'ق ظ', - 'pm' => 'ب ظ', - 'ante_meridiem' => 'قبل از ظهر', - 'post_meridiem' => 'بعد از ظهر', - 'th' => 'ام', - 'ago' => 'قبل', - 'now' => 'الان', - 'later' => 'بعد', - ], - 'validation' => [ - 'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.', - 'jdate_equal' => ':attribute' . ' تاریخ شمسی برابر ' . ':date' . ' نمی باشد.', - 'jdate_not_equal' => ':attribute' . ' تاریخ شمسی نامساوی ' . ':date' . ' نمی باشد.', - 'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.', - 'jdatetime_equal' => ':attribute' . ' تاریخ و زمان شمسی مساوی ' . ':date' . ' نمی باشد.', - 'jdatetime_not_equal' => ':attribute' . ' تاریخ و زمان شمسی نامساوی ' . ':date' . ' نمی باشد.', - 'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':date' . ' باشد.', - 'jdate_after_equal' => ':attribute' . ' تاریخ شمسی باید بعد یا برابر از ' . ':date' . ' باشد.', - 'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':date' . ' باشد.', - 'jdatetime_after_equal' => ':attribute' . ' تاریخ و زمان شمسی باید بعد یا برابر از ' . ':date' . ' باشد.', - 'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':date' . ' باشد.', - '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 deleted file mode 100644 index 49c713f..0000000 --- a/src/Lang/ku.php +++ /dev/null @@ -1,82 +0,0 @@ - [ - '0' => '۰', - '1' => '۱', - '2' => '۲', - '3' => '۳', - '4' => '۴', - '5' => '۵', - '6' => '۶', - '7' => '۷', - '8' => '۸', - '9' => '۹', - ], - 'year_months' => [ - '1' => 'خاکه‌لێوه', - '2' => 'گوڵان', - '3' => 'جۆزەردان', - '4' => 'پووشپەڕ', - '5' => 'گەلاوێژ', - '6' => 'خەرمانان', - '7' => 'ڕەزبەر', - '8' => 'خەزەڵوەر', - '9' => 'سەرماوەز', - '10' => 'بەفرانبار', - '11' => 'ڕێبەندان', - '12' => 'رەشەمە', - ], - 'weekdays' => [ - '1' => 'شه ممه', - '2' => 'یه کشه ممه', - '3' => 'دوو شه ممه', - '4' => 'سی شه ممه', - '5' => 'چوار شه ممه', - '6' => 'په ن شه ممم', - '7' => 'هه ینی', - ], - 'date_units' => [ - 'second' => 'ثانیه', - 'mintue' => 'دقیقه', - 'hour' => 'ساعت', - 'day' => 'روز', - 'week' => 'هفته', - 'month' => 'ماه', - 'yaer' => 'سال', - 'decade' => 'دهه', - 'century' => 'قرن', - ], - 'phrase' => [ - 'am' => 'ق ظ', - 'pm' => 'ب ظ', - 'ante_meridiem' => 'قبل از ظهر', - 'post_meridiem' => 'بعد از ظهر', - 'th' => 'ام', - 'ago' => 'قبل', - 'now' => 'الان', - 'later' => 'بعد', - ], - 'validation' => [ - 'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.', - 'jdate_equal' => ':attribute' . ' تاریخ شمسی برابر ' . ':date' . ' نمی باشد.', - 'jdate_not_equal' => ':attribute' . ' تاریخ شمسی نامساوی ' . ':date' . ' نمی باشد.', - 'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.', - 'jdatetime_equal' => ':attribute' . ' تاریخ و زمان شمسی مساوی ' . ':date' . ' نمی باشد.', - 'jdatetime_not_equal' => ':attribute' . ' تاریخ و زمان شمسی نامساوی ' . ':date' . ' نمی باشد.', - 'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':date' . ' باشد.', - 'jdate_after_equal' => ':attribute' . ' تاریخ شمسی باید بعد یا برابر از ' . ':date' . ' باشد.', - 'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':date' . ' باشد.', - 'jdatetime_after_equal' => ':attribute' . ' تاریخ و زمان شمسی باید بعد یا برابر از ' . ':date' . ' باشد.', - 'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':date' . ' باشد.', - '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 deleted file mode 100644 index 2639790..0000000 --- a/src/Lang/ps.php +++ /dev/null @@ -1,81 +0,0 @@ - [ - '0' => '۰', - '1' => '۱', - '2' => '۲', - '3' => '۳', - '4' => '۴', - '5' => '۵', - '6' => '۶', - '7' => '۷', - '8' => '۸', - '9' => '۹', - ], - 'year_months' => [ - '1' => 'وری', - '2' => 'غویی', - '3' => 'غبرګولی', - '4' => 'چنګاښ', - '5' => 'زمری', - '6' => 'وږی', - '7' => 'تله', - '8' => 'لړم', - '9' => 'لیندۍ', - '10' => 'مرغومی', - '11' => 'سلواغه', - '12' => 'کب', - ], - 'weekdays' => [ - '1' => 'شنبې', - '2' => 'یکشنبه', - '3' => 'دوشنبه', - '4' => 'سې شنبه', - '5' => 'چهارشنبه', - '6' => 'پنج شنبه', - '7' => 'جمعه', - ], - 'date_units' => [ - 'second' => 'ثانیه', - 'mintue' => 'دقیقه', - 'hour' => 'ساعت', - 'day' => 'روز', - 'week' => 'هفته', - 'month' => 'ماه', - 'yaer' => 'سال', - 'century' => 'قرن', - ], - 'phrase' => [ - 'am' => 'ق ظ', - 'pm' => 'ب ظ', - 'ante_meridiem' => 'قبل از ظهر', - 'post_meridiem' => 'بعد از ظهر', - 'th' => 'ام', - 'ago' => 'قبل', - 'now' => 'الان', - 'later' => 'بعد', - ], - 'validation' => [ - 'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.', - 'jdate_equal' => ':attribute' . ' تاریخ شمسی برابر ' . ':date' . ' نمی باشد.', - 'jdate_not_equal' => ':attribute' . ' تاریخ شمسی نامساوی ' . ':date' . ' نمی باشد.', - 'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.', - 'jdatetime_equal' => ':attribute' . ' تاریخ و زمان شمسی مساوی ' . ':date' . ' نمی باشد.', - 'jdatetime_not_equal' => ':attribute' . ' تاریخ و زمان شمسی نامساوی ' . ':date' . ' نمی باشد.', - 'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':date' . ' باشد.', - 'jdate_after_equal' => ':attribute' . ' تاریخ شمسی باید بعد یا برابر از ' . ':date' . ' باشد.', - 'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':date' . ' باشد.', - 'jdatetime_after_equal' => ':attribute' . ' تاریخ و زمان شمسی باید بعد یا برابر از ' . ':date' . ' باشد.', - 'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':date' . ' باشد.', - 'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':date' . ' باشد.', - 'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':date' . ' باشد.', - 'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':date' . ' باشد.', - ], - 'quarters' => [ - '1' => 'بهار', - '2' => 'تابستان', - '3' => 'پاییز', - '4' => 'زمستان', - ], -]; diff --git a/src/Laravel/VertaServiceProvider.php b/src/Laravel/VertaServiceProvider.php index a38dfe7..21665a0 100644 --- a/src/Laravel/VertaServiceProvider.php +++ b/src/Laravel/VertaServiceProvider.php @@ -111,7 +111,6 @@ class VertaServiceProvider extends ServiceProvider foreach ($this->rules as $name => $methods) { if (array_key_exists('extend', $methods) || array_key_exists('replacer', $methods)) { Validator::extend($name, $className . $methods['extend']); - Validator::replacer($name, $className . $methods['replacer']); } } diff --git a/src/Traits/Accessor.php b/src/Traits/Accessor.php deleted file mode 100644 index 44de992..0000000 --- a/src/Traits/Accessor.php +++ /dev/null @@ -1,261 +0,0 @@ - 'Y', - 'month' => 'n', - 'day' => 'j', - 'hour' => 'G', - 'minute' => 'i', - 'second' => 's', - 'micro' => 'u', - 'dayOfWeek' => 'w', - 'dayOfYear' => 'z', - 'weekOfYear' => 'W', - 'daysInMonth' => 't', - 'timestamp' => 'U', - ]; - - if (array_key_exists($name, $formats)) { - return (int) $this->format($formats[$name]); - } elseif ($name === 'quarter') { - return (int) ceil($this->month / static::MONTHS_PER_QUARTER); - } elseif ($name === 'timezone') { - return $this->getTimezone()->getName(); - } - - throw new InvalidArgumentException(sprintf("Unknown getter '%s'", $name)); - } - - /** - * Check if an attribute exists on the object - * - * @param string $name - * @return bool - */ - public function __isset($name) - { - try { - $this->__get($name); - } catch (InvalidArgumentException $e) { - return false; - } - - return true; - } - - /** - * Set a part of the Verta object - * - * @param string $name - * @param \DateTimeZone|int|string $value - * @throws \InvalidArgumentException - */ - public function __set($name, $value) - { - switch ($name) { - case 'year': - case 'month': - case 'day': - case 'hour': - case 'minute': - case 'second': - list($year, $month, $day, $hour, $minute, $second) = explode('-', $this->format('Y-n-j-G-i-s')); - $$name = $value; - $this->setDateTime($year, $month, $day, $hour, $minute, $second); - - break; - - case 'timestamp': - $this->setTimestamp($value); - - break; - - case 'timezone': - case 'tz': - $this->setTimezone(new DateTimeZone($value)); - - break; - - default: - throw new InvalidArgumentException(sprintf("Unknown setter '%s'", $name)); - } - } - - /** - * Set the instance's year - * - * @param int $value - * @return static - */ - public function year($value) - { - $this->year = $value; - - return $this; - } - - /** - * Set the instance's month - * - * @param int $value - * @return static - */ - public function month($value) - { - $this->month = $value; - - return $this; - } - - /** - * Set the instance's day - * - * @param int $value - * @return static - */ - public function day($value) - { - $this->day = $value; - - return $this; - } - - /** - * Set the instance's hour - * - * @param int $value - * @return static - */ - public function hour($value) - { - $this->hour = $value; - - return $this; - } - - /** - * Set the instance's minute - * - * @param int $value - * @return static - */ - public function minute($value) - { - $this->minute = $value; - - return $this; - } - - /** - * Set the instance's second - * - * @param int $value - * @return static - */ - public function second($value) - { - $this->second = $value; - - return $this; - } - - /** - * Set the instance's timestamp - * - * @param int $value - * @return static - */ - public function timestamp($value) - { - return parent::setTimestamp($value); - } - - /** - * Alias for setTimezone() - * - * @param \DateTimeZone|string $value - * - * @return static - */ - public function timezone($value) - { - return parent::setTimezone(new DateTimeZone($value)); - } - - /** - * Set the date and time all together - * - * @param int $year - * @param int $month - * @param int $day - * @param int $hour - * @param int $minute - * @param int $second - * @param int $microseconds - * - * @return Verta - */ - public function setDateTime($year, $month, $day, $hour, $minute, $second = 0, $microseconds = 0) - { - return $this->setDateJalali($year, $month, $day)->setTime($hour, $minute, $second, $microseconds); - } - - /** - * Sets the current date of the DateTime object to a different date. - * Calls modify as a workaround for a php bug - * - * @param int $year - * @param int $month - * @param int $day - * - * @return Verta - */ - public function setDateJalali($year, $month, $day): Verta - { - if (static::isValidDate($year, $month, $day)) { - list($year, $month, $day) = self::getGregorian($year, $month, $day); - parent::setDate($year, $month, $day); - } - - return $this; - } - - /** - * Set the time by time string - * - * @param string $time - * @return Verta - * @throws \InvalidArgumentException - */ - public function setTimeString($time): Verta - { - $time = explode(':', $time); - - $hour = $time[0]; - $minute = $time[1] ?? 0; - $second = $time[2] ?? 0; - - if (static::isValidTime($hour, $minute, $second)) { - parent::setTime($hour, $minute, $second, 0); - } - - return $this; - } -} diff --git a/src/Traits/Boundaries.php b/src/Traits/Boundaries.php deleted file mode 100644 index 4f3d402..0000000 --- a/src/Traits/Boundaries.php +++ /dev/null @@ -1,160 +0,0 @@ -setTime($this->hour, $this->minute, 0); - } - - /** - * Resets the time to 23:59:59 - * - * @return static - */ - public function endMinute() - { - return $this->setTime($this->hour, $this->minute, 59); - } - - /** - * Resets the time to 00:00:00 - * - * @return static - */ - public function startHour() - { - return $this->setTime($this->hour, 0, 0); - } - - /** - * Resets the time to 23:59:59 - * - * @return static - */ - public function endHour() - { - return $this->setTime($this->hour, 59, 59); - } - - /** - * Resets the time to 00:00:00 - * - * @return static - */ - public function startDay() - { - return $this->setTime(0, 0, 0); - } - - /** - * Resets the time to 23:59:59 - * - * @return static - */ - public function endDay() - { - return $this->setTime(23, 59, 59); - } - - /** - * Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00 - * - * @return static - */ - public function startWeek() - { - while ($this->dayOfWeek !== static::$weekStartsAt) { - $this->subDay(); - } - - return $this->startDay(); - } - - /** - * Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59 - * - * @return static - */ - public function endWeek() - { - while ($this->dayOfWeek !== static::$weekEndsAt) { - $this->addDay(); - } - - return $this->endDay(); - } - - /** - * Resets the date to the first day of the month and the time to 00:00:00 - * - * @return static - */ - public function startMonth() - { - return $this->setDateTime($this->year, $this->month, 1, 0, 0, 0); - } - - /** - * Resets the date to end of the month and time to 23:59:59 - * - * @return static - */ - public function endMonth() - { - return $this->setDateTime($this->year, $this->month, $this->daysInMonth, 23, 59, 59); - } - - /** - * Resets the date to the first day of the quarter and the time to 00:00:00 - * - * @return static - */ - public function startQuarter() - { - $month = ($this->quarter - 1) * static::MONTHS_PER_QUARTER + 1; - - return $this->setDateTime($this->year, $month, 1, 0, 0, 0); - } - - /** - * Resets the date to end of the quarter and time to 23:59:59 - * - * @return static - */ - public function endQuarter() - { - $month = $this->quarter * static::MONTHS_PER_QUARTER; - - return $this->setDateJalali($this->year, $month, 1)->endMonth(); - } - - /** - * Resets the date to the first day of the year and the time to 00:00:00 - * - * @return static - */ - public function startYear() - { - return $this->setDateTime($this->year, 1, 1, 0, 0, 0); - } - - /** - * Resets the date to end of the year and time to 23:59:59 - * - * @return static - */ - public function endYear() - { - $day = $this->format('L') ? 30 : 29; - - return $this->setDateTime($this->year, 12, $day, 23, 59, 59); - } -} diff --git a/src/Traits/Comparison.php b/src/Traits/Comparison.php deleted file mode 100644 index f0a5081..0000000 --- a/src/Traits/Comparison.php +++ /dev/null @@ -1,607 +0,0 @@ - 32766) { - return false; - } - if ($month < 1 || $month > 12) { - return false; - } - $dayLastMonthJalali = static::isLeapYear($year) && ($month == 12) ? 30 : static::$daysMonthJalali[intval($month) - 1]; - if ($day < 1 || $day > $dayLastMonthJalali) { - return false; - } - - return true; - } - - /** - * validate a time - * - * @param int $hour - * @param int $minute - * @param int $second - * @return bool - */ - public static function isValidTime($hour, $minute, $second) - { - return $hour >= 0 && $hour <= 23 - && $minute >= 0 && $minute <= 59 - && $second >= 0 && $second <= 59; - } - - /** - * Determines if the instance is equal to another - * - * @param Verta $v - * - * @return bool - */ - public function eq(Verta $v = null) - { - return $this == ($v ?: new static()); - } - - /** - * Determines if the instance is equal to another - * - * @param Verta $v - * - * @see eq() - * - * @return bool - */ - public function equalTo(Verta $v = null) - { - return $this->eq($v); - } - - /** - * Determines if the instance is not equal to another - * - * @param Verta $v - * - * @return bool - */ - public function ne(Verta $v = null) - { - return ! $this->eq($v); - } - - /** - * Determines if the instance is not equal to another - * - * @param Verta $v - * - * @see ne() - * - * @return bool - */ - public function notEqualTo(Verta $v = null) - { - return $this->ne($v); - } - - /** - * Determines if the instance is greater (after) than another - * - * @param Verta $v - * - * @return bool - */ - public function gt(Verta $v = null) - { - return $this > ($v ?: new static()); - } - - /** - * Determines if the instance is greater (after) than another - * - * @param Verta $v - * - * @see gt() - * - * @return bool - */ - public function greaterThan(Verta $v = null) - { - return $this->gt($v); - } - - /** - * Determines if the instance is greater (after) than or equal to another - * - * @param Verta $v - * - * @return bool - */ - public function gte(Verta $v = null) - { - return $this >= ($v ?: new static()); - } - - /** - * Determines if the instance is greater (after) than or equal to another - * - * @param Verta $v - * - * @see gte() - * - * @return bool - */ - public function greaterThanOrEqualTo(Verta $v = null) - { - return $this->gte($v); - } - - /** - * Determines if the instance is less (before) than another - * - * @param Verta $v - * - * @return bool - */ - public function lt(Verta $v = null) - { - return $this < ($v ?: new static()); - } - - /** - * Determines if the instance is less (before) than another - * - * @param Verta $v - * - * @see lt() - * - * @return bool - */ - public function lessThan(Verta $v = null) - { - return $this->lt($v); - } - - /** - * Determines if the instance is less (before) or equal to another - * - * @param Verta $v - * - * @return bool - */ - public function lte(Verta $v = null) - { - return $this <= ($v ?: new static()); - } - - /** - * Determines if the instance is less (before) or equal to another - * - * @param Verta $v - * - * @see lte() - * - * @return bool - */ - public function lessThanOrEqualTo(Verta $v = null) - { - return $this->lte($v); - } - - /** - * Determines if the instance is between two others - * - * @param Verta $v1 - * @param Verta $v2 - * @param bool $equal Indicates if a > and < comparison should be used or <= or >= - * - * @return bool - */ - public function between(Verta $v1, Verta $v2, $equal = true) - { - if ($v1->gt($v2)) { - $temp = $v1; - $v1 = $v2; - $v2 = $temp; - } - - if ($equal) { - return $this->gte($v1) && $this->lte($v2); - } - - return $this->gt($v1) && $this->lt($v2); - } - - /** - * Get the closest date from the instance. - * - * @param Verta $v1 - * @param Verta $v2 - * - * @return static - */ - public function closest(Verta $v1, Verta $v2) - { - return $this->diffSeconds($v1) < $this->diffSeconds($v2) ? $v1 : $v2; - } - - /** - * Get the farthest date from the instance. - * - * @param Verta $v1 - * @param Verta $v2 - * - * @return static - */ - public function farthest(Verta $v1, Verta $v2) - { - return $this->diffSeconds($v1) > $this->diffSeconds($v2) ? $v1 : $v2; - } - - /** - * Get the minimum instance between a given instance (default now) and the current instance. - * - * @param Verta|null $v - * - * @return static - */ - public function min(Verta $v = null) - { - $v = $v ?: static::now($this->getTimezone()); - - return $this->lt($v) ? $this : $v; - } - - /** - * Get the minimum instance between a given instance (default now) and the current instance. - * - * @param Verta|null $v - * - * @see min() - * - * @return static - */ - public function minimum(Verta $v = null) - { - return $this->min($v); - } - - /** - * Get the maximum instance between a given instance (default now) and the current instance. - * - * @param Verta|null $v - * - * @return static - */ - public function max(Verta $v = null) - { - $v = $v ?: static::now($this->getTimezone()); - - return $this->gt($v) ? $this : $v; - } - - /** - * Get the maximum instance between a given instance (default now) and the current instance. - * - * @param Verta|null $v - * - * @see max() - * - * @return static - */ - public function maximum(Verta $v = null) - { - return $this->max($v); - } - - /** - * Determines if the instance is a weekday - * - * @return bool - */ - public function isWeekday() - { - return ! $this->isWeekend(); - } - - /** - * Determines if the instance is a weekend day - * - * @return bool - */ - public function isWeekend() - { - return in_array($this->dayOfWeek, static::$weekendDays); - } - - /** - * Determines if the instance is yesterday - * - * @return bool - */ - public function isYesterday() - { - return $this->formatDate() === static::yesterday($this->getTimezone())->formatDate(); - } - - /** - * Determines if the instance is today - * - * @return bool - */ - public function isToday() - { - return $this->formatDate() === static::now($this->getTimezone())->formatDate(); - } - - /** - * Determines if the instance is tomorrow - * - * @return bool - */ - public function isTomorrow() - { - return $this->formatDate() === static::tomorrow($this->getTimezone())->formatDate(); - } - - /** - * Determines if the instance is within the next week - * - * @return bool - */ - public function isNextWeek(): bool - { - return $this->weekOfYear === static::now($this->getTimezone())->addWeek()->weekOfYear; - } - - /** - * Determines if the instance is within the last week - * - * @return bool - */ - public function isLastWeek() - { - return $this->weekOfYear === static::now($this->getTimezone())->subWeek()->weekOfYear; - } - - /** - * Determines if the instance is within the next month - * - * @return bool - */ - public function isNextMonth() - { - return $this->format('Y-m') === static::now($this->getTimezone())->addMonth()->format('Y-m'); - } - - /** - * Determines if the instance is within the last month - * - * @return bool - */ - public function isLastMonth() - { - return $this->format('Y-m') === static::now($this->getTimezone())->subMonth()->format('Y-m'); - } - - /** - * Determines if the instance is within next year - * - * @return bool - */ - public function isNextYear() - { - return $this->year === static::now($this->getTimezone())->addYear()->year; - } - - /** - * Determines if the instance is within the previous year - * - * @return bool - */ - public function isLastYear() - { - return $this->year === static::now($this->getTimezone())->subYear()->year; - } - - /** - * Determines if the instance is in the future, ie. greater (after) than now - * - * @return bool - */ - public function isFuture() - { - return $this->gt(static::now($this->getTimezone())); - } - - /** - * Determines if the instance is in the past, ie. less (before) than now - * - * @return bool - */ - public function isPast() - { - return $this->lt(static::now($this->getTimezone())); - } - - /** - * Compares the formatted values of the two dates. - * - * @param string $format The date formats to compare. - * @param Verta|null $v The instance to compare with or null to use current day. - * - * @return bool - */ - public function isSameAs($format, Verta $v = null) - { - $v = $v ?: static::now($this->getTimezone()); - - return $this->format($format) === $v->format($format); - } - - /** - * Determines if the instance is in the current year - * - * @return bool - */ - public function isCurrentYear() - { - return $this->isSameYear(); - } - - /** - * Checks if the passed in date is in the same year as the instance year. - * - * @param Verta|null $v The instance to compare with or null to use current day. - * - * @return bool - */ - public function isSameYear(Verta $v = null) - { - return $this->isSameAs('Y', $v); - } - - /** - * Determines if the instance is in the current month - * - * @return bool - */ - public function isCurrentMonth() - { - return $this->isSameMonth(); - } - - /** - * Checks if the passed in date is in the same month as the instance month (and year if needed). - * $this->assertFalse($datetime->isCurrentMonth()); - - * @param Verta|null $v The instance to compare with or null to use current day. - * @param bool $ofSameYear Check if it is the same month in the same year. - * - * @return bool - */ - public function isSameMonth(Verta $v = null, $ofSameYear = false) - { - $format = $ofSameYear ? 'Y-m' : 'm'; - - return $this->isSameAs($format, $v); - } - - /** - * Checks if the passed in date is the same day as the instance current day. - * - * @param Verta $v - * - * @return bool - */ - public function isSameDay(Verta $v) - { - return $this->formatDate() === $v->formatDate(); - } - - /** - * Check if its the birthday. Compares the date/month values of the two dates. - * - * @param Verta|null $dt The instance to compare with or null to use current day. - * - * @return bool - */ - public function isBirthday(Verta $v = null) - { - return $this->isSameAs('md', $v); - } - - /** - * Checks if this day is a Saturday. - * - * @return bool - */ - public function isSaturday() - { - return $this->dayOfWeek === static::SATURDAY; - } - - /** - * Checks if this day is a Sunday. - * - * @return bool - */ - public function isSunday() - { - return $this->dayOfWeek === static::SUNDAY; - } - - /** - * Checks if this day is a Monday. - * - * @return bool - */ - public function isMonday() - { - return $this->dayOfWeek === static::MONDAY; - } - - /** - * Checks if this day is a Tuesday. - * - * @return bool - */ - public function isTuesday() - { - return $this->dayOfWeek === static::TUESDAY; - } - - /** - * Checks if this day is a Wednesday. - * - * @return bool - */ - public function isWednesday() - { - return $this->dayOfWeek === static::WEDNESDAY; - } - - /** - * Checks if this day is a Thursday. - * - * @return bool - */ - public function isThursday() - { - return $this->dayOfWeek === static::THURSDAY; - } - - /** - * Checks if this day is a Friday. - * - * @return bool - */ - public function isFriday() - { - return $this->dayOfWeek === static::FRIDAY; - } -} diff --git a/src/Traits/Creator.php b/src/Traits/Creator.php deleted file mode 100644 index 07502e2..0000000 --- a/src/Traits/Creator.php +++ /dev/null @@ -1,421 +0,0 @@ -getTimestamp()}"; - } elseif (is_int($datetime)) { - $dt = "@$datetime"; - } - - try { - if ($datetime instanceof DateTime) { - parent::__construct($dt); - parent::setTimezone($datetime->getTimezone()); - } else { - parent::__construct($dt, static::createTimeZone($timezone)); - } - self::loadMessages(); - } catch (Exception $exception) { - throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime)); - } - } - - /** - * Create a Verta now datetime - * - * - * @param null $timezone - * @return static - */ - public static function now($timezone = null) - { - return new static(null, $timezone); - } - - /** - * Create a Verta instance for today. - * - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function today($timezone = null) - { - return (new static(null, $timezone))->startDay(); - } - - /** - * Create a Verta instance for tomorrow. - * - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function tomorrow($timezone = null) - { - return (new static(null, $timezone))->addDay()->startDay(); - } - - /** - * Create a Verta instance for yesterday. - * - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function yesterday($timezone = null) - { - return (new static(null, $timezone))->subDay()->startDay(); - } - - /** - * Create a Verta instance from a DateTime one - * - * @param $datetime [optional] - * @param \DateTimeZone|string|null $timezone [optional] - * - * @return static - */ - public static function instance($datetime = null, $timezone = null) - { - return new static($datetime, $timezone); - } - - /** - * Get a copy of the instance. - * - * @return static - */ - public function copy() - { - return clone $this; - } - - /** - * Get a copy of the instance. - * - * @return static - */ - public function clone() - { - return clone $this; - } - - /** - * Create a DateTime instance from Verta - * - * @return datetime $datetime - */ - public function datetime() - { - $dt = new DateTime(date('Y-m-d H:i:s', $this->getTimestamp())); - $dt->setTimezone($this->getTimezone()); - - return $dt; - } - - /** - * Create a Carbon instance from Verta - * - * @return Carbon - */ - public function toCarbon() - { - return Carbon::instance($this->datetime()); - } - - /** - * Create a Verta instance from a DateTime one - * - * @param $datetime [optional] - * @param bool $timezone [optional] - * - * @return static - */ - public static function parse($datetime, $timezone = null) - { - self::loadMessages(); - $names = array_map(function ($value) { - return " $value "; - }, array_values(self::$messages['year_months'])); - $values = array_map(function ($value) { - return "-$value-"; - }, range(1, 12)); - - $formatted = str_replace($names, $values, $datetime); - $formatted = str_replace(array_values(self::$messages['year_months']), range(1, 12), $formatted); - $parse = date_parse($formatted); - if ($parse['error_count'] > 0 || ! self::isValidDate($parse['year'], $parse['month'], $parse['day']) || ! self::isValidTime($parse['hour'], $parse['minute'], $parse['second'])) { - throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime)); - } - - list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']); - list($hour, $minute, $second) = [$parse['hour'], $parse['minute'], $parse['second']]; - - $datetime = sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second); - - return new static($datetime, $timezone); - } - - /** - * Create a Verta instance from a DateTime one - * - * @param string $format - * @param string $datetime [optional] - * @param bool $timezone [optional] - * @return static - */ - public static function parseFormat($format, $datetime, $timezone = null) - { - self::loadMessages(); - $formatted = str_replace(array_values(self::$messages['year_months']), range(1, 12), $datetime); - - $parse = date_parse_from_format($format, $formatted); - if ($parse['error_count'] > 0 || ! self::isValidDate($parse['year'], $parse['month'], $parse['day']) || ! self::isValidTime($parse['hour'], $parse['minute'], $parse['second'])) { - throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime)); - } - list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']); - list($hour, $minute, $second) = [$parse['hour'], $parse['minute'], $parse['second']]; - - $datetime = sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second); - - return new static($datetime, $timezone); - } - - /** - * Create a new Verta instance from a specific date and time gregorain. - * - * If any of feild are set to null their now() values will - * be used. - * - * @param int|null $year - * @param int|null $month - * @param int|null $day - * @param int|null $hour - * @param int|null $minute - * @param int|null $second - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null) - { - return static::createGregorian($year, $month, $day, $hour, $minute, $second, $timezone); - } - - /** - * Create a Verta from just a date gregorian. - * - * @param int|null $year - * @param int|null $month - * @param int|null $day - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function createDate($year = null, $month = null, $day = null, $timezone = null) - { - return static::create($year, $month, $day, null, null, null, $timezone); - } - - /** - * Create a Verta instance from just a time gregorian. - * - * @param int|null $hour - * @param int|null $minute - * @param int|null $second - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function createTime($hour = null, $minute = null, $second = null, $timezone = null) - { - return static::create(null, null, null, $hour, $minute, $second, $timezone); - } - - /** - * Create a Verta instance from a timestamp. - * - * @param int $timestamp - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function createTimestamp($timestamp, $timezone = null) - { - return static::instance($timestamp, $timezone); - } - - /** - * @param null $timezone - * @return DateTimeZone|string|null - */ - protected static function createTimeZone($timezone = null) - { - if ($timezone === null) { - return new DateTimeZone(date_default_timezone_get()); - } elseif ($timezone instanceof DateTimeZone) { - return $timezone; - } else { - $tz = @timezone_open(strval($timezone)); - if ($tz === false) { - throw new InvalidArgumentException(sprintf("Unknown timezone '%s'", $tz)); - } - - return $tz; - } - } - - /** - * Create a new Verta instance from a specific date and time gregorain. - * - * If any of feild are set to null their now() values will - * be used. - * - * @param int|null $year - * @param int|null $month - * @param int|null $day - * @param int|null $hour - * @param int|null $minute - * @param int|null $second - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function createGregorian($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null) - { - $now = (new DateTime())->format('Y-n-j-G-i-s'); - $defaults = array_combine(['year', 'month', 'day', 'hour', 'minute', 'second'], explode('-', $now)); - - $year = $year ?? intval($defaults['year']); - $month = $month ?? intval($defaults['month']); - $day = $day ?? intval($defaults['day']); - $hour = $hour ?? intval($defaults['hour']); - $minute = $minute ?? intval($defaults['minute']); - $second = $second ?? intval($defaults['second']); - - if (! checkdate($month, $day, $year) || ! static::isValidTime($hour, $minute, $second)) { - throw new \InvalidArgumentException('Unknown datetime'); - } - - return new static(sprintf('%s-%s-%s %s:%s:%s', $year, $month, $day, $hour, $minute, $second), $timezone); - } - - /** - * Create a Verta from just a date gregorian. - * - * @param int|null $year - * @param int|null $month - * @param int|null $day - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function createGregorianDate($year = null, $month = null, $day = null, $timezone = null) - { - return static::createGregorian($year, $month, $day, null, null, null, $timezone); - } - - /** - * Create a Verta instance from just a time gregorian. - * - * @param int|null $hour - * @param int|null $minute - * @param int|null $second - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function createGregorianTime($hour = null, $minute = null, $second = null, $timezone = null) - { - return static::createGregorian(null, null, null, $hour, $minute, $second, $timezone); - } - - /** - * Create a new Verta instance from a specific date and time. - * - * If any of feild are set to null their now() values will - * be used. - * - * @param int|null $year - * @param int|null $month - * @param int|null $day - * @param int|null $hour - * @param int|null $minute - * @param int|null $second - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function createJalali($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null) - { - $now = (new static())->format('Y-n-j-G-i-s'); - $defaults = array_combine(['year', 'month', 'day', 'hour', 'minute', 'second'], explode('-', $now)); - - $year = $year ?? intval($defaults['year']); - $month = $month ?? intval($defaults['month']); - $day = $day ?? intval($defaults['day']); - $hour = $hour ?? intval($defaults['hour']); - $minute = $minute ?? intval($defaults['minute']); - $second = $second ?? intval($defaults['second']); - - if (! static::isValidDate($year, $month, $day) || ! static::isValidTime($hour, $minute, $second)) { - throw new \InvalidArgumentException('Unknown datetime'); - } - - return static::parse(sprintf('%s-%s-%s %s:%s:%s', $year, $month, $day, $hour, $minute, $second)); - } - - /** - * Create a Verta from just a date. - * - * @param int|null $year - * @param int|null $month - * @param int|null $day - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function createJalaliDate($year = null, $month = null, $day = null, $timezone = null) - { - return static::createJalali($year, $month, $day, null, null, null, $timezone); - } - - /** - * Create a Verta instance from just a time. - * - * @param int|null $hour - * @param int|null $minute - * @param int|null $second - * @param \DateTimeZone|string|null $timezone - * - * @return static - */ - public static function createJalaliTime($hour = null, $minute = null, $second = null, $timezone = null) - { - return static::createJalali(null, null, null, $hour, $minute, $second, $timezone); - } -} diff --git a/src/Traits/Date.php b/src/Traits/Date.php deleted file mode 100644 index dc58d09..0000000 --- a/src/Traits/Date.php +++ /dev/null @@ -1,59 +0,0 @@ -getTimezone()); - - return (int) $this->diff($v->datetime())->format('%r%y'); - } - - /** - * Get the difference in months - * - * @param Verta|null $v - * - * @return int - */ - public function diffMonths(Verta $v = null) - { - $v = $v ?: static::now($this->getTimezone()); - - return $this->diffYears($v) * static::MONTHS_PER_YEAR + (int) $this->diff($v->datetime())->format('%r%m'); - } - - /** - * Get the difference in weeks - * - * @param Verta|null $v - * - * @return int - */ - public function diffWeeks(Verta $v = null) - { - return (int) ($this->diffDays($v) / static::DAYS_PER_WEEK); - } - - /** - * Get the difference in days - * - * @param Verta|null $v - * - * @return int - */ - public function diffDays(Verta $v = null) - { - $v = $v ?: static::now($this->getTimezone()); - - return (int) $this->diff($v->datetime())->format('%r%a'); - } - - /** - * Get the difference in hours - * - * @param Verta|null $v - * - * @return int - */ - public function diffHours(Verta $v = null) - { - return (int) ($this->diffSeconds($v) / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR); - } - - /** - * Get the difference in minutes - * - * @param Verta|null $v - * - * @return int - */ - public function diffMinutes(Verta $v = null) - { - return (int) ($this->diffSeconds($v) / static::SECONDS_PER_MINUTE); - } - - /** - * Get the difference in seconds - * - * @param Verta|null $v - * - * @return int - */ - public function diffSeconds(Verta $v = null) - { - $v = $v ?: static::now($this->getTimezone()); - - return $v->getTimestamp() - $this->getTimestamp(); - } -} diff --git a/src/Traits/Formatting.php b/src/Traits/Formatting.php deleted file mode 100644 index 40718a7..0000000 --- a/src/Traits/Formatting.php +++ /dev/null @@ -1,478 +0,0 @@ -format(static::$stringFormat); - } - - /** - * The format of the outputted date string (jalali equivalent of php date() function) - * - * @param string $format for example 'Y-m-d H:i:s' - * @return string - */ - protected function date(string $format): string - { - $timestamp = $this->getTimestamp(); - - list($gYear, $gMonth, $gDay, $gWeek) = explode('-', parent::format('Y-m-d-w')); - list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay); - - $pWeek = $gWeek + 1; - - if ($pWeek >= 7) { - $pWeek = 0; - } - - $lengh = strlen($format); - $index = 0; - $result = ''; - - while ($index < $lengh) { - $char = $format[$index]; - if ($char == '\\') { - $result .= $format[++$index]; - $index++; - - continue; - } - $result .= $this->characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek); - - $index++; - } - - return $result; - } - - /** - * The format of the outputted date charactre (jalali equivalent of php date() function) - * - * @param string $char - * @param int $timestamp - * @param int $pYear - * @param int $pMonth - * @param int $pDay - * @param int $pWeek - * @return string - */ - private function characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek) - { - switch ($char) { - # Day - case 'd': - return sprintf('%02s', $pDay); - - case 'D': - return substr(self::$messages['weekdays'][$pWeek + 1], 0, 2); - - case 'j': - return $pDay; - - case 'l': - return self::$messages['weekdays'][$pWeek + 1]; - - case 'N': - return $pWeek + 1; - - case 'w': - return $pWeek; - - case 'z': - return $this->daysYear($pMonth, $pDay); - - case 'S': - return static::$messages['phrase']['th']; - - # Week - case 'W': - return $this->dayOfWeek(); - - # Month - case 'F': - return self::$messages['year_months'][$pMonth]; - - case 'm': - return sprintf('%02s', $pMonth); - - case 'M': - return substr(self::$messages['year_months'][$pMonth], 0, 6); - - case 'n': - return $pMonth; - - 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)); - - case 'Y': - case 'o': - return $pYear; - - case 'y': - return substr($pYear, 2); - - # Time - case 'a': - return static::$messages['phrase'][parent::format('a')]; - - case 'A': - return static::$messages['pharse'][parent::format('a') == 'am' ? 'ante_meridiem' : 'post_meridiem']; - - case 'B': - case 'g': - case 'G': - case 'h': - case 'H': - case 's': - case 'u': - case 'i': - # Timezone - case 'e': - case 'I': - case 'O': - case 'P': - case 'T': - case 'Z': - return parent::format($char); - - # Full Date/Time - case 'c': - return ($pYear . '-' . $pMonth . '-' . $pDay . ' ' . parent::format('H:i:s P')); - - case 'r': - return (substr(self::$messages['weekdays'][$pWeek], 0, 2) . '، ' . $pDay . ' ' . substr(self::$messages['year_months'][$pMonth], 0, 6) . ' ' . $pYear . ' ' . parent::format('H:i:s P')); - - case 'U': - return $timestamp; - - default: - return $char; - } - } - - /** - * The format of the outputted date string (jalali equivalent of php date() function) - * - * @param string $format for example 'Y-m-d H:i:s' - * @return string - */ - protected function dateWord($format) - { - $timestamp = $this->getTimestamp(); - - list($gYear, $gMonth, $gDay, $gWeek) = explode('-', parent::format('Y-m-d-w')); - list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay); - - $pWeek = $gWeek + 1; - - if ($pWeek >= 7) { - $pWeek = 0; - } - - $lengh = strlen($format); - $index = 0; - $result = ''; - - while ($index < $lengh) { - $char = $format[$index]; - if ($char == '\\') { - $result .= $format[++$index]; - $index++; - - continue; - } - $output = $this->characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek); - if (is_numeric($output)) { - $output = (string) new Notowo($output, static::getLocale() == 'en' ? 'en' : 'fa'); - } - $result .= $output; - - $index++; - } - - return $result; - } - - /** - * return day number from first day of year - * - * @param int $month - * @param int $day - * @return type - * @since 5.0.0 - */ - protected function daysYear($month, $day) - { - $days = 0; - for ($i = 1; $i < $month; $i++) { - $days += static::$daysMonthJalali[$i - 1]; - } - - return ($days + $day); - } - - /** - * return week number from first of year - * - * @param int $month - * @param int $day - * @return type - * @since 5.0.0 - */ - protected function dayOfWeek() - { - $offset = $this->clone()->startYear()->format('w'); - $days = $this->format('z'); - - return ceil(($days + $offset) / 7); - } - - /** - * The format of the outputted date string (jalali equivalent of php strftime() function) - * - * @param $format - * @return string - */ - protected function strftime($format) - { - $strftime_date = [ - "%a" => "D", - "%A" => "l", - "%d" => "d", - "%e" => "j", - "%j" => "z", - "%u" => "N", - "%w" => "w", - "%U" => "W", - "%V" => "W", - "%W" => "W", - "%b" => "M", - "%B" => "F", - "%h" => "M", - "%m" => "m", - "%C" => "y", - "%g" => "y", - "%G" => "y", - "%y" => "y", - "%Y" => "Y", - "%H" => "H", - "%I" => "h", - "%l" => "g", - "%M" => "i", - "%p" => "A", - "%P" => "a", - "%r" => "h:i:s A", - "%R" => "H:i", - "%S" => "s", - "%T" => "H:i:s", - "%X" => "h:i:s", - "%z" => "H", - "%Z" => "H", - "%c" => "D j M H:i:s", - "%D" => "d/m/y", - "%F" => "Y-m-d", - "%s" => "U", - "%x" => "d/m/y", - "%n" => "\n", - "%t" => "\t", - "%%" => "%", - "%Q" => "q", - "%q" => "q", - ]; - - return str_replace(array_keys($strftime_date), array_values($strftime_date), $format); - } - - /** - * The format of the outputted date string (jalali equivalent of php strftime() function) - * - * @param string $format - * @return string - */ - #[ReturnTypeWillChange] - public function format($format) - { - return $this->date($this->strftime($format)); - } - - /** - * The format of the outputted date string (gregorian) - * - * @param string $format - * @return string - */ - public function formatGregorian(string $format): string - { - return $this->datetime()->format($format); - } - - /** - * Format the instance as date - * - * @return string - */ - public function formatDatetime(): string - { - return $this->format('Y-m-d H:i:s'); - } - - /** - * Format the instance as date - * - * @return string - */ - public function formatDate() - { - return $this->format('Y-m-d'); - } - - /** - * Format the instance as time - * - * @return string - */ - public function formatTime() - { - return $this->format('H:i:s'); - } - - /** - * Format the instance as date - * - * @return string - */ - public function formatJalaliDatetime() - { - return $this->format('Y/n/j H:i:s'); - } - - /** - * Format the instance as date - * - * @return string - */ - public function formatJalaliDate() - { - return $this->format('Y/n/j'); - } - - /** - * get difference in all - * - * @param Verta|null $v - * - * @return string - */ - public function formatDifference(Verta $v = null) - { - $units = [ - static::SECONDS_PER_MINUTE, - static::MINUTES_PER_HOUR, - static::HOURS_PER_DAY, - static::DAYS_PER_WEEK, - static::WEEKS_PER_MONTH, - static::MONTHS_PER_YEAR, - static::YEARS_PER_DECADE, - static::DECADE_PER_CENTURY, - ]; - $difference = $this->diffSeconds($v); - $absolute = static::$messages['phrase'][$difference < 0 ? 'later' : 'ago']; - - $difference = abs($difference); - - for ($unit = 0; $difference >= $units[$unit] and $unit < count($units) - 1; $unit++) { - $difference /= $units[$unit]; - } - $difference = intval(round($difference)); - - if ($difference === 0) { - return static::$messages['phrase']['now']; - } - - return sprintf('%s %s %s', $difference, array_values(static::$messages['date_units'])[$unit], $absolute); - } - - public function formatWord($format) - { - return $this->dateWord($this->strftime($format)); - } - - /** - * Convert english numbers to persian numbers - * - * @param string $string - * @return string - */ - public static function enToFaNumbers($string) - { - $en = static::getMessages('en'); - $fa = static::getMessages('fa'); - - return str_replace(array_values($en['numbers']), array_values($fa['numbers']), $string); - } - - /** - * Convert english numbers to persian numbers - * - * @param string $string - * @return string - */ - public static function faToEnNumbers($string) - { - $fa = static::getMessages('fa'); - $en = static::getMessages('en'); - - return str_replace(array_values($fa['numbers']), array_values($en['numbers']), $string); - } - - /** - * Convert english numbers to persian numbers - * - * @param string $string - * @return string - */ - public static function arToEnNumbers($string) - { - $ar = static::getMessages('ar'); - $en = static::getMessages('en'); - - return str_replace(array_values($ar['numbers']), array_values($en['numbers']), $string); - } -} diff --git a/src/Traits/Modification.php b/src/Traits/Modification.php deleted file mode 100644 index 7ad60db..0000000 --- a/src/Traits/Modification.php +++ /dev/null @@ -1,370 +0,0 @@ -year($this->year + $value); - } - - /** - * Add a year to the instance - * - * @param int $value - * - * @return static - */ - public function addYear($value = 1) - { - return $this->addYears($value); - } - - /** - * Remove years from the instance. - * - * @param int $value - * - * @return static - */ - public function subYears($value) - { - return $this->addYears(-1 * $value); - } - - /** - * Remove a year from the instance - * - * @param int $value - * - * @return static - */ - public function subYear($value = 1) - { - return $this->subYears($value); - } - - /** - * Add months to the instance. Positive $value travels forward while - * negative $value travels into the past. - * - * @param int $value - * - * @return static - */ - public function addMonths($value) - { - list($year, $month, $day, $hour, $minute, $second) = explode('-', $this->format('Y-m-d-H-i-s')); - $month += $value; - if ($month > 12) { - $year += intval($month / 12); - $month = $month % 12; - } elseif ($month < 1) { - $year += intval($month / 12) - 1; - $month = 12 + ($month % 12); - } - if ($month == 0) { - $year--; - $month = 12; - } - if (($month > 6 && $month < 12 && $day == 31)) { - $day--; - } else { - if ($month == 12 && ($day == 30 || $day == 31)) { - $day = self::isLeapYear($year) ? 30 : 29; - } - } - - return self::createJalali($year, $month, $day, $hour, $minute, $second, $this->getTimeZone()); - } - - /** - * Add a month to the instance - * - * @param int $value - * - * @return static - */ - public function addMonth($value = 1) - { - return $this->addMonths($value); - } - - /** - * Remove a month from the instance - * - * @param int $value - * - * @return static - */ - public function subMonth($value = 1) - { - return $this->subMonths($value); - } - - /** - * Remove months from the instance - * - * @param int $value - * - * @return static - */ - public function subMonths($value) - { - return $this->addMonths(-1 * $value); - } - - /** - * Add days to the instance. Positive $value travels forward while - * negative $value travels into the past. - * - * @param int $value - * - * @return static - */ - public function addDays($value) - { - return $this->modify((int) $value.' day'); - } - - /** - * Add a day to the instance - * - * @param int $value - * - * @return static - */ - public function addDay($value = 1) - { - return $this->addDays($value); - } - - /** - * Remove a day from the instance - * - * @param int $value - * - * @return static - */ - public function subDay($value = 1) - { - return $this->subDays($value); - } - - /** - * Remove days from the instance - * - * @param int $value - * - * @return static - */ - public function subDays($value) - { - return $this->addDays(-1 * $value); - } - - /** - * Add weeks to the instance. Positive $value travels forward while - * negative $value travels into the past. - * - * @param int $value - * - * @return static - */ - public function addWeeks($value) - { - return $this->modify((int) $value.' week'); - } - - /** - * Add a week to the instance - * - * @param int $value - * - * @return static - */ - public function addWeek($value = 1) - { - return $this->addWeeks($value); - } - - /** - * Remove a week from the instance - * - * @param int $value - * - * @return static - */ - public function subWeek($value = 1) - { - return $this->subWeeks($value); - } - - /** - * Remove weeks to the instance - * - * @param int $value - * - * @return static - */ - public function subWeeks($value) - { - return $this->addWeeks(-1 * $value); - } - - /** - * Add hours to the instance. Positive $value travels forward while - * negative $value travels into the past. - * - * @param int $value - * - * @return static - */ - public function addHours($value) - { - return $this->modify((int) $value.' hour'); - } - - /** - * Add an hour to the instance - * - * @param int $value - * - * @return static - */ - public function addHour($value = 1) - { - return $this->addHours($value); - } - - /** - * Remove an hour from the instance - * - * @param int $value - * - * @return static - */ - public function subHour($value = 1) - { - return $this->subHours($value); - } - - /** - * Remove hours from the instance - * - * @param int $value - * - * @return static - */ - public function subHours($value) - { - return $this->addHours(-1 * $value); - } - - /** - * Add minutes to the instance. Positive $value travels forward while - * negative $value travels into the past. - * - * @param int $value - * - * @return static - */ - public function addMinutes($value) - { - return $this->modify((int) $value.' minute'); - } - - /** - * Add a minute to the instance - * - * @param int $value - * - * @return static - */ - public function addMinute($value = 1) - { - return $this->addMinutes($value); - } - - /** - * Remove a minute from the instance - * - * @param int $value - * - * @return static - */ - public function subMinute($value = 1) - { - return $this->subMinutes($value); - } - - /** - * Remove minutes from the instance - * - * @param int $value - * - * @return static - */ - public function subMinutes($value) - { - return $this->addMinutes(-1 * $value); - } - - /** - * Add seconds to the instance. Positive $value travels forward while - * negative $value travels into the past. - * - * @param int $value - * - * @return static - */ - public function addSeconds($value) - { - return $this->modify((int) $value.' second'); - } - - /** - * Add a second to the instance - * - * @param int $value - * - * @return static - */ - public function addSecond($value = 1) - { - return $this->addSeconds($value); - } - - /** - * Remove a second from the instance - * - * @param int $value - * - * @return static - */ - public function subSecond($value = 1) - { - return $this->subSeconds($value); - } - - /** - * Remove seconds from the instance - * - * @param int $value - * - * @return static - */ - public function subSeconds($value) - { - return $this->addSeconds(-1 * $value); - } -} diff --git a/src/Traits/Transformation.php b/src/Traits/Transformation.php deleted file mode 100644 index ffd2707..0000000 --- a/src/Traits/Transformation.php +++ /dev/null @@ -1,89 +0,0 @@ - 1 && (($gy % 4 == 0 && $gy % 100 != 0) || ($gy % 400 == 0))) { - # leap and after Feb - $g_day_no++; - } - $g_day_no += $g_d - 1; - $j_day_no = $g_day_no - 79; - $j_np = intval($j_day_no / 12053); # 12053 = (365 * 33 + 32 / 4) - $j_day_no = $j_day_no % 12053; - $jy = (979 + 33 * $j_np + 4 * intval($j_day_no / 1461)); # 1461 = (365 * 4 + 4 / 4) - $j_day_no %= 1461; - if ($j_day_no >= 366) { - $jy += intval(($j_day_no - 1) / 365); - $j_day_no = ($j_day_no - 1) % 365; - } - for ($i = 0; ($i < 11 && $j_day_no >= static::$daysMonthJalali[$i]); ++$i) { - $j_day_no -= static::$daysMonthJalali[$i]; - } - - return [$jy, $i + 1, $j_day_no + 1]; - } - - /** - * jalali to gregorian convertion - * - * @param int $j_y - * @param int $j_m - * @param int $j_d - * @return array - */ - public static function getGregorian($j_y, $j_m, $j_d) - { - $jy = $j_y - 979; - $jm = $j_m - 1; - $j_day_no = (365 * $jy + intval($jy / 33) * 8 + intval(($jy % 33 + 3) / 4)); - for ($i = 0; $i < $jm; ++$i) { - $j_day_no += static::$daysMonthJalali[$i]; - } - $j_day_no += $j_d - 1; - $g_day_no = $j_day_no + 79; - $gy = (1600 + 400 * intval($g_day_no / 146097)); # 146097 = (365 * 400 + 400 / 4 - 400 / 100 + 400 / 400) - $g_day_no = $g_day_no % 146097; - $leap = 1; - if ($g_day_no >= 36525) { # 36525 = (365 * 100 + 100 / 4) - $g_day_no--; - $gy += (100 * intval($g_day_no / 36524)); # 36524 = (365 * 100 + 100 / 4 - 100 / 100) - $g_day_no = $g_day_no % 36524; - if ($g_day_no >= 365) { - $g_day_no++; - } else { - $leap = 0; - } - } - $gy += (4 * intval($g_day_no / 1461)); # 1461 = (365 * 4 + 4 / 4) - $g_day_no %= 1461; - if ($g_day_no >= 366) { - $leap = 0; - $g_day_no--; - $gy += intval($g_day_no / 365); - $g_day_no = ($g_day_no % 365); - } - for ($i = 0; $g_day_no >= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap)); $i++) { - $g_day_no -= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap)); - } - - return [$gy, $i + 1, $g_day_no + 1]; - } -} diff --git a/src/Traits/Translator.php b/src/Traits/Translator.php deleted file mode 100644 index f01b68f..0000000 --- a/src/Traits/Translator.php +++ /dev/null @@ -1,102 +0,0 @@ -assertEquals(1397, $datetime->year); $this->assertEquals(10, $datetime->month); @@ -29,7 +29,7 @@ class AccessTest extends TestCase public function testSetProperty() { - $datetime = new Verta('2019-01-01 17:20:35', 'Asia/Tehran'); + $datetime = Jalali::parse('1399-01-01 17:20:35', 'Asia/Tehran'); $datetime->year = 1398; $this->assertEquals(1398, $datetime->year); @@ -52,13 +52,13 @@ class AccessTest extends TestCase $datetime->timestamp = 1546382684; $this->assertEquals(1546382684, $datetime->timestamp); - $datetime->tz = 'UTC'; + $datetime->timezone = 'UTC'; $this->assertEquals('UTC', $datetime->timezone); } public function testSetMethods() { - $datetime = Verta::parse('1399-05-12 12:36:32'); + $datetime = Jalali::parse('1399-05-12 12:36:32'); $datetime->year(1395); $this->assertEquals(1395, $datetime->year); @@ -87,7 +87,7 @@ class AccessTest extends TestCase public function testSetDateTime() { - $datetime = verta()->setDateTime(1397, 10, 11, 10, 20, 11); + $datetime = jalali()->setDateTime(1397, 10, 11, 10, 20, 11); $this->assertEquals(1397, $datetime->year); $this->assertEquals(10, $datetime->month); @@ -99,7 +99,7 @@ class AccessTest extends TestCase public function testSetDate() { - $datetime = verta()->setDateJalali(1397, 10, 11); + $datetime = jalali()->setDateJalali(1397, 10, 11); $this->assertEquals(1397, $datetime->year); $this->assertEquals(10, $datetime->month); @@ -108,7 +108,7 @@ class AccessTest extends TestCase public function testSetTime() { - $datetime = verta()->setTime(10, 20, 11); + $datetime = jalali()->setTime(10, 20, 11); $this->assertEquals(10, $datetime->hour); $this->assertEquals(20, $datetime->minute); @@ -117,7 +117,7 @@ class AccessTest extends TestCase public function testSetTimeString() { - $datetime = verta()->setTimeString('10:20:11'); + $datetime = jalali()->setTimeString('10:20:11'); $this->assertEquals(10, $datetime->hour); $this->assertEquals(20, $datetime->minute); diff --git a/tests/ComparisionTest.php b/tests/ComparisionTest.php deleted file mode 100644 index c5a406a..0000000 --- a/tests/ComparisionTest.php +++ /dev/null @@ -1,279 +0,0 @@ -assertTrue($result); - - $result = Verta::isValidDate(-1365, 12, 15); - $this->assertFalse($result); - - $result = Verta::isValidDate(1365, 13, 15); - $this->assertFalse($result); - - $result = Verta::isValidDate(1365, 12, 32); - $this->assertFalse($result); - } - - public function testValidTime() - { - $result = Verta::isValidTime(13, 12, 15); - $this->assertTrue($result); - - $result = Verta::isValidTime(25, 12, 15); - $this->assertFalse($result); - - $result = Verta::isValidTime(14, 65, 15); - $this->assertFalse($result); - - $result = Verta::isValidTime(14, 12, 66); - $this->assertFalse($result); - } - - public function testDiffYears() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->diffYears(Verta::parse('1398-10-10 21:30:50')); - $this->assertEquals(0, $result); - - $result = $datetime->diffYears(Verta::parse('1395-10-10 21:30:50')); - $this->assertEquals(-3, $result); - - $result = $datetime->diffYears(Verta::parse('1399-10-11 21:30:50')); - $this->assertEquals(1, $result); - } - - public function testDiffMonths() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - $result = $datetime->diffMonths($datetime); - - $this->assertEquals(0, $result); - - $result = $datetime->diffMonths(Verta::parse('1399-12-15 21:30:50')); - $this->assertEquals(14, $result); - - $result = $datetime->diffMonths(Verta::parse('1397-08-10 21:30:50')); - $this->assertEquals(-13, $result); - } - - public function testDiffDays() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->diffDays(Verta::parse('1398-10-10 21:30:50')); - $this->assertEquals(0, $result); - - $result = $datetime->diffDays(Verta::parse('1398-10-15 21:30:50')); - $this->assertEquals(5, $result); - - $result = $datetime->diffDays(Verta::parse('1398-10-01 21:30:50')); - $this->assertEquals(-9, $result); - } - - public function testDiffHours() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->diffHours(Verta::parse('1398-10-10 21:30:50')); - $this->assertEquals(0, $result); - - $result = $datetime->diffHours(Verta::parse('1398-10-10 23:30:50')); - $this->assertEquals(2, $result); - - $result = $datetime->diffHours(Verta::parse('1398-10-10 20:30:50')); - $this->assertEquals(-1, $result); - } - - public function testDiffMinutes() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->diffMinutes(Verta::parse('1398-10-10 21:30:50')); - $this->assertEquals(0, $result); - - $result = $datetime->diffMinutes(Verta::parse('1398-10-10 21:40:50')); - $this->assertEquals(10, $result); - - $result = $datetime->diffMinutes(Verta::parse('1398-10-10 20:30:50')); - $this->assertEquals(-60, $result); - } - - public function testDiffSeconds() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->diffSeconds(Verta::parse('1398-10-10 21:30:50')); - $this->assertEquals(0, $result); - - $result = $datetime->diffSeconds(Verta::parse('1398-10-10 21:30:53')); - $this->assertEquals(3, $result); - - - $result = $datetime->diffSeconds(Verta::parse('1398-10-10 21:30:45')); - $this->assertEquals(-5, $result); - } - - public function testEqualTo() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->eq(Verta::parse('1398-10-10 21:30:50')); - $this->assertTrue($result); - - $result = $datetime->eq(Verta::parse('1398-10-10 21:30:51')); - $this->assertFalse($result); - } - - public function testGreaterThan() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->gt(Verta::parse('1398-10-10 21:30:50')); - $this->assertFalse($result); - - $result = $datetime->gt(Verta::parse('1398-10-10 21:30:49')); - $this->assertTrue($result); - } - - public function testGreaterThanOrEqualTo() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->gte(Verta::parse('1398-10-10 21:30:50')); - $this->assertTrue($result); - - $result = $datetime->gte(Verta::parse('1398-10-10 21:30:49')); - $this->assertTrue($result); - - $result = $datetime->gte(Verta::parse('1398-10-10 21:30:51')); - $this->assertFalse($result); - } - - public function testLessThan() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->lt(Verta::parse('1398-10-10 21:30:50')); - $this->assertFalse($result); - - $result = $datetime->lt(Verta::parse('1398-10-10 21:30:51')); - $this->assertTrue($result); - } - - public function testLessThanOrEqualTo() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->lte(Verta::parse('1398-10-10 21:30:50')); - $this->assertTrue($result); - - $result = $datetime->lte(Verta::parse('1398-10-10 21:30:51')); - $this->assertTrue($result); - - - $result = $datetime->lte(Verta::parse('1398-10-10 21:30:49')); - $this->assertFalse($result); - } - - public function testBetween() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->between(Verta::parse('1398-10-10 21:30:50'), Verta::parse('1398-10-11 21:30:50')); - $this->assertTrue($result); - - $result = $datetime->between(Verta::parse('1398-10-10 21:30:50'), Verta::parse('1398-10-11 21:30:50'), false); - $this->assertFalse($result); - - $result = $datetime->between(Verta::parse('1398-10-13 21:30:50'), Verta::parse('1398-10-09 21:30:50')); - $this->assertTrue($result); - } - - public function testClosest() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->closest(Verta::parse('1398-10-10 21:30:01'), Verta::parse('1398-10-11 21:30:50')); - $this->assertEquals($result, Verta::parse('1398-10-10 21:30:01')); - - $result = $datetime->closest(Verta::parse('1398-11-10 21:30:50'), Verta::parse('1398-10-11 21:30:50')); - $this->assertEquals($result, Verta::parse('1398-10-11 21:30:50')); - } - - public function testFarthest() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->farthest(Verta::parse('1398-10-10 21:30:01'), Verta::parse('1398-10-11 21:30:50')); - $this->assertEquals($result, Verta::parse('1398-10-11 21:30:50')); - - $result = $datetime->farthest(Verta::parse('1398-11-10 21:30:50'), Verta::parse('1398-10-11 21:30:50')); - $this->assertEquals($result, Verta::parse('1398-11-10 21:30:50')); - } - - public function testMin() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->min(Verta::parse('1398-10-10 21:30:01')); - $this->assertEquals($result, Verta::parse('1398-10-10 21:30:01')); - - $result = $datetime->min(Verta::parse('1398-10-10 21:30:55')); - $this->assertEquals($result, Verta::parse('1398-10-10 21:30:50')); - } - - public function testMax() - { - $datetime = Verta::parse('1398-10-10 21:30:50'); - - $result = $datetime->max(Verta::parse('1398-10-10 21:30:01')); - $this->assertEquals($result, Verta::parse('1398-10-10 21:30:50')); - - $result = $datetime->max(Verta::parse('1398-10-10 21:30:55')); - $this->assertEquals($result, Verta::parse('1398-10-10 21:30:55')); - } - - public function testIs() - { - $datetime = Verta::parse('1397-10-10 21:30:50'); - $target = Verta::parse('1398-10-10 21:30:01'); - -// Verta::setTestNow('1397-10-10 21:30:50'); - - $this->assertTrue($datetime->isWeekday()); - $this->assertFalse($datetime->isWeekend()); - $this->assertFalse($datetime->isYesterday()); - $this->assertFalse($datetime->isToday()); - $this->assertFalse($datetime->isTomorrow()); - $this->assertFalse($datetime->isNextWeek()); - $this->assertFalse($datetime->isLastWeek()); - $this->assertFalse($datetime->isNextMonth()); - $this->assertFalse($datetime->isLastMonth()); - $this->assertFalse($datetime->isNextYear()); - $this->assertFalse($datetime->isLastYear()); - $this->assertFalse($datetime->isFuture()); - $this->assertTrue($datetime->isPast()); - $this->assertTrue($datetime->isSameAs('m-d', $target)); - $this->assertFalse($datetime->isSameAs('Y-m-d')); - $this->assertFalse($datetime->isCurrentYear()); - $this->assertFalse($datetime->isSameYear($target)); - $this->assertFalse($datetime->isSameDay($target)); - $this->assertTrue($datetime->isBirthday($target)); - $this->assertFalse($datetime->isSaturday()); - $this->assertFalse($datetime->isSunday()); - $this->assertTrue($datetime->isMonday()); - $this->assertFalse($datetime->isTuesday()); - $this->assertFalse($datetime->isWednesday()); - $this->assertFalse($datetime->isThursday()); - $this->assertFalse($datetime->isFriday()); - } -} diff --git a/tests/ComparisonTest.php b/tests/ComparisonTest.php new file mode 100644 index 0000000..320c34e --- /dev/null +++ b/tests/ComparisonTest.php @@ -0,0 +1,304 @@ +assertTrue($result); + + $result = Jalali::isValidDate(-1365, 12, 15); + $this->assertFalse($result); + + $result = Jalali::isValidDate(1365, 13, 15); + $this->assertFalse($result); + + $result = Jalali::isValidDate(1365, 12, 32); + $this->assertFalse($result); + } + + public function testValidTime() + { + $result = Jalali::isValidTime(13, 12, 15); + $this->assertTrue($result); + + $result = Jalali::isValidTime(25, 12, 15); + $this->assertFalse($result); + + $result = Jalali::isValidTime(14, 65, 15); + $this->assertFalse($result); + + $result = Jalali::isValidTime(14, 12, 66); + $this->assertFalse($result); + } + + public function testDiffYears() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->diffYears(Jalali::parse('1398-10-10 21:30:50')); + $this->assertEquals(0, $result); + + $result = $datetime->diffYears(Jalali::parse('1395-10-10 21:30:50')); + $this->assertEquals(-3, $result); + + $result = $datetime->diffYears(Jalali::parse('1399-10-11 21:30:50')); + $this->assertEquals(1, $result); + } + + public function testDiffMonths() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + $result = $datetime->diffMonths($datetime); + + $this->assertEquals(0, $result); + + $result = $datetime->diffMonths(Jalali::parse('1399-12-15 21:30:50')); + $this->assertEquals(14, $result); + + $result = $datetime->diffMonths(Jalali::parse('1397-08-10 21:30:50')); + $this->assertEquals(-13, $result); + } + + public function testDiffDays() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->diffDays(Jalali::parse('1398-10-10 21:30:50')); + $this->assertEquals(0, $result); + + $result = $datetime->diffDays(Jalali::parse('1398-10-15 21:30:50')); + $this->assertEquals(5, $result); + + $result = $datetime->diffDays(Jalali::parse('1398-10-01 21:30:50')); + $this->assertEquals(-9, $result); + } + + public function testDiffWeeks() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->diffWeeks(Jalali::parse('1398-10-10 21:30:50')); + $this->assertEquals(0, $result); + + $result = $datetime->diffWeeks(Jalali::parse('1398-11-15 21:30:50')); + $this->assertEquals(5, $result); + + $result = $datetime->diffWeeks(Jalali::parse('1398-10-01 21:30:50')); + $this->assertEquals(-1, $result); + } + + public function testDiffHours() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->diffHours(Jalali::parse('1398-10-10 21:30:50')); + $this->assertEquals(0, $result); + + $result = $datetime->diffHours(Jalali::parse('1398-10-10 23:30:50')); + $this->assertEquals(2, $result); + + $result = $datetime->diffHours(Jalali::parse('1398-10-10 20:30:50')); + $this->assertEquals(-1, $result); + } + + public function testDiffMinutes() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->diffMinutes(Jalali::parse('1398-10-10 21:30:50')); + $this->assertEquals(0, $result); + + $result = $datetime->diffMinutes(Jalali::parse('1398-10-10 21:40:50')); + $this->assertEquals(10, $result); + + $result = $datetime->diffMinutes(Jalali::parse('1398-10-10 20:30:50')); + $this->assertEquals(-60, $result); + } + + public function testDiffSeconds() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->diffSeconds(Jalali::parse('1398-10-10 21:30:50')); + $this->assertEquals(0, $result); + + $result = $datetime->diffSeconds(Jalali::parse('1398-10-10 21:30:53')); + $this->assertEquals(3, $result); + + + $result = $datetime->diffSeconds(Jalali::parse('1398-10-10 21:30:45')); + $this->assertEquals(-5, $result); + } + + public function testEqualTo() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->eq(Jalali::parse('1398-10-10 21:30:50')); + $this->assertTrue($result); + + $result = $datetime->eq(Jalali::parse('1398-10-10 21:30:51')); + $this->assertFalse($result); + } + + public function testNotEqualTo() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->ne(Jalali::parse('1398-10-10 21:30:50')); + $this->assertFalse($result); + + $result = $datetime->notEqualTo(Jalali::parse('1398-10-10 21:30:51')); + $this->assertTrue($result); + } + + public function testGreaterThan() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->gt(Jalali::parse('1398-10-10 21:30:50')); + $this->assertFalse($result); + + $result = $datetime->greaterThanOrEqualTo(Jalali::parse('1398-10-10 21:30:49')); + $this->assertTrue($result); + } + + public function testGreaterThanOrEqualTo() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->gte(Jalali::parse('1398-10-10 21:30:50')); + $this->assertTrue($result); + + $result = $datetime->gte(Jalali::parse('1398-10-10 21:30:49')); + $this->assertTrue($result); + + $result = $datetime->gte(Jalali::parse('1398-10-10 21:30:51')); + $this->assertFalse($result); + } + + public function testLessThan() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->lt(Jalali::parse('1398-10-10 21:30:50')); + $this->assertFalse($result); + + $result = $datetime->lt(Jalali::parse('1398-10-10 21:30:51')); + $this->assertTrue($result); + } + + public function testLessThanOrEqualTo() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->lte(Jalali::parse('1398-10-10 21:30:50')); + $this->assertTrue($result); + + $result = $datetime->lessThanOrEqualTo(Jalali::parse('1398-10-10 21:30:51')); + $this->assertTrue($result); + + + $result = $datetime->lte(Jalali::parse('1398-10-10 21:30:49')); + $this->assertFalse($result); + } + + public function testBetween() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->between(Jalali::parse('1398-10-10 21:30:50'), Jalali::parse('1398-10-11 21:30:50')); + $this->assertTrue($result); + + $result = $datetime->between(Jalali::parse('1398-10-10 21:30:50'), Jalali::parse('1398-10-11 21:30:50'), false); + $this->assertFalse($result); + + $result = $datetime->between(Jalali::parse('1398-10-13 21:30:50'), Jalali::parse('1398-10-09 21:30:50')); + $this->assertTrue($result); + } + + public function testClosest() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->closest(Jalali::parse('1398-10-10 21:30:01'), Jalali::parse('1398-10-11 21:30:50')); + $this->assertEquals($result, Jalali::parse('1398-10-10 21:30:01')); + + $result = $datetime->closest(Jalali::parse('1398-11-10 21:30:50'), Jalali::parse('1398-10-11 21:30:50')); + $this->assertEquals($result, Jalali::parse('1398-10-11 21:30:50')); + } + + public function testFarthest() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->farthest(Jalali::parse('1398-10-10 21:30:01'), Jalali::parse('1398-10-11 21:30:50')); + $this->assertEquals($result, Jalali::parse('1398-10-11 21:30:50')); + + $result = $datetime->farthest(Jalali::parse('1398-11-10 21:30:50'), Jalali::parse('1398-10-11 21:30:50')); + $this->assertEquals($result, Jalali::parse('1398-11-10 21:30:50')); + } + + public function testMin() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->min(Jalali::parse('1398-10-10 21:30:01')); + $this->assertEquals($result, Jalali::parse('1398-10-10 21:30:01')); + + $result = $datetime->min(Jalali::parse('1398-10-10 21:30:55')); + $this->assertEquals($result, Jalali::parse('1398-10-10 21:30:50')); + } + + public function testMax() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->max(Jalali::parse('1398-10-10 21:30:01')); + $this->assertEquals($result, Jalali::parse('1398-10-10 21:30:50')); + + $result = $datetime->max(Jalali::parse('1398-10-10 21:30:55')); + $this->assertEquals($result, Jalali::parse('1398-10-10 21:30:55')); + } + + public function testIs() + { + $datetime = Jalali::parse('1397-10-10 21:30:50'); + $target = Jalali::parse('1398-10-10 21:30:01'); + +// Jalali::setTestNow('1397-10-10 21:30:50'); + + $this->assertTrue($datetime->isWeekday()); + $this->assertFalse($datetime->isWeekend()); + $this->assertFalse($datetime->isYesterday()); + $this->assertFalse($datetime->isToday()); + $this->assertFalse($datetime->isTomorrow()); + $this->assertFalse($datetime->isNextWeek()); + $this->assertFalse($datetime->isLastWeek()); + $this->assertFalse($datetime->isNextMonth()); + $this->assertFalse($datetime->isLastMonth()); + $this->assertFalse($datetime->isNextYear()); + $this->assertFalse($datetime->isLastYear()); + $this->assertFalse($datetime->isFuture()); + $this->assertTrue($datetime->isPast()); + $this->assertTrue($datetime->isSameAs('m-d', $target)); + $this->assertFalse($datetime->isSameAs('Y-m-d')); + $this->assertFalse($datetime->isCurrentYear()); + $this->assertFalse($datetime->isSameYear($target)); + $this->assertFalse($datetime->isSameDay($target)); + $this->assertTrue($datetime->isBirthday($target)); + $this->assertFalse($datetime->isSaturday()); + $this->assertFalse($datetime->isSunday()); + $this->assertTrue($datetime->isMonday()); + $this->assertFalse($datetime->isTuesday()); + $this->assertFalse($datetime->isWednesday()); + $this->assertFalse($datetime->isThursday()); + $this->assertFalse($datetime->isFriday()); + } +} diff --git a/tests/CreatorTest.php b/tests/CreatorTest.php index 726c1d0..6f54d0d 100644 --- a/tests/CreatorTest.php +++ b/tests/CreatorTest.php @@ -1,11 +1,10 @@ getTimestamp(); - $actual = Verta::now()->getTimestamp(); + $actual = Jalali::now()->getTimestamp(); $this->assertEquals($expected, $actual); } @@ -21,7 +20,7 @@ class CreatorTest extends TestCase public function testHelper() { $expected = (new DateTime())->getTimestamp(); - $actual = verta()->getTimestamp(); + $actual = Jalali()->getTimestamp(); $this->assertEquals($expected, $actual); } @@ -29,7 +28,7 @@ class CreatorTest extends TestCase public function testYesterday() { $expected = (new DateTime("-1 days"))->format('Y-m-d 00:00:00'); - $actual = (string)Verta::yesterday()->formatGregorian('Y-m-d H:i:s'); + $actual = (string)Jalali::yesterday()->formatGregorian('Y-m-d H:i:s'); $this->assertEquals($expected, $actual); } @@ -37,7 +36,7 @@ class CreatorTest extends TestCase public function testToday() { $expected = (new DateTime())->format('Y-m-d 00:00:00'); - $actual = (string)Verta::today()->formatGregorian('Y-m-d H:i:s'); + $actual = (string)Jalali::today()->formatGregorian('Y-m-d H:i:s'); $this->assertEquals($expected, $actual); } @@ -45,25 +44,18 @@ class CreatorTest extends TestCase public function testTomorrow() { $expected = (new DateTime("+1 days"))->format('Y-m-d 00:00:00'); - $actual = (string)Verta::tomorrow()->formatGregorian('Y-m-d H:i:s'); + $actual = (string)Jalali::tomorrow()->formatGregorian('Y-m-d H:i:s'); $this->assertEquals($expected, $actual); } public function testInstance() { - $datetime = (string) new Verta('2019-01-01 10:20:11'); + $datetime = (string) new Jalali('2019-01-01 10:20:11'); $this->assertEquals('1397-10-11 10:20:11', $datetime); - $datetime = (string) Verta::instance('2019-01-01 10:20:11'); - $this->assertEquals('1397-10-11 10:20:11', $datetime); - - $app = ['verta' => new Verta()]; - VertaFacade::setFacadeApplication($app); - - $datetime = (string) VertaFacade::instance('2019-01-01 10:20:11'); - + $datetime = (string) Jalali::instance('2019-01-01 10:20:11'); $this->assertEquals('1397-10-11 10:20:11', $datetime); } @@ -71,43 +63,35 @@ class CreatorTest extends TestCase { $now = new DateTime('now', new DateTimeZone('Asia/Tehran')); - $datetime = new Verta($now); + $datetime = new Jalali($now, 'Asia/Tehran'); $this->assertEquals($now->getTimezone()->getName(), $datetime->getTimezone()->getName()); - $this->assertEquals($now->format('Y-m-d H:i:s'), $datetime->datetime()->format('Y-m-d H:i:s')); } public function testDatetime() { - $datetime = verta('2019-01-01 10:20:11')->datetime()->format('Y-m-d H:i:s'); - - $this->assertEquals('2019-01-01 10:20:11', $datetime); - } - - public function testToCarbon() - { - $datetime = verta('2019-01-01 10:20:11')->toCarbon()->format('Y-m-d H:i:s'); + $datetime = jalali('2019-01-01 10:20:11')->datetime()->format('Y-m-d H:i:s'); $this->assertEquals('2019-01-01 10:20:11', $datetime); } public function testParse() { - $datetime = Verta::parse('1397 دی 11 10:20:11')->formatGregorian('Y-m-d H:i:s'); + $datetime = Jalali::parse('1397 دی 11 10:20:11')->formatGregorian('Y-m-d H:i:s'); $this->assertEquals('2019-01-01 10:20:11', $datetime); } public function testParseFormat() { - $datetime = Verta::parseFormat('Y-m-d H:i:s', '1397-10-11 10:20:11')->formatGregorian('Y-m-d H:i:s'); + $datetime = Jalali::parseFormat('Y-m-d H:i:s', '1397-10-11 10:20:11')->formatGregorian('Y-m-d H:i:s'); $this->assertEquals('2019-01-01 10:20:11', $datetime); } public function testCreate() { - $datetime = Verta::create(2019, 1, 1, 10, 20, 11)->format('Y-m-d H:i:s'); + $datetime = Jalali::create(2019, 1, 1, 10, 20, 11)->format('Y-m-d H:i:s'); $this->assertEquals('1397-10-11 10:20:11', $datetime); } @@ -115,7 +99,7 @@ class CreatorTest extends TestCase public function testCreateDate() { $time = (new DateTime())->format("H:i:s"); - $datetime = Verta::createDate(2019, 1, 1)->format('Y-m-d H:i:s'); + $datetime = Jalali::createDate(2019, 1, 1)->format('Y-m-d H:i:s'); $this->assertEquals("1397-10-11 {$time}", $datetime); } @@ -123,21 +107,21 @@ class CreatorTest extends TestCase public function testCreateTime() { $date = (new DateTime())->format("Y-m-d"); - $datetime = Verta::createTime(15, 19, 51)->formatGregorian('Y-m-d H:i:s'); + $datetime = Jalali::createTime(15, 19, 51)->formatGregorian('Y-m-d H:i:s'); $this->assertEquals("{$date} 15:19:51", $datetime); } public function testCreateTimestamp() { - $datetime = Verta::createTimestamp(1583501791)->format('Y-m-d H:i:s'); + $datetime = Jalali::createTimestamp(1583501791)->format('Y-m-d H:i:s'); $this->assertEquals("1398-12-16 13:36:31", $datetime); } public function testCreateGregorian() { - $datetime = Verta::create(2019, 1, 1, 10, 20, 11)->format('Y-m-d H:i:s'); + $datetime = Jalali::create(2019, 1, 1, 10, 20, 11)->format('Y-m-d H:i:s'); $this->assertEquals('1397-10-11 10:20:11', $datetime); } @@ -145,7 +129,7 @@ class CreatorTest extends TestCase public function testCreateGregorianDate() { $time = (new DateTime())->format("H:i:s"); - $datetime = Verta::createGregorianDate(2019, 1, 1)->format('Y-m-d H:i:s'); + $datetime = Jalali::createGregorianDate(2019, 1, 1)->format('Y-m-d H:i:s'); $this->assertEquals("1397-10-11 {$time}", $datetime); } @@ -153,14 +137,14 @@ class CreatorTest extends TestCase public function testCreateGregorianTime() { $date = (new DateTime())->format("Y-m-d"); - $datetime = Verta::createGregorianTime(15, 19, 51)->formatGregorian('Y-m-d H:i:s'); + $datetime = Jalali::createGregorianTime(15, 19, 51)->formatGregorian('Y-m-d H:i:s'); $this->assertEquals("{$date} 15:19:51", $datetime); } public function testCreateJalali() { - $datetime = Verta::createJalali(1397, 10, 11, 10, 20, 11)->format('Y-m-d H:i:s'); + $datetime = Jalali::createJalali(1397, 10, 11, 10, 20, 11)->format('Y-m-d H:i:s'); $this->assertEquals('1397-10-11 10:20:11', $datetime); } @@ -168,15 +152,15 @@ class CreatorTest extends TestCase public function testCreateJalaliDate() { $time = (new DateTime())->format("H:i:s"); - $datetime = Verta::createJalaliDate(1397, 10, 11)->format('Y-m-d H:i:s'); + $datetime = Jalali::createJalaliDate(1397, 10, 11)->format('Y-m-d H:i:s'); $this->assertEquals("1397-10-11 {$time}", $datetime); } public function testCreateJalaliTime() { - $date = verta()->format("Y-m-d"); - $datetime = Verta::createJalaliTime(15, 19, 51)->format('Y-m-d H:i:s'); + $date = jalali()->format("Y-m-d"); + $datetime = Jalali::createJalaliTime(15, 19, 51)->format('Y-m-d H:i:s'); $this->assertEquals("{$date} 15:19:51", $datetime); } diff --git a/tests/FormatTest.php b/tests/FormatTest.php index b945f58..7e8e3ad 100644 --- a/tests/FormatTest.php +++ b/tests/FormatTest.php @@ -1,111 +1,111 @@ assertEquals('1398-10-10-22-30-50', $datetime); - Verta::resetStringFormat(); - $datetime = (string) Verta::parse('1398-10-10 22:30:50'); + Jalali::resetFormat(); + $datetime = (string) Jalali::parse('1398-10-10 22:30:50'); $this->assertEquals('1398-10-10 22:30:50', $datetime); } public function testFormat() { - $datetime = Verta::parse('1398-10-10 21:30:50')->format('y-n-j-g-i-s'); + $datetime = Jalali::parse('1398-10-10 21:30:50')->format('y-n-j-g-i-s'); $this->assertEquals('98-10-10-9-30-50', $datetime); } public function testFormatGregorian() { - $datetime = Verta::parse('1398-10-10 21:30:50')->formatGregorian('o n j g i s'); + $datetime = Jalali::parse('1398-10-10 21:30:50')->formatGregorian('o n j g i s'); $this->assertEquals('2020 12 31 9 30 50', $datetime); } public function testFormatDatetime() { - $datetime = Verta::parse('1398-10-10 21:30:50')->formatDatetime(); + $datetime = Jalali::parse('1398-10-10 21:30:50')->formatDatetime(); $this->assertEquals('1398-10-10 21:30:50', $datetime); } public function testFormatDate() { - $datetime = Verta::parse('1398-10-10 21:30:50')->formatDate(); + $datetime = Jalali::parse('1398-10-10 21:30:50')->formatDate(); $this->assertEquals('1398-10-10', $datetime); } public function testFormatTime() { - $datetime = Verta::parse('1398-10-10 21:30:50')->formatTime(); + $datetime = Jalali::parse('1398-10-10 21:30:50')->formatTime(); $this->assertEquals('21:30:50', $datetime); } public function testFormatJalaliDatetime() { - $datetime = Verta::parse('1398-10-10 21:30:50')->formatJalaliDatetime(); + $datetime = Jalali::parse('1398-10-10 21:30:50')->formatJalaliDatetime(); $this->assertEquals('1398/10/10 21:30:50', $datetime); } public function testFormatJalaliDate() { - $datetime = Verta::parse('1398-10-10 21:30:50')->formatJalaliDate(); + $datetime = Jalali::parse('1398-10-10 21:30:50')->formatJalaliDate(); $this->assertEquals('1398/10/10', $datetime); } public function testFormatDifference() { - Verta::setLocale('fa'); - $target = Verta::parse('1398-10-10 21:30:50'); + Jalali::setLocale('fa'); + $target = Jalali::parse('1398-10-10 21:30:50'); - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); $difference = $target->formatDifference($datetime); $this->assertEquals('الان', $difference); - $datetime = Verta::parse('1398-10-10 21:30:45'); + $datetime = Jalali::parse('1398-10-10 21:30:45'); $difference = $target->formatDifference($datetime); $this->assertEquals('5 ثانیه بعد', $difference); - $datetime = Verta::parse('1398-10-10 21:31:58'); + $datetime = Jalali::parse('1398-10-10 21:31:58'); $difference = $target->formatDifference($datetime); $this->assertEquals('1 دقیقه قبل', $difference); - $datetime = Verta::parse('1398-10-10 20:30:35'); + $datetime = Jalali::parse('1398-10-10 20:30:35'); $difference = $target->formatDifference($datetime); $this->assertEquals('1 ساعت بعد', $difference); - $datetime = Verta::parse('1398-10-11 21:32:35'); + $datetime = Jalali::parse('1398-10-11 21:32:35'); $difference = $target->formatDifference($datetime); $this->assertEquals('1 روز قبل', $difference); - $datetime = Verta::parse('1398-11-11 21:32:35'); + $datetime = Jalali::parse('1398-11-11 21:32:35'); $difference = $target->formatDifference($datetime); $this->assertEquals('1 ماه قبل', $difference); - $datetime = Verta::parse('1397-09-11 21:32:35'); + $datetime = Jalali::parse('1397-09-11 21:32:35'); $difference = $target->formatDifference($datetime); $this->assertEquals('1 سال بعد', $difference); @@ -113,15 +113,16 @@ class FormatTest extends TestCase public function testFormatWord() { - $datetime = Verta::parse('1398-10-11 21:32:35')->formatWord('l d S F'); + $datetime = Jalali::parse('1398-10-11 21:32:35')->formatWord('l d S F'); $this->assertEquals('چهارشنبه یازده ام دی', $datetime); } public function testFormatQuarter() { - $datetime = Verta::parse('1398-10-10 21:30:50')->formatWord('q'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); - $this->assertEquals('زمستان', $datetime); + $this->assertEquals('زمستان', $datetime->format('Q')); + $this->assertEquals(4, $datetime->format('q')); } } diff --git a/tests/ModificationTest.php b/tests/ModificationTest.php index 684873e..b88373b 100644 --- a/tests/ModificationTest.php +++ b/tests/ModificationTest.php @@ -1,15 +1,15 @@ addYears(2); @@ -18,7 +18,7 @@ class ModificationTest extends TestCase public function testSubYears() { - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); $datetime->subYears(3); @@ -27,7 +27,7 @@ class ModificationTest extends TestCase public function testAddMonths() { - $datetime = Verta::parse('1398-10-30 21:30:50'); + $datetime = Jalali::parse('1398-10-30 21:30:50'); $result = $datetime->addMonths(2)->format('Y-m-d H:i:s'); @@ -36,7 +36,7 @@ class ModificationTest extends TestCase public function testSubMonths() { - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); $result = $datetime->subMonths(3)->format('Y-m-d H:i:s'); @@ -45,7 +45,7 @@ class ModificationTest extends TestCase public function testAddWeeks() { - $datetime = Verta::parse('1398-10-30 21:30:50'); + $datetime = Jalali::parse('1398-10-30 21:30:50'); $result = $datetime->addWeeks(2)->format('Y-m-d H:i:s'); @@ -54,7 +54,7 @@ class ModificationTest extends TestCase public function testSubWeeks() { - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); $result = $datetime->subWeeks(3)->format('Y-m-d H:i:s'); @@ -63,7 +63,7 @@ class ModificationTest extends TestCase public function testAddDays() { - $datetime = Verta::parse('1398-10-30 21:30:50'); + $datetime = Jalali::parse('1398-10-30 21:30:50'); $result = $datetime->addDays(20)->format('Y-m-d H:i:s'); @@ -72,7 +72,7 @@ class ModificationTest extends TestCase public function testSubDays() { - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); $result = $datetime->subDays(7)->format('Y-m-d H:i:s'); @@ -81,25 +81,25 @@ class ModificationTest extends TestCase public function testAddHours() { - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); - $result = $datetime->addHour(6)->format('Y-m-d H:i:s'); + $result = $datetime->addHour()->format('Y-m-d H:i:s'); - $this->assertEquals('1398-10-11 03:30:50', $result); + $this->assertEquals('1398-10-10 22:30:50', $result); } public function testSubHours() { - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); - $result = $datetime->subHour(30)->format('Y-m-d H:i:s'); + $result = $datetime->subHour()->format('Y-m-d H:i:s'); - $this->assertEquals('1398-10-09 15:30:50', $result); + $this->assertEquals('1398-10-10 20:30:50', $result); } public function testAddMinutes() { - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); $result = $datetime->addMinutes(6)->format('Y-m-d H:i:s'); @@ -108,16 +108,16 @@ class ModificationTest extends TestCase public function testSubMinutes() { - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); - $result = $datetime->subMinute(30)->format('Y-m-d H:i:s'); + $result = $datetime->subMinute()->format('Y-m-d H:i:s'); - $this->assertEquals('1398-10-10 21:00:50', $result); + $this->assertEquals('1398-10-10 21:29:50', $result); } public function testAddSeconds() { - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); $result = $datetime->addSeconds(16)->format('Y-m-d H:i:s'); @@ -126,16 +126,25 @@ class ModificationTest extends TestCase public function testSubSeconds() { - $datetime = Verta::parse('1398-10-10 21:30:20'); + $datetime = Jalali::parse('1398-10-10 21:30:20'); $result = $datetime->subSeconds(30)->format('Y-m-d H:i:s'); $this->assertEquals('1398-10-10 21:29:50', $result); } + public function testStartMinute() + { + $datetime = Jalali::parse('1398-10-10 21:30:50'); + + $result = $datetime->startMinute()->format('Y-m-d H:i:s'); + + $this->assertEquals('1398-10-10 21:30:00', $result); + } + public function testStartDay() { - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); $result = $datetime->startDay()->format('Y-m-d H:i:s'); @@ -144,7 +153,7 @@ class ModificationTest extends TestCase public function testEndDay() { - $datetime = Verta::parse('1398-10-10 21:30:20'); + $datetime = Jalali::parse('1398-10-10 21:30:20'); $result = $datetime->endDay()->format('Y-m-d H:i:s'); @@ -153,7 +162,7 @@ class ModificationTest extends TestCase public function testStartWeek() { - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); $result = $datetime->startWeek()->format('Y-m-d H:i:s'); @@ -162,7 +171,7 @@ class ModificationTest extends TestCase public function testEndWeek() { - $datetime = Verta::parse('1398-10-10 21:30:20'); + $datetime = Jalali::parse('1398-10-10 21:30:20'); $result = $datetime->endWeek()->format('Y-m-d H:i:s'); @@ -171,7 +180,7 @@ class ModificationTest extends TestCase public function testStartMonth() { - $datetime = Verta::parse('1398-10-10 21:30:50'); + $datetime = Jalali::parse('1398-10-10 21:30:50'); $result = $datetime->startMonth()->format('Y-m-d H:i:s'); @@ -180,7 +189,7 @@ class ModificationTest extends TestCase public function testEndMonth() { - $datetime = Verta::parse('1398-10-10 21:30:20'); + $datetime = Jalali::parse('1398-10-10 21:30:20'); $result = $datetime->endMonth()->format('Y-m-d H:i:s'); @@ -189,7 +198,7 @@ class ModificationTest extends TestCase public function testStartQuarter() { - $datetime = Verta::parse('1398-11-10 21:30:50'); + $datetime = Jalali::parse('1398-11-10 21:30:50'); $result = $datetime->startQuarter()->format('Y-m-d H:i:s'); @@ -198,7 +207,7 @@ class ModificationTest extends TestCase public function testEndQuarter() { - $datetime = Verta::parse('1398-10-10 21:30:20'); + $datetime = Jalali::parse('1398-10-10 21:30:20'); $result = $datetime->endQuarter()->format('Y-m-d H:i:s'); @@ -207,7 +216,7 @@ class ModificationTest extends TestCase public function testStartYear() { - $datetime = Verta::parse('1398-11-10 21:30:50'); + $datetime = Jalali::parse('1398-11-10 21:30:50'); $result = $datetime->startYear()->format('Y-m-d H:i:s'); @@ -216,7 +225,7 @@ class ModificationTest extends TestCase public function testEndYear() { - $datetime = Verta::parse('1398-10-15 21:30:20'); + $datetime = Jalali::parse('1398-10-15 21:30:20'); $result = $datetime->endYear()->format('Y-m-d H:i:s');