digital-craftsman/datetime-parts
Value objects for precise date/time parts in PHP: Moment (UTC-based) plus Time, Date, Month, Year, Day/Weekday and collections. Avoid misleading DateTime comparisons, handle timezone-safe modifications across DST, with Symfony normalizers and Doctrine types.
Time, Date, Month, Year) without ambiguity, reducing bugs tied to timezone/offset mismatches or redundant data (e.g., storing a Date as a DateTime at midnight).Moment and its parts, simplifying state management and thread safety.Moment, explicit zones for Time/Date), eliminating "off-by-one" errors (e.g., daylight saving time) and improving consistency across microservices.Moment as Moment type in Doctrine) instead of bloated DateTime fields, with built-in normalizers for APIs.FrozenClock enables deterministic testing (e.g., time-freezing for unit tests).mustBeEqualTo()) catch edge cases early (e.g., invalid bookings).DateTime usage in core workflows (e.g., scheduling, bookings) with Moment/Time/Date.Year/Month for precision.Day/Weekday for calendar features (e.g., "business days only" logic).isBeforeInTimeZone()).Clock interface for domain-specific time logic (e.g., "holiday-aware" clocks).DateTime ambiguity (e.g., timezone offsets, midnight assumptions) causes bugs.FrozenClock) without refactoring.DateTime fields storing only dates/times (e.g., created_at as DateTime when a Date suffices).DateTime is prohibitively risky (start with new features).*"This package solves a hidden technical debt problem: timezone and date precision errors cost us X hours/year in debugging and outages. For example, our booking system’s ‘open hours’ logic fails during daylight saving transitions because we’re comparing DateTime objects incorrectly. This library:
DateTime with precise types like Time (for hours) or Date (for days), so ‘Is the facility open?’ is a single, clear comparison.*"This is a drop-in replacement for DateTime that fixes three key pain points:
Time objects directly (e.g., isBeforeInTimeZone($facilityOpenTime)) without normalizing to midnight.Moment but lets you modify in any timezone (e.g., modifyInTimeZone('+1 week', $userTimezone)).DateTime usage is a leaky abstraction (e.g., created_at as DateTime when we only care about the date).Moment for all DateTime fields in new features.Time/Date for granular logic (e.g., business hours, deadlines).new DateTime() calls with SystemClock::now() for consistency.
Tradeoffs:// Before (bug-prone):
if ($now->getTimestamp() < $facilityOpenTime->getTimestamp()) { ... }
// After (clear and timezone-safe):
if ($now->isBeforeInTimeZone($facility->openFrom, $facilityTimeZone)) { ... }
```*
*Let’s pilot this in the booking system first—it’s the highest-risk area for timezone bugs."*
How can I help you explore Laravel packages today?