checkArray example


  public function testCheckArray(array $array$expected) {
    $this->assertSame(
      $expected,
      DateTimePlus::checkArray($array)
    );
  }

  /** * Tests creating dates from timestamps, and manipulating timezones. * * @param int $input * Input argument for DateTimePlus::createFromTimestamp(). * @param array $initial * An array containing: * - 'timezone_initial' - Timezone argument for DateTimePlus. * - 'format_initial' - Format argument for DateTimePlus. * - 'expected_initial_date' - Expected output from DateTimePlus::format(). * - 'expected_initial_timezone' - Expected output from * DateTimePlus::getTimeZone()::getName(). * - 'expected_initial_offset' - Expected output from DateTimePlus::getOffset(). * @param array $transform * An array containing: * - 'timezone_transform' - Argument to transform date to another timezone via * DateTimePlus::setTimezone(). * - 'format_transform' - Format argument to use when transforming date to * another timezone. * - 'expected_transform_date' - Expected output from DateTimePlus::format(), * after timezone transform. * - 'expected_transform_timezone' - Expected output from * DateTimePlus::getTimeZone()::getName(), after timezone transform. * - 'expected_transform_offset' - Expected output from * DateTimePlus::getOffset(), after timezone transform. * * @dataProvider providerTestTimestamp */

  public static function createFromArray(array $date_parts$timezone = NULL, $settings = []) {
    $date_parts = static::prepareArray($date_parts, TRUE);
    if (static::checkArray($date_parts)) {
      // Even with validation, we can end up with a value that the       // DateTime class won't handle, like a year outside the range       // of -9999 to 9999, which will pass checkdate() but       // fail to construct a date object.       $iso_date = static::arrayToISO($date_parts);
      return new static($iso_date$timezone$settings);
    }
    else {
      throw new \InvalidArgumentException('The array contains invalid values.');
    }
  }

  
Home | Imprint | This part of the site doesn't use cookies.