change diffNow method
This commit is contained in:
1 parent
65e7c1fd5d
commit
8f7bc03f34
2 files changed
+62
-59
No files matched your search
@@ -11,20 +11,18 @@ 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
|
||||
In your `config/app.php` add `Hekmatinasser\Verta\VertaServiceProvider::class,` to the end of the `providers` array and add `'Verta' => Hekmatinasser\Verta\Verta::class,` to the end of the `alias` array.
|
||||
|
||||
```php
|
||||
'providers' => [
|
||||
|
||||
Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
|
||||
Illuminate\Auth\AuthServiceProvider::class,
|
||||
...
|
||||
Hekmatinasser\Verta\VertaServiceProvider::class,
|
||||
|
||||
],
|
||||
|
||||
|
||||
'alias' => [
|
||||
|
||||
...
|
||||
'Verta' => Hekmatinasser\Verta\Verta::class,
|
||||
]
|
||||
@@ -34,23 +32,26 @@ In your `config/app.php` add `'Hekmatinasser\Verta\VertaServiceProvider::class'`
|
||||
## Basic Usage
|
||||
|
||||
### Verta
|
||||
You can use verta
|
||||
`use \Verta as Verta ;`
|
||||
#### `$dt = new Verta();`
|
||||
``` php
|
||||
You can use verta in project
|
||||
```php
|
||||
use \Verta as Verta ;`
|
||||
```
|
||||
|
||||
#### Constructors
|
||||
```php
|
||||
// default timestamp is now
|
||||
$dt = new Verta();
|
||||
//OR
|
||||
// OR
|
||||
$dt = Verta::now();
|
||||
//OR
|
||||
|
||||
// pass string datetime
|
||||
$dt = new Verta('2016-12-27 14:12:32');
|
||||
// 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
|
||||
@@ -61,7 +62,10 @@ return new Verta($c); // 1395-12-09 15:05:56
|
||||
|
||||
// pass strings persian date
|
||||
$dt = Verta::parse('1395-10-07 14:12:32');
|
||||
|
||||
```
|
||||
---
|
||||
#### Formating
|
||||
```php
|
||||
// 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
|
||||
@@ -90,54 +94,53 @@ return new Verta(); // 1395/12/12 00:11:35
|
||||
Verta::resetStringFormat();
|
||||
return new Verta(); // 1395-12-12 00:18:04
|
||||
|
||||
// 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)`
|
||||
```php
|
||||
return Verta::getJalali(2015,12,25); // [1394,10,4]
|
||||
```
|
||||
---
|
||||
#### `getGregorian($jYear, $jMonth, $jDay)`
|
||||
```php
|
||||
return Verta::getGregorian(1394,10,4);; // [2015,12,25]
|
||||
```
|
||||
|
||||
---
|
||||
#### `DateTime()`
|
||||
```php
|
||||
$dt = Verta::parse('1395/01/05 23:50:25');
|
||||
return Carbon::instance($dt->DateTime());
|
||||
|
||||
```
|
||||
---
|
||||
#### `isLeapYear($int)`
|
||||
```php
|
||||
echo Verta::isLeapYear(1394); // false
|
||||
echo Verta::isLeapYear(1395); // true
|
||||
```
|
||||
---
|
||||
#### `isValideDate($jYear, $jMonth, $jDay)`
|
||||
```php
|
||||
echo Verta::isValideDate(1394, 12, 30); // false
|
||||
echo Verta::isValideDate(1395, 12, 30); // true
|
||||
```
|
||||
---
|
||||
#### `persianNumbers($string)`
|
||||
```php
|
||||
// change english number to persian
|
||||
$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](http://php.net/manual/en/function.strftime.php).
|
||||
|
||||
---
|
||||
#### Differences
|
||||
```php
|
||||
// get a diffrent time with now
|
||||
$dt = Verta::parse('1395-10-07 14:12:32');
|
||||
return $dt->diffNow(); // 2 ماه پیش
|
||||
|
||||
$dt = Verta::parse('1395/12/12 14:13:50');
|
||||
return $dt->diffNow(); // 5 ثانیه بعد
|
||||
```
|
||||
|
||||
---
|
||||
#### Transformations
|
||||
```php
|
||||
// get jalali a gregorian date
|
||||
return Verta::getJalali(2015,12,25); // [1394,10,4]
|
||||
|
||||
// get gregorian a jalali date
|
||||
return Verta::getGregorian(1394,10,4); // [2015,12,25]
|
||||
|
||||
// export to datetime object
|
||||
$dt = Verta::parse('1395/01/05 23:50:25');
|
||||
$dt = $v->DateTime();
|
||||
|
||||
// export to carbon object
|
||||
$dt = Verta::parse('1395/01/05 23:50:25');
|
||||
$c = Carbon::instance($v->DateTime());
|
||||
```
|
||||
|
||||
---
|
||||
#### Comparisons
|
||||
```php
|
||||
// is leap year
|
||||
echo Verta::isLeapYear(1394); // false
|
||||
echo Verta::isLeapYear(1395); // true
|
||||
|
||||
// is valid date
|
||||
echo Verta::isValideDate(1394, 12, 30); // false
|
||||
echo Verta::isValideDate(1395, 12, 30); // true
|
||||
```
|
||||
|
||||
---
|
||||
## License ##
|
||||
- This package was created and modified by [Nasser Hekmati](https://github.com/hekmatinasser) for Laravel >= 5 and is released under the MIT License.
|
||||
+1
-1
@@ -713,7 +713,7 @@ class Verta extends DateTime {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function diffrentNow()
|
||||
public function diffNow()
|
||||
{
|
||||
$now = time();
|
||||
|
||||
|
||||
Reference in new issue
Block a user