change diffrent format and predefine format

This commit is contained in:
nasser committed 2017-09-19 11:03:03 +04:30
1 parent 2acc6826ab
commit 52f1bd994b
2 files changed
+17 -35

No files matched your search

+16 -21
View File
@@ -8,7 +8,7 @@ Document [English](https://hekmatinasser.github.io/verta/)
- Verta is a jalali calendar that was used in persian datetime - 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. - Calendar conversion is based on the algorithm provided by Vahid Sohrablou, Roozbeh Pournader and Mohammad Tou'si.
Run the Composer update comand Run the Composer update comand
@@ -165,6 +165,16 @@ echo isset($v->timezone); // true
``` ```
--- ---
#### Formating #### Formating
set default format
```php
// set default format
Verta::setStringformat('Y/n/j H:i:s');
return verta(); // 1395/12/12 00:11:35
// reset default format
Verta::resetStringFormat();
return verta(); // 1395-12-12 00:18:04
```
format with php standard format with php standard
```php ```php
$v = verta(); $v = verta();
@@ -174,12 +184,6 @@ return $v; //1395-10-07 14:12:32
``` ```
use predefined format use predefined format
```php ```php
return $v->format('datetime'); // 1395-12-10 23:25:12
return $v->format('date'); // 1395-12-10
return $v->format('time'); // 23:26:35
```
use predefined format method
```php
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
return $v->formatTime(); // 23:26:35 return $v->formatTime(); // 23:26:35
@@ -191,22 +195,13 @@ get Gregorian format
return $v->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 $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
``` ```
set default format
```php
// set default format
Verta::setStringformat('Y/n/j H:i:s');
return verta(); // 1395/12/12 00:11:35
// reset default format
Verta::resetStringFormat();
return verta(); // 1395-12-12 00:18:04
```
difference format difference format
```php ```php
return $v1->diffFormat($v2); // 12 ماه بعد return $v1->formatDifference($v2); // 12 ماه بعد
return $v1->diffFormat($v3); // 1 سال قبل return $v1->formatDifference($v3); // 1 سال قبل
return $v1->addDays(25)->diffFormat(); // 4 هفته بعد compare with now return $v1->addDays(25)->formatDifference(); // 4 هفته بعد compare with now
return $v1->subDays(6)->diffFormat(); // 6 روز قبل return $v1->subDays(6)->formatDifference(); // 6 روز قبل
return verta()->formatDifference(); // الان
``` ```
change number change number
```php ```php
+1 -14
View File
@@ -82,15 +82,6 @@ class Verta extends DateTime {
self::FRIDAY, self::FRIDAY,
); );
/**
* @var array
*/
protected static $formats = array(
'datetime' => 'Y-m-d H:i:s',
'date' => 'Y-m-d',
'time' => 'H:i:s',
);
/** /**
* Default format to use for __toString method when type juggling occurs. * Default format to use for __toString method when type juggling occurs.
*/ */
@@ -1153,10 +1144,6 @@ class Verta extends DateTime {
* @return string * @return string
*/ */
public function format($format) { public function format($format) {
if (in_array($format, array_keys(self::$formats))) {
$format = self::$formats[$format];
}
return $this->strftime($format); return $this->strftime($format);
} }
@@ -1228,7 +1215,7 @@ class Verta extends DateTime {
* *
* @return string * @return string
*/ */
public function diffFormat(Verta $v = null) public function formatDifference(Verta $v = null)
{ {
$difference = $this->diffSeconds($v); $difference = $this->diffSeconds($v);
$absolute = $difference < 0 ? self::POST : self::PRE; $absolute = $difference < 0 ? self::POST : self::PRE;