Fix unit tests for WEEKNUM()

This commit is contained in:
Adrien Crivelli 2016-10-01 22:27:41 +09:00
parent 10da9b3620
commit 23fbc845dd
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
3 changed files with 49 additions and 8 deletions

View File

@ -1242,10 +1242,14 @@ class DateTime
$PHPDateObject = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($dateValue);
$dayOfYear = $PHPDateObject->format('z');
$PHPDateObject->modify('-' . $dayOfYear . ' days');
$dow = $PHPDateObject->format('w');
$daysInFirstWeek = 7 - (($dow + (2 - $method)) % 7);
$dayOfYear -= $daysInFirstWeek;
$weekOfYear = ceil($dayOfYear / 7) + 1;
$firstDayOfFirstWeek = $PHPDateObject->format('w');
$daysInFirstWeek = (6 - $firstDayOfFirstWeek + $method) % 7;
$interval = $dayOfYear - $daysInFirstWeek;
$weekOfYear = floor($interval / 7) + 1;
if ($daysInFirstWeek) {
++$weekOfYear;
}
return (int) $weekOfYear;
}

View File

@ -140,12 +140,9 @@ class DateTimeTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerWEEKNUM
* @group fail19
*/
public function testWEEKNUM()
{
$this->markTestIncomplete('TODO: This test should be fixed');
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([DateTime::class, 'WEEKOFYEAR'], $args);

View File

@ -6,14 +6,54 @@ return [
1,
52,
],
[
'2000-01-01',
1,
1,
],
[
'2000-01-02',
1,
2,
],
[
'2000-01-01',
2,
1,
],
[
'2000-01-03',
2,
2,
],
[
'1995-01-01',
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',
27,
28,
],
[
'3/7/1977',