apie/date-value-objects
Date-related value objects for PHP/Apie that model only the date/time parts you need (LocalDate, Time, HourAndMinutes, UnixTimestamp, DateWithTimezone). Helps validate expected formats without relying on full DateTimeImmutable.
LocalDate vs. DateWithTimezone), aligning with Laravel’s growing adoption of DDD patterns.Carbon in accessors/mutators (e.g., getScheduledAtAttribute(): DateWithTimezone) without modifying database schemas.HourAndMinutes for time slots in a booking API).DateWithTimezone enforces explicit timezone handling vs. Carbon’s implicit defaults.DateTime: Prevents accidental inclusion of irrelevant fields (e.g., microseconds in a LocalDate).EventSchedulerService using DateWithTimezone).UserRepository::findByBirthdate(LocalDate $date)).DateWithTimezone::fromCarbon(Carbon $carbon) and Carbon::fromDateWithTimezone(DateWithTimezone $dwo).Carbon for storage/serialization and value objects for domain logic (e.g., User::birthdate stored as DATE but returned as LocalDate).Validator with custom rules (e.g., LocalDateRule to validate ISO-8601 dates).EventRequest requiring HourAndMinutes for time slots).config('app.use_date_value_objects')).Carbon’s mutable design.UnixTimestamp for logs over DateWithTimezone).DateWithTimezone::fromTimestamp($timestamp) for Eloquent).WorksWithMonths across year boundaries).LocalDate::nextMonth()).Carbon/DateTime? How will interoperability be handled?spatie/laravel-date, ramsey/uuid) been evaluated for Laravel-specific needs?LocalDate for user dates) vs. full replacement of Carbon?Carbon v1.x compatibility checks.getEventDate(): DateWithTimezone).JsonResource returning HourAndMinutes).composer require apie/date-value-objects.CarbonAdapter).LocalDate in projections) and command validation (e.g., DateWithTimezone for event scheduling).Carbon in a New Feature:
DateWithTimezone for a scheduling module instead of Carbon.AppointmentScheduler) that accepts HourAndMinutes.// User.php
public function birthdate(): LocalDate {
return LocalDate::fromDateTime($this->attributes['birthdate']);
}
// CreateAppointmentRequest.php
public function rules(): array {
return [
'time_slot' => ['required', 'date_format:H:i', new ValidHourAndMinutes],
];
}
LocalDate::nextMonth() across year boundaries).// app/Rules/LocalDateRule.php
public function passes($attribute, $value) {
return LocalDate::tryFromString($value) !== null;
}
// AppointmentResource.php
public function toArray($request) {
return [
'time_slot' => $this->whenLoaded('time_slot', fn () => $this->time_slot->toString()),
];
}
LocalDate as DATE, UnixTimestamp as BIGINT).Carbon/DateTime in core domain logic.Carbon with value objects in domain services (e.g., BillingService using LocalDate for month-end calculations).How can I help you explore Laravel packages today?