Fix unit tests for WEEKNUM()
This commit is contained in:
parent
10da9b3620
commit
23fbc845dd
|
@ -1242,10 +1242,14 @@ class DateTime
|
||||||
$PHPDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($dateValue);
|
$PHPDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($dateValue);
|
||||||
$dayOfYear = $PHPDateObject->format('z');
|
$dayOfYear = $PHPDateObject->format('z');
|
||||||
$PHPDateObject->modify('-' . $dayOfYear . ' days');
|
$PHPDateObject->modify('-' . $dayOfYear . ' days');
|
||||||
$dow = $PHPDateObject->format('w');
|
$firstDayOfFirstWeek = $PHPDateObject->format('w');
|
||||||
$daysInFirstWeek = 7 - (($dow + (2 - $method)) % 7);
|
$daysInFirstWeek = (6 - $firstDayOfFirstWeek + $method) % 7;
|
||||||
$dayOfYear -= $daysInFirstWeek;
|
$interval = $dayOfYear - $daysInFirstWeek;
|
||||||
$weekOfYear = ceil($dayOfYear / 7) + 1;
|
$weekOfYear = floor($interval / 7) + 1;
|
||||||
|
|
||||||
|
if ($daysInFirstWeek) {
|
||||||
|
++$weekOfYear;
|
||||||
|
}
|
||||||
|
|
||||||
return (int) $weekOfYear;
|
return (int) $weekOfYear;
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,12 +140,9 @@ class DateTimeTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerWEEKNUM
|
* @dataProvider providerWEEKNUM
|
||||||
* @group fail19
|
|
||||||
*/
|
*/
|
||||||
public function testWEEKNUM()
|
public function testWEEKNUM()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('TODO: This test should be fixed');
|
|
||||||
|
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$expectedResult = array_pop($args);
|
$expectedResult = array_pop($args);
|
||||||
$result = call_user_func_array([DateTime::class, 'WEEKOFYEAR'], $args);
|
$result = call_user_func_array([DateTime::class, 'WEEKOFYEAR'], $args);
|
||||||
|
|
|
@ -6,14 +6,54 @@ return [
|
||||||
1,
|
1,
|
||||||
52,
|
52,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'2000-01-01',
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'2000-01-02',
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'2000-01-01',
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'2000-01-03',
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'1995-01-01',
|
'1995-01-01',
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'1995-01-07',
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'1995-01-08',
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'1995-01-01',
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'1995-01-02',
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'3/7/1977',
|
'3/7/1977',
|
||||||
27,
|
28,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'3/7/1977',
|
'3/7/1977',
|
||||||
|
|
Loading…
Reference in New Issue