papimod / date
Module Papi
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/papimod/date
Requires
- php: >=8.3.0
- papi/papi: ^2.1.0
- papimod/dotenv: ^2.1.0
Requires (Dev)
- phpunit/phpunit: ^12.4
- squizlabs/php_codesniffer: ^4.0
This package is auto-updated.
Last update: 2025-12-18 15:28:25 UTC
README
Description
Help defining the API date format with time zone in your papi.
Also provide a DateService class to convert dates.
Prerequisites Modules
Configuration
DATE_FORMAT (.ENV)
| Required | No |
| Type | string |
| Description | Global date format |
| Default | Y-m-d H:i:s |
DATE_TIMEZONE (.ENV)
| Required | No |
| Type | string |
| Description | Global timezone |
| Default | Europe/Paris |
Definitions
Usage
You can add the following options to your .env file:
DATE_FORMAT="Y-m-d H:i:s"
DATE_TIMEZONE="Europe/Paris"
Import the module when creating your application:
require __DIR__ . "/../vendor/autoload.php"; use Papi\PapiBuilder; use Papimod\Dotenv\DotEnvModule; use Papimod\Date\DateModule; use function DI\create; define("PAPI_DOTENV_DIRECTORY", __DIR__); # Optionnal define("PAPI_DOTENV_FILE", ".env"); # Optionnal $builder = new PapiBuilder(); $builder->setModule( DotEnvModule::class, DateModule::class ) ->build() ->run();
Use the dedicated service anywhere:
final class MyService { private readonly DateService $date_service; public function __construct(DateService $date_service) { $this->date_service = $date_service; } public getUTCNow(): string { $now = new DateTime(); return $this->date_service->format($now); } }