Skip to content

Commit 4da36e0

Browse files
committed
[MYL-380] fix changing the date depending on the locale
1 parent f8c481e commit 4da36e0

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--- Observer/UpdateProductDateAttributes.php 2019-02-14 14:46:57.128821255 +0300
2+
+++ Observer/UpdateProductDateAttributes.php 2019-02-14 14:46:43.893157971 +0300
3+
@@ -98,10 +98,20 @@
4+
{
5+
$product = $observer->getEvent()->getProduct();
6+
$version = $this->versionManager->getCurrentVersion();
7+
-
8+
+ /*
9+
+ * Removed date conversion and formatting
10+
+ * $localStartTime = $this->localeDate->date($version->getStartTime());
11+
+ * $this->setDateTime($product, self::$startDateKeys, $localStartTime->format(DateTime::DATETIME_PHP_FORMAT)));
12+
+ * because we need get a date from DB in the correct DB format (timestamp), and put it into other DB record.
13+
+ * When we convert timestam string in to DataTime object over "$this->localeDate->date", we can break a date,
14+
+ * because it converter use locale and if system locale format disagree with timestamp format, conversion can
15+
+ * break the date (return object with wrong date). If we be pass locale of string into the
16+
+ * "$this->localeDate->date", as a result, we get exactly the same date. So we don`t need a convert date,
17+
+ * we can use timestamp date as it is.
18+
+ * Conversion in this case is an extra code that can lead to errors and waste time.
19+
+ */
20+
if ($version->getStartTime()) {
21+
- $localStartTime = $this->localeDate->date($version->getStartTime());
22+
- $this->setDateTime($product, self::$startDateKeys, $localStartTime->format(DateTime::DATETIME_PHP_FORMAT));
23+
+ $this->setDateTime($product, self::$startDateKeys, $version->getStartTime());
24+
} else {
25+
$date = $product->getData('is_new')
26+
? $this->localeDate->date()->format(DateTime::DATETIME_PHP_FORMAT)
27+
@@ -110,8 +120,7 @@
28+
}
29+
30+
if ($version->getEndTime()) {
31+
- $localEndTime = $this->localeDate->date($version->getEndTime());
32+
- $this->setDateTime($product, self::$endDateKeys, $localEndTime->format(DateTime::DATETIME_PHP_FORMAT));
33+
+ $this->setDateTime($product, self::$endDateKeys, $version->getEndTime());
34+
} else {
35+
$this->setDateTime($product, self::$endDateKeys, null);
36+
}

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ magento/module-catalog-inventory|Patch-Magento\_CatalogInventory-M2.1.x-stock-it
6363
magento/module-catalog-inventory|Patch-Magento_CatalogInventory-M2.2.0-2.2.3-fix-update-stock-item-on-product-save.patch|Fix: Update stock item on product save|>=2.2.0 <2.2.4
6464
magento/module-catalog-inventory|Patch-Magento_CatalogInventory-M2.2.0-2.2.4-stock-index.patch|#12205|>=2.2.0 <2.2.5
6565
magento/module-catalog-rule|Patch-Magento-Catalog-Rule-M2.1.X-cron-job.patch|Q-67970|>= 2.1.0 >= 2.2.0
66+
magento/module-catalog-staging|Patch-Magento_Catalog_Staging-timestam.patch| | ?
6667
magento/module-catalog-url-rewrite|Patch-Magento\_CatalogUrlRewrite-M2.1.4-regeneration-without-changes-fix.patch (install 2 patches *-regeneration-without-changes-fix)|#7874|>=2.1.4 < 2.1.9
6768
magento/module-catalog-widget|Patch-Magento\_CatalogWidget-M2.1.0-widgets-restore-conditions.patch|#2913|< 2.1.8 (2.1.4 n/a)
6869
magento/module-swatches|Patch-Magento\_Swatches-rest-api-visual-swatches-fix.patch| |>= 2.1.4
@@ -82,7 +83,7 @@ magento/module-configurable-product|Patch-Magento_ConfigurableProduct-M2.2.x-fix
8283
magento/module-configurable-product|Patch-Magento_ConfigurableProduct-M2.2.x-fix-min-max-prices_M2.2.6.patch|#15654|>=2.2.6
8384
magento/module-configurable-product|Patch-Magento_Configurable_M2.1.x-fix-get-price.patch|#5519|<2.1.10
8485
magento/module-cache-invalidate|Patch-Magento_CacheInvalidate-M2.1.x-purge-cache.patch|#7614|<2.2
85-
magento/module-config|Patch-Magento_Config-Fix-of-Saving-clone-field-M2.2.6.patch|#19070| 2.2.5 2.2.6
86+
magento/module-config|Patch-Magento_Config-Fix-of-Saving-clone-field-M2.2.6.patch|#19070| 2.2.5 2.2.6
8687

8788
**3th party modules:**
8889

@@ -175,6 +176,9 @@ Full composer.json example:
175176
"magento/module-catalog-rule": {
176177
"Fix: https://magento.stackexchange.com/questions/67970/catalog-price-rules-disappear-after-mid-night": "https://raw.githubusercontent.com/ConvertGroupsAS/magento2-patches/master/Patch-Magento-Catalog-Rule-M2.1.X-cron-job.patch"
177178
},
179+
"magnote/catalog-staging": {
180+
"Fix: changing the date depending on the locale": "https://raw.githubusercontent.com/ConvertGroupsAS/magento2-patches/master/Patch-Magento_Catalog_Staging-timestam.patch"
181+
},
178182
"magento/module-catalog-widget": {
179183
"Fix: https://github.com/magento/magento2/issues/2913": "https://raw.githubusercontent.com/ConvertGroupsAS/magento2-patches/master/Patch-Magento_CatalogWidget-M2.1.0-widgets-restore-conditions.patch"
180184
},

0 commit comments

Comments
 (0)