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

Php Date Bundle Laravel Package

assoconnect/php-date-bundle

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strengths:

    • Aligns well with Symfony/Laravel ecosystems (via Doctrine, Twig, and Symfony components).
    • Provides a time-agnostic abstraction (AbsoluteDate) for business logic, decoupling from system clock, which is valuable for:
      • Time-travel testing (e.g., AbsoluteDateClock for mocking).
      • Event-sourced or CQRS architectures where events are timestamped independently of processing time.
      • Multi-region/timezone applications (via DateTimeZoneType).
    • Integrates seamlessly with Doctrine ORM (custom types) and Symfony Serializer (normalization/denormalization), reducing boilerplate for date handling.
    • Twig extension enables consistent date formatting across templates (e.g., {{ date|date }}).
    • Translatable dates support (via AbsoluteDateTranslatable) for i18n-heavy applications.
  • Gaps:

    • Laravel-specific limitations:
      • Bundle is Symfony-centric (e.g., FrameworkBundle, Clock component). Laravel’s Carbon and Illuminate\Support\Facades\Time are dominant, and this bundle may introduce friction.
      • No native Laravel service provider or config publisher (would require manual wiring).
    • Missing Laravel integrations:
      • No Eloquent model casting or accessors for AbsoluteDate.
      • No Laravel-specific validation rules (e.g., DateValid).
      • No Blade directive support (only Twig).
    • Clock abstraction: While useful, Laravel’s Time facade already handles time mocking in tests, potentially reducing the need for AbsoluteDateClock.

Integration Feasibility

  • High-level feasibility: Moderate (3/5).
    • Symfony compatibility: Requires Symfony components (e.g., Clock, Serializer), which Laravel lacks natively. Would need polyfills or wrappers.
    • Doctrine integration: Feasible if using Doctrine DBAL (not ORM) or bridging Doctrine ORM types via custom accessors.
    • Twig: Requires Twig integration (Laravel uses Blade by default; Twig would need to be added as a dependency).
  • Key dependencies:
    • symfony/clock: Laravel’s Carbon could replace this with minimal effort.
    • symfony/serializer: Laravel’s Illuminate\Support\Serializer or Spatie\ArrayToXml could substitute.
    • ext-intl: Required for timezone handling (Laravel already depends on this).

Technical Risk

  • Critical risks:
    • Clock abstraction conflict: Laravel’s Time facade and Carbon are deeply embedded. Introducing AbsoluteDateClock could create ambiguity in time-aware logic.
    • Performance overhead: Serialization/normalization layers (e.g., AbsoluteDateNormalizer) may add latency in high-throughput APIs.
    • Testing complexity: Time-travel testing is already supported in Laravel via travel() (Laravel Breeze) or mocks Clock, reducing the bundle’s unique value.
  • Mitigation strategies:
    • Hybrid approach: Use AbsoluteDate only for domain-specific timestamps (e.g., audit logs, events) while keeping Carbon for system-level dates.
    • Wrapper layer: Create a Laravel-specific facade to adapt Symfony components (e.g., AbsoluteDate::fromCarbon($carbon)).
    • Selective adoption: Start with Doctrine types (if using Doctrine) and Twig filters, avoiding the Clock abstraction initially.

Key Questions

  1. Business justification:
    • Why adopt AbsoluteDate over Laravel’s native Carbon/Time? What problem does this solve that existing tools don’t?
    • Are there domain-specific use cases (e.g., financial settlements, legal deadlines) where time immutability is critical?
  2. Architectural impact:
    • How would this integrate with Laravel’s event system (e.g., Illuminate\Bus\Dispatchable)? Would events use AbsoluteDate or Carbon?
    • Would this require breaking changes to existing date-handling logic (e.g., replacing created_at timestamps)?
  3. Team readiness:
    • Does the team have experience with Symfony bundles or custom Doctrine types?
    • Is there appetite to maintain a wrapper layer for Laravel-specific adaptations?
  4. Alternatives:
    • Could spatie/laravel-activitylog (for timestamps) or nesbot/carbon (for time manipulation) suffice?
    • Is there a Laravel-native package (e.g., laravel-time) that offers similar abstractions?

