|
|
@@ -35,6 +35,15 @@ trait DateFormatTrait
|
|
|
public static $defaultLocale;
|
|
|
|
|
|
/**
|
|
|
+ * Whether lenient parsing is enabled for IntlDateFormatter.
|
|
|
+ *
|
|
|
+ * Defaults to true which is the default for IntlDateFormatter.
|
|
|
+ *
|
|
|
+ * @var bool
|
|
|
+ */
|
|
|
+ protected static $lenientParsing = true;
|
|
|
+
|
|
|
+ /**
|
|
|
* In-memory cache of date formatters
|
|
|
*
|
|
|
* @var \IntlDateFormatter[]
|
|
|
@@ -77,6 +86,8 @@ trait DateFormatTrait
|
|
|
/**
|
|
|
* Sets the default locale.
|
|
|
*
|
|
|
+ * Set to null to use IntlDateFormatter default.
|
|
|
+ *
|
|
|
* @param string|null $locale The default locale string to be used or null.
|
|
|
* @return void
|
|
|
*/
|
|
|
@@ -86,6 +97,36 @@ trait DateFormatTrait
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Gets whether locale format parsing is set to lenient.
|
|
|
+ *
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public static function lenientParsingEnabled(): bool
|
|
|
+ {
|
|
|
+ return static::$lenientParsing;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Enables lenient parsing for locale formats.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public static function enableLenientParsing(): void
|
|
|
+ {
|
|
|
+ static::$lenientParsing = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Enables lenient parsing for locale formats.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public static function disableLenientParsing(): void
|
|
|
+ {
|
|
|
+ static::$lenientParsing = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Returns a nicely formatted date string for this object.
|
|
|
*
|
|
|
* The format to be used is stored in the static property `Time::niceFormat`.
|
|
|
@@ -346,6 +387,8 @@ trait DateFormatTrait
|
|
|
null,
|
|
|
$pattern
|
|
|
);
|
|
|
+ $formatter->setLenient(static::$lenientParsing);
|
|
|
+
|
|
|
$time = $formatter->parse($time);
|
|
|
if ($time !== false) {
|
|
|
$result = new static('@' . $time);
|