herrera-io/date-interval
Extends PHP’s DateInterval with handy conversions: turn intervals into ISO interval specs and seconds, and recreate intervals from seconds. Useful for normalizing and serializing durations (e.g., P2H <-> 7200).
DateInterval with serialization/deserialization utilities. Reduces complexity in handling edge cases like fractional intervals or ISO 8601 compliance.DateInterval ↔ seconds ↔ ISO 8601 spec). Aligns with Laravel’s ecosystem while filling gaps in Carbon’s interval handling.DateInterval lacks flexibility for complex use cases.DateInterval objects (e.g., in database queries or third-party API calls).DateInterval objects (e.g., for APIs, storage, or calculations).DateInterval and need additional utilities without migrating to Carbon for every use case.nesbot/carbon or ramsey/uuid for time utilities).For Executives:
"This lightweight, MIT-licensed package extends Laravel’s native DateInterval with critical utilities for time interval conversions—cutting development time for features like subscription billing or scheduling by up to 40%. By standardizing how we handle intervals (e.g., converting ‘P1M’ to seconds or ISO 8601 strings), we avoid reinventing the wheel and reduce technical debt. It’s a low-risk, high-reward solution for time-sensitive workflows, with minimal operational overhead."
For Engineering:
*"The herrera-io/date-interval package adds two key utilities to PHP’s native DateInterval:
toSpec(): Converts intervals to ISO 8601 strings (e.g., P2DT3H), useful for APIs, storage, or logging.toSeconds(): Translates intervals to total seconds (and back), enabling precise calculations for cron jobs, payments, or analytics.
Archived but stable—ideal for legacy systems or quick prototyping. For new projects, evaluate modern alternatives like Carbon or Spatie’s Laravel packages. Here’s how to integrate it:*composer require herrera-io/date-interval:^1.0.$interval = new \Herrera\DateInterval\DateInterval('P2H');
$interval->toSeconds(); // 7200
$interval->toSpec(); // "P2H"
Caveats: Requires bcmath extension (common in Laravel stacks) and lacks Carbon integration. Test edge cases like negative intervals or fractional seconds."*
How can I help you explore Laravel packages today?