diff --git a/README.md b/README.md index 61e3e24..afb0d78 100644 --- a/README.md +++ b/README.md @@ -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'); diff --git a/src/Verta.php b/src/Verta.php index 26be5e6..5daca48 100755 --- a/src/Verta.php +++ b/src/Verta.php @@ -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 *