This class can hold a timestamp, and it will be used as in this example where the time is advanced by one week: $entry = $ifd->getEntry(PelTag::DATE_TIME_ORIGINAL); $time = $entry->getValue(); print('The image was taken on the ' . date('jS', $time)); $entry->setValue($time + 7 * 24 * 3600); The example used a standard UNIX timestamp, which is the default for this class. But the Exif format defines dates outside the range of a UNIX timestamp (about 1970 to 2038) and so you can also get access to the timestamp in two other formats: a simple string or a Julian Day Count. Please see the Calendar extension in the PHP Manual for more information about the Julian Day Count.
Author: Martin Geisler (mgeisler@users.sourceforge.net)
Inheritance: extends lsolesen\pel\PelEntryAscii
Example #1
0
 function testTime()
 {
     $entry = new PelEntryTime(42, 10);
     $this->assertEquals($entry->getComponents(), 20);
     $this->assertEquals($entry->getValue(), 10);
     $this->assertEquals($entry->getValue(PelEntryTime::UNIX_TIMESTAMP), 10);
     $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '1970:01:01 00:00:10');
     $this->assertEquals($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 2440588 + 10 / 86400);
     $this->assertEquals($entry->getText(), '1970:01:01 00:00:10');
     // Malformed Exif timestamp.
     $entry->setValue('1970!01-01 00 00 30', PelEntryTime::EXIF_STRING);
     $this->assertEquals($entry->getValue(), 30);
     $entry->setValue(2415021.75, PelEntryTime::JULIAN_DAY_COUNT);
     // This is Jan 1st 1900 at 18:00, outside the range of a UNIX
     // timestamp:
     $this->assertEquals($entry->getValue(), false);
     $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '1900:01:01 18:00:00');
     $this->assertEquals($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 2415021.75);
     $entry->setValue('0000:00:00 00:00:00', PelEntryTime::EXIF_STRING);
     $this->assertEquals($entry->getValue(), false);
     $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '0000:00:00 00:00:00');
     $this->assertEquals($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 0);
     $entry->setValue('9999:12:31 23:59:59', PelEntryTime::EXIF_STRING);
     // this test will fail on 32bit machines
     $this->assertEquals($entry->getValue(), 253402300799);
     $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '9999:12:31 23:59:59');
     $this->assertEquals($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 5373484 + 86399 / 86400);
     // Check day roll-over for SF bug #1699489.
     $entry->setValue('2007:04:23 23:30:00', PelEntryTime::EXIF_STRING);
     $t = $entry->getValue(PelEntryTime::UNIX_TIMESTAMP);
     $entry->setValue($t + 3600);
     $this->assertEquals($entry->getValue(PelEntryTime::EXIF_STRING), '2007:04:24 00:30:00');
 }
Example #2
0
 function testTime()
 {
     $arg1 = new PatternExpectation('/Missing argument 1 for lsolesen.pel.PelEntryTime::__construct()/');
     $arg2 = new PatternExpectation('/Missing argument 2 for lsolesen.pel.PelEntryTime::__construct()/');
     $this->expectError($arg1);
     $this->expectError($arg2);
     $this->expectError('Undefined variable: tag');
     $this->expectError('Undefined variable: timestamp');
     $entry = new PelEntryTime();
     $this->expectError($arg2);
     $this->expectError('Undefined variable: timestamp');
     $entry = new PelEntryTime(42);
     $entry = new PelEntryTime(42, 10);
     $this->assertEqual($entry->getComponents(), 20);
     $this->assertEqual($entry->getValue(), 10);
     $this->assertEqual($entry->getValue(PelEntryTime::UNIX_TIMESTAMP), 10);
     $this->assertEqual($entry->getValue(PelEntryTime::EXIF_STRING), '1970:01:01 00:00:10');
     $this->assertEqual($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 2440588 + 10 / 86400);
     $this->assertEqual($entry->getText(), '1970:01:01 00:00:10');
     // Malformed Exif timestamp.
     $entry->setValue('1970!01-01 00 00 30', PelEntryTime::EXIF_STRING);
     $this->assertEqual($entry->getValue(), 30);
     $entry->setValue(2415021.75, PelEntryTime::JULIAN_DAY_COUNT);
     // This is Jan 1st 1900 at 18:00, outside the range of a UNIX
     // timestamp:
     $this->assertEqual($entry->getValue(), false);
     $this->assertEqual($entry->getValue(PelEntryTime::EXIF_STRING), '1900:01:01 18:00:00');
     $this->assertEqual($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 2415021.75);
     $entry->setValue('0000:00:00 00:00:00', PelEntryTime::EXIF_STRING);
     $this->assertEqual($entry->getValue(), false);
     $this->assertEqual($entry->getValue(PelEntryTime::EXIF_STRING), '0000:00:00 00:00:00');
     $this->assertEqual($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 0);
     $entry->setValue('9999:12:31 23:59:59', PelEntryTime::EXIF_STRING);
     // this test will fail on 32bit machines
     $this->assertEqual($entry->getValue(), 253402300799);
     $this->assertEqual($entry->getValue(PelEntryTime::EXIF_STRING), '9999:12:31 23:59:59');
     $this->assertEqual($entry->getValue(PelEntryTime::JULIAN_DAY_COUNT), 5373484 + 86399 / 86400);
     // Check day roll-over for SF bug #1699489.
     $entry->setValue('2007:04:23 23:30:00', PelEntryTime::EXIF_STRING);
     $t = $entry->getValue(PelEntryTime::UNIX_TIMESTAMP);
     $entry->setValue($t + 3600);
     $this->assertEqual($entry->getValue(PelEntryTime::EXIF_STRING), '2007:04:24 00:30:00');
 }