composer package updates
[openemr.git] / vendor / nesbot / carbon / readme.md
blob5e9d1ccbcd80ecca4dd4cc674a7a4a7ae0d1fb64
1 # Carbon
3 [![Latest Stable Version](https://poser.pugx.org/nesbot/carbon/v/stable.png)](https://packagist.org/packages/nesbot/carbon)
4 [![Total Downloads](https://poser.pugx.org/nesbot/carbon/downloads.png)](https://packagist.org/packages/nesbot/carbon)
5 [![Build Status](https://travis-ci.org/briannesbitt/Carbon.svg?branch=master)](https://travis-ci.org/briannesbitt/Carbon)
6 [![StyleCI](https://styleci.io/repos/5724990/shield?style=flat)](https://styleci.io/repos/5724990)
7 [![codecov.io](https://codecov.io/github/briannesbitt/Carbon/coverage.svg?branch=master)](https://codecov.io/github/briannesbitt/Carbon?branch=master)
8 [![PHP-Eye](https://php-eye.com/badge/nesbot/carbon/tested.svg?style=flat)](https://php-eye.com/package/nesbot/carbon)
9 [![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat)](https://github.com/phpstan/phpstan)
11 A simple PHP API extension for DateTime. [http://carbon.nesbot.com](http://carbon.nesbot.com)
13 ```php
14 use Carbon\Carbon;
16 printf("Right now is %s", Carbon::now()->toDateTimeString());
17 printf("Right now in Vancouver is %s", Carbon::now('America/Vancouver'));  //implicit __toString()
18 $tomorrow = Carbon::now()->addDay();
19 $lastWeek = Carbon::now()->subWeek();
20 $nextSummerOlympics = Carbon::createFromDate(2016)->addYears(4);
22 $officialDate = Carbon::now()->toRfc2822String();
24 $howOldAmI = Carbon::createFromDate(1975, 5, 21)->age;
26 $noonTodayLondonTime = Carbon::createFromTime(12, 0, 0, 'Europe/London');
28 $internetWillBlowUpOn = Carbon::create(2038, 01, 19, 3, 14, 7, 'GMT');
30 // Don't really want this to happen so mock now
31 Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1));
33 // comparisons are always done in UTC
34 if (Carbon::now()->gte($internetWillBlowUpOn)) {
35     die();
38 // Phew! Return to normal behaviour
39 Carbon::setTestNow();
41 if (Carbon::now()->isWeekend()) {
42     echo 'Party!';
44 echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago'
46 // ... but also does 'from now', 'after' and 'before'
47 // rolling up to seconds, minutes, hours, days, months, years
49 $daysSinceEpoch = Carbon::createFromTimestamp(0)->diffInDays();
50 ```
52 ## Installation
54 ### With Composer
56 ```
57 $ composer require nesbot/carbon
58 ```
60 ```json
62     "require": {
63         "nesbot/carbon": "~1.21"
64     }
66 ```
68 ```php
69 <?php
70 require 'vendor/autoload.php';
72 use Carbon\Carbon;
74 printf("Now: %s", Carbon::now());
75 ```
77 <a name="install-nocomposer"/>
79 ### Without Composer
81 Why are you not using [composer](http://getcomposer.org/)? Download [Carbon.php](https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Carbon.php) from the repo and save the file into your project path somewhere.
83 ```php
84 <?php
85 require 'path/to/Carbon.php';
87 use Carbon\Carbon;
89 printf("Now: %s", Carbon::now());
90 ```
92 ## Docs
94 [http://carbon.nesbot.com/docs](http://carbon.nesbot.com/docs)