What you need is a datetime which is 30 minutes later than your given datetime, and a datetime which is 30 minutes before a given datetime. In other words, you need a future datetime and a past datetime. Hence, classes that achieve that are called Future
and Past
. What data do they need to calculate what you need? Apparently, they must have a datetime relative to which to count those 30 minutes, and an interval itself -- 30 minutes in your case. Thus, the desired datetime looks like the following:
use Meringue\ISO8601DateTime\FromCustomFormat as DateTimeCreatedFromCustomFormat;
(new Future(
new DateTimeCreatedFromCustomFormat('H:i', '10:00'),
new NMinutes(30)
))
->value();
If you want to format it somehow, you can do:
use Meringue\ISO8601DateTime\FromCustomFormat as DateTimeCreatedFromCustomFormat;
(new ISO8601Formatted(
new Future(
new DateTimeCreatedFromCustomFormat('H:i', '10:00'),
new NMinutes(30)
),
'H:i'
))
->value();
It's more verbose, but I guess it's way less cryptic than built-in php functions.
If you liked this approach, you can learn some more about the meringue library used in this example, and the overall approach.
-30 minute
without the s?