@@ -82,7 +82,8 @@ public function transform(mixed $dateTime): string
82
82
throw new TransformationFailedException ('Expected a \DateTimeInterface. ' );
83
83
}
84
84
85
- $ value = $ this ->getIntlDateFormatter ()->format ($ dateTime ->getTimestamp ());
85
+ $ timestamp = $ this ->getCalendarConvertingFormatter ()->parse ($ dateTime ->format ('Y-m-d H:i:s ' ));
86
+ $ value = $ this ->getIntlDateFormatter ()->format ($ timestamp );
86
87
87
88
if (0 != intl_get_error_code ()) {
88
89
throw new TransformationFailedException (intl_get_error_message ());
@@ -134,7 +135,7 @@ public function reverseTransform(mixed $value): ?\DateTime
134
135
try {
135
136
if ($ dateOnly ) {
136
137
// we only care about year-month-date, which has been delivered as a timestamp pointing to UTC midnight
137
- $ dateTime = new \DateTime (gmdate ( ' Y-m-d ' , $ timestamp ), new \DateTimeZone ($ this ->outputTimezone ));
138
+ $ dateTime = new \DateTime ($ this -> getCalendarConvertingFormatter ()-> format ( $ timestamp ), new \DateTimeZone ($ this ->outputTimezone ));
138
139
} else {
139
140
// read timestamp into DateTime object - the formatter delivers a timestamp
140
141
$ dateTime = new \DateTime (sprintf ('@%s ' , $ timestamp ));
@@ -196,4 +197,11 @@ protected function isPatternDateOnly(): bool
196
197
// check for the absence of time-related placeholders
197
198
return 0 === preg_match ('#[ahHkKmsSAzZOvVxX]# ' , $ pattern );
198
199
}
200
+
201
+ private function getCalendarConvertingFormatter (): \IntlDateFormatter
202
+ {
203
+ $ timezone = $ this ->isPatternDateOnly () ? 'UTC ' : $ this ->inputTimezone ;
204
+
205
+ return new \IntlDateFormatter (\Locale::getDefault (), \IntlDateFormatter::MEDIUM , \IntlDateFormatter::NONE , new \DateTimeZone ($ timezone ), \IntlDateFormatter::GREGORIAN , 'yyyy-MM-dd HH:mm:ss ' );
C87B
206
+ }
199
207
}
0 commit comments