diff --git a/src/PhpSpreadsheet/Document/Properties.php b/src/PhpSpreadsheet/Document/Properties.php index 3be5a67a..2d461c59 100644 --- a/src/PhpSpreadsheet/Document/Properties.php +++ b/src/PhpSpreadsheet/Document/Properties.php @@ -115,7 +115,7 @@ class Properties // Initialise values $this->lastModifiedBy = $this->creator; $this->created = self::intOrFloatTimestamp(null); - $this->modified = self::intOrFloatTimestamp(null); + $this->modified = $this->created; } /** diff --git a/tests/PhpSpreadsheetTests/Document/PropertiesTest.php b/tests/PhpSpreadsheetTests/Document/PropertiesTest.php index e6c95cd4..0dfb256b 100644 --- a/tests/PhpSpreadsheetTests/Document/PropertiesTest.php +++ b/tests/PhpSpreadsheetTests/Document/PropertiesTest.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Document; +use DateTime; use DateTimeZone; use PhpOffice\PhpSpreadsheet\Document\Properties; use PhpOffice\PhpSpreadsheet\Shared\Date; @@ -14,20 +15,27 @@ class PropertiesTest extends TestCase */ private $properties; + /** @var float */ + private $startTime; + protected function setup(): void { - $this->properties = new Properties(); + do { + // loop to avoid rare situation where timestamp changes + $this->startTime = (float) (new DateTime())->format('U'); + $this->properties = new Properties(); + $endTime = (float) (new DateTime())->format('U'); + } while ($this->startTime !== $endTime); } public function testNewInstance(): void { - $createdTime = $modifiedTime = time(); self::assertSame('Unknown Creator', $this->properties->getCreator()); self::assertSame('Unknown Creator', $this->properties->getLastModifiedBy()); self::assertSame('Untitled Spreadsheet', $this->properties->getTitle()); self::assertSame('', $this->properties->getCompany()); - self::assertSame($createdTime, $this->properties->getCreated()); - self::assertSame($modifiedTime, $this->properties->getModified()); + self::assertEquals($this->startTime, $this->properties->getCreated()); + self::assertEquals($this->startTime, $this->properties->getModified()); } public function testSetCreator(): void @@ -46,10 +54,10 @@ class PropertiesTest extends TestCase */ public function testSetCreated($expectedCreationTime, $created): void { - $expectedCreationTime = $expectedCreationTime ?? time(); + $expectedCreationTime = $expectedCreationTime ?? $this->startTime; $this->properties->setCreated($created); - self::assertSame($expectedCreationTime, $this->properties->getCreated()); + self::assertEquals($expectedCreationTime, $this->properties->getCreated()); } public function providerCreationTime(): array @@ -78,10 +86,10 @@ class PropertiesTest extends TestCase */ public function testSetModified($expectedModifiedTime, $modified): void { - $expectedModifiedTime = $expectedModifiedTime ?? time(); + $expectedModifiedTime = $expectedModifiedTime ?? $this->startTime; $this->properties->setModified($modified); - self::assertSame($expectedModifiedTime, $this->properties->getModified()); + self::assertEquals($expectedModifiedTime, $this->properties->getModified()); } public function providerModifiedTime(): array