Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Fix PelEntryTime causing Unknown format: 0x0 (#191)
Browse files Browse the repository at this point in the history
Thank you @xPaw for fixing this issue!
  • Loading branch information
xPaw committed Feb 18, 2022
1 parent 3229f13 commit b95fe29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/PelEntryTime.php
Expand Up @@ -115,6 +115,7 @@ class PelEntryTime extends PelEntryAscii
public function __construct($tag, $timestamp, $type = self::UNIX_TIMESTAMP)
{
$this->tag = $tag;
$this->format = PelFormat::ASCII;
$this->setValue($timestamp, $type);
}

Expand Down
8 changes: 7 additions & 1 deletion test/AsciiTest.php
Expand Up @@ -27,6 +27,7 @@
use lsolesen\pel\PelEntryAscii;
use lsolesen\pel\PelEntryCopyright;
use lsolesen\pel\PelEntryTime;
use lsolesen\pel\PelFormat;
use lsolesen\pel\PelTag;
use PHPUnit\Framework\TestCase;

Expand All @@ -38,20 +39,24 @@ public function testReturnValues()
$entry = new PelEntryAscii(42);

$entry = new PelEntryAscii(42, 'foo bar baz');
$this->assertEquals($entry->getFormat(), PelFormat::ASCII);
$this->assertEquals($entry->getComponents(), 12);
$this->assertEquals($entry->getValue(), 'foo bar baz');
}

public function testTime()
{
$entry = new PelEntryTime(42, 10);
$entry = new PelEntryTime(PelTag::DATE_TIME_ORIGINAL, 10);

$this->assertEquals($entry->getFormat(), PelFormat::ASCII);
$this->assertEquals($entry->getTag(), PelTag::DATE_TIME_ORIGINAL);
$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');
$this->assertEquals($entry->getBytes(PelConvert::LITTLE_ENDIAN), '1970:01:01 00:00:10' . chr(0x00));

// Malformed Exif timestamp.
$entry->setValue('1970!01-01 00 00 30', PelEntryTime::EXIF_STRING);
Expand Down Expand Up @@ -88,6 +93,7 @@ public function testTime()
public function testCopyright()
{
$entry = new PelEntryCopyright();
$this->assertEquals($entry->getFormat(), PelFormat::ASCII);
$this->assertEquals($entry->getTag(), PelTag::COPYRIGHT);
$value = $entry->getValue();
$this->assertEquals($value[0], '');
Expand Down

0 comments on commit b95fe29

Please sign in to comment.