Carbon Console
Convert timezones and formats with [Carbon][18] wrapped in a PHP7 command line
symfony console application., (*1)
, (*2)
Installation
First make sure you have at least PHP 7 installed.
Then, there are multiple ways to install. Choose the one best for you:, (*3)
Phive
The most preferred method of installation is to use [phive][21].
This avoids dependency conflicts between tools using
different versions of libraries (like Carbon or Symfony Console)., (*4)
Install to some directory that's in your PATH
such as ~/bin
or /usr/local/bin
, (*5)
phive install carbon --target ~/bin
This creates phive.xml
in your current directory.
If you're into versioning your dotfiles, consider creating a symlink to this., (*6)
Then you'll be able to easily update when new versions are released., (*7)
phive update
Download
Download the latest phar release, set it executable,
and move it to a good PATH
, (*8)
Here's a oneline sudo
command to make it available system-wide:, (*9)
curl -sSL https://github.com/jpuck/carbon-console/releases/latest | egrep -o '/jpuck/carbon-console/releases/download/[0-9\.]*/carbon-console.phar"' | head -c-2 | wget --base=https://github.com/ -i - -O carbon && chmod +x carbon && sudo mv carbon /usr/local/bin/
If you don't have sudo
privileges, then you can omit the last part
sudo mv carbon /usr/local/bin/
and just save it somewhere in your user's PATH
such as ~/bin
or simply execute it verbosely with the PHP CLI., (*10)
php carbon-console.phar
Composer
[Registered on packagist][22] for installation using [composer][23]., (*11)
composer global require jpuck/carbon-console
Make sure your PATH
contains the [global bin directory][24] which you can find:, (*12)
composer global config bin-dir --absolute
You can then [add that location to your shell profile or rc so that it's always available][25].
For example, if you're running Ubuntu 16.04 with bash, then this might work:, (*13)
echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc
NOTE that you will probably have to contend with a dependency conflict
sooner or later with each additional package you install.
This is why phive is preferred., (*14)
Source
git clone https://github.com/jpuck/carbon-console.git
cd carbon-console
composer install
./bin/carbon
Usage
After installing, run the list
command to see a list of commands:, (*15)
carbon list
Use the help
command to get help with any command's usage:, (*16)
carbon help convert
The primary command is convert
which defaults input time now and output timezone local., (*17)
Usage:
convert [-o|--timezone-out [TIMEZONE-OUT]] [-f|--format-out [FORMAT-OUT]] [--] [<time-in>]...
See the documentation for a list of supported input formats for
[date, time][19], and [timezones][17]. Also see available [output formats][20]., (*18)
Examples
For the following examples, my system's local timezone is set to UTC., (*19)
When it's 8:00AM in Chicago, what time will it be here?, (*20)
carbon convert 8:00AM America/Chicago
2017-02-16T14:00:00+00:00 UTC
It's 5:18PM here, so what time is it in Casey Station?, (*21)
carbon convert -o Antarctica/Casey
2017-02-17T04:18:12+11:00 Antarctica/Casey
When it's 6:00PM here, what time will it be in Casey Station?, (*22)
carbon convert 6:00PM -o Antarctica/Casey
2017-02-17T05:00:00+11:00 Antarctica/Casey
When it's 6:00PM in Chicago, what time will it be in Casey Station?, (*23)
carbon convert 6:00PM America/Chicago -o Antarctica/Casey
2017-02-17T11:00:00+11:00 Antarctica/Casey
Let's format that output as 12-hour:minute, (*24)
carbon convert 6:00PM America/Chicago -o Antarctica/Casey -f h:iA
11:00AM
If you use spaces in your format, make sure to quote the argument., (*25)
carbon convert 6:00PM America/Chicago -o Antarctica/Casey -f 'h:iA l, F j'
11:00AM Friday, February 17