Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow public use of modifyDays,Weeks, .. and allow negative amount #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
52 changes: 44 additions & 8 deletions src/ExpressiveDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,14 @@ public function minusDays($amount)
* @param bool $invert
* @return ExpressiveDate
*/
protected function modifyDays($amount, $invert = false)
public function modifyDays($amount, $invert = false)
{
if ($amount<0)
{
$amount=abs($amount);
$invert=true;
}

if ($this->isFloat($amount))
{
return $this->modifyHours($amount * 24, $invert);
Expand Down Expand Up @@ -393,8 +399,13 @@ public function minusMonths($amount)
* @param bool $invert
* @return ExpressiveDate
*/
protected function modifyMonths($amount, $invert = false)
public function modifyMonths($amount, $invert = false)
{
if ($amount<0)
{
$amount=abs($amount);
$invert=true;
}
if ($this->isFloat($amount))
{
return $this->modifyWeeks($amount * 4, $invert);
Expand Down Expand Up @@ -457,8 +468,13 @@ public function minusYears($amount)
* @param bool $invert
* @return ExpressiveDate
*/
protected function modifyYears($amount, $invert = false)
public function modifyYears($amount, $invert = false)
{
if ($amount<0)
{
$amount=abs($amount);
$invert=true;
}
if ($this->isFloat($amount))
{
return $this->modifyMonths($amount * 12, $invert);
Expand Down Expand Up @@ -521,8 +537,13 @@ public function minusHours($amount)
* @param bool $invert
* @return ExpressiveDate
*/
protected function modifyHours($amount, $invert = false)
public function modifyHours($amount, $invert = false)
{
if ($amount<0)
{
$amount=abs($amount);
$invert=true;
}
if ($this->isFloat($amount))
{
return $this->modifyMinutes($amount * 60, $invert);
Expand Down Expand Up @@ -585,8 +606,13 @@ public function minusMinutes($amount)
* @param bool $invert
* @return ExpressiveDate
*/
protected function modifyMinutes($amount, $invert = false)
public function modifyMinutes($amount, $invert = false)
{
if ($amount<0)
{
$amount=abs($amount);
$invert=true;
}
if ($this->isFloat($amount))
{
return $this->modifySeconds($amount * 60, $invert);
Expand Down Expand Up @@ -649,8 +675,13 @@ public function minusSeconds($amount)
* @param bool $invert
* @return ExpressiveDate
*/
protected function modifySeconds($amount, $invert = false)
public function modifySeconds($amount, $invert = false)
{
if ($amount<0)
{
$amount=abs($amount);
$invert=true;
}
$interval = new DateInterval("PT{$amount}S");

$this->modifyFromInterval($interval, $invert);
Expand Down Expand Up @@ -708,8 +739,13 @@ public function minusWeeks($amount)
* @param bool $invert
* @return ExpressiveDate
*/
protected function modifyWeeks($amount, $invert = false)
public function modifyWeeks($amount, $invert = false)
{
if ($amount<0)
{
$amount=abs($amount);
$invert=true;
}
if ($this->isFloat($amount))
{
return $this->modifyDays($amount * 7, $invert);
Expand Down Expand Up @@ -1304,4 +1340,4 @@ public function copy()
return clone $this;
}

}
}