Convert timezones and formats with Carbon wrapped in a PHP7 command line symfony console application.
PHP Shell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
src/Commands
tests
.gitattributes
.gitignore
.travis.yml
LICENSE.txt
README.md
composer.json
composer.lock
phpunit.xml.dist

README.md

Carbon Console

Convert timezones and formats with Carbon wrapped in a PHP7 command line symfony console application.

Build Status Codecov Latest Stable Version Total Downloads License

Installation

First make sure you have at least PHP 7 installed. Then, there are multiple ways to install. Choose the one best for you:

Phive

The most preferred method of installation is to use phive. This avoids dependency conflicts between tools using different versions of libraries (like Carbon or Symfony Console).

Install to some directory that's in your PATH such as ~/bin or /usr/local/bin

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.

Then you'll be able to easily update when new versions are released.

phive update

Download

Download the latest phar release, set it executable, and move it to a good PATH

Here's a oneline sudo command to make it available system-wide:

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.

php carbon-console.phar

Composer

Registered on packagist for installation using composer.

composer global require jpuck/carbon-console

Make sure your PATH contains the global bin directory which you can find:

composer global config bin-dir --absolute

You can then add that location to your shell profile or rc so that it's always available. For example, if you're running Ubuntu 16.04 with bash, then this might work:

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.

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:

carbon list

Use the help command to get help with any command's usage:

carbon help convert

The primary command is convert which defaults input time now and output timezone local.

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, and timezones. Also see available output formats.

Examples

For the following examples, my system's local timezone is set to UTC.

When it's 8:00AM in Chicago, what time will it be here?

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?

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?

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?

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

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.

carbon convert 6:00PM America/Chicago -o Antarctica/Casey -f 'h:iA l, F j'
11:00AM Friday, February 17