You are here

public static function Carbon::setTestNow in Persian Date for Drupal 8 8.4

Set a Carbon instance (real or mock) to be returned when a "now" instance is created. The provided instance will be returned specifically under the following conditions:

  • A call to the static now() method, ex. Carbon::now()
  • When a null (or blank string) is passed to the constructor or parse(), ex. new Carbon(null)
  • When the string "now" is passed to the constructor or parse(), ex. new Carbon('now')
  • When a string containing the desired time is passed to Carbon::parse().

Note the timezone parameter was left out of the examples above and has no affect as the mock value will be returned regardless of its value.

To clear the test instance call this method using the default parameter of null.

Parameters

\Drupal\persian_date\Library\Carbon\Carbon|string|null $testNow:

File

src/Library/Carbon/Carbon.php, line 1044

Class

Carbon
A simple API extension for DateTime

Namespace

Drupal\persian_date\Library\Carbon

Code

public static function setTestNow($testNow = null) {
  static::$testNow = is_string($testNow) ? static::parse($testNow) : $testNow;
}