add translation

This commit is contained in:
nasser committed 2021-06-06 11:45:19 +04:30
1 parent d4e87f00e4
commit dc614c2545
20 files changed
+876 -736

No files matched your search

+1 -1
View File
@@ -36,7 +36,7 @@
"extra": { "extra": {
"laravel": { "laravel": {
"providers": [ "providers": [
"Hekmatinasser\\Verta\\VertaServiceProvider" "Hekmatinasser\\Verta\\Laravel\\VertaServiceProvider"
], ],
"aliases": { "aliases": {
"Verta": "Hekmatinasser\\Verta\\Verta" "Verta": "Hekmatinasser\\Verta\\Verta"
+183 -183
View File
@@ -1,98 +1,98 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fa"> <html lang="fa">
<head> <head>
<title>Verta — پکیج تاریخ شمسی در لاراول</title> <title>Verta — پکیج تاریخ شمسی در لاراول</title>
<meta name="description" content=""> <meta name="description" content="">
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <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="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="telephone=no">
<link href="https://fonts.googleapis.com/css2?family=Markazi+Text&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Markazi+Text&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/style.css?v=0.2"> <link rel="stylesheet" href="css/style.css?v=0.2">
</head> </head>
<body dir="rtl"> <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> <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"> <header id="header">
<h1>Verta</h1> <h1>Verta</h1>
<h2>تاریخ شمسی در لاراول</h2> <h2>تاریخ شمسی در لاراول</h2>
</header> </header>
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-sm-3"> <div class="col-sm-3">
<div class="sidebar"> <div class="sidebar">
<div class="sticky"> <div class="sticky">
<ul> <ul>
<li> <li>
<a href="#installation">نصب</a> <a href="#installation">نصب</a>
</li> </li>
<li> <li>
<a href="#usage">نحوه استفاده</a> <a href="#usage">نحوه استفاده</a>
</li> </li>
<li> <li>
<a href="#creator">ایجاد کردن</a> <a href="#creator">ایجاد کردن</a>
</li> </li>
<li> <li>
<a href="#transformation">تبدیل تاریخ</a> <a href="#transformation">تبدیل تاریخ</a>
</li> </li>
<li> <li>
<a href="#property">خصوصیات</a> <a href="#property">خصوصیات</a>
</li> </li>
<li> <li>
<a href="#format">قالب نمایش</a> <a href="#format">قالب نمایش</a>
</li> </li>
<li> <li>
<a href="#modification">تغییر دادن</a> <a href="#modification">تغییر دادن</a>
</li> </li>
<li> <li>
<a href="#comparison">بررسی و مقایسه</a> <a href="#comparison">بررسی و مقایسه</a>
</li> </li>
<li> <li>
<a href="#validation">اعتبار سنجی</a> <a href="#validation">اعتبار سنجی</a>
</li> </li>
</ul> </ul>
</div> </div>
</div> </div>
</div> </div>
<div class="col-sm-9"> <div class="col-sm-9">
<article class="content"> <article class="content">
<h2 id="installation">نصب</h2> <h2 id="installation">نصب</h2>
<p>برای نصب دستور زیر را وارد کنید</p> <p>برای نصب دستور زیر را وارد کنید</p>
<pre>$ composer require hekmatinasser/verta</pre> <pre>$ composer require hekmatinasser/verta</pre>
<p>حال باید پکیج را درون پروژه خود اضافه کنید برای این کار دستور زیر را وارد کنید</p> <p>حال باید پکیج را درون پروژه خود اضافه کنید برای این کار دستور زیر را وارد کنید</p>
<pre>// config/app.php <pre>// config/app.php
'providers' => [ 'providers' => [
... ...
Hekmatinasser\Verta\VertaServiceProvider::class, Hekmatinasser\Verta\VertaServiceProvider::class,
], ],
'alias' => [ 'alias' => [
... ...
'Verta' => Hekmatinasser\Verta\Verta::class, 'Verta' => Hekmatinasser\Verta\Verta::class,
]</pre> ]</pre>
<h2 id="usage">نحوه استفاده</h2> <h2 id="usage">نحوه استفاده</h2>
<p>در بالای هر فایل خود از کلاس ورتا استفاده میکند، از دستور زیر استفاده کنید</p> <p>در بالای هر فایل خود از کلاس ورتا استفاده میکند، از دستور زیر استفاده کنید</p>
<pre> <pre>
use Verta; use Verta;
// or // or
use Hekmatinasser\Verta\Verta; use Hekmatinasser\Verta\Verta;
</pre> </pre>
<h2 id="creator">ایجاد کردن</h2> <h2 id="creator">ایجاد کردن</h2>
<p>برای بدست آوردن تاریخ و زمان کنونی شمسی، از دستور زیر استفاده کنید</p> <p>برای بدست آوردن تاریخ و زمان کنونی شمسی، از دستور زیر استفاده کنید</p>
<pre> <pre>
$v = new Verta(); //1396-02-02 15:32:08 $v = new Verta(); //1396-02-02 15:32:08
$v = verta(); //1396-02-02 15:32:08 $v = verta(); //1396-02-02 15:32:08
</pre> </pre>
<p>برای بدست آوردن تاریخ و زمان به نسبت اکنون، از دستور زیر استفاده کنید</p> <p>برای بدست آوردن تاریخ و زمان به نسبت اکنون، از دستور زیر استفاده کنید</p>
<pre> <pre>
$v = Verta::now(); //1396-02-02 15:32:08 $v = Verta::now(); //1396-02-02 15:32:08
$v = Verta::today(); //1396-03-02 00:00:00 $v = Verta::today(); //1396-03-02 00:00:00
$v = Verta::tomorrow(); // 1396-03-03 00:00:00 $v = Verta::tomorrow(); // 1396-03-03 00:00:00
$v = Verta::yesterday(); // 1396-03-01 00:00:00 $v = Verta::yesterday(); // 1396-03-01 00:00:00
</pre> </pre>
<p>برای بدست آوردن تاریخ و زمان به نسبت اکنون مانند تاریخ زمان پی اچ پی به صورت رشته ، از دستور زیر استفاده کنید</p> <p>برای بدست آوردن تاریخ و زمان به نسبت اکنون مانند تاریخ زمان پی اچ پی به صورت رشته ، از دستور زیر استفاده کنید</p>
<pre> <pre>
$v = new Verta('now'); // 1399-06-18 15:32:08 $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 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 $v = new Verta('last sunday'); //1399-06-16 00:00:00
</pre> </pre>
<p>برای تبدیل تاریخ میلادی خود به شمسی، از دستور زیر استفاده کنید</p> <p>برای تبدیل تاریخ میلادی خود به شمسی، از دستور زیر استفاده کنید</p>
<pre> <pre>
$v = new Verta('2016-12-27 14:12:32'); $v = new Verta('2016-12-27 14:12:32');
$v = Verta::instance('2016-12-25 11:12:36'); $v = Verta::instance('2016-12-25 11:12:36');
$v = Facades\Verta::instance('2016-12-25 11:12:36'); $v = Facades\Verta::instance('2016-12-25 11:12:36');
</pre> </pre>
<p>برای استفاده از عدد تایم استمپ به شمسی، از دستور زیر استفاده کنید</p> <p>برای استفاده از عدد تایم استمپ به شمسی، از دستور زیر استفاده کنید</p>
<pre> <pre>
$v = new Verta(1333857600); $v = new Verta(1333857600);
</pre> </pre>
<p>برای استفاده از کلاس تاریخ و زمان پی اچ پی به شمسی، از دستور زیر استفاده کنید</p> <p>برای استفاده از کلاس تاریخ و زمان پی اچ پی به شمسی، از دستور زیر استفاده کنید</p>
<pre> <pre>
$dt = new \Datetime(); $dt = new \Datetime();
return new Verta($dt); // 1395-12-09 15:05:56 return new Verta($dt); // 1395-12-09 15:05:56
</pre> </pre>
<p>برای استفاده از کلاس کربن به شمسی، از دستور زیر استفاده کنید</p> <p>برای استفاده از کلاس کربن به شمسی، از دستور زیر استفاده کنید</p>
<pre> <pre>
$c = \Carbon::now(); $c = \Carbon::now();
return verta($c); // 1395-12-09 15:05:56 return verta($c); // 1395-12-09 15:05:56
</pre> </pre>
<p>برای استفاده از تاریخ شمسی به صورت رشته، از دستور زیر استفاده کنید</p> <p>برای استفاده از تاریخ شمسی به صورت رشته، از دستور زیر استفاده کنید</p>
<pre> <pre>
$v = Verta::parse('1395-10-07 14:12:32'); $v = Verta::parse('1395-10-07 14:12:32');
$v = Verta::parse('1396 مهر 17'); $v = Verta::parse('1396 مهر 17');
$v = Verta::parseFormat('Y n j','1396 مهر 17'); $v = Verta::parseFormat('Y n j','1396 مهر 17');
</pre> </pre>
<p>در صورتی مقادیر تاریخ میلادی به صورت جداگانه باشد، از دستورات زیر استفاده کنید</p> <p>در صورتی مقادیر تاریخ میلادی به صورت جداگانه باشد، از دستورات زیر استفاده کنید</p>
<pre> <pre>
return Verta::create(); // 1395-12-14 11:17:01 equal now() 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::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::createGregorianDate(2016,12,25); // 1395-10-05 21:35:49 set time now
return Verta::createGregorianTime(15,51,5); // 1396-02-31 15:51:05 set date now return Verta::createGregorianTime(15,51,5); // 1396-02-31 15:51:05 set date now
</pre> </pre>
<p>برای استفاده از عدد تایم استمپ به شمسی، از دستور زیر استفاده کنید</p> <p>برای استفاده از عدد تایم استمپ به شمسی، از دستور زیر استفاده کنید</p>
<pre> <pre>
return Verta::createTimestamp(1488614023); // 1395-12-14 11:23:43 return Verta::createTimestamp(1488614023); // 1395-12-14 11:23:43
</pre> </pre>
<p>در صورتی مقادیر تاریخ شمسی به صورت جداگانه باشد، از دستورات زیر استفاده کنید</p> <p>در صورتی مقادیر تاریخ شمسی به صورت جداگانه باشد، از دستورات زیر استفاده کنید</p>
<pre> <pre>
// get Jalali datetime // get Jalali datetime
return Verta::createJalali(1394,12,29,15,51,5); // 1394-12-29 15:51:05 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::createJalaliDate(1394,12,29); // 1394-12-29 11:18:29 set time now
return Verta::createJalaliTime(15,51,5); // 1395-12-14 15:51:05 set date now return Verta::createJalaliTime(15,51,5); // 1395-12-14 15:51:05 set date now
</pre> </pre>
<h2 id="transformation">تبدیل تاریخ</h2> <h2 id="transformation">تبدیل تاریخ</h2>
<p>برای تبدیل از میلادی به شمسی به صورت ساده، از دستور زیر استفاده کنید</p> <p>برای تبدیل از میلادی به شمسی به صورت ساده، از دستور زیر استفاده کنید</p>
<pre> <pre>
return Verta::getJalali(2015,12,25); // [1394,10,4] return Verta::getJalali(2015,12,25); // [1394,10,4]
</pre> </pre>
<p>برای تبدیل از شمسی به میلادی به صورت ساده، از دستور زیر استفاده کنید</p> <p>برای تبدیل از شمسی به میلادی به صورت ساده، از دستور زیر استفاده کنید</p>
<pre> <pre>
return Verta::getGregorian(1394,10,4); // [2015,12,25] return Verta::getGregorian(1394,10,4); // [2015,12,25]
</pre> </pre>
<p>برای تبدیل تاریخ از ورتا به تاریخ و زمان پی اچ پی، از دستور زیر استفاده کنید</p> <p>برای تبدیل تاریخ از ورتا به تاریخ و زمان پی اچ پی، از دستور زیر استفاده کنید</p>
<pre> <pre>
$dt = verta()->datetime(); $dt = verta()->datetime();
</pre> </pre>
<p>برای تبدیل تاریخ از ورتا به کربن، از دستور زیر استفاده کنید</p> <p>برای تبدیل تاریخ از ورتا به کربن، از دستور زیر استفاده کنید</p>
<pre> <pre>
$c = Carbon::instance($v->datetime()); $c = Carbon::instance($v->datetime());
</pre> </pre>
<h3 id="property">خصوصیات</h3> <h3 id="property">خصوصیات</h3>
<p>برای دریافت مقادیر خصوصیات، از دستورات زیر استفاده کنید</p> <p>برای دریافت مقادیر خصوصیات، از دستورات زیر استفاده کنید</p>
<pre> <pre>
$v = verta(); // 1396-03-14 14:18:23 $v = verta(); // 1396-03-14 14:18:23
return $v->year; // 1396 return $v->year; // 1396
@@ -187,7 +187,7 @@ return $v->daysInMonth; // 31
return $v->timestamp; // 1496557661 return $v->timestamp; // 1496557661
return $v->timezone; // Asia/Tehran return $v->timezone; // Asia/Tehran
</pre> </pre>
<p>برای مقدار دهی خصوصیات، از دستورات زیر استفاده کنید</p> <p>برای مقدار دهی خصوصیات، از دستورات زیر استفاده کنید</p>
<pre> <pre>
$v = verta(); $v = verta();
$v->year = 1395; $v->year = 1395;
@@ -199,7 +199,7 @@ $v->second = 42;
$v->timestamp = 1496557661; $v->timestamp = 1496557661;
$v->timezone = 'Asia/Baku'; $v->timezone = 'Asia/Baku';
</pre> </pre>
<p>برای مقدار دهی خصوصیات با استفاده از تابع، از دستورات زیر استفاده کنید</p> <p>برای مقدار دهی خصوصیات با استفاده از تابع، از دستورات زیر استفاده کنید</p>
<pre> <pre>
$v = $v->year(1395); $v = $v->year(1395);
$v = $v->month(4); // set 13 for next year first month $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->timestamp(1496557661);
$v = $v->timezone('Asia/Baku'); $v = $v->timezone('Asia/Baku');
</pre> </pre>
<p>برای مقدار دهی خصوصیات با یکدیگر، از دستورات زیر استفاده کنید</p> <p>برای مقدار دهی خصوصیات با یکدیگر، از دستورات زیر استفاده کنید</p>
<pre> <pre>
$v = $v->setDateTime(1395, 4, 25, 16, 50, 42); $v = $v->setDateTime(1395, 4, 25, 16, 50, 42);
$v = $v->setDateTime(1395, 4, 25, 16, 50, 42, 1569856); $v = $v->setDateTime(1395, 4, 25, 16, 50, 42, 1569856);
$v = $v->setDate(1395, 4, 25); $v = $v->setDate(1395, 4, 25);
$v = $v->setTimeString('12:25:48'); $v = $v->setTimeString('12:25:48');
</pre> </pre>
<h2 id="format">قالب نمایش</h2> <h2 id="format">قالب نمایش</h2>
<p>برای نمایش تاریخ به شمسی، از دستور زیر استفاده کنید</p> <p>برای نمایش تاریخ به شمسی، از دستور زیر استفاده کنید</p>
<pre> <pre>
$v = verta(); $v = verta();
return $v->format('Y-n-j H:i'); // 1395-10-7 14:12 return $v->format('Y-n-j H:i'); // 1395-10-7 14:12
return $v->format('%B %d، %Y'); // دی 07، 1395 return $v->format('%B %d، %Y'); // دی 07، 1395
return $v; //1395-10-07 14:12:32 return $v; //1395-10-07 14:12:32
</pre> </pre>
<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.strftime.php" target="_blank">strftime</a>
<a href="http://php.net/manual/en/function.date.php" target="_blank">date</a> <a href="http://php.net/manual/en/function.date.php" target="_blank">date</a>
</p> </p>
<p>برای تعیین فرمت خروجی پیش فرض، از دستور زیر استفاده کنید</p> <p>برای تعیین فرمت خروجی پیش فرض، از دستور زیر استفاده کنید</p>
<pre> <pre>
Verta::setStringformat('Y/n/j H:i:s'); Verta::setStringformat('Y/n/j H:i:s');
return verta(); // 1395/12/12 00:11:35 return verta(); // 1395/12/12 00:11:35
</pre> </pre>
<p>برای تنظیم مجددفرمت خروجی به حالت اولیه، از دستور زیر استفاده کنید</p> <p>برای تنظیم مجددفرمت خروجی به حالت اولیه، از دستور زیر استفاده کنید</p>
<pre> <pre>
Verta::resetStringFormat(); Verta::resetStringFormat();
return verta(); // 1395-12-12 00:18:04 return verta(); // 1395-12-12 00:18:04
</pre> </pre>
<p>برای نمایش تاریخ با فرمت های متعارف، از دستور زیر استفاده کنید</p> <p>برای نمایش تاریخ با فرمت های متعارف، از دستور زیر استفاده کنید</p>
<pre> <pre>
return $v->formatDatetime(); // 1395-12-10 23:37:26 return $v->formatDatetime(); // 1395-12-10 23:37:26
return $v->formatDate(); // 1395-12-10 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->formatJalaliDatetime(); // 1395/12/10 23:46:09
return $v->formatJalaliDate(); // 1395/12/10 return $v->formatJalaliDate(); // 1395/12/10
</pre> </pre>
<p>برای نمایش تاریخ به صورت میلادی، از دستور زیر استفاده کنید</p> <p>برای نمایش تاریخ به صورت میلادی، از دستور زیر استفاده کنید</p>
<pre> <pre>
return $v->formatGregorian('Y-m-d H:i:s'); // 2017-05-23 23:21:02 return $v->formatGregorian('Y-m-d H:i:s'); // 2017-05-23 23:21:02
</pre> </pre>
<p>برای نمایش اختلاف تاریخ به صورت واحد زمانی، از دستور زیر استفاده کنید</p> <p>برای نمایش اختلاف تاریخ به صورت واحد زمانی، از دستور زیر استفاده کنید</p>
<p>درصورتی که تاریخ را وارد نکنید، اختلاف با زمان کنونی محاسبه می شود.</p> <p>درصورتی که تاریخ را وارد نکنید، اختلاف با زمان کنونی محاسبه می شود.</p>
<pre> <pre>
return $v1->formatDifference($v2); // 12 ماه بعد return $v1->formatDifference($v2); // 12 ماه بعد
return $v1->formatDifference($v3); // 1 سال قبل return $v1->formatDifference($v3); // 1 سال قبل
@@ -261,7 +261,7 @@ return $v1->addDays(25)->formatDifference(); // 4 هفته بعد
return $v1->subDays(6)->formatDifference(); // 6 روز قبل return $v1->subDays(6)->formatDifference(); // 6 روز قبل
return verta()->formatDifference(); // الان return verta()->formatDifference(); // الان
</pre> </pre>
<p>برای نمایش اعداد به صورت حروف، از دستور زیر استفاده کنید</p> <p>برای نمایش اعداد به صورت حروف، از دستور زیر استفاده کنید</p>
<pre> <pre>
return $v->formatWord('Y'); // یک هزار و سیصد و نود و شش return $v->formatWord('Y'); // یک هزار و سیصد و نود و شش
return $v->formatWord('l dS F'); // چهارشنبه بیست و نه ام شهریور 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('r'); // چهارشنبه یک هزار و سیصد و نود و شش, شش, بیست و نه, بیست و دو:چهل و نه:سی و هشت +04:30
return $v->formatWord('d F ') . $v->year; // بیست و نه شهریور 1396 return $v->formatWord('d F ') . $v->year; // بیست و نه شهریور 1396
</pre> </pre>
<h2 id="modification">تغییر دادن</h2> <h2 id="modification">تغییر دادن</h2>
<p>برای اضافه یا کم کردن از تاریخ خود، از دستور زیر استفاده کنید</p> <p>برای اضافه یا کم کردن از تاریخ خود، از دستور زیر استفاده کنید</p>
<pre> <pre>
$v = verta(); $v = verta();
return $v->addYear(); // 1396-10-07 14:12:32 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->subSecond(); // 1395-10-07 14:12:31
return $v->subSeconds(2); // 1395-10-07 14:12:30 return $v->subSeconds(2); // 1395-10-07 14:12:30
</pre> </pre>
<p>برای بدست آوردن تاریخ شروع و پایان هر بازه زمانی، از دستور زیر استفاده کنید</p> <p>برای بدست آوردن تاریخ شروع و پایان هر بازه زمانی، از دستور زیر استفاده کنید</p>
<pre> <pre>
$v = verta(); // 1396-04-29 14:25:48 $v = verta(); // 1396-04-29 14:25:48
return $v->startDay(); // 1396-04-29 00:00:00 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->startYear(); // 1396-01-01 00:00:00
return $v->endYear(); // 1396-12-29 23:59:59 return $v->endYear(); // 1396-12-29 23:59:59
</pre> </pre>
<h2 id="comparison">بررسی و مقایسه</h2> <h2 id="comparison">بررسی و مقایسه</h2>
<p>برای اعتبار سنجی تاریخ، از دستور زیر استفاده کنید</p> <p>برای اعتبار سنجی تاریخ، از دستور زیر استفاده کنید</p>
<pre> <pre>
return Verta::isLeapYear(1394); // false return Verta::isLeapYear(1394); // false
return Verta::isValidDate(1394, 12, 30); // false return Verta::isValidDate(1394, 12, 30); // false
return Verta::isValidTime(15, 12, 30); // true return Verta::isValidTime(15, 12, 30); // true
</pre> </pre>
<p>برای محاسبه اختلاف تاریخ ها با یکدیگر، از دستور زیر استفاده کنید</p> <p>برای محاسبه اختلاف تاریخ ها با یکدیگر، از دستور زیر استفاده کنید</p>
<pre> <pre>
// diff objects together // diff objects together
$v1 = verta(); // 1396-03-31 22:21:40 $v1 = verta(); // 1396-03-31 22:21:40
@@ -358,7 +358,7 @@ return $v1->diffDays($v3); // -372
return $v3->diffMinutes(); // 536548 return $v3->diffMinutes(); // 536548
return $v3->diffSeconds(); // 12261931 return $v3->diffSeconds(); // 12261931
</pre> </pre>
<p>برای مقایسه تاریخ ها با یکدیگر، از دستور زیر استفاده کنید</p> <p>برای مقایسه تاریخ ها با یکدیگر، از دستور زیر استفاده کنید</p>
<pre> <pre>
return $v1->eq(); // ture alias equalTo() return $v1->eq(); // ture alias equalTo()
return $v1->ne($v2); // true alias notEqualTo() 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->lte($v2); // false alias lessThanOrEqualTo()
return $v1->between($v2, $v3); // false return $v1->between($v2, $v3); // false
</pre> </pre>
<p>برای بررسی تاریخ از لحاظ نزدیکتر یا دورتر بودن و یا کوچکتر و بزرگتر بودن، از دستور زیر استفاده کنید</p> <p>برای بررسی تاریخ از لحاظ نزدیکتر یا دورتر بودن و یا کوچکتر و بزرگتر بودن، از دستور زیر استفاده کنید</p>
<pre> <pre>
return $v1->closest($v2, $v3); // return $v2 object return $v1->closest($v2, $v3); // return $v2 object
return $v1->farthest($v2, $v3); // return $v3 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->maximum($v2); // return $v1
return $v1->max($v2); // return $v1 return $v1->max($v2); // return $v1
</pre> </pre>
<p>برای بررسی تاریخ فعلی، از دستورات زیر استفاده کنید</p> <p>برای بررسی تاریخ فعلی، از دستورات زیر استفاده کنید</p>
<pre> <pre>
return $v1->isWeekday(); // true return $v1->isWeekday(); // true
return $v1->isWeekend(); // false return $v1->isWeekend(); // false
@@ -410,39 +410,39 @@ return $v1->isWednesday(); // false
return $v1->isThursday(); // true return $v1->isThursday(); // true
return $v1->isFriday(); // false return $v1->isFriday(); // false
</pre> </pre>
<h2 id="validation">اعتبار سنجی</h2> <h2 id="validation">اعتبار سنجی</h2>
<p>شما می توانید با اعتبار سنجی لاراول تاریخ های شمسی درون فرم های خود استفاده کنید</p> <p>شما می توانید با اعتبار سنجی لاراول تاریخ های شمسی درون فرم های خود استفاده کنید</p>
<p>شما باید پیام های خطا برای اعتبار سنجی خود در در مسیر فایل های ترجمه خود اضافه کنیدبرای نمونه کد هایی که درون پکیج برای پیام خطا وجود دارد در فایل ترجمه خود قرار دهیدبرای مثال در فایل ترجمه پیام خطا به آرایه عبارات زیر را اضافه کنید</p> <p>شما باید پیام های خطا برای اعتبار سنجی خود در در مسیر فایل های ترجمه خود اضافه کنیدبرای نمونه کد هایی که درون پکیج برای پیام خطا وجود دارد در فایل ترجمه خود قرار دهیدبرای مثال در فایل ترجمه پیام خطا به آرایه عبارات زیر را اضافه کنید</p>
<pre> <pre>
'jdate' => ':attribute تاریخ شمسی معتبر نمی باشد.', 'jdate' => ':attribute تاریخ شمسی معتبر نمی باشد.',
'jdate_equal' => ':attribute تاریخ شمسی برابر :fa-date نمی باشد.', 'jdate_equal' => ':attribute تاریخ شمسی برابر :date نمی باشد.',
'jdate_not_equal' => ':attribute تاریخ شمسی نامساوی :fa-date نمی باشد.', 'jdate_not_equal' => ':attribute تاریخ شمسی نامساوی :date نمی باشد.',
'jdatetime' => ':attribute تاریخ و زمان شمسی معتبر نمی باشد.', 'jdatetime' => ':attribute تاریخ و زمان شمسی معتبر نمی باشد.',
'jdatetime_equal' => ':attribute تاریخ و زمان شمسی مساوی :fa-date نمی باشد.', 'jdatetime_equal' => ':attribute تاریخ و زمان شمسی مساوی :date نمی باشد.',
'jdatetime_not_equal' => ':attribute تاریخ و زمان شمسی نامساوی :fa-date نمی باشد.', 'jdatetime_not_equal' => ':attribute تاریخ و زمان شمسی نامساوی :date نمی باشد.',
'jdate_after' => ':attribute تاریخ شمسی باید بعد از :fa-date باشد.', 'jdate_after' => ':attribute تاریخ شمسی باید بعد از :date باشد.',
'jdate_after_equal' => ':attribute تاریخ شمسی باید بعد یا برابر از :fa-date باشد.', 'jdate_after_equal' => ':attribute تاریخ شمسی باید بعد یا برابر از :date باشد.',
'jdatetime_after' => ':attribute تاریخ و زمان شمسی باید بعد از :fa-date باشد.', 'jdatetime_after' => ':attribute تاریخ و زمان شمسی باید بعد از :date باشد.',
'jdatetime_after_equal' => ':attribute تاریخ و زمان شمسی باید بعد یا برابر از :fa-date باشد.', 'jdatetime_after_equal' => ':attribute تاریخ و زمان شمسی باید بعد یا برابر از :date باشد.',
'jdate_before' => ':attribute تاریخ شمسی باید قبل از :fa-date باشد.', 'jdate_before' => ':attribute تاریخ شمسی باید قبل از :date باشد.',
'jdate_before_equal' => ':attribute تاریخ شمسی باید قبل یا برابر از :fa-date باشد.', 'jdate_before_equal' => ':attribute تاریخ شمسی باید قبل یا برابر از :date باشد.',
'jdatetime_before' => ':attribute تاریخ و زمان شمسی باید قبل از :fa-date باشد.', 'jdatetime_before' => ':attribute تاریخ و زمان شمسی باید قبل از :date باشد.',
'jdatetime_before_equal' => ':attribute تاریخ و زمان شمسی باید قبل یا برابر از :fa-date باشد.', 'jdatetime_before_equal' => ':attribute تاریخ و زمان شمسی باید قبل یا برابر از :date باشد.',
'attributes' => [ 'attributes' => [
'start_date' => 'تاریخ شروع', 'start_date' => 'تاریخ شروع',
'expire_datetime' => 'تاریخ انقضا', 'expire_datetime' => 'تاریخ انقضا',
], ],
</pre> </pre>
<h3>قوانین اعتبار سنجی</h3> <h3>قوانین اعتبار سنجی</h3>
<p>اگر تاریخ شمسی با فرمت معین درست باشد</p> <p>اگر تاریخ شمسی با فرمت معین درست باشد</p>
<p>فرمت پیش فرض Y/m/d می باشد</p> <p>فرمت پیش فرض Y/m/d می باشد</p>
<pre> <pre>
'start_date' => 'jdate' 'start_date' => 'jdate'
'start_date' => 'jdate:Y/m/d' 'start_date' => 'jdate:Y/m/d'
</pre> </pre>
<p>اگر تاریخ شمسی با فرمت تعیین شده مساوی باشد</p> <p>اگر تاریخ شمسی با فرمت تعیین شده مساوی باشد</p>
<p>فرمت پیش فرض Y/m/d می باشد</p> <p>فرمت پیش فرض Y/m/d می باشد</p>
<pre> <pre>
'start_date' => 'jdate_equal' 'start_date' => 'jdate_equal'
@@ -450,134 +450,134 @@ return $v1->isFriday(); // false
'start_date' => 'jdate_equal:1388/01/01,Y/m/d' 'start_date' => 'jdate_equal:1388/01/01,Y/m/d'
</pre> </pre>
<p>اگر تاریخ شمسی با فرمت تعیین شده نامساوی باشد</p> <p>اگر تاریخ شمسی با فرمت تعیین شده نامساوی باشد</p>
<p>فرمت پیش فرض Y/m/d می باشد</p> <p>فرمت پیش فرض Y/m/d می باشد</p>
<pre> <pre>
'start_date' => 'jdate_not_equal' 'start_date' => 'jdate_not_equal'
'start_date' => 'jdate_not_equal:1388/01/01' 'start_date' => 'jdate_not_equal:1388/01/01'
'start_date' => 'jdate_not_equal:1388/01/01,Y/m/d' 'start_date' => 'jdate_not_equal:1388/01/01,Y/m/d'
</pre> </pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد</p> <p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد</p> <p>فرمت پیش فرض Y/m/d H:i:s می باشد</p>
<pre> <pre>
'start_date' => 'jdatetime' 'start_date' => 'jdatetime'
'start_date' => 'jdatetime:Y/m/d H:i:s' 'start_date' => 'jdatetime:Y/m/d H:i:s'
</pre> </pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده مساوی باشد</p> <p>اگر تاریخ و زمان شمسی با فرمت تعیین شده مساوی باشد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد</p> <p>فرمت پیش فرض Y/m/d H:i:s می باشد</p>
<pre> <pre>
'start_date' => 'jdatetime_equal' 'start_date' => 'jdatetime_equal'
'start_date' => 'jdatetime_equal:1388/01/01 12:56:28' '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' 'start_date' => 'jdatetime_equal:1388/01/01 12:56:28,Y/m/d H:i:s'
</pre> </pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده نامساوی باشد</p> <p>اگر تاریخ و زمان شمسی با فرمت تعیین شده نامساوی باشد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد</p> <p>فرمت پیش فرض Y/m/d H:i:s می باشد</p>
<pre> <pre>
'start_date' => 'jdatetime_not_equal' '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'
'start_date' => 'jdatetime_not_equal:1388/01/01 12:56:28,Y/m/d H:i:s' 'start_date' => 'jdatetime_not_equal:1388/01/01 12:56:28,Y/m/d H:i:s'
</pre> </pre>
<p>اگر تاریخ شمسی با فرمت تعیین شده درست باشد و بعد از تاریخ تعیین شده باشد</p> <p>اگر تاریخ شمسی با فرمت تعیین شده درست باشد و بعد از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد</p> <p>درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد</p>
<p>فرمت پیش فرض Y/m/d می باشد</p> <p>فرمت پیش فرض Y/m/d می باشد</p>
<pre> <pre>
'start_date' => 'jdate_after' 'start_date' => 'jdate_after'
'start_date' => 'jdate_after:1388/01/01' 'start_date' => 'jdate_after:1388/01/01'
'start_date' => 'jdate_after:1388/01/01,Y/m/d' 'start_date' => 'jdate_after:1388/01/01,Y/m/d'
</pre> </pre>
<p>اگر تاریخ شمسی با فرمت تعیین شده درست باشد و بعد یا مساوی از تاریخ تعیین شده باشد</p> <p>اگر تاریخ شمسی با فرمت تعیین شده درست باشد و بعد یا مساوی از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد</p> <p>درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد</p>
<p>فرمت پیش فرض Y/m/d می باشد </p> <p>فرمت پیش فرض Y/m/d می باشد </p>
<pre> <pre>
'start_date' => 'jdate_after_equal' 'start_date' => 'jdate_after_equal'
'start_date' => 'jdate_after_equal:1388/01/01' 'start_date' => 'jdate_after_equal:1388/01/01'
'start_date' => 'jdate_after_equal:1388/01/01,Y/m/d' 'start_date' => 'jdate_after_equal:1388/01/01,Y/m/d'
</pre> </pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و بعد از تاریخ تعیین شده باشد</p> <p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و بعد از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد</p> <p>درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد </p> <p>فرمت پیش فرض Y/m/d H:i:s می باشد </p>
<pre> <pre>
'start_date' => 'jdatetime_after' 'start_date' => 'jdatetime_after'
'start_date' => 'jdatetime_after:1388/01/01' 'start_date' => 'jdatetime_after:1388/01/01'
'start_date' => 'jdatetime_after:1388/01/01,Y/m/d' 'start_date' => 'jdatetime_after:1388/01/01,Y/m/d'
</pre> </pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و بعد یا مساوی از تاریخ تعیین شده باشد</p> <p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و بعد یا مساوی از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد</p> <p>درصورتی که تاریخ وارد کنید تاریخ فعلی در نظر میگیرد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد </p> <p>فرمت پیش فرض Y/m/d H:i:s می باشد </p>
<pre> <pre>
'start_date' => 'jdatetime_after_equal' 'start_date' => 'jdatetime_after_equal'
'start_date' => 'jdatetime_after_equal:1388/01/01' 'start_date' => 'jdatetime_after_equal:1388/01/01'
'start_date' => 'jdatetime_after_equal:1388/01/01,Y/m/d' 'start_date' => 'jdatetime_after_equal:1388/01/01,Y/m/d'
</pre> </pre>
<p>اگر تاریخ شمسی با فرمت تعیین شده درست باشد و قبل از تاریخ تعیین شده باشد</p> <p>اگر تاریخ شمسی با فرمت تعیین شده درست باشد و قبل از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد</p> <p>درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد</p>
<p>فرمت پیش فرض Y/m/d می باشد </p> <p>فرمت پیش فرض Y/m/d می باشد </p>
<pre> <pre>
'start_date' => 'jdate_before' 'start_date' => 'jdate_before'
'start_date' => 'jdate_before:1388/01/01' 'start_date' => 'jdate_before:1388/01/01'
'start_date' => 'jdate_before:1388/01/01,Y/m/d' 'start_date' => 'jdate_before:1388/01/01,Y/m/d'
</pre> </pre>
<p>اگر تاریخ شمسی با فرمت تعیین شده درست باشد و قبل یا مساوی از تاریخ تعیین شده باشد</p> <p>اگر تاریخ شمسی با فرمت تعیین شده درست باشد و قبل یا مساوی از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد</p> <p>درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد</p>
<p>فرمت پیش فرض Y/m/d می باشد </p> <p>فرمت پیش فرض Y/m/d می باشد </p>
<pre> <pre>
'start_date' => 'jdate_before_equal' 'start_date' => 'jdate_before_equal'
'start_date' => 'jdate_before_equal:1388/01/01' 'start_date' => 'jdate_before_equal:1388/01/01'
'start_date' => 'jdate_before_equal:1388/01/01,Y/m/d' 'start_date' => 'jdate_before_equal:1388/01/01,Y/m/d'
</pre> </pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و قبل از تاریخ تعیین شده باشد</p> <p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و قبل از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد</p> <p>درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد </p> <p>فرمت پیش فرض Y/m/d H:i:s می باشد </p>
<pre> <pre>
'start_date' => 'jdatetime_before' 'start_date' => 'jdatetime_before'
'start_date' => 'jdatetime_before:1388/01/01' 'start_date' => 'jdatetime_before:1388/01/01'
'start_date' => 'jdatetime_before:1388/01/01,Y/m/d' 'start_date' => 'jdatetime_before:1388/01/01,Y/m/d'
</pre> </pre>
<p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و قبل یا مساوی از تاریخ تعیین شده باشد</p> <p>اگر تاریخ و زمان شمسی با فرمت تعیین شده درست باشد و قبل یا مساوی از تاریخ تعیین شده باشد</p>
<p>درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد</p> <p>درصورتی که تاریخ وارد کنید قبل از تاریخ فعلی باشد باشد</p>
<p>فرمت پیش فرض Y/m/d H:i:s می باشد </p> <p>فرمت پیش فرض Y/m/d H:i:s می باشد </p>
<pre> <pre>
'start_date' => 'jdatetime_before_equal' 'start_date' => 'jdatetime_before_equal'
'start_date' => 'jdatetime_before_equal:1388/01/01' 'start_date' => 'jdatetime_before_equal:1388/01/01'
'start_date' => 'jdatetime_before_equal:1388/01/01,Y/m/d' 'start_date' => 'jdatetime_before_equal:1388/01/01,Y/m/d'
</pre> </pre>
<p>میتوانید با ترکیب قوانین تاریخ را بین دو محدوده بررسی کنید</p> <p>میتوانید با ترکیب قوانین تاریخ را بین دو محدوده بررسی کنید</p>
<pre> <pre>
$validate = Validator::make([ $validate = Validator::make([
'start_date' => '1389/01/31', 'start_date' => '1389/01/31',
'expire_datetime' => '1397/02/16 12:10:00', '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', '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', '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()) { if ($validate->fails()) {
dd($validate->messages()->toArray()); dd($validate->messages()->toArray());
} }
//output //output
array:2 [ array:2 [
"start_date" => array:1 [ "start_date" => array:1 [
0 => "تاریخ شروع تاریخ شمسی باید قبل از ۱۳۹۰/۰۱/۰۱ باشد." 0 => "تاریخ شروع تاریخ شمسی باید قبل از ۱۳۹۰/۰۱/۰۱ باشد."
] ]
"expire_datetime" => array:1 [ "expire_datetime" => array:1 [
0 => "تاریخ انقضا تاریخ و زمان شمسی باید قبل از ۱۳۹۷/۰۲/۱۶ ۱۲:۱۰:۰۰ باشد." 0 => "تاریخ انقضا تاریخ و زمان شمسی باید قبل از ۱۳۹۷/۰۲/۱۶ ۱۲:۱۰:۰۰ باشد."
] ]
] ]
</pre> </pre>
</article> </article>
</div> </div>
</div> </div>
</div> </div>
<footer id="footer"> <footer id="footer">
<div style="text-align: center;"> <div style="text-align: center;">
2020 &copy; 2020 &copy;
</div> </div>
</footer> </footer>
</body> </body>
+77
View File
@@ -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.',
]
];
+77
View File
@@ -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.',
]
];
+77
View File
@@ -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' . ' باشد.',
]
];
+76
View File
@@ -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 <?php
namespace Hekmatinasser\Verta\Validation; namespace Hekmatinasser\Verta\Laravel;
use Hekmatinasser\Verta\Verta; use Hekmatinasser\Verta\Verta;
use Illuminate\Support\Arr;
use phpDocumentor\Reflection\Types\Static_;
class JalaliValidator class JalaliValidator
{ {
@@ -205,22 +207,27 @@ class JalaliValidator
public function replaceDateOrDatetime($message, $attribute, $rule, $parameters) 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) public function replaceDateAfterOrBeforeOrEqual($message, $attribute, $rule, $parameters)
{ {
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d'; $format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
$date = count($parameters) ? $parameters[0] : Verta::instance()->format($format); $date = count($parameters) ? $parameters[0] : Verta::instance()->format($format);
$faDate = Verta::enToFaNumbers($date); if(Verta::getLocale() != 'en') {
return str_replace([':date', ':fa-date'], [$date, $faDate], $message); $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) public function replaceDateTimeAfterOrBeforeOrEqual($message, $attribute, $rule, $parameters)
{ {
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s'; $format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
$date = count($parameters) ? $parameters[0] : Verta::instance()->format($format); $date = count($parameters) ? $parameters[0] : Verta::instance()->format($format);
$faDate = Verta::enToFaNumbers($date); $date = str_replace(array_values($en['numbers']), array_values(Verta::$messages['numbers']), $date);
return str_replace([':date', ':fa-date'], [$date, $faDate], $message); return str_replace(':date', $date, $message);
} }
} }
+118
View File
@@ -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']);
}
}
}
}
+1 -2
View File
@@ -6,7 +6,6 @@ namespace Hekmatinasser\Verta\Traits;
use DateTimeZone; use DateTimeZone;
use Hekmatinasser\Verta\Verta; use Hekmatinasser\Verta\Verta;
use Hekmatinasser\Verta\VertaInterface;
use InvalidArgumentException; use InvalidArgumentException;
trait Accessor trait Accessor
@@ -43,7 +42,7 @@ trait Accessor
return (int) $this->format($formats[$name]); return (int) $this->format($formats[$name]);
case $name === 'quarter': case $name === 'quarter':
return (int) ceil($this->month / VertaInterface::MONTHS_PER_QUARTER); return (int) ceil($this->month / static::MONTHS_PER_QUARTER);
case $name === 'timezone': case $name === 'timezone':
return $this->getTimezone()->getName(); return $this->getTimezone()->getName();
+1 -1
View File
@@ -334,7 +334,7 @@ trait Comparison
*/ */
public function isWeekend() public function isWeekend()
{ {
return in_array($this->dayOfWeek, static::$weekendDays); return in_array($this->dayOfWeek, static::$weekEndsAt);
} }
/** /**
+7 -9
View File
@@ -36,6 +36,7 @@ trait Creator
try { try {
parent::__construct($datetime, static::createTimeZone($timezone)); parent::__construct($datetime, static::createTimeZone($timezone));
parent::setTimezone(static::createTimeZone($timezone)); parent::setTimezone(static::createTimeZone($timezone));
self::loadMessages();
} catch (Exception $exception) { } catch (Exception $exception) {
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime)); throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
} }
@@ -138,16 +139,13 @@ trait Creator
* *
* @return static * @return static
*/ */
public static function parse($datetime , $timezone = null) { public static function parse($datetime , $timezone = null)
$names = array_map(function ($value) { {
return " $value "; $names = array_map(function ($value) { return " $value "; }, array_values(self::$messages['year_months']));
}, self::$monthYear); $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($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); $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'])) { 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)); throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
@@ -169,7 +167,7 @@ trait Creator
* @return static * @return static
*/ */
public static function parseFormat($format, $datetime, $timezone = null) { 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); $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'])) { if($parse['error_count'] > 0 || !self::isValidDate($parse['year'], $parse['month'], $parse['day']) || !self::isValidTime($parse['hour'], $parse['minute'], $parse['second'])) {
+2 -91
View File
@@ -14,6 +14,7 @@ trait Date
use Formatting; use Formatting;
use Modification; use Modification;
use Transformation; use Transformation;
use Translator;
use Boundaries; use Boundaries;
use Difference; use Difference;
@@ -43,10 +44,7 @@ trait Date
* *
* @var array * @var array
*/ */
protected static $weekendDays = [ protected static $weekendDays = [VertaInterface::THURSDAY, VertaInterface::FRIDAY];
VertaInterface::THURSDAY,
VertaInterface::FRIDAY,
];
/** /**
* number day in months gregorian * 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]; 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'];
} }
+139 -287
View File
@@ -44,116 +44,114 @@ trait Formatting
* @param string $format for example 'Y-m-d H:i:s' * @param string $format for example 'Y-m-d H:i:s'
* @return string * @return string
*/ */
protected function date($format){ protected function date($format)
{
$timestamp = $this->getTimestamp(); $timestamp = $this->getTimestamp();
list( $gYear, $gMonth, $gDay, $gWeek ) = explode( '-', parent::format('Y-m-d-w')); list( $gYear, $gMonth, $gDay, $gWeek ) = explode( '-', parent::format('Y-m-d-w'));
list( $pYear, $pMonth, $pDay ) = static::getJalali( $gYear, $gMonth, $gDay ); list( $pYear, $pMonth, $pDay ) = static::getJalali( $gYear, $gMonth, $gDay );
$pWeek = ( $gWeek + 1 );
$pWeek = $gWeek + 1;
if ($pWeek >= 7) { if ($pWeek >= 7) {
$pWeek = 0; $pWeek = 0;
} }
if ($format == '\\') { $lengh = strlen($format);
$format = '//'; $index = 0;
}
$lenghFormat = strlen( $format );
$i = 0;
$result = ''; $result = '';
while ($i < $lenghFormat) { while ($index < $lengh) {
$par = $format[$i]; $char = $format[$index];
if ($par == '\\') { if ($char == '\\') {
$result .= $format[++$i]; $result .= $format[++$index];
$i++; $index++;
continue; continue;
} }
switch ($par) { $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 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 # Day
case 'd': case 'd':
$result .= sprintf( '%02s', $pDay ); return sprintf( '%02s', $pDay );
break;
case 'D': case 'D':
$result .= substr( static::$dayWeek[ $pWeek ], 0, 2 ); return substr( self::$messages['weekdays'][$pWeek+1], 0, 2 );
break;
case 'j': case 'j':
$result .= $pDay; return $pDay;
break;
case 'l': case 'l':
$result .= static::$dayWeek[ $pWeek ]; return self::$messages['weekdays'][$pWeek+1];
break;
case 'N': case 'N':
$result .= $pWeek + 1; return $pWeek+1;
break;
case 'w': case 'w':
$result .= $pWeek; return $pWeek;
break;
case 'z': case 'z':
$result .= $this->daysYear( $pMonth, $pDay ); return $this->daysYear( $pMonth, $pDay );
break;
case 'S': case 'S':
$result .= self::NUMBER_TH; return static::$messages['phrase']['th'];
break;
# Week # Week
case 'W': case 'W':
$result .= ceil( $this->daysYear( $pMonth, $pDay ) / 7 ); return ceil( $this->daysYear( $pMonth, $pDay ) / 7 );
break;
# Month # Month
case 'F': case 'F':
$result .= static::$monthYear[ $pMonth - 1 ]; return self::$messages['year_months'][$pMonth];
break;
case 'm': case 'm':
$result .= sprintf( '%02s', $pMonth ); return sprintf( '%02s', $pMonth );
break;
case 'M': case 'M':
$result .= substr( static::$monthYear[ $pMonth - 1 ], 0, 6 ); return substr(self::$messages['year_months'][$pMonth], 0, 6 );
break;
case 'n': case 'n':
$result .= $pMonth; return $pMonth;
break;
case 't': case 't':
$result .= static::isLeapYear( $pYear ) && ( $pMonth == 12 ) ? 30 : static::$daysMonthJalali[ intval( $pMonth ) - 1 ]; return static::isLeapYear( $pYear ) && ( $pMonth == 12 ) ? 30 : static::$daysMonthJalali[ intval( $pMonth ) - 1 ];
break;
# Years # Years
case 'L': case 'L':
$result .= intval( $this->isLeapYear( $pYear ) ); return intval( $this->isLeapYear( $pYear ) );
break;
case 'Y': case 'Y':
case 'o': case 'o':
$result .= $pYear; return $pYear;
break;
case 'y': case 'y':
$result .= substr( $pYear, 2 ); return substr( $pYear, 2 );
break;
# Time # Time
case 'a': case 'a':
return static::$messages['phrase'][parent::format('a')];
case 'A': case 'A':
if (parent::format( 'a' ) == 'am') { return static::$messages['pharse'][parent::format('a') == 'am' ? 'ante_meridiem' : 'post_meridiem'];
$result .= ( ( $par == 'a' ) ? self::AM : self::ANTE_MERIDIEM );
} else {
$result .= ( ( $par == 'a' ) ? self::PM : self::POST_MERIDIEM );
}
break;
case 'B': case 'B':
case 'g': case 'g':
@@ -170,29 +168,21 @@ trait Formatting
case 'P': case 'P':
case 'T': case 'T':
case 'Z': case 'Z':
$result .= parent::format( $par ); return parent::format( $char );
break;
# Full Date/Time # Full Date/Time
case 'c': case 'c':
$result .= ( $pYear . '-' . $pMonth . '-' . $pDay . ' ' . parent::format( 'H:i:s P' ) ); return ( $pYear . '-' . $pMonth . '-' . $pDay . ' ' . parent::format( 'H:i:s P' ) );
break;
case 'r': case 'r':
$result .= ( substr( static::$dayWeek[ $pWeek ], 0, 2 ) . '، ' . $pDay . ' ' . substr( static::$monthYear[ $pMonth ], 0, 6 ) . ' ' . $pYear . ' ' . parent::format( 'H:i:s P' ) ); return ( substr(self::$messages['weekdays'][$gWeek], 0, 2 ) . '، ' . $pDay . ' ' . substr(self::$messages['year_months'][$pMonth], 0, 6 ) . ' ' . $pYear . ' ' . parent::format( 'H:i:s P' ) );
break;
case 'U': case 'U':
$result .= $timestamp; return $timestamp;
break;
default: default:
$result .= $par; return $char;
} }
$i++;
}
return $result;
} }
/** /**
@@ -205,143 +195,31 @@ trait Formatting
$timestamp = $this->getTimestamp(); $timestamp = $this->getTimestamp();
list($gYear, $gMonth, $gDay, $gWeek) = explode('-', parent::format('Y-m-d-w')); list( $gYear, $gMonth, $gDay, $gWeek ) = explode( '-', parent::format('Y-m-d-w'));
list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay); list( $pYear, $pMonth, $pDay ) = static::getJalali( $gYear, $gMonth, $gDay );
$pWeek = ($gWeek + 1);
$pWeek = $gWeek + 1;
if ($pWeek >= 7) { if ($pWeek >= 7) {
$pWeek = 0; $pWeek = 0;
} }
if ($format == '\\') { $lengh = strlen($format);
$format = '//'; $index = 0;
}
$lenghFormat = strlen($format);
$i = 0;
$result = ''; $result = '';
$word = new Notowo(0, 'fa'); while ($index < $lengh) {
$char = $format[$index];
while ($i < $lenghFormat) { if ($char == '\\') {
$par = $format[$i]; $result .= $format[++$index];
if ($par == '\\') { $index++;
$result .= $format[++$i];
$i ++;
continue; continue;
} }
switch ($par) { $output = $this->characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek);
# Day $result .= (string) new Notowo($output, static::getLocale() == 'en' ? 'en' : 'fa' );
case 'd':
case 'j':
$result .= $word->getWord(strval($pDay));
break;
case 'D': $index++;
$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 ++;
}
return $result; return $result;
} }
@@ -369,93 +247,50 @@ trait Formatting
*/ */
protected function strftime($format) protected function strftime($format)
{ {
$str_format_code = array( $strftime_date = array(
"%a", "%a" => "D",
"%A", "%A" => "l",
"%d", "%d" => "d",
"%e", "%e" => "j",
"%j", "%j" => "z",
"%u", "%u" => "N",
"%w", "%w" => "w",
"%U", "%U" => "W",
"%V", "%V" => "W",
"%W", "%W" => "W",
"%b", "%b" => "M",
"%B", "%B" => "F",
"%h", "%h" => "M",
"%m", "%m" => "m",
"%C", "%C" => "y",
"%g", "%g" => "y",
"%G", "%G" => "y",
"%y", "%y" => "y",
"%Y", "%Y" => "Y",
"%H", "%H" => "H",
"%I", "%I" => "h",
"%l", "%l" => "g",
"%M", "%M" => "i",
"%p", "%p" => "A",
"%P", "%P" => "a",
"%r", "%r" => "h:i:s A",
"%R", "%R" => "H:i",
"%S", "%S" => "s",
"%T", "%T" => "H:i:s",
"%X", "%X" => "h:i:s",
"%z", "%z" => "H",
"%Z", "%Z" => "H",
"%c", "%c" => "D j M H:i:s",
"%D", "%D" => "d/m/y",
"%F", "%F" => "Y-m-d",
"%s", "%s" => "U",
"%x", "%x" => "d/m/y",
"%n", "%n" => "\n",
"%t", "%t" => "\t",
"%%", "%%" => "%",
); );
$date_format_code = array( return str_replace(array_keys($strftime_date), array_values($strftime_date), $format);
"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);
} }
/** /**
@@ -539,20 +374,31 @@ trait Formatting
*/ */
public function formatDifference(Verta $v = null) 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); $difference = $this->diffSeconds($v);
$absolute = $difference < 0 ? self::POST : self::PRE; $result .= static::$messages['phrase'][$difference < 0 ? 'later' : 'ago'];
$difference = abs($difference); $difference = abs($difference);
for ($j = 0; $difference >= static::$unitNumber[$j] and $j < count(static::$unitNumber) - 1; $j++) { for ($unit = 0; $difference >= $units[$unit] and $unit < count($units) - 1; $unit++) {
$difference /= static::$unitNumber[$j]; $difference /= $units[$unit];
} }
$difference = intval(round($difference)); $difference = intval(round($difference));
if($difference === 0) { 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) public function formatWord($format)
@@ -568,7 +414,9 @@ trait Formatting
*/ */
public static function enToFaNumbers($string) 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) 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) 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);
} }
} }
+101
View File
@@ -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;
}
}
-49
View File
@@ -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
View File
@@ -20,7 +20,7 @@ interface VertaInterface
/** /**
* Number unit in date * Number unit in date
*/ */
const YEARS_PER_CENTURY = 100; const DECADE_PER_CENTURY = 10;
const YEARS_PER_DECADE = 10; const YEARS_PER_DECADE = 10;
const MONTHS_PER_YEAR = 12; const MONTHS_PER_YEAR = 12;
const MONTHS_PER_QUARTER = 3; const MONTHS_PER_QUARTER = 3;
@@ -37,14 +37,7 @@ interface VertaInterface
const DEFAULT_STRING_FORMAT = 'Y-m-d H:i:s'; 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 DEFAULT_LOCALE = 'fa';
const PM = 'ب.ظ';
const ANTE_MERIDIEM = 'قبل از ظهر';
const POST_MERIDIEM = 'بعد از ظهر';
const NUMBER_TH = ' ام';
const PRE = 'قبل';
const NOW = 'الان';
const POST = 'بعد';
} }
-44
View File
@@ -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');
}
}
-17
View File
@@ -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.',
];
-18
View File
@@ -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.',
];
-18
View File
@@ -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' . ' باشد.',
];