Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Clock Laravel Package

lcobucci/clock

PSR-20 clock implementation for PHP. Provides a simple, testable way to access the current time with interchangeable clocks like system and frozen clocks, making time-dependent code predictable and easy to unit test.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit: Laravel's dependency injection container aligns perfectly with the Clock abstraction. The interface-based design allows seamless binding of SystemClock in production and FixedClock in tests via service providers, eliminating direct DateTimeImmutable usage in domain logic. This promotes clean architecture and testability while respecting Laravel's existing DI patterns.

Integration feasibility: High. The package is PSR-compliant and framework-agnostic, requiring only minimal Laravel-specific setup (e.g., binding in AppServiceProvider). Existing Laravel time helpers like now() can be wrapped to use the Clock instance without major refactoring. Composer integration is trivial.

Technical risk: Low. Minimal dependencies, small codebase (<100 LOC), and active maintenance (despite the 2025 release date anomaly). Primary risks include timezone handling inconsistencies (the Clock interface doesn't enforce timezones) and legacy code refactoring complexity where DateTimeImmutable is deeply embedded.

Key questions:

  • How to handle timezone consistency across environments when the Clock interface doesn't natively manage timezones?
  • What is the migration path for legacy code using Carbon or DateTimeImmutable directly without breaking existing functionality?
  • Does the package integrate smoothly with Laravel's built-in time testing helpers (e.g., travelTo), or require custom implementations?

Integration Approach

Stack fit: Ideal for Laravel's DI-driven architecture. The Clock interface can be bound to the container with minimal code (e.g., bind(Clock::class, fn() => new SystemClock())), and Laravel's now() helper can be overridden to use the injected Clock instance. Carbon compatibility is maintained by constructing Carbon objects from Clock's DateTimeImmutable outputs.

Migration path:

  1. Phase 1: Create a service provider to bind Clock to SystemClock in production and FixedClock in tests. Wrap Laravel's now() helper to use the Clock instance.
  2. Phase 2: Refactor new features to depend on Clock via constructor/method injection.
  3. Phase 3: Gradually replace DateTimeImmutable in legacy code (prioritizing time-sensitive logic like scheduling, expiration checks, and analytics).
  4. Phase 4: Replace time(), strtotime(), and Carbon direct
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport