<?php final class TimeCurrency { public static function createFromString(string $formatted): self { if (!preg_match('/^(\d{4}):(\d{2}):(\d{1}):(\d{2}):(\d{2})$/', $formatted, $matches)) { throw new \InvalidArgumentException('Invalid currency format.'); } return new self(...array_slice($matches, 1)); } /** @var int */ private $year; /** @var int */ private $weekNumber; /** @var int */ private $day; /** @var int */ private $hour; /** @var int */ private $minute; public function __construct(int $year, int $weekNumber, int $day, int $hour, int $minute) { $this->year = $year; $this->weekNumber = $weekNumber; $this->day = $day; $this->hour = $hour; $this->minute = $minute; } public function addYears(int $addedYears): void { $this->year += $addedYears; } public function __toString(): string { return sprintf('%04d:%02d:%d:%02d:%02d', $this->year, $this->weekNumber, $this->day, $this->hour, $this->minute); } } // Example usage $currency = TimeCurrency::createFromString('2010:21:1:23:21'); $currency->addYears(4); echo $currency;
You have javascript disabled. You will not be able to edit any code.