add set and reset default format
This commit is contained in:
1 parent
d9ea2e2edf
commit
65e7c1fd5d
2 files changed
+43
-19
No files matched your search
@@ -82,6 +82,13 @@ return $dt->formatTime(); // 23:26:35
|
|||||||
return $dt->formatPersianDatetime(); // 1395/12/10 23:46:09
|
return $dt->formatPersianDatetime(); // 1395/12/10 23:46:09
|
||||||
return $dt->formatPersianDate(); // 1395/12/10
|
return $dt->formatPersianDate(); // 1395/12/10
|
||||||
|
|
||||||
|
// set default format
|
||||||
|
Verta::setStringformat('Y/n/j H:i:s');
|
||||||
|
return new Verta(); // 1395/12/12 00:11:35
|
||||||
|
|
||||||
|
// reset default format
|
||||||
|
Verta::resetStringFormat();
|
||||||
|
return new Verta(); // 1395-12-12 00:18:04
|
||||||
|
|
||||||
// get a diffrent time with now
|
// get a diffrent time with now
|
||||||
$dt = Verta::parse('1395-10-07 14:12:32');
|
$dt = Verta::parse('1395-10-07 14:12:32');
|
||||||
|
|||||||
+36
-19
@@ -55,7 +55,23 @@ class Verta extends DateTime {
|
|||||||
/**
|
/**
|
||||||
* Word use in format datetime.
|
* Word use in format datetime.
|
||||||
*/
|
*/
|
||||||
const DEFAULT_TO_STRING_FORMAT = 'Y-m-d H:i:s';
|
const DEFAULT_STRING_FORMAT = 'Y-m-d H:i:s';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format to use for __toString.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected static $stringFormat = self::DEFAULT_STRING_FORMAT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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.
|
||||||
@@ -239,24 +255,6 @@ class Verta extends DateTime {
|
|||||||
self::ENGLISH_NINE,
|
self::ENGLISH_NINE,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected static $formats = array(
|
|
||||||
'datetime' => 'Y-m-d H:i:s',
|
|
||||||
'date' => 'Y-m-d',
|
|
||||||
'time' => 'H:i:s',
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Format to use for __toString method when type juggling occurs.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected static $stringFormat = self::DEFAULT_TO_STRING_FORMAT;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***************************** CONSTRUCT ****************************/
|
/***************************** CONSTRUCT ****************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -356,6 +354,25 @@ class Verta extends DateTime {
|
|||||||
|
|
||||||
/***************************** STRING FORMATED ****************************/
|
/***************************** STRING FORMATED ****************************/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the format used to the default when type juggling a Carbon instance to a string
|
||||||
|
*/
|
||||||
|
public static function resetStringFormat()
|
||||||
|
{
|
||||||
|
static::setStringFormat(static::DEFAULT_STRING_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default format used when type juggling a Carbon instance to a string
|
||||||
|
*
|
||||||
|
* @param string $format
|
||||||
|
*/
|
||||||
|
public static function setStringFormat($format)
|
||||||
|
{
|
||||||
|
static::$stringFormat = $format;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format the instance as a string using the set format
|
* Format the instance as a string using the set format
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in new issue
Block a user