PHPackages                             cmixin/season - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. cmixin/season

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cmixin/season
=============

Carbon mixin to handle business days and opening hours

1.0.0(2y ago)42.8k↓39.3%1MITPHPPHP &gt;=8.2CI passing

Since Jul 29Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/kylekatarnls/season)[ Packagist](https://packagist.org/packages/cmixin/season)[ Fund](https://opencollective.com/Carbon)[ Fund](https://tidelift.com/funding/github/packagist/nesbot/carbon)[ RSS](/packages/cmixin-season/feed)WikiDiscussions main Synced 2d ago

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

Season
======

[](#season)

[![Latest Stable Version](https://camo.githubusercontent.com/bec2c6e2436b4c193081d31badce0d2361792ba04a4a588440b45e149f423cbc/68747470733a2f2f706f7365722e707567782e6f72672f636d6978696e2f736561736f6e2f762f737461626c652e706e67)](https://packagist.org/packages/cmixin/season)[![GitHub Actions](https://github.com/kylekatarnls/business-time/workflows/Tests/badge.svg)](https://github.com/kylekatarnls/season/actions)[![Code Climate](https://camo.githubusercontent.com/c41c034aef8d00dc4a0775703a7028ba695a5d6ffae4aab3e9e057b394753913/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6b796c656b617461726e6c732f736561736f6e2f6261646765732f6770612e737667)](https://codeclimate.com/github/kylekatarnls/season)[![Test Coverage](https://camo.githubusercontent.com/1f7e11657376862b5e9b069ad6725cd9f773fa8b4c51cb3d8a3deb413bf51fa8/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6b796c656b617461726e6c732f736561736f6e2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/kylekatarnls/season/coverage)[![StyleCI](https://camo.githubusercontent.com/c8a3dc81712cc6ad01950ad9d8c2dfa645f5222d99a573d88a769a25e8157183/68747470733a2f2f7374796c6563692e696f2f7265706f732f3635353233393430372f736869656c643f6272616e63683d6d61696e267374796c653d666c6174)](https://styleci.io/repos/655239407)

`DateTime` modifiers such as `startOfSeason`, `isInSummer`

- `Season` can be used as a service which can work with any `DateTime` or `DateTimeImmutable` object or date strings (which includes any subclass such as `Carbon` or `Chronos`).
- Or it can be used as a mixin to call the methods directly on `Carbon` objects.
- Mixin get automatically enabled on Laravel if auto-discovery is on.

How to use
==========

[](#how-to-use)

The simple way
--------------

[](#the-simple-way)

```
(new \Season\Season)->isInSummer('2022-06-25')
(new \Season\Season)->isInSummer(new DateTimeImmutable('2022-06-25'))
(new \Season\Season)->isInSummer(Carbon::now())
```

Methods are available from the class `\Season\Season` which is cheap to create, so you can just call methods from a new class everytime.

As a good practice, it's recommended you import the class with `use Season\Season;`at the beginning of the file:

```
use Season\Season;

(new Season)->isInSummer('2022-06-25');
(new Season)->isInSummer(new DateTimeImmutable('2022-06-25'));
```

And also to keep the same instance to re-use multiple times:

```
use Season\Season;

$season = new Season();
$season->isInSummer('2022-06-25');
$season->isInSummer(new DateTimeImmutable('2022-06-25'));
```

As a service
------------

[](#as-a-service)

You can use dependency injection with your framework:

```
use Season\Season;
use Psr\Clock\ClockInterface;

class ProductController
{
    public function new(Season $season, ClockInterface $clock)
    {
        $seasonName = $season->getSeason($clock->now())->getName();
    }
}
```

With Laravel it will be provided by default.

With Symfony, you'll have to register `\Season\Season` as a service and so edit **config/services.yaml** the following way:

```
services:
    _defaults:
        # ensure you get the tag 'controller.service_arguments'
        # if you need services to be available as controller
        # methods arguments:
        tags: [ 'controller.service_arguments' ]

    # then add the class name as a service
    Season\Season:
```

Learn more from Symfony documentation: [Configuring Services in the Container](https://symfony.com/doc/current/service_container.html#creating-configuring-services-in-the-container)

As Carbon methods (mixin)
-------------------------

[](#as-carbon-methods-mixin)

```
use Carbon\Carbon;
use Cmixin\SeasonMixin;

// On Laravel, the mixin will be loaded by default.
// On other applications/framework, you can enable it with:
Carbon::mixin(SeasonMixin::class);

Carbon::parse('2022-06-25')->isInSummer();
```

You can use mixin on `CarbonImmutable`, `Carbon` or any of their subclasses.

Configuration
=============

[](#configuration)

Disable mixin in Laravel
------------------------

[](#disable-mixin-in-laravel)

If you use Laravel but don't want to enable `Season` mixin globally for `Carbon`, you can remove it from auto-discovery using:

```
"extra": {
    "laravel": {
        "dont-discover": [
            "cmixin/season"
        ]
    }
},
```

Customize days
--------------

[](#customize-days)

By default, `Season` is created with the following config:

```
[
    3  => 20, // spring
    6  => 21, // summer
    9  => 22, // fall
    12 => 21, // winter
]
```

mapping the month (as key) with the day (as value) for each season start.

But you can pass a custom config with other days as long as the keys remain.

```
use Season\Season;

$season = new Season([
    3  => 21, // spring
    6  => 21, // summer
    9  => 21, // fall
    12 => 21, // winter
]);
```

In Laravel, you can set the config in **config/season.php** which will apply to both the mixin and the service:

```
