Weave 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

lcobucci/clock is a lightweight clock abstraction for PHP that decouples code from DateTimeImmutable. Use SystemClock for real time or FrozenClock for tests, making time-dependent logic easy to control and verify.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Time-sensitive feature delivery: Supports features that depend on “now” — expirations, trial periods, retry windows, cache TTLs, scheduled actions, SLA timers, audit timestamps, and eligibility checks. The package makes the clock injectable rather than hidden inside new DateTimeImmutable() calls.
  • Roadmap sequencing: Treat this as infrastructure hygiene, not a customer-facing feature. It is most valuable before scaling time-dependent workflows or when flaky time-based tests slow releases.
  • Build vs. buy: Building a small Clock interface and frozen test clock is technically cheap, but this package provides a PSR-20-compatible abstraction, SystemClock, FrozenClock, named constructors, and time adjustment helpers. Buying is a low-cost, MIT-licensed way to avoid custom test utilities and reinforce standards.
  • Use cases to prioritize: adoption in shared libraries, JWT/token validation, subscription and billing logic, promotions, reservation systems, and any Laravel/PHP service where QA needs deterministic time. It is also useful when multiple teams need a common contract for “current time.”
  • Product risk reduction: Deterministic clocks reduce flaky tests and make edge cases reproducible — midnight boundaries, DST transitions, expired tokens, grace periods, and scheduled releases. That improves confidence in release decisions.

When to Consider This Package

  • Adopt when: the codebase instantiates DateTimeImmutable directly in business logic; tests use sleeps or real-time waiting; teams need PSR-20 interoperability; you maintain reusable PHP packages; or you already depend on libraries in the lcobucci ecosystem, such as JWT tooling.
  • Adopt when: you want explicit timezone behavior in production and a frozen clock in tests without introducing a large framework dependency.
  • Check PHP version first: recent releases track modern PHP. The 3.6 line requires PHP 8.4; earlier 3.x lines support older versions. Confirm the chosen version matches the platform’s PHP baseline.
  • Look elsewhere when: the product is a straightforward Laravel monolith already standardizing on Carbon and Laravel’s date test helpers, with no PSR-20 or package-interoperability requirement. Carbon is better for rich date manipulation, formatting, and human-readable date logic.
  • Look elsewhere when: you need a full scheduling system, timezone database management, calendar/business-day logic, or enterprise support. This package is intentionally small and does not provide those capabilities.
  • Dependency risk: it is a micro-dependency with a narrow API and MIT license, which limits lock-in. However, it is not a high-velocity feature package and should be treated as stable plumbing. Vet maintenance expectations against the team’s dependency policy, especially if the application requires long-term vendor support.

How to Pitch It (Stakeholders)

  • To executives: This is a small, low-cost, standards-aligned dependency that improves reliability of time-sensitive features and reduces flaky test cycles. It carries minimal lock-in, is MIT-licensed, and supports faster, more predictable releases without adding customer-facing complexity.
  • To engineering: It gives us a PSR-20 clock contract, a production SystemClock, and a FrozenClock for deterministic tests. We can inject time instead of hiding it in constructors, simulate expiry and grace-period behavior, and make timezone assumptions explicit. It is framework-agnostic and fits Laravel/PHP services without forcing a larger date library.
  • To product and QA: It enables reproducible tests for expirations, trials, retries, and scheduled behavior. We can validate boundary conditions — midnight, DST, token expiry — without waiting for real time to pass.
  • PM framing: Fund adoption as engineering hygiene in time-dependent areas, not as a standalone roadmap item. Success measures: fewer flaky time-based tests, faster test suites, fewer production incidents around expiry/scheduling, and clearer ownership of timezone behavior. Do not adopt it as a silver bullet for all date logic; pair it with Carbon or existing Laravel conventions where rich date manipulation is needed.
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.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console