From 502e5ac6941a10e39ef1e559c91565bdb07a4d14 Mon Sep 17 00:00:00 2001 From: Bunyamin Date: Mon, 8 Oct 2018 09:34:26 -0300 Subject: [PATCH] New class and interface created for time format convertion --- app/code/Magento/Store/etc/di.xml | 6 ++ app/etc/di.xml | 1 + .../Timezone/LocalizedDateToUtcConverter.php | 86 +++++++++++++++++++ .../LocalizedDateToUtcConverterInterface.php | 17 ++++ 4 files changed, 110 insertions(+) create mode 100644 lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/LocalizedDateToUtcConverter.php create mode 100644 lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/LocalizedDateToUtcConverterInterface.php diff --git a/app/code/Magento/Store/etc/di.xml b/app/code/Magento/Store/etc/di.xml index be005264b7bbf..f9e003aca69af 100644 --- a/app/code/Magento/Store/etc/di.xml +++ b/app/code/Magento/Store/etc/di.xml @@ -294,6 +294,12 @@ Magento\Store\Model\ScopeInterface::SCOPE_STORE + + + Magento\Directory\Helper\Data::XML_PATH_DEFAULT_TIMEZONE + Magento\Store\Model\ScopeInterface::SCOPE_STORE + + Magento\Directory\Helper\Data::XML_PATH_DEFAULT_LOCALE diff --git a/app/etc/di.xml b/app/etc/di.xml index db979f9b76382..282a0af4f46a5 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -146,6 +146,7 @@ + diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/LocalizedDateToUtcConverter.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/LocalizedDateToUtcConverter.php new file mode 100644 index 0000000000000..23dadc11cc6ef --- /dev/null +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/LocalizedDateToUtcConverter.php @@ -0,0 +1,86 @@ +localeResolver = $localeResolver; + $this->scopeConfig = $scopeConfig; + $this->scopeType = $scopeType; + $this->defaultTimezonePath = $defaultTimezonePath; + } + + /** + * @inheritdoc + */ + public function convertLocalizedDateToUtc($date) + { + $locale = $this->localeResolver->getLocale(); + $formatter = new \IntlDateFormatter( + $locale, + \IntlDateFormatter::MEDIUM, + \IntlDateFormatter::MEDIUM, + $this->getConfigTimezone(), + null, + null + ); + $unixTime = $formatter->parse($date); + $dateTime = new DateTime($this); + $dateUniversal = $dateTime->gmtDate(null, $unixTime); + $date = new \DateTime($dateUniversal, new \DateTimeZone($this->getConfigTimezone())); + + $date->setTimezone(new \DateTimeZone('UTC')); + + return $date->format($this->defaultFormat); + } +} \ No newline at end of file diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/LocalizedDateToUtcConverterInterface.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/LocalizedDateToUtcConverterInterface.php new file mode 100644 index 0000000000000..277900c46badf --- /dev/null +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/LocalizedDateToUtcConverterInterface.php @@ -0,0 +1,17 @@ +