add set and reset default format

This commit is contained in:
Nasser Hekmati committed 2017-03-02 00:19:58 +03:30
1 parent d9ea2e2edf
commit 65e7c1fd5d
2 files changed
+43 -19

No files matched your search

+7
View File
@@ -82,6 +82,13 @@ return $dt->formatTime(); // 23:26:35
return $dt->formatPersianDatetime(); // 1395/12/10 23:46:09
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
$dt = Verta::parse('1395-10-07 14:12:32');
+36 -19
View File
@@ -55,7 +55,23 @@ class Verta extends 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.
@@ -239,24 +255,6 @@ class Verta extends DateTime {
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 ****************************/
/**
@@ -356,6 +354,25 @@ class Verta extends DateTime {
/***************************** 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
*