diff --git a/vendor/magento/module-ui/Component/Filters.php b/vendor/magento/module-ui/Component/Filters.php index fe02c23af9c..054b3ab8175 100644 --- a/vendor/magento/module-ui/Component/Filters.php +++ b/vendor/magento/module-ui/Component/Filters.php @@ -5,6 +5,8 @@ */ namespace Magento\Ui\Component; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponent\ObserverInterface; use Magento\Framework\View\Element\UiComponentFactory; @@ -44,16 +46,42 @@ class Filters extends AbstractComponent implements ObserverInterface protected $uiComponentFactory; /** - * @inheritDoc + * @var TimezoneInterface + */ + private $localeDate; + + /** + * Filters constructor. + * + * @param ContextInterface $context + * @param UiComponentFactory $uiComponentFactory + * @param array $components + * @param array $data + * @param TimezoneInterface|null $localeDate */ public function __construct( ContextInterface $context, UiComponentFactory $uiComponentFactory, array $components = [], - array $data = [] + array $data = [], + ?TimezoneInterface $localeDate = null ) { parent::__construct($context, $components, $data); $this->uiComponentFactory = $uiComponentFactory; + $this->localeDate = $localeDate ?? ObjectManager::getInstance()->get(TimezoneInterface::class); + } + + /** + * @inheritDoc + */ + public function prepare() + { + $config = $this->getData('config'); + // Set date format pattern by current locale + $localeDateFormat = $this->localeDate->getDateFormat(); + $config['options']['dateFormat'] = $localeDateFormat; + $this->setData('config', $config); + parent::prepare(); } /** diff --git a/vendor/magento/module-ui/view/base/web/js/form/element/date.js b/vendor/magento/module-ui/view/base/web/js/form/element/date.js index ac28271e90a..681ad143a43 100644 --- a/vendor/magento/module-ui/view/base/web/js/form/element/date.js +++ b/vendor/magento/module-ui/view/base/web/js/form/element/date.js @@ -120,7 +120,7 @@ define([ if (this.options.showsTime) { shiftedValue = moment.tz(value, 'UTC').tz(this.storeTimeZone); } else { - shiftedValue = moment(value, this.outputDateFormat); + shiftedValue = moment(value, this.outputDateFormat, true); } if (!shiftedValue.isValid()) { diff --git a/vendor/magento/module-ui/view/base/web/js/grid/filters/filters.js b/vendor/magento/module-ui/view/base/web/js/grid/filters/filters.js index 78016ee489a..a44a35c6bec 100644 --- a/vendor/magento/module-ui/view/base/web/js/grid/filters/filters.js +++ b/vendor/magento/module-ui/view/base/web/js/grid/filters/filters.js @@ -120,7 +120,10 @@ define([ * * @returns {Filters} Chainable. */ - initialize: function () { + initialize: function (config) { + if (typeof config.options !== 'undefined' && config.options.dateFormat) { + this.constructor.defaults.templates.filters.dateRange.dateFormat = config.options.dateFormat; + } _.bindAll(this, 'updateActive'); this._super() diff --git a/vendor/magento/module-ui/view/base/web/js/grid/filters/range.js b/vendor/magento/module-ui/view/base/web/js/grid/filters/range.js index ccfba8e98b6..169fbf18785 100644 --- a/vendor/magento/module-ui/view/base/web/js/grid/filters/range.js +++ b/vendor/magento/module-ui/view/base/web/js/grid/filters/range.js @@ -51,7 +51,10 @@ define([ * * @returns {Range} Chainable. */ - initialize: function () { + initialize: function (config) { + if (config.dateFormat) { + this.constructor.defaults.templates.date.pickerDefaultDateFormat = config.dateFormat; + } this._super() .initChildren(); diff --git a/vendor/magento/module-ui/view/base/web/js/lib/validation/rules.js b/vendor/magento/module-ui/view/base/web/js/lib/validation/rules.js index 08f67955976..6aaedf47511 100644 --- a/vendor/magento/module-ui/view/base/web/js/lib/validation/rules.js +++ b/vendor/magento/module-ui/view/base/web/js/lib/validation/rules.js @@ -1069,12 +1069,12 @@ define([ $.mage.__('This link is not allowed.') ], 'validate-dob': [ - function (value) { + function (value, param, params) { if (value === '') { return true; } - return moment(value).isBefore(moment()); + return moment.utc(value, params.dateFormat).isSameOrBefore(moment.utc()); }, $.mage.__('The Date of Birth should not be greater than today.') ]