Skip to content

Commit

Permalink
[MYL-380] fix changing the date depending on the locale
Browse files Browse the repository at this point in the history
  • Loading branch information
danilconvert committed Feb 14, 2019
1 parent f8c481e commit eb98a8d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
36 changes: 36 additions & 0 deletions Patch-Magento_Catalog_Staging-timestam.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--- Observer/UpdateProductDateAttributes.php 2019-02-14 14:46:57.128821255 +0300
+++ Observer/UpdateProductDateAttributes.php 2019-02-14 14:46:43.893157971 +0300
@@ -98,10 +98,20 @@
{
$product = $observer->getEvent()->getProduct();
$version = $this->versionManager->getCurrentVersion();
-
+ /*
+ * Removed date conversion and formatting
+ * $localStartTime = $this->localeDate->date($version->getStartTime());
+ * $this->setDateTime($product, self::$startDateKeys, $localStartTime->format(DateTime::DATETIME_PHP_FORMAT)));
+ * because we need get a date from DB in the correct DB format (timestamp), and put it into other DB record.
+ * When we convert timestam string in to DataTime object over "$this->localeDate->date", we can break a date,
+ * because it converter use locale and if system locale format disagree with timestamp format, conversion can
+ * break the date (return object with wrong date). If we be pass locale of string into the
+ * "$this->localeDate->date", as a result, we get exactly the same date. So we don`t need a convert date,
+ * we can use timestamp date as it is.
+ * Conversion in this case is an extra code that can lead to errors and waste time.
+ */
if ($version->getStartTime()) {
- $localStartTime = $this->localeDate->date($version->getStartTime());
- $this->setDateTime($product, self::$startDateKeys, $localStartTime->format(DateTime::DATETIME_PHP_FORMAT));
+ $this->setDateTime($product, self::$startDateKeys, $version->getStartTime());
} else {
$date = $product->getData('is_new')
? $this->localeDate->date()->format(DateTime::DATETIME_PHP_FORMAT)
@@ -110,8 +120,7 @@
}

if ($version->getEndTime()) {
- $localEndTime = $this->localeDate->date($version->getEndTime());
- $this->setDateTime($product, self::$endDateKeys, $localEndTime->format(DateTime::DATETIME_PHP_FORMAT));
+ $this->setDateTime($product, self::$endDateKeys, $version->getEndTime());
} else {
$this->setDateTime($product, self::$endDateKeys, null);
}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ magento/module-catalog-inventory|Patch-Magento\_CatalogInventory-M2.1.x-stock-it
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
magento/module-catalog-inventory|Patch-Magento_CatalogInventory-M2.2.0-2.2.4-stock-index.patch|#12205|>=2.2.0 <2.2.5
magento/module-catalog-rule|Patch-Magento-Catalog-Rule-M2.1.X-cron-job.patch|Q-67970|>= 2.1.0 >= 2.2.0
magento/module-catalog-staging|Patch-Magento_Catalog_Staging-timestam.patch| | ?
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
magento/module-catalog-widget|Patch-Magento\_CatalogWidget-M2.1.0-widgets-restore-conditions.patch|#2913|< 2.1.8 (2.1.4 n/a)
magento/module-swatches|Patch-Magento\_Swatches-rest-api-visual-swatches-fix.patch| |>= 2.1.4
Expand All @@ -82,7 +83,7 @@ magento/module-configurable-product|Patch-Magento_ConfigurableProduct-M2.2.x-fix
magento/module-configurable-product|Patch-Magento_ConfigurableProduct-M2.2.x-fix-min-max-prices_M2.2.6.patch|#15654|>=2.2.6
magento/module-configurable-product|Patch-Magento_Configurable_M2.1.x-fix-get-price.patch|#5519|<2.1.10
magento/module-cache-invalidate|Patch-Magento_CacheInvalidate-M2.1.x-purge-cache.patch|#7614|<2.2
magento/module-config|Patch-Magento_Config-Fix-of-Saving-clone-field-M2.2.6.patch|#19070| 2.2.5 2.2.6
magento/module-config|Patch-Magento_Config-Fix-of-Saving-clone-field-M2.2.6.patch|#19070| 2.2.5 2.2.6

**3th party modules:**

Expand Down Expand Up @@ -175,6 +176,9 @@ Full composer.json example:
"magento/module-catalog-rule": {
"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"
},
"magento/module-catalog-staging": {
"Fix: changing the date depending on the locale": "https://raw.githubusercontent.com/ConvertGroupsAS/magento2-patches/master/Patch-Magento_Catalog_Staging-timestam.patch"
},
"magento/module-catalog-widget": {
"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"
},
Expand Down

0 comments on commit eb98a8d

Please sign in to comment.