Does anybody know of an elegant way of using the PHP DateTime relative formats feature well for DateTime's that are not the current time?
Basically - I can create a new DateTime with a RelativeFormat from the current time very easily with
new DateTime('first monday of this week');
It would be incredibly useful to be able to do the same with other dates, so something like either:
new DateTime('first monday of 4 Jun 2022'); -> Should return 30 May 2022
or
$time = DateTime::createFromFormat('Y-m-d H:i:s', '2022-06-4 12:00:00);
$time->modify('first monday of week') -> Should return 30 May 2022
I know that this could be done with a function that mangles the date with various permutations of strtotime() but if anybody knows of a PHP library or something built into Relative Formats that I haven't found in the documentation which could achieve it more gracefully I'd be very grateful for the pointer.