File tree Expand file tree Collapse file tree 5 files changed +82
-2
lines changed Expand file tree Collapse file tree 5 files changed +82
-2
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ class Mutator implements HydratorInterface
3333 public function hydrate ($ object , array $ data )
3434 {
3535 foreach ($ data as $ property => $ value ) {
36+
3637 $ mutator = $ this ->determineMutator ($ property );
3738
3839 if (method_exists ($ object , $ mutator )) {
Original file line number Diff line number Diff line change @@ -136,7 +136,11 @@ public function mapRawData(array $data)
136136 $ value = sprintf ('%1$sm ' , $ value );
137137 break ;
138138 case self ::CREATEDATE :
139- $ value = DateTime::createFromFormat ('Y:m:d H:i:s ' , $ value );
139+ try {
140+ $ value = new DateTime ($ value );
141+ } catch (\Exception $ exception ) {
142+ continue 2 ;
143+ }
140144 break ;
141145 case self ::EXPOSURETIME :
142146 $ value = '1/ ' . round (1 / $ value );
Original file line number Diff line number Diff line change 1313
1414use PHPExif \Exif ;
1515use DateTime ;
16+ use Exception ;
1617
1718/**
1819 * PHP Exif Native Mapper
@@ -142,7 +143,11 @@ public function mapRawData(array $data)
142143 // manipulate the value if necessary
143144 switch ($ field ) {
144145 case self ::DATETIMEORIGINAL :
145- $ value = DateTime::createFromFormat ('Y:m:d H:i:s ' , $ value );
146+ try {
147+ $ value = new DateTime ($ value );
148+ } catch (Exception $ exception ) {
149+ continue 2 ;
150+ }
146151 break ;
147152 case self ::EXPOSURETIME :
148153 // normalize ExposureTime
Original file line number Diff line number Diff line change @@ -236,4 +236,39 @@ public function testSetNumericInProperty()
236236
237237 $ this ->assertEquals ($ expected , $ reflProperty ->getValue ($ this ->mapper ));
238238 }
239+
240+ public function testMapRawDataCorrectlyFormatsDifferentDateTimeString ()
241+ {
242+ $ rawData = array (
243+ \PHPExif \Mapper \Exiftool::CREATEDATE => '2014-12-15 00:12:00 '
244+ );
245+
246+ $ mapped = $ this ->mapper ->mapRawData (
247+ $ rawData
248+ );
249+
250+ $ result = reset ($ mapped );
251+ $ this ->assertInstanceOf ('\DateTime ' , $ result );
252+ $ this ->assertEquals (
253+ reset ($ rawData ),
254+ $ result ->format ("Y-m-d H:i:s " )
255+ );
256+ }
257+
258+ public function testMapRawDataCorrectlyIgnoresInvalidCreateDate ()
259+ {
260+ $ rawData = array (
261+ \PHPExif \Mapper \Exiftool::CREATEDATE => 'Invalid Date String '
262+ );
263+
264+ $ result = $ this ->mapper ->mapRawData (
265+ $ rawData
266+ );
267+
268+ $ this ->assertCount (0 , $ result );
269+ $ this ->assertNotEquals (
270+ reset ($ rawData ),
271+ $ result
272+ );
273+ }
239274}
Original file line number Diff line number Diff line change @@ -187,4 +187,39 @@ public function testMapRawDataCorrectlyFormatsGPSData()
187187 $ expected = '40.333452380952,-20.167314814815 ' ;
188188 $ this ->assertEquals ($ expected , reset ($ result ));
189189 }
190+
191+ public function testMapRawDataCorrectlyFormatsDifferentDateTimeString ()
192+ {
193+ $ rawData = array (
194+ \PHPExif \Mapper \Native::DATETIMEORIGINAL => '2014-12-15 00:12:00 '
195+ );
196+
197+ $ mapped = $ this ->mapper ->mapRawData (
198+ $ rawData
199+ );
200+
201+ $ result = reset ($ mapped );
202+ $ this ->assertInstanceOf ('\DateTime ' , $ result );
203+ $ this ->assertEquals (
204+ reset ($ rawData ),
205+ $ result ->format ("Y-m-d H:i:s " )
206+ );
207+ }
208+
209+ public function testMapRawDataCorrectlyIgnoresInvalidCreateDate ()
210+ {
211+ $ rawData = array (
212+ \PHPExif \Mapper \Native::DATETIMEORIGINAL => 'Invalid Date String '
213+ );
214+
215+ $ result = $ this ->mapper ->mapRawData (
216+ $ rawData
217+ );
218+
219+ $ this ->assertCount (0 , $ result );
220+ $ this ->assertNotEquals (
221+ reset ($ rawData ),
222+ $ result
223+ );
224+ }
190225}
You can’t perform that action at this time.
0 commit comments