Integration Approach

Stack Fit

  • Compatibility matrix:

    Component Laravel Native Symfony Bundle Workaround Needed
    Doctrine Types ❌ No ✅ Yes Custom Eloquent accessors
    Twig Filters ❌ (Blade) ✅ Yes Add Twig as dependency
    Serialization ✅ (Partial) ✅ Yes Polyfill Serializer
    Time Abstraction ✅ (Carbon) ✅ (Clock) Hybrid AbsoluteDate + Carbon
    Translatable Dates ❌ No ✅ Yes Manual i18n integration
  • Laravel-specific adaptations required:

    • Service Provider: Register bundle components (Doctrine types, Twig extensions) via Laravel’s register().
    • Clock Polyfill: Create a LaravelClock class extending AbsoluteDateClock to integrate with Carbon.
    • Eloquent Bridge: Add AbsoluteDate accessors/cast types for models (e.g., protected $dates = ['absolute_created_at'];).
    • Blade Compatibility: Either:
      • Use Twig for templates (add twig/twig via Composer).
      • Create Blade directives mirroring Twig filters (e.g., @date($variable)).

Migration Path

  1. Phase 1: Proof of Concept (2 weeks)
    • Isolate a single feature (e.g., AbsoluteDateType for a new model field).
    • Test with a non-critical module (e.g., audit logs).
    • Validate performance impact (benchmarks for serialization/normalization).
  2. Phase 2: Core Integration (4 weeks)
    • Add Twig/Blade support for date formatting.
    • Implement AbsoluteDateClock for time-travel testing (replace travel() where needed).
    • Migrate one critical domain entity (e.g., Order timestamps).
  3. Phase 3: Full Adoption (6+ weeks)
    • Replace Carbon-based timestamps with AbsoluteDate in new features.
    • Deprecate old date-handling logic via feature flags.
    • Train team on AbsoluteDate patterns (e.g., "never use now(); use AbsoluteDate::now()").

Compatibility

  • Backward compatibility:
    • Low risk for new projects; high risk for legacy code relying on Carbon/Time.
    • Mitigation: Use adapters (e.g., AbsoluteDate::fromCarbon($carbon)) during transition.
  • Dependency conflicts:
    • symfony/clock and symfony/serializer may conflict with Laravel’s autowiring. Solution: Explicitly bind interfaces to Laravel implementations.
    • ext-intl is already required by Laravel for Carbon.

Sequencing

  1. Prerequisites:
    • Ensure Doctrine DBAL is installed if using custom types (Laravel’s Eloquent ORM may not need this).
    • Add twig/twig if using Twig templates (or implement Blade directives).
  2. Order of operations:
    • Step 1: Add bundle via Composer (assoconnect/php-date-bundle).
    • Step 2: Register the bundle in config/app.php (Symfony-style) or create a Laravel service provider.
    • Step 3: Implement AbsoluteDate for new model fields (avoid touching existing created_at/updated_at).
    • Step 4: Replace Carbon-based logic in business services (e.g., OrderService::calculateDeadline()).
    • Step 5: Migrate tests to use AbsoluteDateClock for time-travel scenarios.
    • Step 6: Deprecate old date-handling patterns via PHPStan/Rector.

Operational Impact

Maintenance

  • Pros:
    • Reduced boilerplate: Centralized date handling (e.g., formatting, timezone conversion) via bundle.
    • Consistent behavior: AbsoluteDate ensures time immutability across services.
    • Testing: Easier time-travel testing with AbsoluteDateClock.
  • Cons:
    • Additional layer: Debugging may require tracing through AbsoluteDateCarbon → DB.
    • Dependency bloat: Adds Symfony components (`
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