- How do I install and use dcarbone/gotime in a Laravel project?
- Install via Composer with `composer require dcarbone/gotime`. Use the `Time` class for Go-like time operations (e.g., `Time::Now()`) and `Duration` for parsing/manipulating time spans (e.g., `Duration::Parse('5s')`). Requires PHP 8.1+ and no Laravel-specific setup.
- Does this package support Laravel’s Carbon facade or Eloquent timestamps?
- No, it doesn’t integrate with Carbon or Eloquent. For Eloquent models, manually cast time fields using accessors/mutators. For Carbon compatibility, consider hybrid usage (e.g., use `gotime` for calculations, Carbon for I/O).
- What Laravel versions does dcarbone/gotime support?
- The package targets PHP 8.1+, which aligns with Laravel 9+ and 10. It’s framework-agnostic but works seamlessly with modern Laravel stacks. No Laravel-specific dependencies or version locks exist.
- How accurate is the nanosecond precision in production?
- Nanosecond precision is stored internally as integers (e.g., `5s` = `5e9`), but PHP’s `DateTime` and `DateInterval` may introduce edge cases (e.g., floating-point math). Test thoroughly for critical paths like scheduling or rate limiting.
- Can I use gotime for timezone-aware operations like Carbon?
- No, `gotime` treats durations as timezone-agnostic. For timezone handling, fall back to Carbon or PHP’s native `DateTime` methods. Use `gotime` for internal calculations where timezone context isn’t needed.
- Are there breaking changes in v1.0.1, and how do I migrate?
- The changelog lacks specifics, but v1.0.1 likely includes bug fixes without breaking changes. If upgrading from beta, review the `Time` class docs (still marked beta) for deprecated methods or API shifts.
- How does gotime compare to Carbon for Laravel APIs?
- Use `gotime` for internal time math (e.g., parsing `'1h30m'` or scheduling) and Carbon for user-facing dates/API responses. `gotime`’s fluent methods reduce boilerplate, but Carbon’s UX (e.g., `now()`, `parse()`) is superior for external interactions.
- What alternatives exist for Go-like time handling in Laravel?
- For simpler cases, consider `spatie/calendar` or custom `DateInterval` logic. For UUID-time hybrids, pair `ramsey/uuid` with Carbon. If nanosecond precision is critical, benchmark `gotime` against Carbon’s `createFromTimestamp()` for edge cases.
- How do I serialize gotime objects to JSON or APIs?
- Use `json_encode()` on `Duration` objects to output nanoseconds as integers (e.g., `5000000000` for `5s`). For `Time` objects, cast to a `DateTime` or format manually (e.g., `$time->format('Y-m-d')`). Avoid direct serialization of `Time` objects.
- Is dcarbone/gotime actively maintained, and who supports it?
- The package is v1.0 stable with low GitHub activity (2 stars, no dependents). Maintenance appears active (bug fixes in v1.0.1), but long-term support depends on the author. Monitor the repo for updates or consider forking if critical.