Skip to content

Commit 3f89d88

Browse files
committed
bug#8809 [Form] enforce correct timezone (Burgov)
This PR was merged into the 2.2 branch. Discussion ---------- [Form] enforce correct timezone | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | not sure if this is a BC break... | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - I'm using the Form component to handle JSON requests which come from AJAX requests. The JSON is formed by the Angular toJson method A typical request would be: ``` { name: "Some name" start: "2013-08-21T05:00:00.000Z" end: "2013-08-21T15:00:00.000Z" } ``` Note that in this case, what I entered in my input boxes are 7:00 for start and 17:00 for end times. As you can see, Angular (or Chrome, I'm not sure), converts this to the "Z" timezone. Since I cannot enforce the correct timezone client side, the timezone will differ from the one configured in the DateTimeType, however, instead of resulting in either an error or a conversion to the correct timezone, I get a datetime object in the wrong timezone, eventually resulting in wrong values in the database. By checking the required output timezone against the actual timezone of the input datetime object, rather than the expected timezone supplied, this problem is solved. Commits ------- b0349a1 [Form] check the required output timezone against the actual timezone of the input datetime object, rather than the expected timezone supplied
2 parents 599740e + 916b2c3 commit 3f89d88

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function reverseTransform($rfc3339)
5858
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
5959
}
6060

61-
if ($this->outputTimezone !== $this->inputTimezone) {
61+
if ($this->outputTimezone !== $dateTime->getTimezone()->getName()) {
6262
try {
6363
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
6464
} catch (\Exception $e) {

Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function reverseTransformProvider()
6565
// format without seconds, as appears in some browsers
6666
array('UTC', 'UTC', '2010-02-03 04:05:00 UTC', '2010-02-03T04:05Z'),
6767
array('America/New_York', 'Asia/Hong_Kong', '2010-02-03 04:05:00 America/New_York', '2010-02-03T17:05+08:00'),
68+
array('Europe/Amsterdam', 'Europe/Amsterdam', '2013-08-21 10:30:00 Europe/Amsterdam', '2013-08-21T08:30:00Z')
6869
));
6970
}
7071

0 commit comments

Comments
 (0)