Files
PhpSpreadsheet/tests/data/Calculation/DateTime/YEARFRAC.php
T
oleibman 80a20fc991 100% Coverage for Calculation/DateTime (#1870)
* 100% Coverage for Calculation/DateTime

The code in DateTime is now completely covered.
Along the way, some errors were discovered and corrected.
- The tests which have had to be changed at the start of every year are
replaced by more robust equivalents which do not require annual changes.
- Several places in the code where Gnumeric and OpenOffice were thought to differ
from Excel do not appear to have had any justification.
I have left a comment where such code has been removed.
- Use DateTime when possible rather than date, time, or strftime functions to avoid
potential Y2038 problems.
- Some impossible code has been removed, replaced by an explanatory comment.
- NETWORKDAYS had a bug when the start date was Sunday. There had been no tests
of this condition.
- Some functions allow boolean and null arguments where a number is expected.
This is more complicated than the equivalent situations in MathTrig because
the initial date for these calculations can be Day 1 rather than Day 0.
- More testing for dates from 1900-01-01 through the fictitious
everywhere-but-Excel 1900-01-29.
    - This showed that there is an additional Excel bug - Excel evaluates
WEEKNUM(emptycell) as 0, which is not a valid result for
WEEKNUM without a second argument.
PhpSpreadsheet now duplicates this bug.
    - There is a similar and even worse bug for 1904-01-01 in 1904 calculations.
Weeknum returns 0 for this,
but returns the correct value for arguments of 0 or null.
    - DATEVALUE should accept 1900-02-29 (sigh) and relatives.
PhpSpreadsheet now duplicates this bug.
- Testing bootstrap sets default timezone. This appears to be a relic from
the releases of PHP where the unwise decision, subsequenly reversed,
was made to issue messages for
"no default timezone is set" rather than just use a sensible default.
This was a disruptive setting for some of the tests I added.
There is only one test in the entire suite which is default-timezone-dependent.
Setting and resetting of default timezone is moved to that test
(Reader/ODS/ODSTest), and out of bootstrap.
- There had been no testing of NOW() function.
- DATEVALUE test had no tests for 1904 calendar and needs some.
- DATE test changed 1900/1904 calendar in use without restoring it.
- WEEKDAY test had no tests for 1904 calendar and needs some.
    - Which revealed a bug in Shared/Date (excelToDateTimeObject was not
recognizing 1904-01-01 as valid when 1904 calendar is in use).
    - And an additional bug in that legal 1904-calendar values in the 0.0-1.0
range yielded the same "wrong" answers as 1900-calendar (see "One note" below).
Also the comment for one of the calendar-1904 tests was wrong in attempting
to identify what time of day the fraction represented.

I had wanted to break this up into a set of smaller modules, a process already
started for Engineering and MathTrig.
However the number of source code changes was sufficient that I wanted
a clean delta for this request.
If it is merged, I will work on breaking it up afterwards.

One note - Shared/Date/excelToDateTimeObject, when calendar-1900 is in use,
returns an unexpected result if its argument is between 0 and 1,
which is nominally invalid for that calendar.
It uses a base-1970 calendar in that instance. That check is not justifiable
for calendar-1904, where values in that range are legal,
so I made the check specific to calendar-1900,
and adjusted 3 1904 unit test results accordingly. However, I have to admit that
I don't understand why that check should be made even for calendar-1900.
It certainly doesn't match anything that Excel does.
I would recommend scrapping that code altogether.
If agreed, I would do this as part of the break-up into smaller modules.

Another note -
more controversially, it is clear that PhpSpreadsheet needs to support
the Excel and PHP date formats. Although it requires further study,
I am not convinced that it needs to support Unix timestamp format.
Since that is a potential source of Y2038 problems on 32-bit systems,
I would like to open a PR to deprecate the use of that format.
Please let me know if you are aware of a valid reason to continue to support it.
2021-02-27 20:43:22 +01:00

565 lines
8.4 KiB
PHP

<?php
return [
[
0.025,
'2007-1-1',
'2007-1-10',
0,
],
[
0.025,
'2007-1-10',
'2007-1-1',
0,
],
[
0.024657534246580001,
'2007-1-1',
'2007-1-10',
1,
],
[
0.025,
'2007-1-1',
'2007-1-10',
2,
],
[
0.024657534246580001,
'2007-1-1',
'2007-1-10',
3,
],
[
0.025,
'2007-1-1',
'2007-1-10',
4,
],
[
1.0,
'2007-1-1',
'2007-12-31',
0,
],
[
0.99726027397259998,
'2007-1-1',
'2007-12-31',
1,
],
[
1.01111111111111,
'2007-1-1',
'2007-12-31',
2,
],
[
0.99726027397259998,
'2007-1-1',
'2007-12-31',
3,
],
[
0.99722222222222001,
'2007-1-1',
'2007-12-31',
4,
],
[
1.5,
'2007-1-1',
'2008-7-1',
0,
],
[
1.49658002735978,
'2007-1-1',
'2008-7-1',
1,
],
[
1.5194444444444399,
'2007-1-1',
'2008-7-1',
2,
],
[
1.4986301369863,
'2007-1-1',
'2008-7-1',
3,
],
[
1.5,
'2007-1-1',
'2008-7-1',
4,
],
[
0.083333333333329998,
'2007-1-1',
'2007-1-31',
0,
],
[
0.082191780821919996,
'2007-1-1',
'2007-1-31',
1,
],
[
0.083333333333329998,
'2007-1-1',
'2007-1-31',
2,
],
[
0.082191780821919996,
'2007-1-1',
'2007-1-31',
3,
],
[
0.080555555555560002,
'2007-1-1',
'2007-1-31',
4,
],
[
0.083333333333329998,
'2007-1-1',
'2007-2-1',
0,
],
[
0.084931506849319993,
'2007-1-1',
'2007-2-1',
1,
],
[
0.08611111111111,
'2007-1-1',
'2007-2-1',
2,
],
[
0.084931506849319993,
'2007-1-1',
'2007-2-1',
3,
],
[
0.083333333333329998,
'2007-1-1',
'2007-2-1',
4,
],
[
0.15833333333333,
'2007-1-1',
'2007-2-28',
0,
],
[
0.15890410958904,
'2007-1-1',
'2007-2-28',
1,
],
[
0.16111111111111001,
'2007-1-1',
'2007-2-28',
2,
],
[
0.15890410958904,
'2007-1-1',
'2007-2-28',
3,
],
[
0.15833333333333,
'2007-1-1',
'2007-2-28',
4,
],
[
0.0027777777777800001,
'2007-1-31',
'2007-2-1',
0,
],
[
0.0027397260273999999,
'2007-1-31',
'2007-2-1',
1,
],
[
0.0027777777777800001,
'2007-1-31',
'2007-2-1',
2,
],
[
0.0027397260273999999,
'2007-1-31',
'2007-2-1',
3,
],
[
0.0027777777777800001,
'2007-1-31',
'2007-2-1',
4,
],
[
0.08611111111111,
'2007-1-31',
'2007-3-1',
0,
],
[
0.07945205479452,
'2007-1-31',
'2007-3-1',
1,
],
[
0.080555555555560002,
'2007-1-31',
'2007-3-1',
2,
],
[
0.07945205479452,
'2007-1-31',
'2007-3-1',
3,
],
[
0.08611111111111,
'2007-1-31',
'2007-3-1',
4,
],
[
0.16666666666666999,
'2007-1-31',
'2007-3-31',
0,
],
[
0.16164383561644,
'2007-1-31',
'2007-3-31',
1,
],
[
0.16388888888889,
'2007-1-31',
'2007-3-31',
2,
],
[
0.16164383561644,
'2007-1-31',
'2007-3-31',
3,
],
[
0.16666666666666999,
'2007-1-31',
'2007-3-31',
4,
],
[
0.66666666666666996,
'2008-1-1',
'2008-9-1',
0,
],
[
0.66666666666666996,
'2008-1-1',
'2008-9-1',
1,
],
[
0.67777777777778003,
'2008-1-1',
'2008-9-1',
2,
],
[
0.66849315068492998,
'2008-1-1',
'2008-9-1',
3,
],
[
0.66666666666666996,
'2008-1-1',
'2008-9-1',
4,
],
[
1.1666666666666701,
'2007-2-1',
'2008-4-1',
0,
],
[
1.16279069767442,
'2007-2-1',
'2008-4-1',
1,
],
[
1.18055555555556,
'2007-2-1',
'2008-4-1',
2,
],
[
1.16438356164384,
'2007-2-1',
'2008-4-1',
3,
],
[
1.1666666666666701,
'2007-2-1',
'2008-4-1',
4,
],
[
47.524999999999999,
'1960-12-19',
'2008-6-28',
0,
],
[
47.52162252765670,
'1960-12-19',
'2008-6-28',
1,
],
[
48.216666666666697,
'1960-12-19',
'2008-6-28',
2,
],
[
47.556164383561601,
'1960-12-19',
'2008-6-28',
3,
],
[
47.524999999999999,
'1960-12-19',
'2008-6-28',
4,
],
[
25.558333333333302,
'1982-12-7',
'2008-6-28',
0,
],
[
25.5571892111134,
'1982-12-7',
'2008-6-28',
1,
],
[
25.9305555555556,
'1982-12-7',
'2008-6-28',
2,
],
[
25.575342465753401,
'1982-12-7',
'2008-6-28',
3,
],
[
25.558333333333302,
'1982-12-7',
'2008-6-28',
4,
],
[
0.163934426,
'1960-01-01',
'1960-03-01',
1,
],
[
0.161643836,
'1961-01-01',
'1961-03-01',
1,
],
[
0.161643836,
'1963-03-01',
'1963-01-01',
1,
],
[
1.086183311,
'1960-01-01',
'1961-02-01',
1,
],
[
1.084931507,
'1961-01-01',
'1962-02-01',
1,
],
[
1.083447332,
'1963-01-01',
'1964-02-01',
1,
],
[
1.162790698,
'1963-01-01',
'1964-03-01',
1,
],
[
0.841530055,
'2020-02-28',
'2021-01-01',
1,
],
[
0.764383562,
'2020-03-28',
'2021-01-01',
1,
],
[
0.841530055,
'2023-04-28',
'2024-03-01',
1,
],
[
0.838797814,
'2023-04-28',
'2024-02-29',
1,
],
[
0.838356164,
'2023-04-28',
'2024-02-28',
1,
],
[
0.753424658,
'2023-04-28',
'2024-01-28',
1,
],
[
0.753424658,
'2022-04-28',
'2023-01-28',
1,
],
[
1.0,
'2020-01-01',
'2021-01-01',
1,
],
[
0.99726776,
'2020-02-28',
'2021-02-27',
1,
],
[
0.764383562,
'2020-03-28',
'2021-01-01',
1,
],
[
0.841530055,
'2023-04-28',
'2024-03-01',
1,
],
[
0.838797814,
'2023-04-28',
'2024-02-29',
1,
],
[
0.838356164,
'2023-04-28',
'2024-02-28',
1,
],
[
0.753424658,
'2023-04-28',
'2024-01-28',
1,
],
[
0.753424658,
'2022-04-28',
'2023-01-28',
1,
],
[
1.082191781,
'2022-04-28',
'2023-05-28',
1,
],
[
1.002739726,
'2022-04-27',
'2023-04-28',
1,
],
[
0.084699454,
'2024-04-27',
'2024-05-28',
1,
],
[
0.084931507,
'2023-04-27',
'2023-05-28',
1,
],
[
2.085766423,
'2023-04-27',
'2025-05-28',
1,
],
['#VALUE!', '2023-04-27', 'ABQZ', 1],
['#VALUE!', 'ABQZ', '2023-04-07', 1],
];