PHPackages                             railt/carbon-extension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. railt/carbon-extension

AbandonedArchivedLibrary[API Development](/categories/api)

railt/carbon-extension
======================

An extension that provides objects for working with a date and time using the Carbon library

1.3.1(7y ago)086MITPHPPHP ^7.1.3

Since Jun 4Pushed 7y ago1 watchersCompare

[ Source](https://github.com/railt/carbon-extension)[ Packagist](https://packagist.org/packages/railt/carbon-extension)[ Docs](http://railt.org)[ RSS](/packages/railt-carbon-extension/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

 [![Railt](https://camo.githubusercontent.com/0b50c2bf674e95ba4fc92f5ac922a73a5b58bf284e5b44808fe5e30c674b2ca5/68747470733a2f2f7261696c742e6f72672f696d616765732f6c6f676f2d6461726b2e737667)](https://camo.githubusercontent.com/0b50c2bf674e95ba4fc92f5ac922a73a5b58bf284e5b44808fe5e30c674b2ca5/68747470733a2f2f7261696c742e6f72672f696d616765732f6c6f676f2d6461726b2e737667)

 [![Travis CI](https://camo.githubusercontent.com/ab6c3f546e243c6996cfe431499795628e82baa879e62221a7772eb07da845a6/68747470733a2f2f7472617669732d63692e6f72672f7261696c742f636172626f6e2d657874656e73696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/railt/carbon-extension) [![StyleCI](https://camo.githubusercontent.com/ce69630ffa8fb58c0bb0b60e3652d0efd718ffe666d9b71580a03c58258ec254/68747470733a2f2f7374796c6563692e696f2f7265706f732f3133303336303739352f736869656c643f623d6d6173746572)](https://styleci.io/repos/130360795?branch=master) [![Code coverage](https://camo.githubusercontent.com/1d66c7cb65cd3b47cc686eefa187a1b38a0608dc92f0e0cc586839d5e976e844/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7261696c742f636172626f6e2d657874656e73696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/railt/carbon-extension/?branch=master) [![Scrutinizer CI](https://camo.githubusercontent.com/98f243f8e077e5064958100f640beabb432478e8ed26aa960b5d3df792e4e136/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7261696c742f636172626f6e2d657874656e73696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/railt/carbon-extension/?branch=master) [![Latest Stable Version](https://camo.githubusercontent.com/e0d58dc87314d17b32f2b36f5024b5277c0672c1d6c630ed9fd7e012891b3fa0/68747470733a2f2f706f7365722e707567782e6f72672f7261696c742f636172626f6e2d657874656e73696f6e2f76657273696f6e)](https://packagist.org/packages/railt/carbon-extension) [![Latest Unstable Version](https://camo.githubusercontent.com/882532d887747efdfd6a5466c3d34d46cdc706491c28f20b3b5c691dcce2702a/68747470733a2f2f706f7365722e707567782e6f72672f7261696c742f636172626f6e2d657874656e73696f6e2f762f756e737461626c65)](https://packagist.org/packages/railt/carbon-extension) [![License MIT](https://camo.githubusercontent.com/3715434e6eae33e5eba5b358841604cdf4a7a39ff3d33ace352a1bcf8bc2574c/68747470733a2f2f706f7365722e707567782e6f72672f7261696c742f636172626f6e2d657874656e73696f6e2f6c6963656e7365)](https://raw.githubusercontent.com/railt/carbon-extension/master/LICENSE)

Carbon Extension
================

[](#carbon-extension)

**Table of contents**

- [Installation](#installation)
    - [Laravel](#laravel)
    - [Symfony](#symfony)
- [Output](#output)
    - [Formats](#output-formats)
- [Input](#input)
    - [Formats](#input-formats)

Installation
------------

[](#installation)

- `composer require railt/carbon-extension`
- Add extension to your application:

```
$app = new Railt\Foundation\Application();

$app->extend(Railt\CarbonExtension\Extension::class); // Here
```

### Laravel

[](#laravel)

In that case, if you use [Laravel Service Provider](https://github.com/railt/laravel-provider)this extension can be added as follows:

Open the `railt.php` configuration file and add:

```
'extensions' => [
    // ...
    \Railt\CarbonExtension\Extension::class, // Here
]
```

### Symfony

[](#symfony)

In that case, if you use [Symfony Bundle](https://github.com/railt/symfony-bundle)this extension can be added as follows:

Open the `config.yml` configuration file and add:

```
railt:
    extensions:
        - Railt\CarbonExtension\Extension # Here
```

Output
------

[](#output)

You can use it within your types. After you add type `Carbon`, two optional arguments appear in the field which is defined by this type.

Those. Client will see the following scheme:

```
# Definition
type YourExampleType {
    id: ID!
    some: String!
    createdAt: Carbon!
}

# What the client will see
type YourExampleType {
    id: ID!
    some: String!
    createdAt(
        """
        An argument that provides a format of the given value that
        are contained in a CarbonFormat enumeration type.
        """
        format: CarbonFormat = RFC3339
    ): Carbon!
}
```

In order to correctly return data - just pass the date type.

> Note: The "createdAt" field should provide datetime compatible type, like:
>
> 1. DateTime object:
> 2. Carbon object:
> 3. String datetime format
> 4. Integer timestamp

```
public function resolver(): array
{
    return [
        'id'        => 42,
        'some'      => 'Example',
        'createdAt' => '2018-04-28T17:55:27+00:00', // Yesterday
    ];
}
```

The request might look like this:

```
{
    example {
        id
        some
        a: createdAt(format: COOKIE)
        b: createdAt(format: HUMAN_READABLE)
    }
}
```

The response is as follows:

```
{
    "example": {
        "id": 42,
        "some": "Example",
        "createdAt": "Saturday, 28-Apr-2018 17:55:27 GMT+0000",
        "a": "Saturday, 28-Apr-2018 17:55:27 GMT+0000",
        "b": "4 months ago"
    }
}
```

### Output formats

[](#output-formats)

The return value can correspond to one of the valid formats defined in the `CarbonFormat` enumeration. In order to specify what date format in the response you want to see - it should be passed as the value of the `format` argument.

```
{
    example {
        createdAt(format: COOKIE)
        # createdAt field date will return in the COOKIE format.
    }
}
```

Below is a list of valid `CarbonFormat` enum formats:

- **ISO8601** - ISO-8601 date format.

> Example: `2005-08-15T15:52:01+00:00`Note: This format is an alias of the RFC 3339 specification: ISO8601: RFC3339:

- **RFC822** - RFC 822 date format.

> Example: `Mon, 15 Aug 05 15:52:01 +0000`

- **RFC850** - RFC 850 date format.

> Example: `Monday, 15-Aug-05 15:52:01 UTC`

- **RFC1036** - RFC 1036 date format.

> Example: `Mon, 15 Aug 05 15:52:01 +0000`

- **RFC1123** - RFC 1123 date format.

> Example: `Mon, 15 Aug 2005 15:52:01 +0000`

- **RFC2822** - RFC 2822 date format.

> Example: `Mon, 15 Aug 2005 15:52:01 +0000`

- **RFC3339** - RFC 3339 date format.

> Example: `2005-08-15T15:52:01+00:00`Note: This format is an alias of the ISO-8601 specification: RFC3339: ISO8601:

- **RFC3339\_EXTENDED** - RFC 3339 date format. In contrast to the usual RFC3339 additionally contains milliseconds.

> Example: `2005-08-15T15:52:01.000+00:00`

- **RFC7231** - RFC 7231 date format.

> Example: `Mon, 15 Aug 2005 15:52:01 GMT`

- **COOKIE** - HTTP Cookies date format.

> Example: `Monday, 15-Aug-2005 15:52:01 UTC`

- **DATE\_TIME** - Simple DateTime format.

> Example: `2005-08-15 15:52:01`

- **DATE** - Simple Date format.

> Example: `2005-08-15`

- **TIME** - Simple Time format.

> Example: `15:52:01`

- **RSS** - RSS date format.

> Example: `Mon, 15 Aug 2005 15:52:01 +0000`

- **W3C** - World Wide Web Consortium date format.

> Example: `2005-08-15T15:52:01+00:00`

- **HUMAN\_READABLE** - Human readable string.

> Example: `2 days ago`

Input
-----

[](#input)

A scalar `Carbon` type can be passed as an argument to any field. In this case it will be coerced into `Carbon` PHP object.

```
# Definition
type Example {
    field(arg: Carbon!): String
}
```

```
// Resolver
// Note: "$arg" argument definition similar with "$input->get('arg')"
public function handle(\DateTimeInterface $arg)
{
    return $arg->format(\DateTime::RFC3339);
}
```

```
# Query
{
    field(arg: "now")
}
```

```
{
    "field": "2018-04-29T17:55:27+00:00"
}
```

### Input formats

[](#input-formats)

As the admissible input values, the [following formats](http://php.net/manual/en/datetime.formats.php) are allowed:

- [Time Formats](http://php.net/manual/en/datetime.formats.time.php)
- [Date Formats](http://php.net/manual/en/datetime.formats.date.php)
- [Compound Formats](http://php.net/manual/en/datetime.formats.compound.php)
- [Relative Formats](http://php.net/manual/en/datetime.formats.relative.php)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~224 days

Total

2

Last Release

2674d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Top Contributors

[![SerafimArts](https://avatars.githubusercontent.com/u/2461257?v=4)](https://github.com/SerafimArts "SerafimArts (15 commits)")

---

Tags

carbondatetime-formatextensionrailtgraphqldatetimetimedatecarbonextensionrailt

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/railt-carbon-extension/health.svg)

```
[![Health](https://phpackages.com/badges/railt-carbon-extension/health.svg)](https://phpackages.com/packages/railt-carbon-extension)
```

###  Alternatives

[jenssegers/date

A date library to help you work with dates in different languages

1.8k11.2M80](/packages/jenssegers-date)[carbonphp/carbon-doctrine-types

Types to use Carbon in Doctrine

213220.4M8](/packages/carbonphp-carbon-doctrine-types)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
