Skip to content

Commit fbc219d

Browse files
committed
Added randomly selected years for weekcount calculation. Fixed coding style.
1 parent 56e5844 commit fbc219d

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

core/Base/Date.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static function compare(Date $left, Date $right)
119119
public static function getWeekCountInYear($year)
120120
{
121121
$weekCount = date('W', mktime(0, 0, 0, 12, 31, $year));
122-
122+
123123
if ($weekCount == '01') {
124124
return date('W', mktime(0, 0, 0, 12, 24, $year));
125125
} else {

test/core/DateTest.class.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,9 @@ public function testDayDifference()
4141

4242
$left = Timestamp::create('2008-03-29 03:00:00');
4343
$right = Timestamp::create('2008-03-30 03:00:00');
44-
45-
$this->dayDifferenceTest($left, $right, 1);
4644

47-
$weekCount = Date::getWeekCountInYear(2012);
48-
$this->assertEquals($weekCount, 52, "Week count is incorrect");
45+
$this->dayDifferenceTest($left, $right, 1);
4946

50-
$dateFromWeekNumberStamp = Date::makeFromWeek(5, 2012)->toStamp();
51-
$expectedDate = Date::create('2012-01-30 00:00:00')->toStamp();
52-
$this->assertEquals($dateFromWeekNumberStamp, $expectedDate, 'Creating date from week number is incorrect.');
53-
5447
// unsolved giv's case
5548
// $left = Timestamp::create('2008-10-25 03:00:00');
5649
// $right = Timestamp::create('2008-10-26 02:59:00');
@@ -74,6 +67,38 @@ public function testDateComparsion()
7467
return $this;
7568
}
7669

70+
/**
71+
* @test
72+
**/
73+
public function testWeekCount()
74+
{
75+
$weekCount = Date::getWeekCountInYear(2012);
76+
$this->assertEquals($weekCount, 52, "Week count is incorrect");
77+
78+
$dateFromWeekNumberStamp = Date::makeFromWeek(5, 2012)->toStamp();
79+
$expectedDate = Date::create('2012-01-30 00:00:00')->toStamp();
80+
$this->assertEquals($dateFromWeekNumberStamp, $expectedDate, 'Creating date from week number is incorrect.');
81+
82+
$weekCount2009 = Date::getWeekCountInYear(2009);
83+
$expectedCount2009 = 53;
84+
$this->assertEquals($weekCount2009, $expectedCount2009, 'Week count for 2009 year is incorrect.');
85+
86+
$weekBegin2009Stamp = Date::makeFromWeek(53, 2009)->toStamp();
87+
$expectedDate2009 = Date::create('2009-12-28 00:00:00')->toStamp();
88+
$this->assertEquals($weekBegin2009Stamp, $expectedDate2009, 'Week 53 for 2009 starts with incorrect date.');
89+
90+
$this->
91+
assertEquals(
92+
Date::makeFromWeek(1,2010)->toStamp(),
93+
Date::create('2010-01-04')->toStamp(),
94+
'Week 1 for 2010 starts with incorrect date.'
95+
);
96+
97+
$this->assertEquals(Date::getWeekCountInYear(1996), 52, 'Incorrect week count in 1996 year');
98+
99+
$this->assertEquals(Date::getWeekCountInYear(1976), 53, 'Incorrect week count in 1976 year');
100+
}
101+
77102
public function testMakeFromWeek()
78103
{
79104
$this->makeFromWeekTest(Date::create('2009-12-28'));

0 commit comments

Comments
 (0)