update readme file

This commit is contained in:
Nasser Hekmati committed 2017-06-02 14:19:51 +04:30
1 parent b9636265f4
commit d39bfc1a03
2 files changed
+78 -78

No files matched your search

+64 -65
View File
@@ -10,7 +10,7 @@ Run the Composer update comand
$ composer require hekmatinasser/verta $ composer require hekmatinasser/verta
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. In your `config/app.php` add `Hekmatinasser\Verta\VertaServiceProvider::class,` to the `providers` array and add `'Verta' => Hekmatinasser\Verta\Verta::class,` to the `alias` array.
```php ```php
'providers' => [ 'providers' => [
@@ -33,26 +33,27 @@ In your `config/app.php` add `Hekmatinasser\Verta\VertaServiceProvider::class,`
### Verta ### Verta
You can use verta in project You can use verta in project
```php ```php
use \Verta as Verta ;` use Verta;
``` ```
#### Constructors #### Constructors
```php ```php
// default timestamp is now // default timestamp is now
$dt = new Verta(); $v = new Verta();
// OR // OR
$dt = Verta::now(); //1396-02-02 15:32:08 $v = verta(); //1396-02-02 15:32:08
$dt = Verta::today(); //1396-03-02 00:00:00 $v = Verta::now(); //1396-02-02 15:32:08
$dt = Verta::tomorrow(); // 1396-03-03 00:00:00 $v = Verta::today(); //1396-03-02 00:00:00
$dt = Verta::yesterday(); // 1396-03-01 00:00:00 $v = Verta::tomorrow(); // 1396-03-03 00:00:00
$v = Verta::yesterday(); // 1396-03-01 00:00:00
// pass string datetime // pass string datetime
$dt = new Verta('2016-12-27 14:12:32'); $v = new Verta('2016-12-27 14:12:32');
// OR // OR
$dt = Verta::instance('2016-12-25 11:12:36'); $v = Verta::instance('2016-12-25 11:12:36');
// pass timestamps // pass timestamps
$dt = new Verta(1333857600); $v = new Verta(1333857600);
//pass datetime object //pass datetime object
$dt = new \Datetime(); $dt = new \Datetime();
@@ -60,10 +61,10 @@ return new Verta($dt); // 1395-12-09 15:05:56
// pass carbon object // pass carbon object
$c = \Carbon::now(); $c = \Carbon::now();
return new Verta($c); // 1395-12-09 15:05:56 return verta($c); // 1395-12-09 15:05:56
// pass strings persian date // pass strings persian date
$dt = Verta::parse('1395-10-07 14:12:32'); $v = Verta::parse('1395-10-07 14:12:32');
// create from a specific date and time // create from a specific date and time
return Verta::create(); // 1395-12-14 11:17:01 equal now() return Verta::create(); // 1395-12-14 11:17:01 equal now()
@@ -85,28 +86,26 @@ return Verta::createJalaliTime(15,51,5); // 1395-12-14 15:51:05 set date now
#### Formating #### Formating
```php ```php
// format the timestamp // format the timestamp
$dt = new Verta('2016-12-27 14:12:32'); $v = verta();
return $dt->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 $dt->format('%B %d، %Y'); // دی 07، 1395 return $v->format('%B %d، %Y'); // دی 07، 1395
return $dt; //1395-10-07 14:12:32 return $v; //1395-10-07 14:12:32
// use predefined format // use predefined format
$dt = new Verta(); return $v->format('datetime'); // 1395-12-10 23:25:12
return $dt->format('datetime'); // 1395-12-10 23:25:12 return $v->format('date'); // 1395-12-10
return $dt->format('date'); // 1395-12-10 return $v->format('time'); // 23:26:35
return $dt->format('time'); // 23:26:35
// use predefined format method // use predefined format method
$dt = new Verta(); return $v->formatDatetime(); // 1395-12-10 23:37:26
return $dt->formatDatetime(); // 1395-12-10 23:37:26 return $v->formatDate(); // 1395-12-10
return $dt->formatDate(); // 1395-12-10 return $v->formatTime(); // 23:26:35
return $dt->formatTime(); // 23:26:35 return $v->formatJalaliDatetime(); // 1395/12/10 23:46:09
return $dt->formatJalaliDatetime(); // 1395/12/10 23:46:09 return $v->formatJalaliDate(); // 1395/12/10
return $dt->formatJalaliDate(); // 1395/12/10
// get gregorain datetime // get gregorain datetime
return $dt->DateTime()->format('Y-m-d H:i:s'); // 2017-05-23 23:21:02 return $v->DateTime()->format('Y-m-d H:i:s'); // 2017-05-23 23:21:02
return $dt->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
// set default format // set default format
Verta::setStringformat('Y/n/j H:i:s'); Verta::setStringformat('Y/n/j H:i:s');
@@ -117,8 +116,8 @@ Verta::resetStringFormat();
return new Verta(); // 1395-12-12 00:18:04 return new Verta(); // 1395-12-12 00:18:04
// change english number to persian // change english number to persian
$dt = Verta::parse('1396-10-07 14:12:32'); $v = Verta::parse('1396-10-07 14:12:32');
return Verta::persianNumbers($dt); // ۱۳۹۶-۱۰-۰۷ ۱۴:۱۲:۳۲ return Verta::persianNumbers($v); // ۱۳۹۶-۱۰-۰۷ ۱۴:۱۲:۳۲
``` ```
For help in building your formats, checkout the [PHP strftime() docs](http://php.net/manual/en/function.strftime.php). For help in building your formats, checkout the [PHP strftime() docs](http://php.net/manual/en/function.strftime.php).
@@ -126,41 +125,41 @@ For help in building your formats, checkout the [PHP strftime() docs](http://php
#### Calculation #### Calculation
```php ```php
// add and sub unit datetime // add and sub unit datetime
$dt = Verta::parse('1395-10-07 14:12:32'); $v = verta();
return $dt->addYear(); // 1396-10-07 14:12:32 return $v->addYear(); // 1396-10-07 14:12:32
return $dt->addYears(4); // 1399-10-07 14:12:32 return $v->addYears(4); // 1399-10-07 14:12:32
return $dt->subYear(); // 1394-10-07 14:12:32 return $v->subYear(); // 1394-10-07 14:12:32
return $dt->subYears(2); // 1393-10-07 14:12:32 return $v->subYears(2); // 1393-10-07 14:12:32
return $dt->addMonth(); // 1395-11-07 14:12:32 return $v->addMonth(); // 1395-11-07 14:12:32
return $dt->addMonths(5); // 1396-03-07 14:12:32 return $v->addMonths(5); // 1396-03-07 14:12:32
return $dt->subMonth(); // 1395-09-07 14:12:32 return $v->subMonth(); // 1395-09-07 14:12:32
return $dt->subMonths(2); // 1395-08-07 14:12:32 return $v->subMonths(2); // 1395-08-07 14:12:32
return $dt->addWeek(); // 1395-10-12 14:12:32 return $v->addWeek(); // 1395-10-12 14:12:32
return $dt->addWeeks(3); // 1395-10-26 14:12:32 return $v->addWeeks(3); // 1395-10-26 14:12:32
return $dt->subWeek(); // 1395-09-30 14:12:32 return $v->subWeek(); // 1395-09-30 14:12:32
return $dt->subWeeks(2); // 1395-09-27 14:12:32 return $v->subWeeks(2); // 1395-09-27 14:12:32
return $dt->addDay(); // 1395-10-08 14:12:32 return $v->addDay(); // 1395-10-08 14:12:32
return $dt->addDays(3); // 1395-10-11 14:12:32 return $v->addDays(3); // 1395-10-11 14:12:32
return $dt->subDay(); // 1395-10-06 14:12:32 return $v->subDay(); // 1395-10-06 14:12:32
return $dt->subDays(2); // 1395-09-05 14:12:32 return $v->subDays(2); // 1395-09-05 14:12:32
return $dt->addHour(); // 1395-10-07 15:12:32 return $v->addHour(); // 1395-10-07 15:12:32
return $dt->addHours(5); // 1395-10-07 19:12:32 return $v->addHours(5); // 1395-10-07 19:12:32
return $dt->subHour(); // 1395-10-07 13:12:32 return $v->subHour(); // 1395-10-07 13:12:32
return $dt->subHours(2); // 1395-10-07 12:12:32 return $v->subHours(2); // 1395-10-07 12:12:32
return $dt->addMinute(); // 1395-10-07 14:13:32 return $v->addMinute(); // 1395-10-07 14:13:32
return $dt->addMinutes(3); // 1395-10-07 14:15:32 return $v->addMinutes(3); // 1395-10-07 14:15:32
return $dt->subMinute(); // 1395-10-07 14:11:32 return $v->subMinute(); // 1395-10-07 14:11:32
return $dt->subMinutes(2); // 1395-10-07 14:10:32 return $v->subMinutes(2); // 1395-10-07 14:10:32
return $dt->addSecond(); // 1395-10-07 14:12:33 return $v->addSecond(); // 1395-10-07 14:12:33
return $dt->addSeconds(3); // 1395-10-07 14:12:35 return $v->addSeconds(3); // 1395-10-07 14:12:35
return $dt->subSecond(); // 1395-10-07 14:12:31 return $v->subSecond(); // 1395-10-07 14:12:31
return $dt->subSeconds(2); // 1395-10-07 14:12:30 return $v->subSeconds(2); // 1395-10-07 14:12:30
``` ```
--- ---
@@ -179,11 +178,11 @@ echo Verta::isValideTime(15, 62, 50); // false
echo Verta::isValideTime(15, 12, 30); // true echo Verta::isValideTime(15, 12, 30); // true
// get a diffrent time with now // get a diffrent time with now
$dt = Verta::parse('1395-10-07 14:12:32'); $v = Verta::parse('1395-10-07 14:12:32');
return $dt->diffNow(); // 2 ماه پیش return $v->diffNow(); // 2 ماه پیش
$dt = Verta::parse('1395/12/12 14:13:50'); $v = Verta::parse('1395/12/12 14:13:50');
return $dt->diffNow(); // 5 ثانیه بعد return $v->diffNow(); // 5 ثانیه بعد
``` ```
--- ---
@@ -196,11 +195,11 @@ return Verta::getJalali(2015,12,25); // [1394,10,4]
return Verta::getGregorian(1394,10,4); // [2015,12,25] return Verta::getGregorian(1394,10,4); // [2015,12,25]
// export to datetime object // export to datetime object
$dt = Verta::parse('1395/01/05 23:50:25'); $v = Verta::parse('1395/01/05 23:50:25');
$dt = $v->DateTime(); $dt = $v->DateTime();
// export to carbon object // export to carbon object
$dt = Verta::parse('1395/01/05 23:50:25'); $v = Verta::parse('1395/01/05 23:50:25');
$c = Carbon::instance($v->DateTime()); $c = Carbon::instance($v->DateTime());
``` ```
+14 -13
View File
@@ -10,7 +10,7 @@ namespace Hekmatinasser\Verta;
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Closure;
use DateTime; use DateTime;
use DateTimeZone; use DateTimeZone;
use DatePeriod; use DatePeriod;
@@ -268,41 +268,42 @@ class Verta extends DateTime {
public static function now() { public static function now() {
return new static(); return new static();
} }
/** /**
* Create a Carbon instance for today. * Create a Verta instance for today.
* *
* @param \DateTimeZone|string|null $tz * @param \DateTimeZone|string|null $timezone
* *
* @return static * @return static
*/ */
public static function today($tz = null) public static function today($timezone = null)
{ {
return static::now($tz)->startOfDay(); return static::now($timezone)->startOfDay();
} }
/** /**
* Create a Carbon instance for tomorrow. * Create a Verta instance for tomorrow.
* *
* @param \DateTimeZone|string|null $tz * @param \DateTimeZone|string|null $timezone
* *
* @return static * @return static
*/ */
public static function tomorrow($tz = null) public static function tomorrow($timezone = null)
{ {
return static::today($tz)->addDay(); return static::today($timezone)->addDay();
} }
/** /**
* Create a Carbon instance for yesterday. * Create a Verta instance for yesterday.
* *
* @param \DateTimeZone|string|null $tz * @param \DateTimeZone|string|null $timezone
* *
* @return static * @return static
*/ */
public static function yesterday($tz = null) public static function yesterday($timezone = null)
{ {
return static::today($tz)->subDay(); return static::today($timezone)->subDay();
} }
/** /**