HourTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class HourTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerHOUR
  8. *
  9. * @param mixed $expectedResult
  10. */
  11. public function testHOUR($expectedResult, string $dateTimeValue): void
  12. {
  13. $this->mightHaveException($expectedResult);
  14. $sheet = $this->getSheet();
  15. $sheet->getCell('A1')->setValue("=HOUR($dateTimeValue)");
  16. $sheet->getCell('B1')->setValue('1954-11-23 2:23:46');
  17. self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
  18. }
  19. public function providerHOUR(): array
  20. {
  21. return require 'tests/data/Calculation/DateTime/HOUR.php';
  22. }
  23. /**
  24. * @dataProvider providerHourArray
  25. */
  26. public function testHourArray(array $expectedResult, string $array): void
  27. {
  28. $calculation = Calculation::getInstance();
  29. $formula = "=HOUR({$array})";
  30. $result = $calculation->_calculateFormulaValue($formula);
  31. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  32. }
  33. public function providerHourArray(): array
  34. {
  35. return [
  36. 'row vector' => [[[1, 13, 19]], '{"2022-02-09 01:02:03", "2022-02-09 13:14:15", "2022-02-09 19:20:21"}'],
  37. 'column vector' => [[[1], [13], [19]], '{"2022-02-09 01:02:03"; "2022-02-09 13:14:15"; "2022-02-09 19:20:21"}'],
  38. 'matrix' => [[[1, 13], [19, 23]], '{"2022-02-09 01:02:03", "2022-02-09 13:14:15"; "2022-02-09 19:20:21", "1999-12-31 23:59:59"}'],
  39. ];
  40. }
  41. }