novaday-co / laravel-persian-datetime-helper
Persian DateTime Helper for Laravel
dev-master
2021-09-20 08:01 UTC
Requires
- php: >=7
- illuminate/support: ^6|^7|^8
- morilog/jalali: 3.*
Requires (Dev)
- phpunit/phpunit: ~8.0
This package is auto-updated.
Last update: 2024-10-29 06:12:51 UTC
README
Install
Composer
Installing with composer is recommended and it simply works :
composer require novaday-co/laravel-persian-datetime-helper
Download
You can download latest version from the Github: Download
Quick start
To use in your project, just import DateTimeHelper
class :
$instance = DateTimeHelper::parse('1400-04-13 15:16:10') : Jalalian $instance = DateTimeHelper::parse('1400/04/13 15:16:10') : Jalalian $instance = DateTimeHelper::parse('1400_04_13 15:16:10') : Jalalian DateTimeHelper::parse('1400-04-13 15:16:10')->format('Y-m-d') : string // 1400-04-13 DateTimeHelper::parse('1400/04/13 15:16:10')->format('Y/m/d') : string // 1400/04/13
// Accept H:i Format DateTimeHelper::parse('1400/04/13 15:16')->format('Y-m-d H:i:s') : string ('Y-m-d H:i:s') // 1400-04-13 15:16:00
// Clone $jalaliDateTime = DateTimeHelper::parse('1400-04-13 15:16:10'); $cloneJalaliDateTime = DateTimeHelper::copy($jalaliDateTime)->format('Y-m-d H:i:s'); // 1400-04-13 15:16:10 // $jalaliDateTime == $cloneJalaliDateTime // $jalaliDateTime !== $cloneJalaliDateTime
//ignore multiple space from input $instance = DateTimeHelper::parse('1400-04-13 15:16:10')->format('Y-m-d H:i:s') : string // 1400-04-13 15:16:10
DateTimeHelper::jalaliToGregorian('1400-04-13 15:16:10') : string ('Y-m-d H:i:s') // 2021-07-04 15:16:10 DateTimeHelper::jalaliToGregorian('1400-04-13') : string ('Y-m-d H:i:s') // 2021-07-04 00:00:00
DateTimeHelper::jalaliDiffInMonths('1400-02-23 10:27:52', '1400-04-23 15:16:10') : int // 2 DateTimeHelper::jalaliDiffInMonths('1400-02-23', '1400-04-23') : int // 2
DateTimeHelper::jalaliDiffInDays('1400-02-13 15:16:10', '1400-02-23 10:27:52') : int // 9 DateTimeHelper::jalaliDiffInDays('1400-02-13', '1400-02-23') : int // 10
DateTimeHelper::jalaliDiffInHours('1400-04-23 15:16:10', '1400-04-23 22:27:52') : int // 7 DateTimeHelper::jalaliDiffInHours('15:16:10', '22:27:52') : int // 7
DateTimeHelper::jalaliDiffInMinutes('1400-04-23 15:16:10', '1400-04-23 22:27:52') : int // 431 DateTimeHelper::jalaliDiffInMinutes('15:16:10', '22:27:52') : int // 431
DateTimeHelper::clearTime('1400-04-23 15:16:10') : string ('Y-m-d H:i:s') // 1400-04-23 00:00:00
DateTimeHelper::getMinutes('1400-04-23 15:16:10') : int // 916 = 15*60 + 16
DateTimeHelper::firstDayOfMonth('1400-04-23 15:16:10') : string ('Y-m-d H:i:s') // 1400-04-01 00:00:00 DateTimeHelper::firstDayOfMonth('1400-04-23') : string ('Y-m-d H:i:s') // 1400-04-01 00:00:00
DateTimeHelper::lastDayOfMonth('1400-04-23 15:16:10') : string ('Y-m-d H:i:s') // 1400-04-31 00:00:00 DateTimeHelper::lastDayOfMonth('1400-08-23') : string ('Y-m-d H:i:s') // 1400-08-30 00:00:00
DateTimeHelper::firstDayOfYear() : string ('Y-m-d H:i:s') // 1400-01-01 00:00:00
DateTimeHelper::lastDayOfYear() : string ('Y-m-d H:i:s') // 1400-12-29 23:59:59