Skip to content

Commit

Permalink
Merge pull request #1 from wprigollopes/date-format-option
Browse files Browse the repository at this point in the history
Date format option added
  • Loading branch information
wprigollopes committed Jan 17, 2023
2 parents a7ba091 + 32bd88d commit 02998f8
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class Sitemap
* @var XMLWriter
*/
private $writer;

/**
* @var dateFormat
*/
private $dateFormat = 'c';

/**
* @param string $filePath path of the file to write to
Expand Down Expand Up @@ -312,7 +317,7 @@ private function addSingleLanguageItem($location, $lastModified, $changeFrequenc
$this->writer->writeElement('loc', $location);

if ($lastModified !== null) {
$this->writer->writeElement('lastmod', date('c', $lastModified));
$this->writer->writeElement('lastmod', date($this->dateFormat, $lastModified));
}

if ($changeFrequency !== null) {
Expand Down Expand Up @@ -361,7 +366,7 @@ private function addMultiLanguageItem($locations, $lastModified, $changeFrequenc
$this->writer->writeElement('loc', $url);

if ($lastModified !== null) {
$this->writer->writeElement('lastmod', date('c', $lastModified));
$this->writer->writeElement('lastmod', date($this->dateFormat, $lastModified));
}

if ($changeFrequency !== null) {
Expand Down Expand Up @@ -517,4 +522,13 @@ public function setStylesheet($stylesheetUrl)
$this->stylesheet = $stylesheetUrl;
}
}
}

/**
* Allow to choose the date format pattern
* @param string DateTimeInterface::format pattern
*/
public function setDateFormat($dateFormat)
{
$this->dateFormat = $dateFormat;
}
}

0 comments on commit 02998f8

Please sign in to comment.