/** * DateDiffCalculator that calculates diff to the past in one of the units: * - seconds * - minutes * - "yesterday" * - hours * - days * - weeks (up to 14 days) * - full date * * @return DateDiffCalculator */ public static function upTo2Weeks() { return self::getOrCreate('up-to-2-weeks', function () { return new DateDiffCalculator([RangeRule::createForNegativeValues(2 * DateUnits::WEEK, INF, function (DateDiffRequest $request) { return DateDiffResult::createFullDate($request); }), Rules::weeksAgo(), Rules::yesterday(), Rules::daysAgo(), Rules::hoursAgo(), Rules::minutesAgo(), Rules::secondsAgo()]); }); }
public function testCreatingForNegativeValues() { $condition = RangeRule::createForNegativeValues(10, 100, 'trim'); $this->assertTrue($condition->isApplicable($this->createRequestForSeconds(-10))); $this->assertTrue($condition->isApplicable($this->createRequestForSeconds(-100))); $this->assertTrue($condition->isApplicable($this->createRequestForSeconds(-50))); $this->assertFalse($condition->isApplicable($this->createRequestForSeconds(0))); $this->assertFalse($condition->isApplicable($this->createRequestForSeconds(-150))); $this->assertFalse($condition->isApplicable($this->createRequestForSeconds(-5))); }