<commit_before><?php

/**
 * SPHPlayground Framework (http://playgound.samiholck.com/)
 *
 * @link      https://github.com/samhol/SPHP-framework for the source repository
 * @copyright Copyright (c) 2007-2018 <NAME> <<EMAIL>>
 * @license   https://opensource.org/licenses/MIT The MIT License
 */

namespace Sphp\Html\DateTime;

use DateTimeInterface;
use Sphp\DateTime\DateTime;
use Sphp\Html\ContainerTag;
use Sphp\DateTime\DateTimes;

/**
 * Implements an HTML &lt;time&gt; tag
 *
 * @author  <NAME> <<EMAIL>>
 * @link    http://www.w3schools.com/tags/tag_time.asp w3schools HTML API
 * @license https://opensource.org/licenses/MIT The MIT License
 * @link    https://github.com/samhol/SPHP-framework GitHub repository
 * @filesource
 */
class TimeTag extends ContainerTag implements TimeTagInterface {

  /**
   * the datetime object
   *
   * @var DateTime 
   */
  private $dateTime;

  /**
   * @var string
   */
  private $format;

  /**
   * Constructor
   *
   * @param  mixed $dateTime the datetime object
   * @param  string $format the format of the outputted date string
   * @param  mixed $content optional content of the components
   */
  public function __construct($dateTime = null, string $format = 'c', $content = null) {
    parent::__construct('time', $content);
    $this->setDateTime($dateTime);
    $this->setFormat($format);
  }

  public function __destruct() {
    parent::__destruct();
  }

  public function __clone() {
    parent::__clone();
  }

  public function setFormat(string $format = self::DATE_TIME) {
    $this->format = $format;
    return $this;
  }

  public function getFormat(): string {
    return $this->format;
  }

  public function setDateTime($dateTime) {
    if (!$dateTime instanceof DateTimeInterface && !$dateTime instanceof DateTime) {
      $dateTime = new DateTime($dateTime);
    }
    $this->dateTime = $dateTime;
    $this->attributes()->setAttribute('datetime', $this->dateTime->format($this->getFormat()));
    return $this;
  }

  /**
   * Creates a &lt;time&gt; tag object showing week number
   * 
   * @param  mixed $dateTime
   * @return TimeTag new instance
   */
  public static function weekNumber($dateTime = null): TimeTag {
    if ($dateTime === null) {
      $dateTime = DateTimes::dateTimeImmutable($dateTime);
    }
    return (new TimeTag($dateTime, 'Y-\WW', $dateTime->format('W')));
  }

}
<commit_msg>Update TimeTag.php<commit_after><?php

/**
 * SPHPlayground Framework (http://playgound.samiholck.com/)
 *
 * @link      https://github.com/samhol/SPHP-framework for the source repository
 * @copyright Copyright (c) 2007-2018 <NAME> <<EMAIL>>
 * @license   https://opensource.org/licenses/MIT The MIT License
 */

namespace Sphp\Html\DateTime;

use DateTimeInterface;
use Sphp\DateTime\DateTime;
use Sphp\Html\ContainerTag;
use Sphp\DateTime\DateTimes;

/**
 * Implements an HTML &lt;time&gt; tag
 *
 * @author  <NAME> <<EMAIL>>
 * @link    http://www.w3schools.com/tags/tag_time.asp w3schools HTML API
 * @license https://opensource.org/licenses/MIT The MIT License
 * @link    https://github.com/samhol/SPHP-framework GitHub repository
 * @filesource
 */
class TimeTag extends ContainerTag implements TimeTagInterface {

  /**
   * the datetime object
   *
   * @var DateTime 
   */
  private $dateTime;

  /**
   * @var string
   */
  private $format;

  /**
   * Constructor
   *
   * @param  mixed $dateTime the datetime object
   * @param  string $format the format of the outputted date string
   * @param  mixed $content optional content of the components
   */
  public function __construct($dateTime = null, string $format = 'c', $content = null) {
    parent::__construct('time', $content);
    $this->setFormat($format);
    $this->setDateTime($dateTime);
  }

  public function __destruct() {
    parent::__destruct();
  }

  public function __clone() {
    parent::__clone();
  }

  public function setFormat(string $format = self::DATE_TIME) {
    $this->format = $format;
    return $this;
  }

  public function getFormat(): string {
    return $this->format;
  }

  public function setDateTime($dateTime) {
    if (!$dateTime instanceof DateTimeInterface && !$dateTime instanceof DateTime) {
      $dateTime = new DateTime($dateTime);
    }
    $this->dateTime = $dateTime;
    $this->attributes()->setAttribute('datetime', $this->dateTime->format($this->getFormat()));
    return $this;
  }

  /**
   * Creates a &lt;time&gt; tag object showing week number
   * 
   * @param  mixed $dateTime
   * @return TimeTag new instance
   */
  public static function weekNumber($dateTime = null): TimeTag {
    if ($dateTime === null) {
      $dateTime = DateTimes::dateTimeImmutable($dateTime);
    }
    return (new TimeTag($dateTime, 'Y-\WW', $dateTime->format('W')));
  }

}

{'fraction_non_alphanumeric': 0.14231817229092433, 'fraction_numerical': 0.004191993292810731, 'mean_word_length': 3.4639850327408794, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 37, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2352066', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1462, 'n_words': 365}