Skip to content

Latest commit

 

History

History
74 lines (50 loc) · 1.67 KB

index.md

File metadata and controls

74 lines (50 loc) · 1.67 KB

Quick start

This extension adds support for creating date&time immutable objects.


Installation

The best way to install fastybird/datetime-factory is using Composer:

composer require fastybird/datetime-factory

After that, you have to register extension in config.neon.

extensions:
    fbDateTimeFactory: FastyBird\DateTimeFactory\DI\DateTimeFactoryExtension

Configuration

This extension has some configuration options:

fbDateTimeFactory:
    timeZone: Europe/Prague
    system: true # Use system clock
    frozen: unixtimestam or DateTimeInterface # Could be used in tests for easy date settings

Where:

  • timezone is string representation you custom time zone. Default value is UTC

Use DateTimeFactory

This extension register DateTimeFactory to you container. This service could be used in your presenters, controllers, models, etc.

use FastyBird\DateTimeFactory;

class YourCustomPresenter
{

    /** @var DateTimeFactory\Clock */
    private DateTimeFactory\Clock $dateTimeFactory;
    
    public function __construct(
        DateTimeFactory\Clock $dateTimeFactory
    ) {
        $this->dateTime = $dateTime;
    }

    public function actionSomethingToDo()
    {
        // your cool code here...

        $now = $this->dateTime->getNow();

        $article->setCreatedAt($now);

        // your cool code here...
    }
}

The only one method of factory: $dateTime->getNow() is returning immutable DateTime object.


Homepage http://www.fastybird.com and repository https://github.com/FastyBird/datetime-factory.