DayTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class DayTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerDAY
  8. *
  9. * @param mixed $expectedResultExcel
  10. */
  11. public function testDAY($expectedResultExcel, string $dateTimeValue): void
  12. {
  13. $this->mightHaveException($expectedResultExcel);
  14. $sheet = $this->getSheet();
  15. $sheet->getCell('B1')->setValue('1954-11-23');
  16. $sheet->getCell('A1')->setValue("=DAY($dateTimeValue)");
  17. self::assertSame($expectedResultExcel, $sheet->getCell('A1')->getCalculatedValue());
  18. }
  19. public function providerDAY(): array
  20. {
  21. return require 'tests/data/Calculation/DateTime/DAY.php';
  22. }
  23. /**
  24. * @dataProvider providerDAYOpenOffice
  25. *
  26. * @param mixed $expectedResultOpenOffice
  27. */
  28. public function testDAYOpenOffice($expectedResultOpenOffice, string $dateTimeValue): void
  29. {
  30. self::setOpenOffice();
  31. $this->mightHaveException($expectedResultOpenOffice);
  32. $sheet = $this->getSheet();
  33. $sheet->getCell('A2')->setValue("=DAY($dateTimeValue)");
  34. self::assertSame($expectedResultOpenOffice, $sheet->getCell('A2')->getCalculatedValue());
  35. }
  36. public function providerDAYOpenOffice(): array
  37. {
  38. return require 'tests/data/Calculation/DateTime/DAYOpenOffice.php';
  39. }
  40. /**
  41. * @dataProvider providerDayArray
  42. */
  43. public function testDayArray(array $expectedResult, string $array): void
  44. {
  45. $calculation = Calculation::getInstance();
  46. $formula = "=DAY({$array})";
  47. $result = $calculation->_calculateFormulaValue($formula);
  48. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  49. }
  50. public function providerDayArray(): array
  51. {
  52. return [
  53. 'row vector' => [[[1, 12, 22]], '{"2022-01-01", "2022-06-12", "2023-07-22"}'],
  54. 'column vector' => [[[1], [3], [6]], '{"2022-01-01"; "2022-01-03"; "2022-01-06"}'],
  55. 'matrix' => [[[1, 10], [15, 31]], '{"2022-01-01", "2022-01-10"; "2022-08-15", "2022-12-31"}'],
  56. ];
  57. }
  58. }