migrate to 8

This commit is contained in:
nasser committed 2022-07-03 20:26:41 +04:30
1 parent c1f61c5db3
commit f4cbf76e52
32 files changed
+417 -5141

No files matched your search

+4 -4
View File
@@ -17,10 +17,10 @@
"Verta" "Verta"
], ],
"require": { "require": {
"php": "^7.3|^8.0", "php": "^8.0",
"illuminate/support": "^6.0|^7.0|^8.0|^9.0", "illuminate/support": "^^8.0|^9.0",
"illuminate/validation": "^6.0|^7.0|^8.0|^9.0", "illuminate/validation": "^^8.0|^9.0",
"hekmatinasser/notowo": "^1.0" "hekmatinasser/jalali": "^8.0"
}, },
"require-dev": { "require-dev": {
"orchestra/testbench": "^4.18|^5.20|^6.24|^7.0" "orchestra/testbench": "^4.18|^5.20|^6.24|^7.0"
Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

-214
View File
@@ -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%;
}
}
-633
View File
@@ -1,633 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Verta — Laravel plugin Jalali datetime</title>
<meta name="description" content="">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="../css/style.css?v=0.2">
</head>
<body>
<a href="https://github.com/hekmatinasser/verta" target="_blank"><img
style="position: fixed; top: 0; right: 0; border: 0; z-index: 1000;"
src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67"
alt="Fork me on GitHub"></a>
<header id="header">
<h1>Verta</h1>
<h2>Laravel plugin Jalali datetime</h2>
</header>
<div class="container">
<div class="row">
<div class="col-sm-3">
<div class="sidebar">
<div class="sticky">
<ul>
<li>
<a href="#installation">Installation</a>
</li>
<li>
<a href="#usage">Usage</a>
</li>
<li>
<a href="#creator">Creator</a>
</li>
<li>
<a href="#transformation">Transformation</a>
</li>
<li>
<a href="#property">Property</a>
</li>
<li>
<a href="#format">Format</a>
</li>
<li>
<a href="#modification">Modification</a>
</li>
<li>
<a href="#comparison">Comparison</a>
</li>
<li>
<a href="#validation">Validation Laravel</a>
</li>
</ul>
</div>
</div>
</div>
<div class="col-sm-9">
<article class="content">
<h2 id="installation">Installation</h2>
<p>Enter the following command to install Verta</p>
<pre>$ composer require hekmatinasser/verta</pre>
<p>You can add the package to your project by entering the following command</p>
<pre>// config/app.php
'providers' => [
...
Hekmatinasser\Verta\Laravel\VertaServiceProvider::class,
],
'alias' => [
...
'Verta' => Hekmatinasser\Verta\Verta::class,
]</pre>
<h2 id="usage">Usage</h2>
<p>Use the following command at the top of each file of the use Verta class</p>
<pre>
use Verta;
// or
use Hekmatinasser\Verta\Verta;
</pre>
<h2 id="creator">Creator</h2>
<p>To get the current datetime, use the following command</p>
<pre>
$v = new Verta(); //1396-02-02 15:32:08
$v = verta(); //1396-02-02 15:32:08
</pre>
<p>To get the current date and time, use the following command</p>
<pre>
$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
</pre>
<p>To get the current date and time similar datetime string, use the following command </p>
<pre>
$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
</pre>
<p>To convert your Gregorian datetime, use the following command</p>
<pre>
$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');
</pre>
<p>To use the timestamp number, use the following command</p>
<pre>
$v = new Verta(1333857600);
</pre>
<p>To use the Datetime class PHP, use the following command</p>
<pre>
$dt = new \Datetime();
return new Verta($dt); // 1395-12-09 15:05:56
</pre>
<p>To use the Carbon class, use the following command</p>
<pre>
$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();
</pre>
<p>To use the jalali datetime as a string, use the following command</p>
<pre>
$v = Verta::parse('1395-10-07 14:12:32');
$v = Verta::parse('1396 مهر 17');
$v = Verta::parseFormat('Y n j','1396 مهر 17');
</pre>
<p>If the date values are separate, use the following commands</p>
<pre>
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
</pre>
<p>To use the timestamp numeric, use the following command</p>
<pre>
return Verta::createTimestamp(1488614023); // 1395-12-14 11:23:43
</pre>
<p>If the date jalali values are separate, use the following commands</p>
<pre>
// 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
</pre>
<h2 id="transformation">Transformations</h2>
<p>Gregorian to Jalali date, use the following command</p>
<pre>
return Verta::getJalali(2015,12,25); // [1394,10,4]
</pre>
<p>Jalali to Gregorian date, use the following command</p>
<pre>
return Verta::getGregorian(1394,10,4); // [2015,12,25]
</pre>
<p>Verta to Datatime PHP, use the following command</p>
<pre>
$dt = verta()->datetime();
</pre>
<p>Verta to Carbon, use the following command</p>
<pre>
$c = Carbon::instance($v->datetime());
// or
$c = $v->toCarbon();
</pre>
<h3 id="property">Property</h3>
<p>To get property, use the following command</p>
<pre>
$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
</pre>
<p>To set property, use the following command</p>
<pre>
$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';
</pre>
<p>To set property with method, use the following command</p>
<pre>
$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');
</pre>
<p>To set property together, use the following command</p>
<pre>
$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');
</pre>
<h2 id="format">Format</h2>
<p>To output format, use the following command</p>
<pre>
$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
</pre>
<p>Read the PHP manual to create the format you want</p>
<p>
<a href="http://php.net/manual/en/function.strftime.php" target="_blank">strftime</a>
<a href="http://php.net/manual/en/function.date.php" target="_blank">date</a>
</p>
<p>To default output format, use the following command</p>
<pre>
Verta::setStringformat('Y/n/j H:i:s');
return verta(); // 1395/12/12 00:11:35
</pre>
<p>To reset output format, use the following command</p>
<pre>
Verta::resetStringFormat();
return verta(); // 1395-12-12 00:18:04
</pre>
<p>To display the datetime in standard formats, use the following command</p>
<pre>
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
</pre>
<p>To output format Gregorian, use the following command</p>
<pre>
return $v->formatGregorian('Y-m-d H:i:s'); // 2017-05-23 23:21:02
</pre>
<p>To display the date difference as a unit of time, use the following command</p>
<p>If you do set parameter, the difference is calculated with the current time</p>
<pre>
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(); // الان
</pre>
<p>To display numbers in alphabetical order, use the following command</p>
<pre>
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
</pre>
<h2 id="modification">Modification</h2>
<p>To add or sub datetime, use the following command</p>
<pre>
$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
</pre>
<pre>
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
</pre>
<pre>
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
</pre>
<pre>
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
</pre>
<pre>
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
</pre>
<pre>
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
</pre>
<pre>
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
</pre>
<p>To get start or end datetime period, use the following command</p>
<pre>
$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
</pre>
<pre>
return $v->startWeek(); // 1396 1396-04-24 00:00:00
return $v->endWeek(); // 1396-04-30 23:59:59
</pre>
<pre>
return $v->startMonth(); // 1396-04-01 00:00:00
return $v->endMonth(); // 1396-04-31 00:00:00
</pre>
<pre>
return $v->startQuarter(); // 1396-04-01 00:00:00
return $v->endQuarter(); // 1396-06-31 23:59:59
</pre>
<pre>
return $v->startYear(); // 1396-01-01 00:00:00
return $v->endYear(); // 1396-12-29 23:59:59
</pre>
<pre>
return $v->startHour(); // 1396-04-29 14:00:00
return $v->endHour(); // 1396-04-29 14:59:59
</pre>
<pre>
return $v->startMinute(); // 1396-04-29 14:25:00
return $v->endMinute(); // 1396-04-29 14:25:59
</pre>
<h2 id="comparison">Comparison</h2>
<p>To validate datetime, use the following command</p>
<pre>
return Verta::isLeapYear(1394); // false
return Verta::isValidDate(1394, 12, 30); // false
return Verta::isValidTime(15, 12, 30); // true
</pre>
<p>To difference datetime together, use the following command</p>
<pre>
// 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
</pre>
<p>To compere datetime together, use the following command</p>
<pre>
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
</pre>
<p>To compere datetime for closest, farthest, min or max together, use the following command</p>
<pre>
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
</pre>
<p>To compere datetime now, use the following command</p>
<pre>
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
</pre>
<h2 id="validation">Laravel Validator</h2>
<p>You can validate form with Validator Laravel</p>
<p>You need to define error messages for jdate, ... rules in validation.php in lang folders.</p>
<pre>
'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',
],
</pre>
<h3>Validation Rules</h3>
<p>Determines if an input is a valid Jalali date with the specified format</p>
<p>The default format is Y/m/d</p>
<pre>
'start_date' => 'jdate'
'start_date' => 'jdate:Y/m/d'
</pre>
<p>Determines if an input is a valid Jalali date with the specified format and it is equal a given
date</p>
<p>The default format is Y/m/d</p>
<pre>
'start_date' => 'jdate_equal'
'start_date' => 'jdate_equal:1388/01/01'
'start_date' => 'jdate_equal:1388/01/01,Y/m/d'
</pre>
<p>Determines if an input is a valid Jalali date with the specified format and it is not equal a
given date</p>
<p>The default format is Y/m/d</p>
<pre>
'start_date' => 'jdate_not_equal'
'start_date' => 'jdate_not_equal:1388/01/01'
'start_date' => 'jdate_not_equal:1388/01/01,Y/m/d'
</pre>
<p>Determines if an input is a valid Jalali datetime with the specified format</p>
<p>The default format is Y/m/d H:i:s</p>
<pre>
'start_date' => 'jdatetime'
'start_date' => 'jdatetime:Y/m/d H:i:s'
</pre>
<p>Determines if an input is a valid Jalali datetime with the specified format and it is equal a
given datetime</p>
<p>The default format is Y/m/d H:i:s</p>
<pre>
'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'
</pre>
<p>Determines if an input is a valid Jalali datetime with the specified format and it is not equal a
given datetime</p>
<p>The default format is Y/m/d H:i:s</p>
<pre>
'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'
</pre>
<p>Determines if an input is a valid Jalali date with the specified format and it is after a given
date</p>
<p>The default date is now</p>
<p>The default format is Y/m/d</p>
<pre>
'start_date' => 'jdate_after'
'start_date' => 'jdate_after:1388/01/01'
'start_date' => 'jdate_after:1388/01/01,Y/m/d'
</pre>
<p>Determines if an input is a valid Jalali datetime with the specified format and it is after or
equal a given datetime</p>
<p>The default date is now</p>
<p>The default format is Y/m/d</p>
<pre>
'start_date' => 'jdate_after_equal'
'start_date' => 'jdate_after_equal:1388/01/01'
'start_date' => 'jdate_after_equal:1388/01/01,Y/m/d'
</pre>
<p>Determines if an input is a valid Jalali datetime with the specified format and it is after a
given datetime</p>
<p>The default date is now</p>
<p>The default format is Y/m/d H:i:s</p>
<pre>
'start_date' => 'jdatetime_after'
'start_date' => 'jdatetime_after:1388/01/01'
'start_date' => 'jdatetime_after:1388/01/01,Y/m/d'
</pre>
<p>Determines if an input is a valid Jalali datetime with the specified format and it is after or
equal a given datetime</p>
<p>The default date is now</p>
<p>The default format is Y/m/d H:i:s</p>
<pre>
'start_date' => 'jdatetime_after_equal'
'start_date' => 'jdatetime_after_equal:1388/01/01'
'start_date' => 'jdatetime_after_equal:1388/01/01,Y/m/d'
</pre>
<p>Determines if an input is a valid Jalali date with the specified format and it is before a given
date</p>
<p>The default date is now</p>
<p>The default format is Y/m/d</p>
<pre>
'start_date' => 'jdate_before'
'start_date' => 'jdate_before:1388/01/01'
'start_date' => 'jdate_before:1388/01/01,Y/m/d'
</pre>
<p>Determines if an input is a valid Jalali date with the specified format and it is before or equal
a given date</p>
<p>The default date is now</p>
<p>The default format is Y/m/d</p>
<pre>
'start_date' => 'jdate_before_equal'
'start_date' => 'jdate_before_equal:1388/01/01'
'start_date' => 'jdate_before_equal:1388/01/01,Y/m/d'
</pre>
<p>Determines if an input is a valid Jalali datetime with the specified format and it is before a
given date-time</p>
<p>The default date is now</p>
<p>The default format is Y/m/d H:i:s</p>
<pre>
'start_date' => 'jdatetime_before'
'start_date' => 'jdatetime_before:1388/01/01'
'start_date' => 'jdatetime_before:1388/01/01,Y/m/d'
</pre>
<p>Determines if an input is a valid Jalali datetime with the specified format and it is before or
equal a given datetime</p>
<p>The default date is now</p>
<p>The default format is Y/m/d H:i:s</p>
<pre>
'start_date' => 'jdatetime_before_equal'
'start_date' => 'jdatetime_before_equal:1388/01/01'
'start_date' => 'jdatetime_before_equal:1388/01/01,Y/m/d'
</pre>
<p>Can combine the rules of the between the two boundaries</p>
<pre>
$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."
]
]
</pre>
<h2 id="traslation">Traslation</h2>
<p>You can show weekdays, months , messages in the languages available in Verta To view supported
languages, go to the folder <a
href="https://github.com/hekmatinasser/verta/tree/master/src/Lang">langs</a></p>
<p>To set locale, use the following command</p>
<pre>
Verta::setLocale('fa');
</pre>
<p>To get current locale, use the following command</p>
<pre>
Verta::getLocale(); // fa
</pre>
<p>To reset locale to fa, use the following command</p>
<pre>
Verta::resetLocale();
</pre>
</article>
</div>
</div>
</div>
<footer id="footer">
<div style="text-align: center;">
2017-2021 &copy;
</div>
</footer>
</body>
</html>
-635
View File
@@ -1,635 +0,0 @@
<!DOCTYPE html>
<html lang="fa">
<head>
<title>Verta — پکیج تاریخ شمسی در لاراول</title>
<meta name="description" content="">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<meta name="format-detection" content="telephone=no">
<link href="https://fonts.googleapis.com/css2?family=Markazi+Text&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/style.css?v=0.2">
</head>
<body dir="rtl">
<a href="https://github.com/hekmatinasser/verta" target="_blank"><img
style="position: fixed; top: 0; right: 0; border: 0; z-index: 1000;"
src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67"
alt="Fork me on GitHub"></a>
<header id="header">
<h1>Verta</h1>
<h2>تاریخ شمسی در لاراول</h2>
</header>
<div class="container">
<div class="row">
<div class="col-sm-3">
<div class="sidebar">
<div class="sticky">
<ul>
<li>
<a href="#installation">نصب</a>
</li>
<li>
<a href="#usage">نحوه استفاده</a>
</li>
<li>
<a href="#creator">ایجاد کردن</a>
</li>
<li>
<a href="#transformation">تبدیل تاریخ</a>
</li>
<li>
<a href="#property">خصوصیات</a>
</li>
<li>
<a href="#format">قالب نمایش</a>
</li>
<li>
<a href="#modification">تغییر دادن</a>
</li>
<li>
<a href="#comparison">بررسی و مقایسه</a>
</li>
<li>
<a href="#validation">اعتبار سنجی</a>
</li>
<li>
<a href="#traslation">زبان</a>
</li>
</ul>
</div>
</div>
</div>
<div class="col-sm-9">
<article class="content">
<h2 id="installation">نصب</h2>
<p>برای نصب دستور زیر را وارد کنید</p>
<pre>$ composer require hekmatinasser/verta</pre>
<p>می توانید پکیج را درون پروژه خود اضافه کنید برای این کار دستور زیر را وارد کنید</p>
<pre>// config/app.php
'providers' => [
...
Hekmatinasser\Verta\Laravel\VertaServiceProvider::class,
],
'alias' => [
...
'Verta' => Hekmatinasser\Verta\Verta::class,
]</pre>
<h2 id="usage">نحوه استفاده</h2>
<p>در بالای هر فایل خود از کلاس ورتا استفاده میکند، از دستور زیر استفاده کنید</p>
<pre>
use Verta;
// or
use Hekmatinasser\Verta\Verta;
</pre>
<h2 id="creator">ایجاد کردن</h2>
<p>برای بدست آوردن تاریخ و زمان کنونی شمسی، از دستور زیر استفاده کنید</p>
<pre>
$v = new Verta(); //1396-02-02 15:32:08
$v = verta(); //1396-02-02 15:32:08
</pre>
<p>برای بدست آوردن تاریخ و زمان به نسبت اکنون، از دستور زیر استفاده کنید</p>
<pre>
$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
</pre>
<p>برای بدست آوردن تاریخ و زمان به نسبت اکنون مانند تاریخ زمان پی اچ پی به صورت رشته ، از دستور زیر
استفاده کنید</p>
<pre>
$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
</pre>
<p>برای تبدیل تاریخ میلادی خود به شمسی، از دستور زیر استفاده کنید</p>
<pre>
$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');
</pre>
<p>برای استفاده از عدد تایم استمپ به شمسی، از دستور زیر استفاده کنید</p>
<pre>
$v = new Verta(1333857600);
</pre>
<p>برای استفاده از کلاس تاریخ و زمان پی اچ پی به شمسی، از دستور زیر استفاده کنید</p>
<pre>
$dt = new \Datetime();
return new Verta($dt); // 1395-12-09 15:05:56
</pre>
<p>برای استفاده از کلاس کربن به شمسی، از دستور زیر استفاده کنید</p>
<pre>
$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();
</pre>
<p>برای استفاده از تاریخ شمسی به صورت رشته، از دستور زیر استفاده کنید</p>
<pre>
$v = Verta::parse('1395-10-07 14:12:32');
$v = Verta::parse('1396 مهر 17');
$v = Verta::parseFormat('Y n j','1396 مهر 17');
</pre>
<p>در صورتی مقادیر تاریخ میلادی به صورت جداگانه باشد، از دستورات زیر استفاده کنید</p>
<pre>
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
</pre>
<p>برای استفاده از عدد تایم استمپ به شمسی، از دستور زیر استفاده کنید</p>
<pre>
return Verta::createTimestamp(1488614023); // 1395-12-14 11:23:43
</pre>
<p>در صورتی مقادیر تاریخ شمسی به صورت جداگانه باشد، از دستورات زیر استفاده کنید</p>
<pre>
// 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
</pre>
<h2 id="transformation">تبدیل تاریخ</h2>
<p>برای تبدیل از میلادی به شمسی به صورت ساده، از دستور زیر استفاده کنید</p>
<pre>
return Verta::getJalali(2015,12,25); // [1394,10,4]
</pre>
<p>برای تبدیل از شمسی به میلادی به صورت ساده، از دستور زیر استفاده کنید</p>
<pre>
return Verta::getGregorian(1394,10,4); // [2015,12,25]
</pre>
<p>برای تبدیل تاریخ از ورتا به تاریخ و زمان پی اچ پی، از دستور زیر استفاده کنید</p>
<pre>
$dt = verta()->datetime();
</pre>
<p>برای تبدیل تاریخ از ورتا به کربن، از دستور زیر استفاده کنید</p>
<pre>
$c = Carbon::instance($v->datetime());
// or
$c = $v->toCarbon();
</pre>
<h3 id="property">خصوصیات</h3>
<p>برای دریافت مقادیر خصوصیات، از دستورات زیر استفاده کنید</p>
<pre>
$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
</pre>
<p>برای مقدار دهی خصوصیات، از دستورات زیر استفاده کنید</p>
<pre>
$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';
</pre>
<p>برای مقدار دهی خصوصیات با استفاده از تابع، از دستورات زیر استفاده کنید</p>
<pre>
$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');
</pre>
<p>برای مقدار دهی خصوصیات با یکدیگر، از دستورات زیر استفاده کنید</p>
<pre>
$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');
</pre>
<h2 id="format">قالب نمایش</h2>
<p>برای نمایش تاریخ به شمسی، از دستور زیر استفاده کنید</p>
<pre>
$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
</pre>
<p>برای ساخت فرمت نمایش مورد نظر خود راهنمای پی اچ پی را مطالعه کنید</p>
<p>
<a href="http://php.net/manual/en/function.strftime.php" target="_blank">strftime</a>
<a href="http://php.net/manual/en/function.date.php" target="_blank">date</a>
</p>
<p>برای تعیین فرمت خروجی پیش فرض، از دستور زیر استفاده کنید</p>
<pre>
Verta::setStringformat('Y/n/j H:i:s');
return verta(); // 1395/12/12 00:11:35
</pre>
<p>برای تنظیم مجددفرمت خروجی به حالت اولیه، از دستور زیر استفاده کنید</p>
<pre>
Verta::resetStringFormat();
return verta(); // 1395-12-12 00:18:04
</pre>
<p>برای نمایش تاریخ با فرمت های متعارف، از دستور زیر استفاده کنید</p>
<pre>
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
</pre>
<p>برای نمایش تاریخ به صورت میلادی، از دستور زیر استفاده کنید</p>
<pre>
return $v->formatGregorian('Y-m-d H:i:s'); // 2017-05-23 23:21:02
</pre>
<p>برای نمایش اختلاف تاریخ به صورت واحد زمانی، از دستور زیر استفاده کنید</p>
<p>درصورتی که تاریخ را وارد نکنید، اختلاف با زمان کنونی محاسبه می شود.</p>
<pre>
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(); // الان
</pre>
<p>برای نمایش اعداد به صورت حروف، از دستور زیر استفاده کنید</p>
<pre>
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
</pre>
<h2 id="modification">تغییر دادن</h2>
<p>برای اضافه یا کم کردن از تاریخ خود، از دستور زیر استفاده کنید</p>
<pre>
$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
</pre>
<pre>
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
</pre>
<pre>
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
</pre>
<pre>
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
</pre>
<pre>
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
</pre>
<pre>
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
</pre>
<pre>
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
</pre>
<p>برای بدست آوردن تاریخ شروع و پایان هر بازه زمانی، از دستور زیر استفاده کنید</p>
<pre>
$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
</pre>
<pre>
return $v->startWeek(); // 1396 1396-04-24 00:00:00
return $v->endWeek(); // 1396-04-30 23:59:59
</pre>
<pre>
return $v->startMonth(); // 1396-04-01 00:00:00
return $v->endMonth(); // 1396-04-31 00:00:00
</pre>
<pre>
return $v->startQuarter(); // 1396-04-01 00:00:00
return $v->endQuarter(); // 1396-06-31 23:59:59
</pre>
<pre>
return $v->startYear(); // 1396-01-01 00:00:00
return $v->endYear(); // 1396-12-29 23:59:59
</pre>
<pre>
return $v->startHour(); // 1396-04-29 14:00:00
return $v->endHour(); // 1396-04-29 14:59:59
</pre>
<pre>
return $v->startMinute(); // 1396-04-29 14:25:00
return $v->endMinute(); // 1396-04-29 14:25:59
</pre>
<h2 id="comparison">بررسی و مقایسه</h2>
<p>برای اعتبار سنجی تاریخ، از دستور زیر استفاده کنید</p>
<pre>
return Verta::isLeapYear(1394); // false
return Verta::isValidDate(1394, 12, 30); // false
return Verta::isValidTime(15, 12, 30); // true
</pre>
<p>برای محاسبه اختلاف تاریخ ها با یکدیگر، از دستور زیر استفاده کنید</p>
<pre>
// 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
</pre>
<p>برای مقایسه تاریخ ها با یکدیگر، از دستور زیر استفاده کنید</p>
<pre>
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
</pre>
<p>برای بررسی تاریخ از لحاظ نزدیکتر یا دورتر بودن و یا کوچکتر و بزرگتر بودن، از دستور زیر استفاده
کنید</p>
<pre>
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
</pre>
<p>برای بررسی تاریخ فعلی، از دستورات زیر استفاده کنید</p>
<pre>
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
</pre>
<h2 id="validation">اعتبار سنجی</h2>
<p>شما می توانید با اعتبار سنجی لاراول تاریخ های شمسی درون فرم های خود استفاده کنید</p>
<p>شما باید پیام های خطا برای اعتبار سنجی خود در در مسیر فایل های ترجمه خود اضافه کنید ارور های
ترجمه شده برای زبان های قابل پشتیبانی در <a
href="https://github.com/hekmatinasser/verta/tree/master/src/Lang">زبان ها</a> مراجعه کنید
قرار دارد .برای نمونه کد هایی که درون پکیج برای پیام خطا وجود دارد در فایل ترجمه خود قرار
دهیدبرای مثال در فایل ترجمه پیام خطا به آرایه عبارات زیر را اضافه کنید</p>
<pre>
'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' => 'تاریخ انقضا',
],
</pre>
<h3>قوانین اعتبار سنجی</h3>
<p>اگر تاریخ شمسی با فرمت معین درست باشد</p>
<p>فرمت پیش فرض Y/m/d می باشد</p>
<pre>
'start_date' => 'jdate'
'start_date' => 'jdate:Y/m/d'
</pre>
<p>اگر تاریخ شمسی با فرمت تعیین شده مساوی باشد</p>
<p>فرمت پیش فرض Y/m/d می باشد</p>
<pre>
'start_date' => 'jdate_equal'
'start_date' => 'jdate_equal:1388/01/01'
'start_date' => 'jdate_equal:1388/01/01,Y/m/d'
</pre>
<p>اگر تاریخ شمسی با فرمت تعیین شده نامساوی باشد</p>
<p>فرمت پیش فرض Y/m/d می باشد</p>
<pre>
'start_date' => 'jdate_not_equal'
'start_date' => 'jdate_not_equal:1388/01/01'
'start_date' => 'jdate_not_equal:1388/01/01,Y/m/d'
</pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد</p>
<pre>
'start_date' => 'jdatetime'
'start_date' => 'jdatetime:Y/m/d H:i:s'
</pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده مساوی باشد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد</p>
<pre>
'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'
</pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده نامساوی باشد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد</p>
<pre>
'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'
</pre>
<p>اگر تاریخ شمسی با فرمت تعیین شده درست باشد و بعد از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد</p>
<p>فرمت پیش فرض Y/m/d می باشد</p>
<pre>
'start_date' => 'jdate_after'
'start_date' => 'jdate_after:1388/01/01'
'start_date' => 'jdate_after:1388/01/01,Y/m/d'
</pre>
<p>اگر تاریخ شمسی با فرمت تعیین شده درست باشد و بعد یا مساوی از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد</p>
<p>فرمت پیش فرض Y/m/d می باشد </p>
<pre>
'start_date' => 'jdate_after_equal'
'start_date' => 'jdate_after_equal:1388/01/01'
'start_date' => 'jdate_after_equal:1388/01/01,Y/m/d'
</pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و بعد از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد </p>
<pre>
'start_date' => 'jdatetime_after'
'start_date' => 'jdatetime_after:1388/01/01'
'start_date' => 'jdatetime_after:1388/01/01,Y/m/d'
</pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و بعد یا مساوی از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد </p>
<pre>
'start_date' => 'jdatetime_after_equal'
'start_date' => 'jdatetime_after_equal:1388/01/01'
'start_date' => 'jdatetime_after_equal:1388/01/01,Y/m/d'
</pre>
<p>اگر تاریخ شمسی با فرمت تعیین شده درست باشد و قبل از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد</p>
<p>فرمت پیش فرض Y/m/d می باشد </p>
<pre>
'start_date' => 'jdate_before'
'start_date' => 'jdate_before:1388/01/01'
'start_date' => 'jdate_before:1388/01/01,Y/m/d'
</pre>
<p>اگر تاریخ شمسی با فرمت تعیین شده درست باشد و قبل یا مساوی از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد</p>
<p>فرمت پیش فرض Y/m/d می باشد </p>
<pre>
'start_date' => 'jdate_before_equal'
'start_date' => 'jdate_before_equal:1388/01/01'
'start_date' => 'jdate_before_equal:1388/01/01,Y/m/d'
</pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و قبل از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد </p>
<pre>
'start_date' => 'jdatetime_before'
'start_date' => 'jdatetime_before:1388/01/01'
'start_date' => 'jdatetime_before:1388/01/01,Y/m/d'
</pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و قبل یا مساوی از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد </p>
<pre>
'start_date' => 'jdatetime_before_equal'
'start_date' => 'jdatetime_before_equal:1388/01/01'
'start_date' => 'jdatetime_before_equal:1388/01/01,Y/m/d'
</pre>
<p>میتوانید با ترکیب قوانین تاریخ را بین دو محدوده بررسی کنید</p>
<pre>
$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 => "تاریخ انقضا تاریخ و زمان شمسی باید قبل از ۱۳۹۷/۰۲/۱۶ ۱۲:۱۰:۰۰ باشد."
]
]
</pre>
<h2 id="traslation">زبان ها</h2>
<p>شما میتوانید ایام و ماه ها و پیام را به زبان های موجود در ورتا نمایش دهید برای مشاهده زبان ها
پشتیبانی می شود به پوشه زیر مشاهده
<a href="https://github.com/hekmatinasser/verta/tree/master/src/Lang">زبان ها</a> مراجعه کنید
</p>
<p>برای تعیین زبان پیام های از دستور زیر استفاده کنید</p>
<pre>
Verta::setLocale('fa');
</pre>
<p>برای دریافت زبان جاری پیام های از دستور زیر استفاده کنید</p>
<pre>
Verta::getLocale(); // fa
</pre>
<p>برای ریست کردن زبان به فارسی از دستور زیر استفاده کنید</p>
<pre>
Verta::resetLocale();
</pre>
<p>برای افزودن زبان های دیگر نمونه فایل های موجود را برای ادغام با پروژه ارسال کنید</p>
</article>
</div>
</div>
</div>
<footer id="footer">
<div style="text-align: center;">
2017-2021 &copy;
</div>
</footer>
</body>
</html>
-82
View File
@@ -1,82 +0,0 @@
<?php
return [
'numbers' => [
'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' => 'شتاء',
],
];
-82
View File
@@ -1,82 +0,0 @@
<?php
return [
'numbers' => [
'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' => 'زمستان',
],
];
-82
View File
@@ -1,82 +0,0 @@
<?php
return [
'numbers' => [
'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',
],
];
-82
View File
@@ -1,82 +0,0 @@
<?php
return [
'numbers' => [
'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' => 'زمستان',
],
];
-82
View File
@@ -1,82 +0,0 @@
<?php
return [
'numbers' => [
'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' => 'زمستان',
],
];
-82
View File
@@ -1,82 +0,0 @@
<?php
return [
'numbers' => [
'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' => 'زمستان',
],
];
-81
View File
@@ -1,81 +0,0 @@
<?php
return [
'numbers' => [
'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' => 'زمستان',
],
];
-1
View File
@@ -111,7 +111,6 @@ class VertaServiceProvider extends ServiceProvider
foreach ($this->rules as $name => $methods) { foreach ($this->rules as $name => $methods) {
if (array_key_exists('extend', $methods) || array_key_exists('replacer', $methods)) { if (array_key_exists('extend', $methods) || array_key_exists('replacer', $methods)) {
Validator::extend($name, $className . $methods['extend']); Validator::extend($name, $className . $methods['extend']);
Validator::replacer($name, $className . $methods['replacer']); Validator::replacer($name, $className . $methods['replacer']);
} }
} }
-261
View File
@@ -1,261 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
use DateTimeZone;
use Hekmatinasser\Verta\Verta;
use InvalidArgumentException;
trait Accessor
{
/**
* Get a part of the Verta object
*
* @param string $name
* @return string|int
*@throws InvalidArgumentException
*/
public function __get($name)
{
static $formats = [
'year' => '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;
}
}
-160
View File
@@ -1,160 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
trait Boundaries
{
/**
* Resets the time to 00:00:00
*
* @return static
*/
public function startMinute()
{
return $this->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);
}
}
-607
View File
@@ -1,607 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
use Hekmatinasser\Verta\Verta;
trait Comparison
{
/**
* check jalali the instance is a leap year
*
* @param int $year
* @return bool
*/
public static function isLeapYear($year)
{
return in_array(($year % 33), [1 , 5 , 9 , 13 ,17 , 22 , 26 , 30]);
}
/**
* validate a jalali date (jalali equivalent of php checkdate() function)
*
* @param int $month
* @param int $day
* @param int $year
* @return bool
*/
public static function isValidDate($year, $month, $day)
{
if ($year < 0 || $year > 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;
}
}
-421
View File
@@ -1,421 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
use DateTime;
use DateTimeZone;
use Exception;
use Illuminate\Support\Carbon;
use InvalidArgumentException;
trait Creator
{
/**
* create object of Jalali
*
* @param DateTime|string|int|null $datetime [optional]
* @param DateTimeZone|string|null $timezone [optional]
* @internal param timestamp $timestamp [optional]
*/
public function __construct($datetime = null, $timezone = null)
{
$dt = $datetime;
if (empty($datetime)) {
$dt = 'now';
} elseif (is_string($datetime)) {
$dt = self::faToEnNumbers(self::arToEnNumbers($datetime));
} elseif ($datetime instanceof DateTime) {
$dt = "@{$datetime->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);
}
}
-59
View File
@@ -1,59 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
use Hekmatinasser\Verta\VertaInterface;
trait Date
{
use Accessor;
use Comparison;
use Creator;
use Formatting;
use Modification;
use Transformation;
use Translator;
use Boundaries;
use Difference;
/**
* Format to use for __toString.
*
* @var string
*/
protected static $stringFormat = VertaInterface::DEFAULT_STRING_FORMAT;
/**
* First day of week.
*
* @var int
*/
protected static $weekStartsAt = VertaInterface::SATURDAY;
/**
* Last day of week.
*
* @var int
*/
protected static $weekEndsAt = VertaInterface::FRIDAY;
/**
* Days of weekend.
*
* @var array
*/
protected static $weekendDays = [VertaInterface::THURSDAY, VertaInterface::FRIDAY];
/**
* number day in months gregorian
*
* @var array
*/
protected static $daysMonthGregorian = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
/**
* number day in month jalali
*
* @var array
*/
protected static $daysMonthJalali = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29];
}
-100
View File
@@ -1,100 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
use Hekmatinasser\Verta\Verta;
trait Difference
{
/**
* Get the difference in years
*
* @param Verta|null $v
*
* @return int
*/
public function diffYears(Verta $v = null)
{
$v = $v ?: static::now($this->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();
}
}
-478
View File
@@ -1,478 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
use Hekmatinasser\Notowo\Notowo;
use Hekmatinasser\Verta\Verta;
use ReturnTypeWillChange;
trait Formatting
{
/**
* Reset the format used to the default when type juggling a Verta instance to a string
*/
public static function resetStringFormat()
{
static::setStringFormat(static::DEFAULT_STRING_FORMAT);
}
/**
* Set the default format used when type juggling a Verta instance to a string
*
* @param string $format
*/
public static function setStringFormat($format)
{
static::$stringFormat = $format;
}
/**
* Format the instance as a string using the set format
*
* @return string
*/
public function __toString()
{
return $this->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);
}
}
-370
View File
@@ -1,370 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
trait Modification
{
/**
* Add years to the instance. Positive $value travel forward while
* negative $value travel into the past.
*
* @param int $value
*
* @return static
*/
public function addYears($value)
{
return $this->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);
}
}
-89
View File
@@ -1,89 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
trait Transformation
{
/**
* gregorian to jalali convertion
*
* @param int $g_y
* @param int $g_m
* @param int $g_d
* @return array
*/
public static function getJalali($g_y, $g_m, $g_d)
{
$gy = $g_y - 1600;
$gm = $g_m - 1;
$g_day_no = (365 * $gy + intval(($gy + 3) / 4) - intval(($gy + 99) / 100) + intval(($gy + 399) / 400));
for ($i = 0; $i < $gm; ++$i) {
$g_day_no += static::$daysMonthGregorian[$i];
}
if ($gm > 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];
}
}
-102
View File
@@ -1,102 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
trait Translator
{
/**
* List of custom localized messages.
*
* @var array
*/
public static $messages = [];
/**
* List of custom localized messages.
*
* @var array
*/
public static $locale;
/**
* Reset the format used to the default when type juggling a Verta instance to a string
*/
public static function resetLocale()
{
static::setStringFormat(static::DEFAULT_LOCALE);
}
/**
* Set the default locale
*
* @param string $locale
*/
public static function setLocale($locale)
{
if ($messages = static::loadMessages($locale)) {
static::$locale = $locale;
}
return $messages;
}
/**
* Get the default locale
*
* @param string $locale
*/
public static function getLocale()
{
return static::$locale ?: static::DEFAULT_LOCALE;
}
/**
* Return a singleton instance of Translator.
*
* @param string|null $locale optional initial locale ("fa" - by default)
*
* @return bool
*/
public static function loadMessages($locale = null)
{
if ($messages = static::getMessages($locale)) {
static::$messages = $messages;
return true;
}
return false;
}
/**
* Set messages of a locale and take file first if present.
*
* @param string $locale
*
* @return mixed
*/
public static function getMessages($locale = null)
{
if (file_exists($filename = dirname(__DIR__).'/Lang/'.($locale ?: static::getLocale()).'.php')) {
return require $filename;
}
return false;
}
/**
* Set messages of a locale and take file first if present.
*
* @param string $locale
* @param array $messages
*
* @return $this
*/
public function setMessages($locale, $messages)
{
if (static::loadMessages($locale)) {
static::$messages = array_merge(static::$messages, $messages);
}
static::$messages = $messages;
}
}
+3 -4
View File
@@ -2,10 +2,9 @@
namespace Hekmatinasser\Verta; namespace Hekmatinasser\Verta;
use DateTime; use Hekmatinasser\Jalali\Jalali;
use Hekmatinasser\Verta\Traits\Date;
class Verta extends DateTime implements VertaInterface class Verta extends Jalali
{ {
use Date;
} }
-41
View File
@@ -1,41 +0,0 @@
<?php
namespace Hekmatinasser\Verta;
interface VertaInterface
{
/**
* The day constants
*/
public const SATURDAY = 0;
public const SUNDAY = 1;
public const MONDAY = 2;
public const TUESDAY = 3;
public const WEDNESDAY = 4;
public const THURSDAY = 5;
public const FRIDAY = 6;
/**
* Number unit in date
*/
public const DECADE_PER_CENTURY = 10;
public const YEARS_PER_DECADE = 10;
public const MONTHS_PER_YEAR = 12;
public const MONTHS_PER_QUARTER = 3;
public const WEEKS_PER_YEAR = 52;
public const WEEKS_PER_MONTH = 4.35;
public const DAYS_PER_WEEK = 7;
public const HOURS_PER_DAY = 24;
public const MINUTES_PER_HOUR = 60;
public const SECONDS_PER_MINUTE = 60;
/**
* Word use in format datetime.
*/
public const DEFAULT_STRING_FORMAT = 'Y-m-d H:i:s';
/**
* Word use in format datetime.
*/
public const DEFAULT_LOCALE = 'fa';
}
+5 -3
View File
@@ -1,13 +1,15 @@
<?php <?php
use Hekmatinasser\Verta\Verta;
if (! function_exists('verta')) { if (! function_exists('verta')) {
/** /**
* @param null $datetime * @param null $datetime
* @param null $timezone * @param null $timezone
* @return \Hekmatinasser\Verta\Verta * @return Verta
*/ */
function verta($datetime = null, $timezone = null) function verta($datetime = null, $timezone = null): Verta
{ {
return new \Hekmatinasser\Verta\Verta($datetime, $timezone); return new Verta($datetime, $timezone);
} }
} }
+10 -10
View File
@@ -1,15 +1,15 @@
<?php <?php
namespace Hekmatinasser\Verta\Tests; namespace Hekmatinasser\Jalali\Tests;
use Hekmatinasser\Verta\Verta; use Hekmatinasser\Jalali\Jalali;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class AccessTest extends TestCase class AccessTest extends TestCase
{ {
public function testGetProperty() public function testGetProperty()
{ {
$datetime = Verta('2019-01-01 17:20:35', 'Asia/Tehran'); $datetime = new Jalali('2019-01-01 17:20:35', 'Asia/Tehran');
$this->assertEquals(1397, $datetime->year); $this->assertEquals(1397, $datetime->year);
$this->assertEquals(10, $datetime->month); $this->assertEquals(10, $datetime->month);
@@ -29,7 +29,7 @@ class AccessTest extends TestCase
public function testSetProperty() 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; $datetime->year = 1398;
$this->assertEquals(1398, $datetime->year); $this->assertEquals(1398, $datetime->year);
@@ -52,13 +52,13 @@ class AccessTest extends TestCase
$datetime->timestamp = 1546382684; $datetime->timestamp = 1546382684;
$this->assertEquals(1546382684, $datetime->timestamp); $this->assertEquals(1546382684, $datetime->timestamp);
$datetime->tz = 'UTC'; $datetime->timezone = 'UTC';
$this->assertEquals('UTC', $datetime->timezone); $this->assertEquals('UTC', $datetime->timezone);
} }
public function testSetMethods() public function testSetMethods()
{ {
$datetime = Verta::parse('1399-05-12 12:36:32'); $datetime = Jalali::parse('1399-05-12 12:36:32');
$datetime->year(1395); $datetime->year(1395);
$this->assertEquals(1395, $datetime->year); $this->assertEquals(1395, $datetime->year);
@@ -87,7 +87,7 @@ class AccessTest extends TestCase
public function testSetDateTime() 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(1397, $datetime->year);
$this->assertEquals(10, $datetime->month); $this->assertEquals(10, $datetime->month);
@@ -99,7 +99,7 @@ class AccessTest extends TestCase
public function testSetDate() public function testSetDate()
{ {
$datetime = verta()->setDateJalali(1397, 10, 11); $datetime = jalali()->setDateJalali(1397, 10, 11);
$this->assertEquals(1397, $datetime->year); $this->assertEquals(1397, $datetime->year);
$this->assertEquals(10, $datetime->month); $this->assertEquals(10, $datetime->month);
@@ -108,7 +108,7 @@ class AccessTest extends TestCase
public function testSetTime() public function testSetTime()
{ {
$datetime = verta()->setTime(10, 20, 11); $datetime = jalali()->setTime(10, 20, 11);
$this->assertEquals(10, $datetime->hour); $this->assertEquals(10, $datetime->hour);
$this->assertEquals(20, $datetime->minute); $this->assertEquals(20, $datetime->minute);
@@ -117,7 +117,7 @@ class AccessTest extends TestCase
public function testSetTimeString() public function testSetTimeString()
{ {
$datetime = verta()->setTimeString('10:20:11'); $datetime = jalali()->setTimeString('10:20:11');
$this->assertEquals(10, $datetime->hour); $this->assertEquals(10, $datetime->hour);
$this->assertEquals(20, $datetime->minute); $this->assertEquals(20, $datetime->minute);
-279
View File
@@ -1,279 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Tests;
use Hekmatinasser\Verta\Verta;
use PHPUnit\Framework\TestCase;
class ComparisonTest extends TestCase
{
public function testValidDate()
{
$result = Verta::isValidDate(1365, 12, 15);
$this->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());
}
}
+304
View File
@@ -0,0 +1,304 @@
<?php
namespace Hekmatinasser\Jalali\Tests;
use Hekmatinasser\Jalali\Jalali;
use PHPUnit\Framework\TestCase;
class ComparisonTest extends TestCase
{
public function testValidDate()
{
$result = Jalali::isValidDate(1365, 12, 15);
$this->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());
}
}
+24 -40
View File
@@ -1,11 +1,10 @@
<?php <?php
namespace Hekmatinasser\Verta\Tests; namespace Hekmatinasser\Jalali\Tests;
use DateTime; use DateTime;
use DateTimeZone; use DateTimeZone;
use Hekmatinasser\Verta\Facades\Verta as VertaFacade; use Hekmatinasser\Jalali\Jalali;
use Hekmatinasser\Verta\Verta;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class CreatorTest extends TestCase class CreatorTest extends TestCase
@@ -13,7 +12,7 @@ class CreatorTest extends TestCase
public function testNow() public function testNow()
{ {
$expected = (new DateTime())->getTimestamp(); $expected = (new DateTime())->getTimestamp();
$actual = Verta::now()->getTimestamp(); $actual = Jalali::now()->getTimestamp();
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
@@ -21,7 +20,7 @@ class CreatorTest extends TestCase
public function testHelper() public function testHelper()
{ {
$expected = (new DateTime())->getTimestamp(); $expected = (new DateTime())->getTimestamp();
$actual = verta()->getTimestamp(); $actual = Jalali()->getTimestamp();
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
@@ -29,7 +28,7 @@ class CreatorTest extends TestCase
public function testYesterday() public function testYesterday()
{ {
$expected = (new DateTime("-1 days"))->format('Y-m-d 00:00:00'); $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); $this->assertEquals($expected, $actual);
} }
@@ -37,7 +36,7 @@ class CreatorTest extends TestCase
public function testToday() public function testToday()
{ {
$expected = (new DateTime())->format('Y-m-d 00:00:00'); $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); $this->assertEquals($expected, $actual);
} }
@@ -45,25 +44,18 @@ class CreatorTest extends TestCase
public function testTomorrow() public function testTomorrow()
{ {
$expected = (new DateTime("+1 days"))->format('Y-m-d 00:00:00'); $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); $this->assertEquals($expected, $actual);
} }
public function testInstance() 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); $this->assertEquals('1397-10-11 10:20:11', $datetime);
$datetime = (string) Verta::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);
$app = ['verta' => new Verta()];
VertaFacade::setFacadeApplication($app);
$datetime = (string) VertaFacade::instance('2019-01-01 10:20:11');
$this->assertEquals('1397-10-11 10:20:11', $datetime); $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')); $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->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() public function testDatetime()
{ {
$datetime = verta('2019-01-01 10:20:11')->datetime()->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 testToCarbon()
{
$datetime = verta('2019-01-01 10:20:11')->toCarbon()->format('Y-m-d H:i:s');
$this->assertEquals('2019-01-01 10:20:11', $datetime); $this->assertEquals('2019-01-01 10:20:11', $datetime);
} }
public function testParse() 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); $this->assertEquals('2019-01-01 10:20:11', $datetime);
} }
public function testParseFormat() 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); $this->assertEquals('2019-01-01 10:20:11', $datetime);
} }
public function testCreate() 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); $this->assertEquals('1397-10-11 10:20:11', $datetime);
} }
@@ -115,7 +99,7 @@ class CreatorTest extends TestCase
public function testCreateDate() public function testCreateDate()
{ {
$time = (new DateTime())->format("H:i:s"); $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); $this->assertEquals("1397-10-11 {$time}", $datetime);
} }
@@ -123,21 +107,21 @@ class CreatorTest extends TestCase
public function testCreateTime() public function testCreateTime()
{ {
$date = (new DateTime())->format("Y-m-d"); $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); $this->assertEquals("{$date} 15:19:51", $datetime);
} }
public function testCreateTimestamp() 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); $this->assertEquals("1398-12-16 13:36:31", $datetime);
} }
public function testCreateGregorian() 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); $this->assertEquals('1397-10-11 10:20:11', $datetime);
} }
@@ -145,7 +129,7 @@ class CreatorTest extends TestCase
public function testCreateGregorianDate() public function testCreateGregorianDate()
{ {
$time = (new DateTime())->format("H:i:s"); $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); $this->assertEquals("1397-10-11 {$time}", $datetime);
} }
@@ -153,14 +137,14 @@ class CreatorTest extends TestCase
public function testCreateGregorianTime() public function testCreateGregorianTime()
{ {
$date = (new DateTime())->format("Y-m-d"); $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); $this->assertEquals("{$date} 15:19:51", $datetime);
} }
public function testCreateJalali() 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); $this->assertEquals('1397-10-11 10:20:11', $datetime);
} }
@@ -168,15 +152,15 @@ class CreatorTest extends TestCase
public function testCreateJalaliDate() public function testCreateJalaliDate()
{ {
$time = (new DateTime())->format("H:i:s"); $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); $this->assertEquals("1397-10-11 {$time}", $datetime);
} }
public function testCreateJalaliTime() public function testCreateJalaliTime()
{ {
$date = verta()->format("Y-m-d"); $date = jalali()->format("Y-m-d");
$datetime = Verta::createJalaliTime(15, 19, 51)->format('Y-m-d H:i:s'); $datetime = Jalali::createJalaliTime(15, 19, 51)->format('Y-m-d H:i:s');
$this->assertEquals("{$date} 15:19:51", $datetime); $this->assertEquals("{$date} 15:19:51", $datetime);
} }
+26 -25
View File
@@ -1,111 +1,111 @@
<?php <?php
namespace Hekmatinasser\Verta\Tests; namespace Hekmatinasser\Jalali\Tests;
use Hekmatinasser\Verta\Verta; use Hekmatinasser\Jalali\Jalali;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class FormatTest extends TestCase class FormatTest extends TestCase
{ {
public function testSetFormat() public function testSetFormat()
{ {
Verta::setStringFormat('Y-m-d-H-i-s'); Jalali::setFormat('Y-m-d-H-i-s');
$datetime = (string) Verta::parse('1398-10-10 22:30:50'); $datetime = (string) Jalali::parse('1398-10-10 22:30:50');
$this->assertEquals('1398-10-10-22-30-50', $datetime); $this->assertEquals('1398-10-10-22-30-50', $datetime);
Verta::resetStringFormat(); Jalali::resetFormat();
$datetime = (string) Verta::parse('1398-10-10 22:30:50'); $datetime = (string) Jalali::parse('1398-10-10 22:30:50');
$this->assertEquals('1398-10-10 22:30:50', $datetime); $this->assertEquals('1398-10-10 22:30:50', $datetime);
} }
public function testFormat() 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); $this->assertEquals('98-10-10-9-30-50', $datetime);
} }
public function testFormatGregorian() 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); $this->assertEquals('2020 12 31 9 30 50', $datetime);
} }
public function testFormatDatetime() 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); $this->assertEquals('1398-10-10 21:30:50', $datetime);
} }
public function testFormatDate() 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); $this->assertEquals('1398-10-10', $datetime);
} }
public function testFormatTime() 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); $this->assertEquals('21:30:50', $datetime);
} }
public function testFormatJalaliDatetime() 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); $this->assertEquals('1398/10/10 21:30:50', $datetime);
} }
public function testFormatJalaliDate() 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); $this->assertEquals('1398/10/10', $datetime);
} }
public function testFormatDifference() public function testFormatDifference()
{ {
Verta::setLocale('fa'); Jalali::setLocale('fa');
$target = Verta::parse('1398-10-10 21:30:50'); $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); $difference = $target->formatDifference($datetime);
$this->assertEquals('الان', $difference); $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); $difference = $target->formatDifference($datetime);
$this->assertEquals('5 ثانیه بعد', $difference); $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); $difference = $target->formatDifference($datetime);
$this->assertEquals('1 دقیقه قبل', $difference); $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); $difference = $target->formatDifference($datetime);
$this->assertEquals('1 ساعت بعد', $difference); $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); $difference = $target->formatDifference($datetime);
$this->assertEquals('1 روز قبل', $difference); $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); $difference = $target->formatDifference($datetime);
$this->assertEquals('1 ماه قبل', $difference); $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); $difference = $target->formatDifference($datetime);
$this->assertEquals('1 سال بعد', $difference); $this->assertEquals('1 سال بعد', $difference);
@@ -113,15 +113,16 @@ class FormatTest extends TestCase
public function testFormatWord() 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); $this->assertEquals('چهارشنبه یازده ام دی', $datetime);
} }
public function testFormatQuarter() 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'));
} }
} }
+41 -32
View File
@@ -1,15 +1,15 @@
<?php <?php
namespace Hekmatinasser\Verta\Tests; namespace Hekmatinasser\Jalali\Tests;
use Hekmatinasser\Verta\Verta; use Hekmatinasser\Jalali\Jalali;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ModificationTest extends TestCase class ModificationTest extends TestCase
{ {
public function testAddYears() public function testAddYears()
{ {
$datetime = Verta::parse('1398-10-10 21:30:50'); $datetime = Jalali::parse('1398-10-10 21:30:50');
$datetime->addYears(2); $datetime->addYears(2);
@@ -18,7 +18,7 @@ class ModificationTest extends TestCase
public function testSubYears() public function testSubYears()
{ {
$datetime = Verta::parse('1398-10-10 21:30:50'); $datetime = Jalali::parse('1398-10-10 21:30:50');
$datetime->subYears(3); $datetime->subYears(3);
@@ -27,7 +27,7 @@ class ModificationTest extends TestCase
public function testAddMonths() 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'); $result = $datetime->addMonths(2)->format('Y-m-d H:i:s');
@@ -36,7 +36,7 @@ class ModificationTest extends TestCase
public function testSubMonths() 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'); $result = $datetime->subMonths(3)->format('Y-m-d H:i:s');
@@ -45,7 +45,7 @@ class ModificationTest extends TestCase
public function testAddWeeks() 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'); $result = $datetime->addWeeks(2)->format('Y-m-d H:i:s');
@@ -54,7 +54,7 @@ class ModificationTest extends TestCase
public function testSubWeeks() 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'); $result = $datetime->subWeeks(3)->format('Y-m-d H:i:s');
@@ -63,7 +63,7 @@ class ModificationTest extends TestCase
public function testAddDays() 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'); $result = $datetime->addDays(20)->format('Y-m-d H:i:s');
@@ -72,7 +72,7 @@ class ModificationTest extends TestCase
public function testSubDays() 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'); $result = $datetime->subDays(7)->format('Y-m-d H:i:s');
@@ -81,25 +81,25 @@ class ModificationTest extends TestCase
public function testAddHours() 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() 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() 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'); $result = $datetime->addMinutes(6)->format('Y-m-d H:i:s');
@@ -108,16 +108,16 @@ class ModificationTest extends TestCase
public function testSubMinutes() 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() 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'); $result = $datetime->addSeconds(16)->format('Y-m-d H:i:s');
@@ -126,16 +126,25 @@ class ModificationTest extends TestCase
public function testSubSeconds() 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'); $result = $datetime->subSeconds(30)->format('Y-m-d H:i:s');
$this->assertEquals('1398-10-10 21:29:50', $result); $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() 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'); $result = $datetime->startDay()->format('Y-m-d H:i:s');
@@ -144,7 +153,7 @@ class ModificationTest extends TestCase
public function testEndDay() 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'); $result = $datetime->endDay()->format('Y-m-d H:i:s');
@@ -153,7 +162,7 @@ class ModificationTest extends TestCase
public function testStartWeek() 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'); $result = $datetime->startWeek()->format('Y-m-d H:i:s');
@@ -162,7 +171,7 @@ class ModificationTest extends TestCase
public function testEndWeek() 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'); $result = $datetime->endWeek()->format('Y-m-d H:i:s');
@@ -171,7 +180,7 @@ class ModificationTest extends TestCase
public function testStartMonth() 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'); $result = $datetime->startMonth()->format('Y-m-d H:i:s');
@@ -180,7 +189,7 @@ class ModificationTest extends TestCase
public function testEndMonth() 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'); $result = $datetime->endMonth()->format('Y-m-d H:i:s');
@@ -189,7 +198,7 @@ class ModificationTest extends TestCase
public function testStartQuarter() 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'); $result = $datetime->startQuarter()->format('Y-m-d H:i:s');
@@ -198,7 +207,7 @@ class ModificationTest extends TestCase
public function testEndQuarter() 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'); $result = $datetime->endQuarter()->format('Y-m-d H:i:s');
@@ -207,7 +216,7 @@ class ModificationTest extends TestCase
public function testStartYear() 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'); $result = $datetime->startYear()->format('Y-m-d H:i:s');
@@ -216,7 +225,7 @@ class ModificationTest extends TestCase
public function testEndYear() 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'); $result = $datetime->endYear()->format('Y-m-d H:i:s');