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

Gotime Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strengths:
    • Stable v1.0 release: Mitigates risk of breaking changes, signaling maturity.
    • Go-like API consistency remains intact, reducing cognitive load for polyglot teams.
    • Nanosecond precision and JSON serialization (integers) still resolve PHP’s DateInterval limitations.
    • Fluent methods (e.g., Time::Now().Add(Duration::Parse('5s'))) retain readability advantages.
    • New Time class stability: Likely resolves beta-era gaps (e.g., missing Format()), though changelog lacks specifics.
  • Gaps:
    • Still no Carbon integration: Manual adaptation remains required (e.g., no Carbon::instance($gotime)).
    • Limited timezone handling: Still treats durations as timezone-agnostic.
    • No Laravel facade: Explicit namespace imports (use DCarbone\Go\Time) persist as boilerplate.
    • No Eloquent integration: Custom accessors/mutators still mandatory for time fields.

Integration Feasibility

  • Pros:
    • v1.0 stability: Reduces risk of breaking changes in core functionality.
    • Composer-friendly: Zero-config installation unchanged (composer require dcarbone/gotime).
    • PHP 8.1+ strict typing: Continues alignment with Laravel’s modern stack.
    • DateInterval bridge: Conversion logic remains intact for DateTime interoperability.
  • Cons:
    • No Eloquent integration: Still requires custom accessors/mutators for created_at/updated_at.
    • Testing overhead: Edge cases (e.g., DST, leap seconds) still need validation.
    • Floating-point precision: Nanosecond backing may still introduce edge cases (e.g., 0.05s parsing).
    • Type flexibility: mixed return types may still conflict with Laravel’s strict typing.

Technical Risk

  • Medium (Reduced from High):
    • Precision edge cases: Nanosecond arithmetic risks persist but are now less likely to break due to v1.0 stability.
    • Performance overhead: DurationDateInterval conversions remain a concern but are now validated in production.
    • Maintenance risk: Low stars (2) and no dependents still suggest minimal community support, but v1.0 suggests active maintenance.
    • Type safety: @phpstan-ignore-line may still be needed, but reduced risk of breaking changes.
  • Mitigations:
    • Benchmark: Compare gotime vs. Carbon for critical paths (e.g., Duration::add() in scheduling).
    • Hybrid approach: Use gotime for internal calculations, Carbon for I/O (e.g., user-facing dates).
    • Fallback: Implement custom Duration class if gotime proves unstable (e.g., for nanosecond precision).

Key Questions

  1. Use Case Validation:
    • Is this for internal calculations (e.g., rate limiting, scheduling) or user-facing dates (where Carbon’s UX is superior)?
    • Are there existing DateInterval edge cases (e.g., 24h + 1s) that need testing?
  2. Carbon Compatibility:
    • Can we extend Carbon to use gotime under the hood (e.g., via traits) to avoid duplication?
  3. Maintenance:
    • Who will triage issues? The package’s low activity (2 stars, no dependents) raises long-term support concerns despite v1.0.
  4. Alternatives:
    • Would spatie/calendar or custom Duration logic suffice for simpler cases?
    • Is ramsey/uuid + Carbon a viable alternative for UUID-time hybrid use cases?
  5. Laravel-Specific:
    • How will this interact with Laravel’s Carbon facade (e.g., now(), parse())?
    • Are there plans to add a gotime service provider or facade for Laravel?
  6. v1.0.1 Specifics:
    • What changes were made in v1.0.1? (Changelog lacks details; assume bug fixes but no new features.)
    • Are there any breaking changes or deprecations introduced in v1.0.1?

Integration Approach

Stack Fit

  • Laravel Alignment:
    • Pros:
      • v1.0 stability reduces risk of breaking changes in core functionality.
      • JSON serialization (nanoseconds as integers) still simplifies API responses.
      • Fluent methods reduce boilerplate in controllers/services.
    • Cons:
      • No built-in facade or service provider (unlike Carbon).
      • No Eloquent integration (requires custom accessors/mutators).
  • Recommended Stack:
    • Core: Use gotime for internal time math (e.g., duration parsing, scheduling, rate limiting).
    • Edge Cases: Fall back to Carbon for timezone-aware operations (e.g., now('Asia/Tokyo')).
    • APIs: Serialize Duration as JSON nanos for consistency across microservices.
    • Database: Store durations as nanoseconds in BIGINT fields (e.g., duration_nanos).

Migration Path

  1. Phase 1: Pilot Project (Low Risk)
    • Scope: Replace DateInterval in a single service (e.g., JobDispatcher or RateLimiter).
    • Example:
      // Before (DateInterval)
      $interval = DateInterval::createFromDateString('5 seconds');
      $job->delay($interval);
      
      // After (gotime)
      $duration = Time::ParseDuration('5s');
      $job->delay($duration->DateInterval());
      
    • Validation: Test with edge cases (e.g., 0.05s, 24h + 1s).
  2. Phase 2: Hybrid Integration (Medium Risk)
    • Create a 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());
          }
      }
      
    • Use in services:
      class SchedulerService {
          use TimeHelper;
      
          public function scheduleJob(Duration $duration) {
              $carbonTime = $this->durationToCarbon($duration);
              // Use Carbon for timezone-aware logic...
          }
      }
      
  3. Phase 3: Full Adoption (High Risk)
    • Replace all DateInterval usages with gotime in new features.
    • Add custom accessors for Eloquent models:
      // models/Job.php
      public function getDurationAttribute(): Duration {
          return Time::ParseDuration($this->attributes['duration']);
      }
      public function setDurationAttribute(Duration $duration): void {
          $this->attributes['duration'] = $duration->String();
      }
      
    • Update API contracts: Ensure Duration serialization matches microservice expectations (e.g., JSON nanos).

Compatibility

  • PHP 8.1+: Required by gotime; Laravel 9+ supports this.
  • Carbon: No direct integration, but DateTime interoperability exists (e.g., Duration::DateInterval()).
  • Database:
    • Store durations as nanoseconds in BIGINT (e.g., duration_nanos).
    • Use custom accessors to convert between Duration and stored values.
  • Testing:
    • Update PHPUnit to v10.5+ (required by gotime).
    • Test edge cases: DST transitions, leap seconds, and floating-point precision (e.g., 0.05s).
  • Laravel-Specific:
    • No facade: Requires manual namespace imports (use DCarbone\Go\Time).
    • No service provider: May need custom binding in AppServiceProvider.

Sequencing

  1. Low-Risk First:
    • Start with duration parsing (ParseDuration('5s')) in non-critical paths (e.g., logging, metrics).
    • Avoid the Time class until fully vetted (though v1.0 reduces risk).
  2. Medium-Risk Next:
    • Replace DateInterval in scheduling or rate limiting services.
    • Test DurationDateInterval conversions under load.
  3. High-Risk Last:
    • Adopt in user-facing features (e.g., calendar UI) where Carbon’s UX is superior.

Operational Impact

Maintenance

  • Pros:
    • v1.0 stability reduces maintenance overhead from breaking changes.
    • Lightweight (~500 LOC) with minimal dependencies
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky