Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/Base/Date.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ public static function compare(Date $left, Date $right)

public static function getWeekCountInYear($year)
{
return date('W', mktime(0, 0, 0, 12, 31, $year));
$weekCount = date('W', mktime(0, 0, 0, 12, 31, $year));

if ($weekCount == '01') {
return date('W', mktime(0, 0, 0, 12, 24, $year));
} else {
return $weekCount;
}
}

public function __construct($date)
Expand Down
36 changes: 34 additions & 2 deletions test/core/DateTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function testDayDifference()

$left = Timestamp::create('2008-03-29 03:00:00');
$right = Timestamp::create('2008-03-30 03:00:00');

$this->dayDifferenceTest($left, $right, 1);

// unsolved giv's case
// $left = Timestamp::create('2008-10-25 03:00:00');
// $right = Timestamp::create('2008-10-26 02:59:00');
Expand All @@ -67,6 +67,38 @@ public function testDateComparsion()
return $this;
}

/**
* @test
**/
public function testWeekCount()
{
$weekCount = Date::getWeekCountInYear(2012);
$this->assertEquals($weekCount, 52, "Week count is incorrect");

$dateFromWeekNumberStamp = Date::makeFromWeek(5, 2012)->toStamp();
$expectedDate = Date::create('2012-01-30 00:00:00')->toStamp();
$this->assertEquals($dateFromWeekNumberStamp, $expectedDate, 'Creating date from week number is incorrect.');

$weekCount2009 = Date::getWeekCountInYear(2009);
$expectedCount2009 = 53;
$this->assertEquals($weekCount2009, $expectedCount2009, 'Week count for 2009 year is incorrect.');

$weekBegin2009Stamp = Date::makeFromWeek(53, 2009)->toStamp();
$expectedDate2009 = Date::create('2009-12-28 00:00:00')->toStamp();
$this->assertEquals($weekBegin2009Stamp, $expectedDate2009, 'Week 53 for 2009 starts with incorrect date.');

$this->
assertEquals(
Date::makeFromWeek(1,2010)->toStamp(),
Date::create('2010-01-04')->toStamp(),
'Week 1 for 2010 starts with incorrect date.'
);

$this->assertEquals(Date::getWeekCountInYear(1996), 52, 'Incorrect week count in 1996 year');

$this->assertEquals(Date::getWeekCountInYear(1976), 53, 'Incorrect week count in 1976 year');
}

public function testMakeFromWeek()
{
$this->makeFromWeekTest(Date::create('2009-12-28'));
Expand Down