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.
DateInterval limitations.Time::Now().Add(Duration::Parse('5s'))) retain readability advantages.Time class stability: Likely resolves beta-era gaps (e.g., missing Format()), though changelog lacks specifics.Carbon::instance($gotime)).use DCarbone\Go\Time) persist as boilerplate.composer require dcarbone/gotime).DateTime interoperability.created_at/updated_at.0.05s parsing).mixed return types may still conflict with Laravel’s strict typing.Duration ↔ DateInterval conversions remain a concern but are now validated in production.@phpstan-ignore-line may still be needed, but reduced risk of breaking changes.gotime vs. Carbon for critical paths (e.g., Duration::add() in scheduling).gotime for internal calculations, Carbon for I/O (e.g., user-facing dates).Duration class if gotime proves unstable (e.g., for nanosecond precision).DateInterval edge cases (e.g., 24h + 1s) that need testing?Carbon to use gotime under the hood (e.g., via traits) to avoid duplication?spatie/calendar or custom Duration logic suffice for simpler cases?ramsey/uuid + Carbon a viable alternative for UUID-time hybrid use cases?Carbon facade (e.g., now(), parse())?gotime service provider or facade for Laravel?Carbon).gotime for internal time math (e.g., duration parsing, scheduling, rate limiting).Carbon for timezone-aware operations (e.g., now('Asia/Tokyo')).Duration as JSON nanos for consistency across microservices.BIGINT fields (e.g., duration_nanos).DateInterval in a single service (e.g., JobDispatcher or RateLimiter).// Before (DateInterval)
$interval = DateInterval::createFromDateString('5 seconds');
$job->delay($interval);
// After (gotime)
$duration = Time::ParseDuration('5s');
$job->delay($duration->DateInterval());
0.05s, 24h + 1s).TimeHelper trait to wrap gotime + Carbon:
trait TimeHelper {
public function parseDuration(string $str): Duration {
return Time::ParseDuration($str);
}
public function carbonNow(): Carbon {
return Carbon::now();
}
public function durationToCarbon(Duration $duration): Carbon {
return Carbon::now()->add($duration->DateInterval());
}
}
class SchedulerService {
use TimeHelper;
public function scheduleJob(Duration $duration) {
$carbonTime = $this->durationToCarbon($duration);
// Use Carbon for timezone-aware logic...
}
}
DateInterval usages with gotime in new features.// models/Job.php
public function getDurationAttribute(): Duration {
return Time::ParseDuration($this->attributes['duration']);
}
public function setDurationAttribute(Duration $duration): void {
$this->attributes['duration'] = $duration->String();
}
Duration serialization matches microservice expectations (e.g., JSON nanos).gotime; Laravel 9+ supports this.DateTime interoperability exists (e.g., Duration::DateInterval()).BIGINT (e.g., duration_nanos).Duration and stored values.gotime).0.05s).use DCarbone\Go\Time).AppServiceProvider.ParseDuration('5s')) in non-critical paths (e.g., logging, metrics).Time class until fully vetted (though v1.0 reduces risk).DateInterval in scheduling or rate limiting services.Duration ↔ DateInterval conversions under load.How can I help you explore Laravel packages today?