-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Convert string to DateTime object for languages other than English #18083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-engcom-team
merged 24 commits into
magento:2.3-develop
from
bnymn:feature/issue-5037
Nov 6, 2018
Merged
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ae42612
Fix date format for different locales
bnymn c4fa85b
Move formatter into string conversion block
bnymn 6bda779
Convert internationalized date into DateTime object
bnymn a4f80a9
Force pattern if locale not found
bnymn 14d9528
Replaced {@inheritdoc} with the actual documentation in order to fix …
bnymn da580fc
Merge branch '2.3-develop' of github.com:magento/magento2 into featur…
bnymn 16a7f0b
Use @inheritdoc and revert back code change
bnymn 9315dd6
Revert back code change to fix BiC
bnymn 42cd228
Revert back @deprecated tag
bnymn ddeaf36
Revert back new lines
bnymn 6cc9034
Revert back documentation change in API interface
bnymn 28617c0
Fix documentation change for code smell
bnymn fd0ab03
Fix documentation
bnymn 1b03c19
Revert back change
bnymn c6c2ffe
Rever-back unit test
bnymn 502e5ac
New class and interface created for time format convertion
bnymn 51e8fe7
Convert local timestamp into GMT timestamp
bnymn a8c7768
Fix docblocks
slavvka 127b1b8
Fix docblock
slavvka 526bfc9
Fix docblock
slavvka edc962d
Fix static tests
slavvka 4fe8c7a
Fix static test
slavvka e27de55
Fix static test
slavvka 0d0c210
Fix static test
slavvka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
lib/internal/Magento/Framework/Stdlib/DateTime/Timezone/LocalizedDateToUtcConverter.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Magento\Framework\Stdlib\DateTime\Timezone; | ||
|
|
||
| use Magento\Framework\Stdlib\DateTime\TimezoneInterface; | ||
| use Magento\Framework\Locale\ResolverInterface; | ||
| use Magento\Framework\App\Config\ScopeConfigInterface; | ||
|
|
||
| /** | ||
| * Class LocalizedDateToUtcConverter | ||
| */ | ||
| class LocalizedDateToUtcConverter implements LocalizedDateToUtcConverterInterface | ||
| { | ||
| /** | ||
| * Contains default date format | ||
| * | ||
| * @var string | ||
| */ | ||
| private $defaultFormat = 'Y-m-d H:i:s'; | ||
|
|
||
| /** | ||
| * @var TimezoneInterface | ||
| */ | ||
| private $timezone; | ||
|
|
||
| /** | ||
| * @var ResolverInterface | ||
| */ | ||
| private $localeResolver; | ||
|
|
||
| /** | ||
| * LocalizedDateToUtcConverter constructor. | ||
| * | ||
| * @param ResolverInterface $localeResolver | ||
| */ | ||
| public function __construct( | ||
| TimezoneInterface $timezone, | ||
| ResolverInterface $localeResolver | ||
| ) | ||
| { | ||
| $this->timezone = $timezone; | ||
| $this->localeResolver = $localeResolver; | ||
| } | ||
|
|
||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function convertLocalizedDateToUtc($date) | ||
| { | ||
| $configTimezone = $this->timezone->getConfigTimezone(); | ||
| $locale = $this->localeResolver->getLocale(); | ||
|
|
||
| $formatter = new \IntlDateFormatter( | ||
| $locale, | ||
| \IntlDateFormatter::MEDIUM, | ||
| \IntlDateFormatter::MEDIUM, | ||
| $configTimezone | ||
| ); | ||
|
|
||
| $localTimestamp = $formatter->parse($date); | ||
| $gmtTimestamp = $this->timezone->date($localTimestamp)->getTimestamp(); | ||
| $formattedUniversalTime = date($this->defaultFormat, $gmtTimestamp); | ||
|
|
||
| $date = new \DateTime($formattedUniversalTime, new \DateTimeZone($configTimezone)); | ||
| $date->setTimezone(new \DateTimeZone('UTC')); | ||
|
|
||
| return $date->format($this->defaultFormat); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...ernal/Magento/Framework/Stdlib/DateTime/Timezone/LocalizedDateToUtcConverterInterface.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Magento\Framework\Stdlib\DateTime\Timezone; | ||
|
|
||
| interface LocalizedDateToUtcConverterInterface | ||
| { | ||
| /** | ||
| * @param string $data | ||
| * @return string | ||
| */ | ||
| public function convertLocalizedDateToUtc($date); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a new line in the end |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.