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