77
88namespace Magento \Framework \Stdlib \DateTime \Timezone ;
99
10+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
1011use Magento \Framework \Locale \ResolverInterface ;
1112use Magento \Framework \App \Config \ScopeConfigInterface ;
1213
@@ -23,62 +24,49 @@ class LocalizedDateToUtcConverter implements LocalizedDateToUtcConverterInterfac
2324 private $ defaultFormat = 'Y-m-d H:i:s ' ;
2425
2526 /**
26- * @var ResolverInterface
27- */
28- private $ localeResolver ;
29-
30- /**
31- * @var ScopeConfigInterface
32- */
33- private $ scopeConfig ;
34-
35- /**
36- * @var string
27+ * @var TimezoneInterface
3728 */
38- private $ scopeType ;
29+ private $ timezone ;
3930
4031 /**
41- * @var string
32+ * @var ResolverInterface
4233 */
43- private $ defaultTimezonePath ;
34+ private $ localeResolver ;
4435
4536 /**
4637 * LocalizedDateToUtcConverter constructor.
4738 *
4839 * @param ResolverInterface $localeResolver
4940 */
5041 public function __construct (
51- ResolverInterface $ localeResolver ,
52- ScopeConfigInterface $ scopeConfig ,
53- $ scopeType ,
54- $ defaultTimezonePath
42+ TimezoneInterface $ timezone ,
43+ ResolverInterface $ localeResolver
5544 )
5645 {
46+ $ this ->timezone = $ timezone ;
5747 $ this ->localeResolver = $ localeResolver ;
58- $ this ->scopeConfig = $ scopeConfig ;
59- $ this ->scopeType = $ scopeType ;
60- $ this ->defaultTimezonePath = $ defaultTimezonePath ;
6148 }
6249
6350 /**
6451 * @inheritdoc
6552 */
6653 public function convertLocalizedDateToUtc ($ date )
6754 {
55+ $ configTimezone = $ this ->timezone ->getConfigTimezone ();
6856 $ locale = $ this ->localeResolver ->getLocale ();
57+
6958 $ formatter = new \IntlDateFormatter (
7059 $ locale ,
7160 \IntlDateFormatter::MEDIUM ,
7261 \IntlDateFormatter::MEDIUM ,
73- $ this ->getConfigTimezone (),
74- null ,
75- null
62+ $ configTimezone
7663 );
77- $ unixTime = $ formatter ->parse ($ date );
78- $ dateTime = new DateTime ($ this );
79- $ dateUniversal = $ dateTime ->gmtDate (null , $ unixTime );
80- $ date = new \DateTime ($ dateUniversal , new \DateTimeZone ($ this ->getConfigTimezone ()));
8164
65+ $ localTimestamp = $ formatter ->parse ($ date );
66+ $ gmtTimestamp = $ this ->timezone ->date ($ localTimestamp )->getTimestamp ();
67+ $ formattedUniversalTime = date ($ this ->defaultFormat , $ gmtTimestamp );
68+
69+ $ date = new \DateTime ($ formattedUniversalTime , new \DateTimeZone ($ configTimezone ));
8270 $ date ->setTimezone (new \DateTimeZone ('UTC ' ));
8371
8472 return $ date ->format ($ this ->defaultFormat );
0 commit comments