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

Fix PelEntryTime causing Unknown format: 0x0 #191

Merged
merged 1 commit into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/PelEntryTime.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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