- Does kdyby/datetime-provider work with Laravel out of the box?
- No. kdyby/datetime-provider is a Nette DI compiler extension, so Laravel's container has no automatic way to register or resolve its services. You would have to hand-write service provider bindings and effectively reimplement the Nette wiring yourself, at which point you are using only a small amount of vendor code. For a Laravel app, use Carbon's test helpers or a PSR-20 clock instead.
- How do I install kdyby/datetime-provider and what dependencies does it add?
- Running composer require kdyby/datetime-provider pulls in nette/di and likely nette/utils, importing a second, unrelated DI container into your dependency graph. The published constraints predate PHP 8.x, so expect to relax or fork them before it installs on modern PHP. The last tagged release was 2018-02-14, roughly seven years ago.
- How do I freeze or mock the current time in Laravel tests without this package?
- Laravel ships Illuminate\Support\Carbon::setTestNow(), plus travel(), travelTo() and freezeTime() on the test case. Calling Carbon::setTestNow('2024-01-01 00:00:00') freezes now globally for the request, and calling it with no argument resets it. That covers the frozen-clock use case this package was built for, with no extra dependency.
- What is PSR-20 and can I bind a clock service in a Laravel service provider?
- PSR-20 defines Psr\Clock\ClockInterface with a single now(): DateTimeImmutable method, and was ratified in 2023. You can bind Symfony\Component\Clock\Clock from symfony/clock to that interface in AppServiceProvider, then swap in MockClock or a frozen clock in tests. It is framework-agnostic, actively maintained, and already a transitive dependency in many Symfony and Laravel-adjacent stacks.
- Is kdyby/datetime-provider still maintained and does it support PHP 8?
- No. The last release is from February 2018, the php and nette/* constraints predate PHP 8, and the repository has around 10 stars with zero dependents. Runtime behavior on PHP 8.1 through 8.4 is unverified, so you would be validating and possibly patching it yourself. There is no issue history or community to fall back on if something breaks.
- What license does kdyby/datetime-provider use, and can I vendor it?
- Packagist and GitHub report NOASSERTION, meaning the license could not be classified automatically. Until someone reads the LICENSE file and legal signs off, treat it as all-rights-reserved: no redistribution and no vendoring into a proprietary repository. That alone often blocks adoption at larger companies.
- How do I keep one consistent timezone across a Laravel request?
- Laravel reads its default timezone from config/app.php via app.timezone and applies it to Carbon, so every Carbon::now() call in a request shares the same zone. If you need a per-request override, call date_default_timezone_set() early in middleware, or pass an explicit offset to Carbon::setTestNow() in tests. Storing timestamps in UTC and rendering in the user's zone is the usual pattern.
- When is a time provider abstraction actually worth adding to a Laravel app?
- A clock abstraction pays off when domain logic needs a deterministic notion of now, for example billing periods, trial expiries or scheduled reports you want to test without sleeping. In Laravel, Carbon::setTestNow() already gives you most of that inside tests, so a separate provider mainly helps when you need to inject clocks into plain PHP classes that are not test-case aware. If you go that route, bind PSR-20 rather than pulling in a Nette extension.
- Can I keep using Carbon alongside a clock abstraction?
- Yes. Carbon implements CarbonInterface and DateTimeInterface, and Carbon::now() respects the frozen time set by Carbon::setTestNow(). A PSR-20 clock can return CarbonImmutable::now() from its now() method, so domain code can depend on ClockInterface while the rest of the app keeps using Carbon. Avoid mixing raw new DateTime() calls with the injected clock, or you lose the consistency you added the abstraction for.
- What are the best alternatives to kdyby/datetime-provider for Laravel?
- For Laravel, the practical options are Carbon's built-in setTestNow, travel and freezeTime helpers, and PSR-20 via symfony/clock bound to Psr\Clock\ClockInterface in a service provider. If you want a ready-made contract plus a test double, a small SystemClock and FrozenClock pair wrapping Carbon is only a few dozen lines of code. The Kdyby package's only real advantage is its Nette integration, which is no advantage in a Laravel codebase.