Repository navigation
Recruiter\Clock 5.0.0
π Breaking Changes
- BREAKING: Replaced
psr/clockdependency with Symfony Clock (symfony/clock: ^7.3) - BREAKING: Removed deprecated
current()method from Clock interface - usenow()instead - BREAKING: Major refactoring of clock implementations to integrate with Symfony Clock framework
- BREAKING: Replaced integer constants with type-safe enums:
UTCDateTimeRange::LESS_THANβComparisonOperator::LessThanUTCDateTimeRange::LESS_THAN_EQUALSβComparisonOperator::LessThanOrEqualsUTCDateTimeRange::ASCENDINGβDirection::AscendingUTCDateTimeRange::DESCENDINGβDirection::Descending
β¨ New Features
- Symfony Clock Integration - All clock implementations now support Symfony Clock methods:
sleep(float|int $seconds)- Sleep functionality with time advancement for test clockswithTimeZone(\DateTimeZone|string $timezone)- Timezone-aware clock creation
- Enhanced PSR Clock Support - New
PsrMicrotimeClockadapter for existing PSR Clock implementations - Docker Development Improvements:
- XDebug support with dedicated
devDocker target - Test coverage reporting with
make test-coveragecommand - Enhanced development workflow with better container setup
- XDebug support with dedicated
π οΈ Improvements
- Enhanced Type Safety with new enum-based APIs replacing magic constants
- Comprehensive Test Suite - Added extensive test coverage for all clock implementations
- Streamlined Development Workflow:
- Simplified Docker configuration with multi-stage builds
- Better Makefile with coverage support
- Improved CI/CD with dependency caching
- Code Modernization:
- Simplified constructor logic in
ProgressiveClock - Enhanced
FixedClockto prevent mutation from external DateTime objects - Better separation of concerns with new trait
SymfonySupport
- Simplified constructor logic in
π¦ Dependencies
- Replaced
psr/clock: ^1.0withsymfony/clock: ^7.3 - Enhanced development dependencies for better testing and code quality
π§ API Changes
Core Clock Interface
All clock implementations now extend Symfony's ClockInterface and provide unified access to specialized clock types:
use Recruiter\Clock\SystemClock;
$clock = new SystemClock();
// Primary interface - Symfony Clock compliant
$dateTimeImmutable = $clock->now(); // Returns DateTimeImmutable
// Access specialized clock implementations
$utcClock = $clock->asUTC(); // Returns UTCClock for MongoDB integration
$microtimeClock = $clock->asMicrotime(); // Returns MicrotimeClock for float timestamps
$stopWatch = $clock->stopWatch(); // Returns StopWatch for timing operations
// NEW: Symfony Clock methods
$clock->sleep(1.5); // Sleep for 1.5 seconds (advances test clocks)
$utcClock = $clock->withTimeZone('UTC'); // Create timezone-aware variantAvailable Clock Implementations
SystemClock- Production clock using system time (wraps SymfonyNativeClock)ManualClock- Test clock with manual time control (wraps SymfonyMockClock)SettableClock- Switchable clock that can override any base clock with fixed timeProgressiveClock- Auto-advancing clock that increments on each callDelayedClock- Clock with configurable delay offset
Automatic Clock Wrapping
All clock implementations automatically provide access to specialized interfaces through the AbstractClock base class:
asUTC()βPsrUTCClock- Wraps any clock for customUTCDateTimeoperations (battle-tested for MongoDB-heavy apps)asMicrotime()βPsrMicrotimeClock- Wraps any clock for float timestamp operationsstopWatch()βClockStopWatch- Wraps any clock for elapsed time measurements
This ensures consistent access to specialized datetime handling, microtime operations, and timing functionality across all clock implementations.
Enum Migration Example:
// Before v5.0.0
if ($range->direction() === UTCDateTimeRange::ASCENDING) { ... }
if ($range->toOperator() === UTCDateTimeRange::LESS_THAN) { ... }
// v5.0.0+
if ($range->direction() === Direction::Ascending) { ... }
if ($range->toOperator() === ComparisonOperator::LessThan) { ... }π Migration Guide
- Update dependencies - Replace
psr/clockwithsymfony/clock: ^7.3 - Replace deprecated
current()calls - Update all$clock->current()to$clock->now() - Update enum usage - Replace integer constants with new enum values:
- Import
use Recruiter\DateTime\{ComparisonOperator, Direction}; - Update comparisons to use enum values instead of class constants
- Import
- Optional: Leverage new Symfony Clock features like
sleep()andwithTimeZone()
current() method has been removed. All code must use now() instead.