File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed 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 @@ -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