d9ea2e2edff94b761cdcd9164801a1b795bfd4e2
hekmatinasser/verta
-
This package compatible with Laravel
>=5&< 6.0 -
Verta is a jalali calendar that was used in persian datetime
-
Calendar conversion is based on the algorithm provided by Morteza Parvini, Vahid Sohrablou, Roozbeh Pournader and Mohammad Tou'si.
Run the Composer update comand
$ composer require hekmatinasser/verta
In your config/app.php add 'Hekmatinasser\Verta\VertaServiceProvider::class' to the end of the $providers array
'providers' => [
Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
Illuminate\Auth\AuthServiceProvider::class,
...
Hekmatinasser\Verta\VertaServiceProvider::class,
],
'alias' => [
...
'Verta' => Hekmatinasser\Verta\Verta::class,
]
Basic Usage
Verta
You can use verta
use \Verta as Verta ;
$dt = new Verta();
// default timestamp is now
$dt = new Verta();
//OR
$dt = Verta::now();
//OR
$dt = Verta::instance('2016-12-25 11:12:36');
// pass timestamps
$dt = new Verta(1333857600);
// pass string datetime
$dt = new Verta('2016-12-27 14:12:32');
//pass datetime object
$dt = new \Datetime();
return new Verta($dt); // 1395-12-09 15:05:56
// pass carbon object
$c = \Carbon::now();
return new Verta($c); // 1395-12-09 15:05:56
// pass strings persian date
$dt = Verta::parse('1395-10-07 14:12:32');
// format the timestamp
$dt = new Verta('2016-12-27 14:12:32');
return $dt->format('Y-n-j H:i'); // 1395-10-7 14:12
return $dt->format('%B %d، %Y'); // دی 07، 1395
return $dt; //1395-10-07 14:12:32
// use predefined format
$dt = new Verta();
return $dt->format('datetime'); // 1395-12-10 23:25:12
return $dt->format('date'); // 1395-12-10
return $dt->format('time'); // 23:26:35
// use predefined format method
$dt = new Verta();
return $dt->formatDatetime(); // 1395-12-10 23:37:26
return $dt->formatDate(); // 1395-12-10
return $dt->formatTime(); // 23:26:35
return $dt->formatPersianDatetime(); // 1395/12/10 23:46:09
return $dt->formatPersianDate(); // 1395/12/10
// get a diffrent time with now
$dt = Verta::parse('1395-10-07 14:12:32');
return $dt->diffrentNow(); // 2 ماه پیش
$dt = Verta::parse('1396-10-07 14:12:32');
return $dt->diffrentNow(); // 10 ماه بعد
getJalali($gYear, $gMonth, $gDay)
return Verta::getJalali(2015,12,25); // [1394,10,4]
getGregorian($jYear, $jMonth, $jDay)
return Verta::getGregorian(1394,10,4);; // [2015,12,25]
DateTime()
$dt = Verta::parse('1395/01/05 23:50:25');
return Carbon::instance($dt->DateTime());
isLeapYear($int)
echo Verta::isLeapYear(1394); // false
echo Verta::isLeapYear(1395); // true
isValideDate($jYear, $jMonth, $jDay)
echo Verta::isValideDate(1394, 12, 30); // false
echo Verta::isValideDate(1395, 12, 30); // true
persianNumbers($string)
$dt = Verta::parse('1396-10-07 14:12:32');
return Verta::persianNumbers($dt); // ۱۳۹۶-۱۰-۰۷ ۱۴:۱۲:۳۲
Formatting
For help in building your formats, checkout the PHP strftime() docs.
License
- This package was created and modified by Nasser Hekmati for Laravel >= 5 and is released under the MIT License.
Description
تبدیل تاریخ میلادی به شمسی برای لاراول و کار با تاریخ جلالی و اعتبارسنجی تاریخ
398 KiB
0 Stars
1 Watchers
0 Forks
Languages
PHP
100%