Skip to content

Commit bab8195

Browse files
author
Christophe Badoit
committed
fix(datetimes): try to fix the timezones problem
1 parent eda0cd6 commit bab8195

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/Definition/DatetimeType.php

+10-12
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class DatetimeType extends ScalarType {
2525
* @return array
2626
*/
2727
public function serialize($value) {
28-
return $this->toTimestamp($value);
28+
$carbon = new Carbon($value);
29+
$carbon->timezone('UTC');
30+
$str = $carbon->toIso8601String();
31+
return $str;
2932
}
3033

3134
/**
@@ -35,26 +38,21 @@ public function serialize($value) {
3538
* @return array|null
3639
*/
3740
public function parseValue($value) {
38-
return new Carbon($value);
41+
$carbon = new Carbon($value);
42+
$carbon->timezone(config('app.timezone'));
43+
return $carbon;
3944
}
4045

4146
/**
4247
* {@inheritDoc}
4348
*/
4449
public function parseLiteral($valueNode, ?array $variables = null) {
4550
if ($valueNode instanceof StringValueNode) {
46-
return new Carbon($valueNode->value);
51+
$carbon = new Carbon($valueNode->value);
52+
$carbon->timezone(config('app.timezone'));
53+
return $carbon;
4754
}
4855
return null;
4956
}
5057

51-
/**
52-
* Turn value into timestamp
53-
*
54-
* @param string|int $value
55-
* @return int
56-
*/
57-
private function toTimestamp($value) {
58-
return (new Carbon($value))->toRfc3339String();
59-
}
6058
}

0 commit comments

Comments
 (0)