You can use supported date and time formats to make a human-readable string, which may then be used to initialize and calculate the difference in seconds:
$diff = "3 days 5 hours 10 seconds";
$now = strtotime('2010-04-01 00:00:00'); // No leap year funny business
$then = strtotime($diff, $now);
$diff = $then - $now;
echo "
Now: " . date('r', $now) . "
Then: " . date('r', $then) . "
Diff (seconds): $diff";
https://ignite.io/code/51338967ec221e0d3b000000
Note: The concern about leap year is whether it will calculate the seconds correctly (add/remove a day?). If this is possible, it should be tested independently.
The above outputs:
Now: Thu, 01 Apr 2010 00:00:00 +0000
Then: Sun, 04 Apr 2010 05:00:10 +0000
Diff (seconds): 277210
Which would then let you do:
[mailer]
; Period before trial expiration an email should be sent.
; Use PHP-supported time statements in an expression to
; specify an interval, such as 3 days, or 72 hours, etc.
; See: http://www.php.net/manual/en/datetime.formats.php
expires = 3 days;
As I noted in the comments, you can also use DateTimeInterval::createFromString()
with DateTime::diff
to do the same thing.
I will note as well that getting the string formatted correctly, while not difficult, can sometimes be trickier than you might think. For simple strings like 3 days
that's not hard, but 3d
doesn't work. So the time that is calculated should be validated, and an error provided to the person setting the configuration if what was entered is not a valid expression, or is "out of bounds" to what was expected (in the past maybe?).