add translation
This commit is contained in:
1 parent
d4e87f00e4
commit
dc614c2545
20 files changed
+941
-801
No files matched your search
+1
-1
@@ -36,7 +36,7 @@
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Hekmatinasser\\Verta\\VertaServiceProvider"
|
||||
"Hekmatinasser\\Verta\\Laravel\\VertaServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"Verta": "Hekmatinasser\\Verta\\Verta"
|
||||
|
||||
+183
-183
@@ -1,98 +1,98 @@
|
||||
<!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">
|
||||
<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>
|
||||
<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>
|
||||
</ul>
|
||||
</div>
|
||||
<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>
|
||||
</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>
|
||||
</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
|
||||
<pre>// config/app.php
|
||||
'providers' => [
|
||||
...
|
||||
Hekmatinasser\Verta\VertaServiceProvider::class,
|
||||
...
|
||||
Hekmatinasser\Verta\VertaServiceProvider::class,
|
||||
],
|
||||
|
||||
'alias' => [
|
||||
...
|
||||
'Verta' => Hekmatinasser\Verta\Verta::class,
|
||||
...
|
||||
'Verta' => Hekmatinasser\Verta\Verta::class,
|
||||
]</pre>
|
||||
<h2 id="usage">نحوه استفاده</h2>
|
||||
<p>در بالای هر فایل خود از کلاس ورتا استفاده میکند، از دستور زیر استفاده کنید</p>
|
||||
<h2 id="usage">نحوه استفاده</h2>
|
||||
<p>در بالای هر فایل خود از کلاس ورتا استفاده میکند، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
use Verta;
|
||||
// or
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
</pre>
|
||||
<h2 id="creator">ایجاد کردن</h2>
|
||||
<p>برای بدست آوردن تاریخ و زمان کنونی شمسی، از دستور زیر استفاده کنید</p>
|
||||
<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>
|
||||
<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>
|
||||
<p>برای بدست آوردن تاریخ و زمان به نسبت اکنون مانند تاریخ زمان پی اچ پی به صورت رشته ، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
$v = new Verta('now'); // 1399-06-18 15:32:08
|
||||
$v = new Verta('-1 day'); //1399-06-17 15:07:04
|
||||
@@ -101,34 +101,34 @@ $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>
|
||||
<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>
|
||||
<p>برای استفاده از عدد تایم استمپ به شمسی، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
$v = new Verta(1333857600);
|
||||
</pre>
|
||||
<p>برای استفاده از کلاس تاریخ و زمان پی اچ پی به شمسی، از دستور زیر استفاده کنید</p>
|
||||
<p>برای استفاده از کلاس تاریخ و زمان پی اچ پی به شمسی، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
$dt = new \Datetime();
|
||||
return new Verta($dt); // 1395-12-09 15:05:56
|
||||
</pre>
|
||||
<p>برای استفاده از کلاس کربن به شمسی، از دستور زیر استفاده کنید</p>
|
||||
<p>برای استفاده از کلاس کربن به شمسی، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
$c = \Carbon::now();
|
||||
return verta($c); // 1395-12-09 15:05:56
|
||||
</pre>
|
||||
<p>برای استفاده از تاریخ شمسی به صورت رشته، از دستور زیر استفاده کنید</p>
|
||||
<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>
|
||||
<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
|
||||
@@ -140,36 +140,36 @@ 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>
|
||||
<p>برای استفاده از عدد تایم استمپ به شمسی، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
return Verta::createTimestamp(1488614023); // 1395-12-14 11:23:43
|
||||
</pre>
|
||||
<p>در صورتی مقادیر تاریخ شمسی به صورت جداگانه باشد، از دستورات زیر استفاده کنید</p>
|
||||
<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>
|
||||
<h2 id="transformation">تبدیل تاریخ</h2>
|
||||
<p>برای تبدیل از میلادی به شمسی به صورت ساده، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
return Verta::getJalali(2015,12,25); // [1394,10,4]
|
||||
</pre>
|
||||
<p>برای تبدیل از شمسی به میلادی به صورت ساده، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
<p>برای تبدیل از شمسی به میلادی به صورت ساده، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
return Verta::getGregorian(1394,10,4); // [2015,12,25]
|
||||
</pre>
|
||||
<p>برای تبدیل تاریخ از ورتا به تاریخ و زمان پی اچ پی، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
<p>برای تبدیل تاریخ از ورتا به تاریخ و زمان پی اچ پی، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
$dt = verta()->datetime();
|
||||
</pre>
|
||||
<p>برای تبدیل تاریخ از ورتا به کربن، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
<p>برای تبدیل تاریخ از ورتا به کربن، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
$c = Carbon::instance($v->datetime());
|
||||
</pre>
|
||||
<h3 id="property">خصوصیات</h3>
|
||||
<p>برای دریافت مقادیر خصوصیات، از دستورات زیر استفاده کنید</p>
|
||||
<h3 id="property">خصوصیات</h3>
|
||||
<p>برای دریافت مقادیر خصوصیات، از دستورات زیر استفاده کنید</p>
|
||||
<pre>
|
||||
$v = verta(); // 1396-03-14 14:18:23
|
||||
return $v->year; // 1396
|
||||
@@ -187,7 +187,7 @@ return $v->daysInMonth; // 31
|
||||
return $v->timestamp; // 1496557661
|
||||
return $v->timezone; // Asia/Tehran
|
||||
</pre>
|
||||
<p>برای مقدار دهی خصوصیات، از دستورات زیر استفاده کنید</p>
|
||||
<p>برای مقدار دهی خصوصیات، از دستورات زیر استفاده کنید</p>
|
||||
<pre>
|
||||
$v = verta();
|
||||
$v->year = 1395;
|
||||
@@ -199,7 +199,7 @@ $v->second = 42;
|
||||
$v->timestamp = 1496557661;
|
||||
$v->timezone = 'Asia/Baku';
|
||||
</pre>
|
||||
<p>برای مقدار دهی خصوصیات با استفاده از تابع، از دستورات زیر استفاده کنید</p>
|
||||
<p>برای مقدار دهی خصوصیات با استفاده از تابع، از دستورات زیر استفاده کنید</p>
|
||||
<pre>
|
||||
$v = $v->year(1395);
|
||||
$v = $v->month(4); // set 13 for next year first month
|
||||
@@ -210,37 +210,37 @@ $v = $v->second(42);
|
||||
$v = $v->timestamp(1496557661);
|
||||
$v = $v->timezone('Asia/Baku');
|
||||
</pre>
|
||||
<p>برای مقدار دهی خصوصیات با یکدیگر، از دستورات زیر استفاده کنید</p>
|
||||
<p>برای مقدار دهی خصوصیات با یکدیگر، از دستورات زیر استفاده کنید</p>
|
||||
<pre>
|
||||
$v = $v->setDateTime(1395, 4, 25, 16, 50, 42);
|
||||
$v = $v->setDateTime(1395, 4, 25, 16, 50, 42, 1569856);
|
||||
$v = $v->setDate(1395, 4, 25);
|
||||
$v = $v->setTimeString('12:25:48');
|
||||
</pre>
|
||||
<h2 id="format">قالب نمایش</h2>
|
||||
<p>برای نمایش تاریخ به شمسی، از دستور زیر استفاده کنید</p>
|
||||
<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; //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>
|
||||
<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>
|
||||
<p>برای تنظیم مجددفرمت خروجی به حالت اولیه، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
Verta::resetStringFormat();
|
||||
return verta(); // 1395-12-12 00:18:04
|
||||
</pre>
|
||||
<p>برای نمایش تاریخ با فرمت های متعارف، از دستور زیر استفاده کنید</p>
|
||||
<p>برای نمایش تاریخ با فرمت های متعارف، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
return $v->formatDatetime(); // 1395-12-10 23:37:26
|
||||
return $v->formatDate(); // 1395-12-10
|
||||
@@ -248,12 +248,12 @@ return $v->formatTime(); // 23:26:35
|
||||
return $v->formatJalaliDatetime(); // 1395/12/10 23:46:09
|
||||
return $v->formatJalaliDate(); // 1395/12/10
|
||||
</pre>
|
||||
<p>برای نمایش تاریخ به صورت میلادی، از دستور زیر استفاده کنید</p>
|
||||
<p>برای نمایش تاریخ به صورت میلادی، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
return $v->formatGregorian('Y-m-d H:i:s'); // 2017-05-23 23:21:02
|
||||
</pre>
|
||||
<p>برای نمایش اختلاف تاریخ به صورت واحد زمانی، از دستور زیر استفاده کنید</p>
|
||||
<p>درصورتی که تاریخ را وارد نکنید، اختلاف با زمان کنونی محاسبه می شود.</p>
|
||||
<p>برای نمایش اختلاف تاریخ به صورت واحد زمانی، از دستور زیر استفاده کنید</p>
|
||||
<p>درصورتی که تاریخ را وارد نکنید، اختلاف با زمان کنونی محاسبه می شود.</p>
|
||||
<pre>
|
||||
return $v1->formatDifference($v2); // 12 ماه بعد
|
||||
return $v1->formatDifference($v3); // 1 سال قبل
|
||||
@@ -261,7 +261,7 @@ return $v1->addDays(25)->formatDifference(); // 4 هفته بعد
|
||||
return $v1->subDays(6)->formatDifference(); // 6 روز قبل
|
||||
return verta()->formatDifference(); // الان
|
||||
</pre>
|
||||
<p>برای نمایش اعداد به صورت حروف، از دستور زیر استفاده کنید</p>
|
||||
<p>برای نمایش اعداد به صورت حروف، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
return $v->formatWord('Y'); // یک هزار و سیصد و نود و شش
|
||||
return $v->formatWord('l dS F'); // چهارشنبه بیست و نه ام شهریور
|
||||
@@ -269,8 +269,8 @@ 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>
|
||||
<h2 id="modification">تغییر دادن</h2>
|
||||
<p>برای اضافه یا کم کردن از تاریخ خود، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
$v = verta();
|
||||
return $v->addYear(); // 1396-10-07 14:12:32
|
||||
@@ -314,7 +314,7 @@ 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>
|
||||
<p>برای بدست آوردن تاریخ شروع و پایان هر بازه زمانی، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
$v = verta(); // 1396-04-29 14:25:48
|
||||
return $v->startDay(); // 1396-04-29 00:00:00
|
||||
@@ -336,14 +336,14 @@ return $v->endQuarter(); // 1396-06-31 23:59:59
|
||||
return $v->startYear(); // 1396-01-01 00:00:00
|
||||
return $v->endYear(); // 1396-12-29 23:59:59
|
||||
</pre>
|
||||
<h2 id="comparison">بررسی و مقایسه</h2>
|
||||
<p>برای اعتبار سنجی تاریخ، از دستور زیر استفاده کنید</p>
|
||||
<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>
|
||||
<p>برای محاسبه اختلاف تاریخ ها با یکدیگر، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
// diff objects together
|
||||
$v1 = verta(); // 1396-03-31 22:21:40
|
||||
@@ -358,7 +358,7 @@ return $v1->diffDays($v3); // -372
|
||||
return $v3->diffMinutes(); // 536548
|
||||
return $v3->diffSeconds(); // 12261931
|
||||
</pre>
|
||||
<p>برای مقایسه تاریخ ها با یکدیگر، از دستور زیر استفاده کنید</p>
|
||||
<p>برای مقایسه تاریخ ها با یکدیگر، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
return $v1->eq(); // ture alias equalTo()
|
||||
return $v1->ne($v2); // true alias notEqualTo()
|
||||
@@ -368,7 +368,7 @@ return $v1->lt($v2); // false alias lessThan()
|
||||
return $v1->lte($v2); // false alias lessThanOrEqualTo()
|
||||
return $v1->between($v2, $v3); // false
|
||||
</pre>
|
||||
<p>برای بررسی تاریخ از لحاظ نزدیکتر یا دورتر بودن و یا کوچکتر و بزرگتر بودن، از دستور زیر استفاده کنید</p>
|
||||
<p>برای بررسی تاریخ از لحاظ نزدیکتر یا دورتر بودن و یا کوچکتر و بزرگتر بودن، از دستور زیر استفاده کنید</p>
|
||||
<pre>
|
||||
return $v1->closest($v2, $v3); // return $v2 object
|
||||
return $v1->farthest($v2, $v3); // return $v3 object
|
||||
@@ -377,7 +377,7 @@ return $v1->min($v2); // return $v2
|
||||
return $v1->maximum($v2); // return $v1
|
||||
return $v1->max($v2); // return $v1
|
||||
</pre>
|
||||
<p>برای بررسی تاریخ فعلی، از دستورات زیر استفاده کنید</p>
|
||||
<p>برای بررسی تاریخ فعلی، از دستورات زیر استفاده کنید</p>
|
||||
<pre>
|
||||
return $v1->isWeekday(); // true
|
||||
return $v1->isWeekend(); // false
|
||||
@@ -410,39 +410,39 @@ return $v1->isWednesday(); // false
|
||||
return $v1->isThursday(); // true
|
||||
return $v1->isFriday(); // false
|
||||
</pre>
|
||||
<h2 id="validation">اعتبار سنجی</h2>
|
||||
<p>شما می توانید با اعتبار سنجی لاراول تاریخ های شمسی درون فرم های خود استفاده کنید</p>
|
||||
<p>شما باید پیام های خطا برای اعتبار سنجی خود در در مسیر فایل های ترجمه خود اضافه کنیدبرای نمونه کد هایی که درون پکیج برای پیام خطا وجود دارد در فایل ترجمه خود قرار دهیدبرای مثال در فایل ترجمه پیام خطا به آرایه عبارات زیر را اضافه کنید</p>
|
||||
<h2 id="validation">اعتبار سنجی</h2>
|
||||
<p>شما می توانید با اعتبار سنجی لاراول تاریخ های شمسی درون فرم های خود استفاده کنید</p>
|
||||
<p>شما باید پیام های خطا برای اعتبار سنجی خود در در مسیر فایل های ترجمه خود اضافه کنیدبرای نمونه کد هایی که درون پکیج برای پیام خطا وجود دارد در فایل ترجمه خود قرار دهیدبرای مثال در فایل ترجمه پیام خطا به آرایه عبارات زیر را اضافه کنید</p>
|
||||
<pre>
|
||||
'jdate' => ':attribute تاریخ شمسی معتبر نمی باشد.',
|
||||
'jdate_equal' => ':attribute تاریخ شمسی برابر :fa-date نمی باشد.',
|
||||
'jdate_not_equal' => ':attribute تاریخ شمسی نامساوی :fa-date نمی باشد.',
|
||||
'jdate_equal' => ':attribute تاریخ شمسی برابر :date نمی باشد.',
|
||||
'jdate_not_equal' => ':attribute تاریخ شمسی نامساوی :date نمی باشد.',
|
||||
'jdatetime' => ':attribute تاریخ و زمان شمسی معتبر نمی باشد.',
|
||||
'jdatetime_equal' => ':attribute تاریخ و زمان شمسی مساوی :fa-date نمی باشد.',
|
||||
'jdatetime_not_equal' => ':attribute تاریخ و زمان شمسی نامساوی :fa-date نمی باشد.',
|
||||
'jdate_after' => ':attribute تاریخ شمسی باید بعد از :fa-date باشد.',
|
||||
'jdate_after_equal' => ':attribute تاریخ شمسی باید بعد یا برابر از :fa-date باشد.',
|
||||
'jdatetime_after' => ':attribute تاریخ و زمان شمسی باید بعد از :fa-date باشد.',
|
||||
'jdatetime_after_equal' => ':attribute تاریخ و زمان شمسی باید بعد یا برابر از :fa-date باشد.',
|
||||
'jdate_before' => ':attribute تاریخ شمسی باید قبل از :fa-date باشد.',
|
||||
'jdate_before_equal' => ':attribute تاریخ شمسی باید قبل یا برابر از :fa-date باشد.',
|
||||
'jdatetime_before' => ':attribute تاریخ و زمان شمسی باید قبل از :fa-date باشد.',
|
||||
'jdatetime_before_equal' => ':attribute تاریخ و زمان شمسی باید قبل یا برابر از :fa-date باشد.',
|
||||
'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' => 'تاریخ انقضا',
|
||||
'start_date' => 'تاریخ شروع',
|
||||
'expire_datetime' => 'تاریخ انقضا',
|
||||
],
|
||||
</pre>
|
||||
<h3>قوانین اعتبار سنجی</h3>
|
||||
<p>اگر تاریخ شمسی با فرمت معین درست باشد</p>
|
||||
<p>فرمت پیش فرض Y/m/d می باشد</p>
|
||||
<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>
|
||||
<p>اگر تاریخ شمسی با فرمت تعیین شده مساوی باشد</p>
|
||||
<p>فرمت پیش فرض Y/m/d می باشد</p>
|
||||
|
||||
<pre>
|
||||
'start_date' => 'jdate_equal'
|
||||
@@ -450,134 +450,134 @@ return $v1->isFriday(); // false
|
||||
'start_date' => 'jdate_equal:1388/01/01,Y/m/d'
|
||||
</pre>
|
||||
|
||||
<p>اگر تاریخ شمسی با فرمت تعیین شده نامساوی باشد</p>
|
||||
<p>فرمت پیش فرض Y/m/d می باشد</p>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<p>میتوانید با ترکیب قوانین تاریخ را بین دو محدوده بررسی کنید</p>
|
||||
<pre>
|
||||
$validate = Validator::make([
|
||||
'start_date' => '1389/01/31',
|
||||
'expire_datetime' => '1397/02/16 12:10:00',
|
||||
'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',
|
||||
'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());
|
||||
dd($validate->messages()->toArray());
|
||||
}
|
||||
|
||||
//output
|
||||
//output
|
||||
array:2 [
|
||||
"start_date" => array:1 [
|
||||
0 => "تاریخ شروع تاریخ شمسی باید قبل از ۱۳۹۰/۰۱/۰۱ باشد."
|
||||
]
|
||||
"expire_datetime" => array:1 [
|
||||
0 => "تاریخ انقضا تاریخ و زمان شمسی باید قبل از ۱۳۹۷/۰۲/۱۶ ۱۲:۱۰:۰۰ باشد."
|
||||
]
|
||||
"start_date" => array:1 [
|
||||
0 => "تاریخ شروع تاریخ شمسی باید قبل از ۱۳۹۰/۰۱/۰۱ باشد."
|
||||
]
|
||||
"expire_datetime" => array:1 [
|
||||
0 => "تاریخ انقضا تاریخ و زمان شمسی باید قبل از ۱۳۹۷/۰۲/۱۶ ۱۲:۱۰:۰۰ باشد."
|
||||
]
|
||||
]
|
||||
</pre>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer id="footer">
|
||||
<div style="text-align: center;">
|
||||
2020 ©
|
||||
</div>
|
||||
<div style="text-align: center;">
|
||||
2020 ©
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<?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' => 'مئة عام'
|
||||
],
|
||||
'pharse' => [
|
||||
'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.',
|
||||
]
|
||||
];
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<?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'
|
||||
],
|
||||
'pharse' => [
|
||||
'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.',
|
||||
]
|
||||
];
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<?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' => 'قرن'
|
||||
],
|
||||
'pharse' => [
|
||||
'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' . ' باشد.',
|
||||
]
|
||||
];
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<?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' => 'قرن'
|
||||
],
|
||||
'pharse' => [
|
||||
'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' . ' باشد.',
|
||||
]
|
||||
];
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Hekmatinasser\Verta\Validation;
|
||||
namespace Hekmatinasser\Verta\Laravel;
|
||||
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Support\Arr;
|
||||
use phpDocumentor\Reflection\Types\Static_;
|
||||
|
||||
class JalaliValidator
|
||||
{
|
||||
@@ -205,22 +207,27 @@ class JalaliValidator
|
||||
|
||||
public function replaceDateOrDatetime($message, $attribute, $rule, $parameters)
|
||||
{
|
||||
return $message;
|
||||
|
||||
$message = Verta::loadMessages();
|
||||
return Arr::get(static::$messages, $message, $message);
|
||||
}
|
||||
|
||||
public function replaceDateAfterOrBeforeOrEqual($message, $attribute, $rule, $parameters)
|
||||
{
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||
$date = count($parameters) ? $parameters[0] : Verta::instance()->format($format);
|
||||
$faDate = Verta::enToFaNumbers($date);
|
||||
return str_replace([':date', ':fa-date'], [$date, $faDate], $message);
|
||||
if(Verta::getLocale() != 'en') {
|
||||
$en = Verta::getMessages('en');
|
||||
$date = str_replace(array_values($en['numbers']), array_values(Verta::$messages['numbers']), $date);
|
||||
}
|
||||
return str_replace(':date', $date, $message);
|
||||
}
|
||||
|
||||
public function replaceDateTimeAfterOrBeforeOrEqual($message, $attribute, $rule, $parameters)
|
||||
{
|
||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||
$date = count($parameters) ? $parameters[0] : Verta::instance()->format($format);
|
||||
$faDate = Verta::enToFaNumbers($date);
|
||||
return str_replace([':date', ':fa-date'], [$date, $faDate], $message);
|
||||
$date = str_replace(array_values($en['numbers']), array_values(Verta::$messages['numbers']), $date);
|
||||
return str_replace(':date', $date, $message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Hekmatinasser\Verta\Laravel;
|
||||
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class VertaServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
private $rules = [
|
||||
'jdate' => [
|
||||
'extend' => 'validateDate',
|
||||
'replacer' => 'replaceDateOrDatetime'
|
||||
],
|
||||
'jdate_equal' => [
|
||||
'extend' => 'validateDateEqual',
|
||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual'
|
||||
],
|
||||
'jdate_not_equal' => [
|
||||
'extend' => 'validateDateNotEqual',
|
||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual'
|
||||
],
|
||||
'jdatetime' => [
|
||||
'extend' => 'validateDateTime',
|
||||
'replacer' => 'replaceDateOrDatetime'
|
||||
],
|
||||
'jdatetime_equal' => [
|
||||
'extend' => 'validateDateTimeEqual',
|
||||
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual'
|
||||
],
|
||||
'jdatetime_not_equal' => [
|
||||
'extend' => 'validateDateTimeNotEqual',
|
||||
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual'
|
||||
],
|
||||
'jdate_after' => [
|
||||
'extend' => 'validateDateAfter',
|
||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual'
|
||||
],
|
||||
'jdate_after_equal' => [
|
||||
'extend' => 'validateDateAfterEqual',
|
||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual'
|
||||
],
|
||||
'jdatetime_after' => [
|
||||
'extend' => 'validateDateTimeAfter',
|
||||
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual'
|
||||
],
|
||||
'jdatetime_after_equal' => [
|
||||
'extend' => 'validateDateTimeAfterEqual',
|
||||
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual'
|
||||
],
|
||||
'jdate_before' => [
|
||||
'extend' => 'validateDateBefore',
|
||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual'
|
||||
],
|
||||
'jdate_before_equal' => [
|
||||
'extend' => 'validateDateBeforeEqual',
|
||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual'
|
||||
],
|
||||
'jdatetime_before' => [
|
||||
'extend' => 'validateDateTimeBefore',
|
||||
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual'
|
||||
],
|
||||
'jdatetime_before_equal' => [
|
||||
'extend' => 'validateDateTimeBeforeEqual',
|
||||
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual'
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Bootstrap the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->loadValidators();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind('verta', function ($app) {
|
||||
return new Verta;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array('verta');
|
||||
}
|
||||
|
||||
public function loadValidators()
|
||||
{
|
||||
$className = JalaliValidator::class . '@';
|
||||
|
||||
foreach ($this->rules as $name => $methods) {
|
||||
|
||||
if (array_key_exists('extend', $methods) || array_key_exists('replacer', $methods)) {
|
||||
|
||||
Validator::extend($name, $className . $methods['extend']);
|
||||
|
||||
Validator::replacer($name, $className . $methods['replacer']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ namespace Hekmatinasser\Verta\Traits;
|
||||
|
||||
use DateTimeZone;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Hekmatinasser\Verta\VertaInterface;
|
||||
use InvalidArgumentException;
|
||||
|
||||
trait Accessor
|
||||
@@ -43,7 +42,7 @@ trait Accessor
|
||||
return (int) $this->format($formats[$name]);
|
||||
|
||||
case $name === 'quarter':
|
||||
return (int) ceil($this->month / VertaInterface::MONTHS_PER_QUARTER);
|
||||
return (int) ceil($this->month / static::MONTHS_PER_QUARTER);
|
||||
|
||||
case $name === 'timezone':
|
||||
return $this->getTimezone()->getName();
|
||||
|
||||
@@ -334,7 +334,7 @@ trait Comparison
|
||||
*/
|
||||
public function isWeekend()
|
||||
{
|
||||
return in_array($this->dayOfWeek, static::$weekendDays);
|
||||
return in_array($this->dayOfWeek, static::$weekEndsAt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,6 +36,7 @@ trait Creator
|
||||
try {
|
||||
parent::__construct($datetime, static::createTimeZone($timezone));
|
||||
parent::setTimezone(static::createTimeZone($timezone));
|
||||
self::loadMessages();
|
||||
} catch (Exception $exception) {
|
||||
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
|
||||
}
|
||||
@@ -138,16 +139,13 @@ trait Creator
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function parse($datetime , $timezone = null) {
|
||||
$names = array_map(function ($value) {
|
||||
return " $value ";
|
||||
}, self::$monthYear);
|
||||
public static function parse($datetime , $timezone = null)
|
||||
{
|
||||
$names = array_map(function ($value) { return " $value "; }, array_values(self::$messages['year_months']));
|
||||
$values = array_map(function ($value) { return "-$value-"; }, range(1,12));
|
||||
|
||||
$values = array_map(function ($value) {
|
||||
return "-$value-";
|
||||
}, range(1,12));
|
||||
$formatted = str_replace($names, $values, $datetime);
|
||||
$formatted = str_replace(self::$monthYear, range(1,12), $formatted);
|
||||
$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));
|
||||
@@ -169,7 +167,7 @@ trait Creator
|
||||
* @return static
|
||||
*/
|
||||
public static function parseFormat($format, $datetime, $timezone = null) {
|
||||
$formatted = str_replace(self::$monthYear, range(1,12), $datetime);
|
||||
$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'])) {
|
||||
|
||||
+2
-91
@@ -14,6 +14,7 @@ trait Date
|
||||
use Formatting;
|
||||
use Modification;
|
||||
use Transformation;
|
||||
use Translator;
|
||||
use Boundaries;
|
||||
use Difference;
|
||||
|
||||
@@ -43,10 +44,7 @@ trait Date
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $weekendDays = [
|
||||
VertaInterface::THURSDAY,
|
||||
VertaInterface::FRIDAY,
|
||||
];
|
||||
protected static $weekendDays = [VertaInterface::THURSDAY, VertaInterface::FRIDAY];
|
||||
|
||||
/**
|
||||
* number day in months gregorian
|
||||
@@ -62,91 +60,4 @@ trait Date
|
||||
*/
|
||||
protected static $daysMonthJalali = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29];
|
||||
|
||||
/**
|
||||
* month name jalali
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $monthYear = [
|
||||
'فروردین',
|
||||
'اردیبهشت',
|
||||
'خرداد',
|
||||
'تیر',
|
||||
'مرداد',
|
||||
'شهریور',
|
||||
'مهر',
|
||||
'آبان',
|
||||
'آذر',
|
||||
'دی',
|
||||
'بهمن',
|
||||
'اسفند',
|
||||
];
|
||||
|
||||
/**
|
||||
* Names of days of the week.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $dayWeek = [
|
||||
'شنبه',
|
||||
'یکشنبه',
|
||||
'دوشنبه',
|
||||
'سه شنبه',
|
||||
'چهارشنبه',
|
||||
'پنج شنبه',
|
||||
'جمعه',
|
||||
];
|
||||
|
||||
/**
|
||||
* unit date name.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $unitName = [
|
||||
'ثانیه',
|
||||
'دقیقه',
|
||||
'ساعت',
|
||||
'روز',
|
||||
'هفته',
|
||||
'ماه',
|
||||
'سال',
|
||||
'قرن'
|
||||
];
|
||||
|
||||
/**
|
||||
* unit date number.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $unitNumber = [
|
||||
VertaInterface::SECONDS_PER_MINUTE,
|
||||
VertaInterface::MINUTES_PER_HOUR,
|
||||
VertaInterface::HOURS_PER_DAY,
|
||||
VertaInterface::DAYS_PER_WEEK,
|
||||
VertaInterface::WEEKS_PER_MONTH,
|
||||
VertaInterface::MONTHS_PER_YEAR,
|
||||
VertaInterface::YEARS_PER_DECADE,
|
||||
];
|
||||
|
||||
/**
|
||||
* arabic number.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected static $arabicNumber = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
|
||||
|
||||
/**
|
||||
* persian number.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $persianNumber = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
|
||||
|
||||
/**
|
||||
* english number.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $englishNumber = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||
}
|
||||
+204
-352
@@ -44,157 +44,147 @@ trait Formatting
|
||||
* @param string $format for example 'Y-m-d H:i:s'
|
||||
* @return string
|
||||
*/
|
||||
protected function date($format){
|
||||
protected function date($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 );
|
||||
|
||||
$pWeek = $gWeek + 1;
|
||||
|
||||
if ($pWeek >= 7) {
|
||||
$pWeek = 0;
|
||||
}
|
||||
|
||||
if ($format == '\\') {
|
||||
$format = '//';
|
||||
}
|
||||
|
||||
$lenghFormat = strlen( $format );
|
||||
$i = 0;
|
||||
$lengh = strlen($format);
|
||||
$index = 0;
|
||||
$result = '';
|
||||
|
||||
while ($i < $lenghFormat) {
|
||||
$par = $format[$i];
|
||||
if ($par == '\\') {
|
||||
$result .= $format[++$i];
|
||||
$i++;
|
||||
while ($index < $lengh) {
|
||||
$char = $format[$index];
|
||||
if ($char == '\\') {
|
||||
$result .= $format[++$index];
|
||||
$index++;
|
||||
continue;
|
||||
}
|
||||
switch ($par) {
|
||||
# Day
|
||||
case 'd':
|
||||
$result .= sprintf( '%02s', $pDay );
|
||||
break;
|
||||
$result .= $this->characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek);
|
||||
|
||||
case 'D':
|
||||
$result .= substr( static::$dayWeek[ $pWeek ], 0, 2 );
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
$result .= $pDay;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
$result .= static::$dayWeek[ $pWeek ];
|
||||
break;
|
||||
|
||||
case 'N':
|
||||
$result .= $pWeek + 1;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
$result .= $pWeek;
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
$result .= $this->daysYear( $pMonth, $pDay );
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
$result .= self::NUMBER_TH;
|
||||
break;
|
||||
|
||||
# Week
|
||||
case 'W':
|
||||
$result .= ceil( $this->daysYear( $pMonth, $pDay ) / 7 );
|
||||
break;
|
||||
|
||||
# Month
|
||||
case 'F':
|
||||
$result .= static::$monthYear[ $pMonth - 1 ];
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
$result .= sprintf( '%02s', $pMonth );
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
$result .= substr( static::$monthYear[ $pMonth - 1 ], 0, 6 );
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
$result .= $pMonth;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
$result .= static::isLeapYear( $pYear ) && ( $pMonth == 12 ) ? 30 : static::$daysMonthJalali[ intval( $pMonth ) - 1 ];
|
||||
break;
|
||||
|
||||
# Years
|
||||
case 'L':
|
||||
$result .= intval( $this->isLeapYear( $pYear ) );
|
||||
break;
|
||||
|
||||
case 'Y':
|
||||
case 'o':
|
||||
$result .= $pYear;
|
||||
break;
|
||||
|
||||
case 'y':
|
||||
$result .= substr( $pYear, 2 );
|
||||
break;
|
||||
|
||||
# Time
|
||||
case 'a':
|
||||
case 'A':
|
||||
if (parent::format( 'a' ) == 'am') {
|
||||
$result .= ( ( $par == 'a' ) ? self::AM : self::ANTE_MERIDIEM );
|
||||
} else {
|
||||
$result .= ( ( $par == 'a' ) ? self::PM : self::POST_MERIDIEM );
|
||||
}
|
||||
break;
|
||||
|
||||
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':
|
||||
$result .= parent::format( $par );
|
||||
break;
|
||||
|
||||
# Full Date/Time
|
||||
case 'c':
|
||||
$result .= ( $pYear . '-' . $pMonth . '-' . $pDay . ' ' . parent::format( 'H:i:s P' ) );
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
$result .= ( substr( static::$dayWeek[ $pWeek ], 0, 2 ) . '، ' . $pDay . ' ' . substr( static::$monthYear[ $pMonth ], 0, 6 ) . ' ' . $pYear . ' ' . parent::format( 'H:i:s P' ) );
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
$result .= $timestamp;
|
||||
break;
|
||||
|
||||
default:
|
||||
$result .= $par;
|
||||
}
|
||||
|
||||
$i++;
|
||||
$index++;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The format of the outputted date charactre (jalali equivalent of php date() function)
|
||||
*
|
||||
* @param string $char
|
||||
* @param integer $timestamp
|
||||
* @param integer $pYear
|
||||
* @param integer $pMonth
|
||||
* @param integer $pDay
|
||||
* @param integer $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 ceil( $this->daysYear( $pMonth, $pDay ) / 7 );
|
||||
|
||||
# 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 ];
|
||||
|
||||
# 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'][$gWeek], 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)
|
||||
*
|
||||
@@ -205,143 +195,31 @@ trait Formatting
|
||||
|
||||
$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);
|
||||
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;
|
||||
}
|
||||
|
||||
if ($format == '\\') {
|
||||
$format = '//';
|
||||
}
|
||||
|
||||
$lenghFormat = strlen($format);
|
||||
$i = 0;
|
||||
$lengh = strlen($format);
|
||||
$index = 0;
|
||||
$result = '';
|
||||
|
||||
$word = new Notowo(0, 'fa');
|
||||
|
||||
while ($i < $lenghFormat) {
|
||||
$par = $format[$i];
|
||||
if ($par == '\\') {
|
||||
$result .= $format[++$i];
|
||||
$i ++;
|
||||
while ($index < $lengh) {
|
||||
$char = $format[$index];
|
||||
if ($char == '\\') {
|
||||
$result .= $format[++$index];
|
||||
$index++;
|
||||
continue;
|
||||
}
|
||||
switch ($par) {
|
||||
# Day
|
||||
case 'd':
|
||||
case 'j':
|
||||
$result .= $word->getWord(strval($pDay));
|
||||
break;
|
||||
$output = $this->characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek);
|
||||
$result .= (string) new Notowo($output, static::getLocale() == 'en' ? 'en' : 'fa' );
|
||||
|
||||
case 'D':
|
||||
$result .= substr(static::$dayWeek[$pWeek], 0, 2);
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
$result .= static::$dayWeek[$pWeek];
|
||||
break;
|
||||
|
||||
case 'N':
|
||||
$result .= $word->getWord(strval($pWeek + 1));
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
$result .= $word->getWord(strval($pWeek));
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
$result .= $word->getWord(strval($this->daysYear($pMonth, $pDay)));
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
$result .= self::NUMBER_TH;
|
||||
break;
|
||||
|
||||
# Week
|
||||
case 'W':
|
||||
$result .= $word->getWord(strval(ceil($this->daysYear($pMonth, $pDay) / 7)));
|
||||
break;
|
||||
|
||||
# Month
|
||||
case 'F':
|
||||
$result .= static::$monthYear[$pMonth-1];
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
case 'n':
|
||||
$result .= $word->getWord(strval($pMonth));
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
$result .= substr(static::$monthYear[$pMonth-1], 0, 6);
|
||||
break;
|
||||
|
||||
case 't':
|
||||
$result .= $word->getWord(strval(static::isLeapYear($pYear) && ($pMonth == 12) ? 30 : static::$daysMonthJalali[intval($pMonth)-1]));
|
||||
break;
|
||||
|
||||
# Years
|
||||
case 'L':
|
||||
$result .= intval($this->isLeapYear($pYear));
|
||||
break;
|
||||
|
||||
case 'Y':
|
||||
case 'o':
|
||||
$result .= $word->getWord(strval($pYear));
|
||||
break;
|
||||
|
||||
case 'y':
|
||||
$result .= $word->getWord(strval(substr($pYear, 2)));
|
||||
break;
|
||||
|
||||
# Time
|
||||
case 'a':
|
||||
$result .= (parent::format('a') == 'am' ? self::AM : self::PM);
|
||||
case 'A':
|
||||
$result .= (parent::format('a') == 'am' ? self::ANTE_MERIDIEM : self::POST_MERIDIEM);
|
||||
break;
|
||||
case 'B':
|
||||
case 'g':
|
||||
case 'G':
|
||||
case 'h':
|
||||
case 'H':
|
||||
case 's':
|
||||
case 'u':
|
||||
case 'i':
|
||||
$result .= $word->getWord(strval(parent::format($par)));
|
||||
break;
|
||||
case 'e':
|
||||
case 'I':
|
||||
case 'O':
|
||||
case 'P':
|
||||
case 'T':
|
||||
case 'Z':
|
||||
$result .= parent::format($par);
|
||||
break;
|
||||
|
||||
# Full Date/Time
|
||||
case 'c':
|
||||
$result .= $this->dateWord('Y, m, d, H:i:s P');
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
$result .= $this->dateWord('l Y, m, d, H:i:s P');
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
$result .= $word->getWord(strval($timestamp));
|
||||
break;
|
||||
|
||||
default:
|
||||
$result .= $par;
|
||||
}
|
||||
$i ++;
|
||||
$index++;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -369,93 +247,50 @@ trait Formatting
|
||||
*/
|
||||
protected function strftime($format)
|
||||
{
|
||||
$str_format_code = array(
|
||||
"%a",
|
||||
"%A",
|
||||
"%d",
|
||||
"%e",
|
||||
"%j",
|
||||
"%u",
|
||||
"%w",
|
||||
"%U",
|
||||
"%V",
|
||||
"%W",
|
||||
"%b",
|
||||
"%B",
|
||||
"%h",
|
||||
"%m",
|
||||
"%C",
|
||||
"%g",
|
||||
"%G",
|
||||
"%y",
|
||||
"%Y",
|
||||
"%H",
|
||||
"%I",
|
||||
"%l",
|
||||
"%M",
|
||||
"%p",
|
||||
"%P",
|
||||
"%r",
|
||||
"%R",
|
||||
"%S",
|
||||
"%T",
|
||||
"%X",
|
||||
"%z",
|
||||
"%Z",
|
||||
"%c",
|
||||
"%D",
|
||||
"%F",
|
||||
"%s",
|
||||
"%x",
|
||||
"%n",
|
||||
"%t",
|
||||
"%%",
|
||||
$strftime_date = array(
|
||||
"%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",
|
||||
"%%" => "%",
|
||||
);
|
||||
|
||||
$date_format_code = array(
|
||||
"D",
|
||||
"l",
|
||||
"d",
|
||||
"j",
|
||||
"z",
|
||||
"N",
|
||||
"w",
|
||||
"W",
|
||||
"W",
|
||||
"W",
|
||||
"M",
|
||||
"F",
|
||||
"M",
|
||||
"m",
|
||||
"y",
|
||||
"y",
|
||||
"y",
|
||||
"y",
|
||||
"Y",
|
||||
"H",
|
||||
"h",
|
||||
"g",
|
||||
"i",
|
||||
"A",
|
||||
"a",
|
||||
"h:i:s A",
|
||||
"H:i",
|
||||
"s",
|
||||
"H:i:s",
|
||||
"h:i:s",
|
||||
"H",
|
||||
"H",
|
||||
"D j M H:i:s",
|
||||
"d/m/y",
|
||||
"Y-m-d",
|
||||
"U",
|
||||
"d/m/y",
|
||||
"\n",
|
||||
"\t",
|
||||
"%",
|
||||
);
|
||||
|
||||
return str_replace($str_format_code, $date_format_code, $format);
|
||||
return str_replace(array_keys($strftime_date), array_values($strftime_date), $format);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -539,20 +374,31 @@ trait Formatting
|
||||
*/
|
||||
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 = $difference < 0 ? self::POST : self::PRE;
|
||||
$result .= static::$messages['phrase'][$difference < 0 ? 'later' : 'ago'];
|
||||
|
||||
$difference = abs($difference);
|
||||
|
||||
for ($j = 0; $difference >= static::$unitNumber[$j] and $j < count(static::$unitNumber) - 1; $j++) {
|
||||
$difference /= static::$unitNumber[$j];
|
||||
for ($unit = 0; $difference >= $units[$unit] and $unit < count($units) - 1; $unit++) {
|
||||
$difference /= $units[$unit];
|
||||
}
|
||||
$difference = intval(round($difference));
|
||||
|
||||
if($difference === 0) {
|
||||
return self::NOW;
|
||||
return static::$messages['phrase']['now'];
|
||||
}
|
||||
|
||||
return sprintf('%s %s %s', $difference, static::$unitName[$j], $absolute);
|
||||
return sprintf('%s %s %s', $difference, array_values(static::$messages['date_units'])[$unit], $absolute);
|
||||
}
|
||||
|
||||
public function formatWord($format)
|
||||
@@ -568,7 +414,9 @@ trait Formatting
|
||||
*/
|
||||
public static function enToFaNumbers($string)
|
||||
{
|
||||
return str_replace(self::$englishNumber, self::$persianNumber, $string);
|
||||
$en = static::getMessages('en');
|
||||
$fa = static::getMessages('fa');
|
||||
return str_replace(array_values($en['numbers']), array_values($fa['numbers']), $string);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -579,7 +427,9 @@ trait Formatting
|
||||
*/
|
||||
public static function faToEnNumbers($string)
|
||||
{
|
||||
return str_replace(self::$persianNumber, self::$englishNumber, $string);
|
||||
$fa = static::getMessages('fa');
|
||||
$en = static::getMessages('en');
|
||||
return str_replace(array_values($fa['numbers']), array_values($en['numbers']), $string);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -590,7 +440,9 @@ trait Formatting
|
||||
*/
|
||||
public static function arToEnNumbers($string)
|
||||
{
|
||||
return str_replace(self::$arabicNumber, self::$englishNumber, $string);
|
||||
$ar = static::getMessages('ar');
|
||||
$en = static::getMessages('en');
|
||||
return str_replace(array_values($ar['numbers']), array_values($en['numbers']), $string);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Hekmatinasser\Verta\Traits;
|
||||
|
||||
|
||||
trait Translator
|
||||
{
|
||||
/**
|
||||
* List of custom localized messages.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $messages = array();
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
static::$locale = $locale;
|
||||
static::loadMessages($locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Hekmatinasser\Verta\Validation;
|
||||
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Hekmatinasser\Verta\Validation\JalaliValidator;
|
||||
|
||||
class ValidatorLoader
|
||||
{
|
||||
const EXTEND_INDEX = 0;
|
||||
|
||||
const REPLACER_INDEX = 1;
|
||||
|
||||
const DATE_VALIDATORS = [
|
||||
'jdate' => ['validateDate', 'replaceDateOrDatetime'],
|
||||
'jdate_equal' => ['validateDateEqual', 'replaceDateAfterOrBeforeOrEqual'],
|
||||
'jdate_not_equal' => ['validateDateNotEqual', 'replaceDateAfterOrBeforeOrEqual'],
|
||||
'jdatetime' => ['validateDateTime', 'replaceDateOrDatetime'],
|
||||
'jdatetime_equal' => ['validateDateTimeEqual', 'replaceDateTimeAfterOrBeforeOrEqual'],
|
||||
'jdatetime_not_equal' => ['validateDateTimeNotEqual', 'replaceDateTimeAfterOrBeforeOrEqual'],
|
||||
'jdate_after' => ['validateDateAfter', 'replaceDateAfterOrBeforeOrEqual'],
|
||||
'jdate_after_equal' => ['validateDateAfterEqual', 'replaceDateAfterOrBeforeOrEqual'],
|
||||
'jdatetime_after' => ['validateDateTimeAfter', 'replaceDateTimeAfterOrBeforeOrEqual'],
|
||||
'jdatetime_after_equal' => ['validateDateTimeAfterEqual', 'replaceDateTimeAfterOrBeforeOrEqual'],
|
||||
'jdate_before' => ['validateDateBefore', 'replaceDateAfterOrBeforeOrEqual'],
|
||||
'jdate_before_equal' => ['validateDateBeforeEqual', 'replaceDateAfterOrBeforeOrEqual'],
|
||||
'jdatetime_before' => ['validateDateTimeBefore', 'replaceDateTimeAfterOrBeforeOrEqual'],
|
||||
'jdatetime_before_equal' => ['validateDateTimeBeforeEqual', 'replaceDateTimeAfterOrBeforeOrEqual'],
|
||||
];
|
||||
|
||||
|
||||
public static function loadValidators()
|
||||
{
|
||||
$validatorClass = JalaliValidator::class . '@';
|
||||
|
||||
foreach (self::DATE_VALIDATORS as $name => $methods) {
|
||||
|
||||
if (!is_array($methods) || count($methods) < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Validator::extend($name, $validatorClass . $methods[self::EXTEND_INDEX]);
|
||||
|
||||
if (array_key_exists(self::REPLACER_INDEX, $methods)) {
|
||||
Validator::replacer($name, $validatorClass . $methods[self::REPLACER_INDEX]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-10
@@ -20,7 +20,7 @@ interface VertaInterface
|
||||
/**
|
||||
* Number unit in date
|
||||
*/
|
||||
const YEARS_PER_CENTURY = 100;
|
||||
const DECADE_PER_CENTURY = 10;
|
||||
const YEARS_PER_DECADE = 10;
|
||||
const MONTHS_PER_YEAR = 12;
|
||||
const MONTHS_PER_QUARTER = 3;
|
||||
@@ -37,14 +37,7 @@ interface VertaInterface
|
||||
const DEFAULT_STRING_FORMAT = 'Y-m-d H:i:s';
|
||||
|
||||
/**
|
||||
* Default format to use for __toString method when type juggling occurs.
|
||||
* Word use in format datetime.
|
||||
*/
|
||||
const AM = 'ق.ظ';
|
||||
const PM = 'ب.ظ';
|
||||
const ANTE_MERIDIEM = 'قبل از ظهر';
|
||||
const POST_MERIDIEM = 'بعد از ظهر';
|
||||
const NUMBER_TH = ' ام';
|
||||
const PRE = 'قبل';
|
||||
const NOW = 'الان';
|
||||
const POST = 'بعد';
|
||||
const DEFAULT_LOCALE = 'fa';
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Hekmatinasser\Verta;
|
||||
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Hekmatinasser\Verta\Validation\ValidatorLoader;
|
||||
|
||||
class VertaServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Bootstrap the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
ValidatorLoader::loadValidators();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind('verta', function ($app) {
|
||||
return new Verta;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array('verta');
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
return [
|
||||
'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.',
|
||||
];
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'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.',
|
||||
];
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.',
|
||||
'jdate_equal' => ':attribute' . ' تاریخ شمسی برابر ' . ':fa-date' . ' نمی باشد.',
|
||||
'jdate_not_equal' => ':attribute' . ' تاریخ شمسی نامساوی ' . ':fa-date' . ' نمی باشد.',
|
||||
'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.',
|
||||
'jdatetime_equal' => ':attribute' . ' تاریخ و زمان شمسی مساوی ' . ':fa-date' . ' نمی باشد.',
|
||||
'jdatetime_not_equal' => ':attribute' . ' تاریخ و زمان شمسی نامساوی ' . ':fa-date' . ' نمی باشد.',
|
||||
'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':fa-date' . ' باشد.',
|
||||
'jdate_after_equal' => ':attribute' . ' تاریخ شمسی باید بعد یا برابر از ' . ':fa-date' . ' باشد.',
|
||||
'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':fa-date' . ' باشد.',
|
||||
'jdatetime_after_equal' => ':attribute' . ' تاریخ و زمان شمسی باید بعد یا برابر از ' . ':fa-date' . ' باشد.',
|
||||
'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':fa-date' . ' باشد.',
|
||||
'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':fa-date' . ' باشد.',
|
||||
'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':fa-date' . ' باشد.',
|
||||
'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':fa-date' . ' باشد.',
|
||||
];
|
||||
Reference in new issue
Block a user