Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated readme

  • Loading branch information...
commit 47c879bdcf473b893995c729c58080a3be349d0f 1 parent ad97e34
@nicholas-eden authored
Showing with 31 additions and 7 deletions.
  1. +19 −7 readme.md
  2. +12 −0 readme.src.md
View
26 readme.md
@@ -177,13 +177,13 @@ To accompany `now()`, a few other static instantiation helpers exist to create w
```php
$now = Carbon::now();
-echo $now; // 2013-08-21 00:33:54
+echo $now; // 2013-09-05 23:34:13
$today = Carbon::today();
-echo $today; // 2013-08-21 00:00:00
+echo $today; // 2013-09-05 00:00:00
$tomorrow = Carbon::tomorrow('Europe/London');
-echo $tomorrow; // 2013-08-22 00:00:00
+echo $tomorrow; // 2013-09-07 00:00:00
$yesterday = Carbon::yesterday();
-echo $yesterday; // 2013-08-20 00:00:00
+echo $yesterday; // 2013-09-04 00:00:00
```
The next group of static helpers are the `createXXX()` helpers. Most of the static `create` functions allow you to provide as many or as few arguments as you want and will provide default values for all others. Generally default values are the current date, time or timezone. Higher values will wrap appropriately but invalid values will throw an `InvalidArgumentException` with an informative message. The message is obtained from an [DateTime::getLastErrors()](http://php.net/manual/en/datetime.getlasterrors.php) call.
@@ -261,7 +261,7 @@ echo Carbon::parse('now'); // 2001-05-21 12:00:00
var_dump(Carbon::hasTestNow()); // bool(true)
Carbon::setTestNow(); // clear the mock
var_dump(Carbon::hasTestNow()); // bool(false)
-echo Carbon::now(); // 2013-08-21 00:33:54
+echo Carbon::now(); // 2013-09-05 23:34:13
```
A more meaning full example:
@@ -296,6 +296,18 @@ echo $product->getPrice(); // 100
Carbon::setTestNow();
```
+Relative phrases are also mocked according to the given "now" instance.
+
+```php
+$knownDate = Carbon::create(2001, 5, 21, 12); // create testing date
+Carbon::setTestNow($knownDate); // set the mock
+echo new Carbon('tomorrow'); // 2001-05-21 12:00:00
+echo new Carbon('yesterday'); // 2001-05-21 12:00:00
+echo new Carbon('next wednesday'); // 2001-05-21 12:00:00
+echo new Carbon('last friday'); // 2001-05-21 12:00:00
+echo new Carbon('this thursday'); // 2001-05-21 12:00:00
+```
+
<a name="api-getters"/>
### Getters
@@ -316,7 +328,7 @@ var_dump($dt->dayOfYear); // int(248)
var_dump($dt->weekOfYear); // int(36)
var_dump($dt->daysInMonth); // int(30)
var_dump($dt->timestamp); // int(1346901971)
-var_dump(Carbon::createFromDate(1975, 5, 21)->age); // int(38) calculated vs now in the same tz
+var_dump(Carbon::createFromDate(1975, 5, 21)->age); // int(25) calculated vs now in the same tz
var_dump($dt->quarter); // int(3)
// Returns an int of seconds difference from UTC (+/- sign included)
@@ -414,7 +426,7 @@ Unfortunately the base class DateTime does not have any localization support. T
```php
setlocale(LC_TIME, 'German');
-echo $dt->formatLocalized('%A %d %B %Y'); // Donnerstag 25 Dezember 1975
+echo $dt->formatLocalized('%A %d %B %Y'); // Thursday 25 December 1975
setlocale(LC_TIME, '');
echo $dt->formatLocalized('%A %d %B %Y'); // Thursday 25 December 1975
```
View
12 readme.src.md
@@ -306,6 +306,18 @@ $product = new SeasonalProduct(100);
{{::lint(Carbon::setTestNow();)}}
```
+Relative phrases are also mocked according to the given "now" instance.
+
+```php
+{{::lint($knownDate = Carbon::create(2001, 5, 21, 12);/*pad(54)*/)}} // create testing date
+{{::lint(Carbon::setTestNow($knownDate);/*pad(54)*/)}} // set the mock
+{{testaid1::exec(echo new Carbon('tomorrow');/*pad(54)*/)}} // {{testaid1_eval}}
+{{testaid2::exec(echo new Carbon('yesterday');/*pad(54)*/)}} // {{testaid2_eval}}
+{{testaid3::exec(echo new Carbon('next wednesday');/*pad(54)*/)}} // {{testaid3_eval}}
+{{testaid4::exec(echo new Carbon('last friday');/*pad(54)*/)}} // {{testaid4_eval}}
+{{testaid5::exec(echo new Carbon('this thursday');/*pad(54)*/)}} // {{testaid5_eval}}
+```
+
<a name="api-getters"/>
### Getters
Please sign in to comment.
Something went wrong with that request. Please try again.