Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
   4  
   5  class DateTime extends DateTimeWizard
   6  {
   7      /**
   8       * @var string[]
   9       */
  10      protected array $separators;
  11  
  12      /**
  13       * @var array<DateTimeWizard|string>
  14       */
  15      protected array $formatBlocks;
  16  
  17      /**
  18       * @param null|string|string[] $separators
  19       *          If you want to use only a single format block, then pass a null as the separator argument
  20       * @param DateTimeWizard|string ...$formatBlocks
  21       */
  22      public function __construct($separators, ...$formatBlocks)
  23      {
  24          $this->separators = $this->padSeparatorArray(
  25              is_array($separators) ? $separators : [$separators],
  26              count($formatBlocks) - 1
  27          );
  28          $this->formatBlocks = array_map([$this, 'mapFormatBlocks'], $formatBlocks);
  29      }
  30  
  31      /**
  32       * @param DateTimeWizard|string $value
  33       */
  34      private function mapFormatBlocks($value): string
  35      {
  36          // Any date masking codes are returned as lower case values
  37          if (is_object($value)) {
  38              // We can't explicitly test for Stringable until PHP >= 8.0
  39              return $value;
  40          }
  41  
  42          // Wrap any string literals in quotes, so that they're clearly defined as string literals
  43          return $this->wrapLiteral($value);
  44      }
  45  
  46      public function format(): string
  47      {
  48          return implode('', array_map([$this, 'intersperse'], $this->formatBlocks, $this->separators));
  49      }
  50  }