Skip to content

Commit

Permalink
the start of century of 2100 is 2001
Browse files Browse the repository at this point in the history
  • Loading branch information
omoon committed Jun 27, 2015
1 parent cb030f3 commit 6dcbe43
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Carbon/Carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ public function endOfDecade()
*/
public function startOfCentury()
{
return $this->startOfYear()->year($this->year - $this->year % static::YEARS_PER_CENTURY + 1);
return $this->startOfYear()->year(($this->year - 1) - ($this->year - 1) % static::YEARS_PER_CENTURY + 1);
}

/**
Expand All @@ -2296,7 +2296,7 @@ public function startOfCentury()
*/
public function endOfCentury()
{
return $this->endOfYear()->year($this->year - $this->year % static::YEARS_PER_CENTURY + static::YEARS_PER_CENTURY);
return $this->endOfYear()->year(($this->year - 1) - ($this->year - 1) % static::YEARS_PER_CENTURY + static::YEARS_PER_CENTURY);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/StartEndOfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ public function testStartOfCenturyFromNow()

public function testStartOfCenturyFromFirstDay()
{
$dt = Carbon::create(2000, 1, 1, 1, 1, 1)->startOfCentury();
$dt = Carbon::create(2001, 1, 1, 1, 1, 1)->startOfCentury();
$this->assertCarbon($dt, 2001, 1, 1, 0, 0, 0);
}

public function testStartOfCenturyFromLastDay()
{
$dt = Carbon::create(2009, 12, 31, 23, 59, 59)->startOfCentury();
$dt = Carbon::create(2100, 12, 31, 23, 59, 59)->startOfCentury();
$this->assertCarbon($dt, 2001, 1, 1, 0, 0, 0);
}

Expand All @@ -199,13 +199,13 @@ public function testEndOfCenturyFromNow()

public function testEndOfCenturyFromFirstDay()
{
$dt = Carbon::create(2000, 1, 1, 1, 1, 1)->endOfCentury();
$dt = Carbon::create(2001, 1, 1, 1, 1, 1)->endOfCentury();
$this->assertCarbon($dt, 2100, 12, 31, 23, 59, 59);
}

public function testEndOfCenturyFromLastDay()
{
$dt = Carbon::create(2099, 12, 31, 23, 59, 59)->endOfCentury();
$dt = Carbon::create(2100, 12, 31, 23, 59, 59)->endOfCentury();
$this->assertCarbon($dt, 2100, 12, 31, 23, 59, 59);
}

Expand Down

0 comments on commit 6dcbe43

Please sign in to comment.