dcarbone/gotime
Go-inspired time utilities for PHP 8.1+: a Duration type (parse/format like 5s, JSON as nanoseconds) plus helpers to generate DateInterval specs for DateTime add/sub. Includes a Time wrapper around DateTime aiming for Go time.Time-style APIs.
5s → 5000000000 nanos). Critical for microservices exchanging time intervals (e.g., job delays, rate limits).DateInterval with nanosecond-backed durations, ensuring accurate logging of transaction latencies (e.g., "payment processed in 123ms").Time::Now().Add(Duration::Parse('1h'))), reducing context-switching costs.DateInterval usage in favor of gotime::Duration for new features (e.g., scheduling, time-based validations).Adopt if:
DateInterval’s microsecond gaps are unacceptable.time package and want to reduce cognitive load when switching to PHP.Avoid if:
CarbonInterval, CarbonPeriod, Laravel integrations). The dual-maintenance cost may outweigh benefits.DateTime limits (this package uses nanoseconds internally but delegates arithmetic to DateTime).5s in UTC but apply to a local timezone"). This package treats durations as timezone-agnostic.spatie/schedule or Laravel’s built-in scheduler instead.Look Elsewhere if:
spatie/calendar or Carbon’s modify().DateTime, which may introduce overhead.For Executives:
"This package lets us write time-sensitive logic in PHP as cleanly as Go—critical for our [X Initiative] where we’re integrating Go and PHP microservices. For example, instead of manually calculating (60 * 60 * 1000) for milliseconds, we’ll parse durations like 30m or 2.5h in a single line, reducing bugs in scheduling and payment workflows. It’s a low-risk upgrade (MIT license, minimal dependencies) that aligns with our goal to [reduce technical debt/improve developer velocity]. The nanosecond precision also ensures we meet compliance requirements for audit logs in [Y Regulation]."
For Engineers: *"Gotime solves three key pain points:
DateInterval::createFromDateString('5 seconds')—just Duration::Parse('5s').time package, this feels familiar (e.g., Time::Now().Add(Duration::Parse('1h'))).Tradeoffs:
Time class is in beta, so we’d avoid it for now and focus on Duration.Proposal: Let’s pilot it in [Z Service] where we’re hitting time-parsing edge cases. If successful, we can phase it into new features and gradually replace DateInterval usages."*
For Product Managers: *"This package enables us to:
Example: For our [Payment Processing] feature, we’d replace:
// Before (error-prone)
$delay = DateInterval::createFromDateString('1 minute');
with:
// After (explicit, precise)
$delay = Time::ParseDuration('1m')->DateInterval();
This reduces ambiguity and aligns with our Go backend’s time handling."*
How can I help you explore Laravel packages today?