IsoWeekNumTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class IsoWeekNumTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerISOWEEKNUM
  8. *
  9. * @param mixed $expectedResult
  10. * @param string $dateValue
  11. */
  12. public function testISOWEEKNUM($expectedResult, $dateValue): void
  13. {
  14. $this->mightHaveException($expectedResult);
  15. $sheet = $this->getSheet();
  16. $sheet->getCell('A1')->setValue("=ISOWEEKNUM($dateValue)");
  17. $sheet->getCell('B1')->setValue('1954-11-23');
  18. self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
  19. }
  20. public function providerISOWEEKNUM(): array
  21. {
  22. return require 'tests/data/Calculation/DateTime/ISOWEEKNUM.php';
  23. }
  24. /**
  25. * @dataProvider providerISOWEEKNUM1904
  26. *
  27. * @param mixed $expectedResult
  28. * @param string $dateValue
  29. */
  30. public function testISOWEEKNUM1904($expectedResult, $dateValue): void
  31. {
  32. $this->mightHaveException($expectedResult);
  33. self::setMac1904();
  34. $sheet = $this->getSheet();
  35. $sheet->getCell('A1')->setValue("=ISOWEEKNUM($dateValue)");
  36. $sheet->getCell('B1')->setValue('1954-11-23');
  37. self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
  38. }
  39. public function providerISOWEEKNUM1904(): array
  40. {
  41. return require 'tests/data/Calculation/DateTime/ISOWEEKNUM1904.php';
  42. }
  43. /**
  44. * @dataProvider providerIsoWeekNumArray
  45. */
  46. public function testIsoWeekNumArray(array $expectedResult, string $array): void
  47. {
  48. $calculation = Calculation::getInstance();
  49. $formula = "=ISOWEEKNUM({$array})";
  50. $result = $calculation->_calculateFormulaValue($formula);
  51. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  52. }
  53. public function providerIsoWeekNumArray(): array
  54. {
  55. return [
  56. 'row vector' => [[[52, 23, 29]], '{"2022-01-01", "2022-06-12", "2023-07-22"}'],
  57. 'column vector' => [[[52], [13], [26]], '{"2023-01-01"; "2023-04-01"; "2023-07-01"}'],
  58. 'matrix' => [[[53, 52], [52, 52]], '{"2021-01-01", "2021-12-31"; "2023-01-01", "2023-12-31"}'],
  59. ];
  60. }
  61. }