Days360Test.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class Days360Test extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerDAYS360
  8. *
  9. * @param mixed $expectedResult
  10. */
  11. public function testDAYS360($expectedResult, string $formula): void
  12. {
  13. $this->mightHaveException($expectedResult);
  14. $sheet = $this->getSheet();
  15. $sheet->getCell('B1')->setValue('2000-02-29');
  16. $sheet->getCell('C1')->setValue('2000-03-31');
  17. $sheet->getCell('A1')->setValue("=DAYS360($formula)");
  18. self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
  19. }
  20. public function providerDAYS360(): array
  21. {
  22. return require 'tests/data/Calculation/DateTime/DAYS360.php';
  23. }
  24. /**
  25. * @dataProvider providerDays360Array
  26. */
  27. public function testDays360Array(array $expectedResult, string $startDate, string $endDate, ?string $methods): void
  28. {
  29. $calculation = Calculation::getInstance();
  30. if ($methods === null) {
  31. $formula = "=DAYS360({$startDate}, {$endDate})";
  32. } else {
  33. $formula = "=DAYS360({$startDate}, {$endDate}, {$methods})";
  34. }
  35. $result = $calculation->_calculateFormulaValue($formula);
  36. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  37. }
  38. public function providerDays360Array(): array
  39. {
  40. return [
  41. 'row vector #1' => [[[360, 199, -201]], '{"2022-01-01", "2022-06-12", "2023-07-22"}', '"2022-12-31"', null],
  42. 'column vector #1' => [[[360], [358], [355]], '{"2022-01-01"; "2022-01-03"; "2022-01-06"}', '"2022-12-31"', null],
  43. 'matrix #1' => [[[0, -9], [-224, -360]], '{"2022-01-01", "2022-01-10"; "2022-08-15", "2022-12-31"}', '"2021-12-31"', null],
  44. 'column vector with methods' => [[[360, 359], [358, 357], [355, 354]], '{"2022-01-01"; "2022-01-03"; "2022-01-06"}', '"2022-12-31"', '{FALSE, TRUE}'],
  45. ];
  46. }
  47. }