Hello.
Working on my cooking recipes profile I need some time conversion to preptime duration as per ISO 8601. For the moment I have a few lines of code that take the value of $page->recipe_cook_time (in minutes) and convert it to human readable time for the frontend (ex. 1d 2h 35m):
$d = floor ($page->recipe_cooking_time / 1440);
$h = floor (($page->recipe_cooking_time - $d * 1440) / 60);
$m = $page->recipe_cooking_time - ($d * 1440) - ($h * 60);
if ($d > 0) {
$cooking_time = $d . ' d ';
}
if ($h > 0) {
$cooking_time .= $h . 'h ';
}
if ($m > 0) {
$cooking_time .= $m . 'min';
}
Now I am trying to convert the minutes of $page->recipe_cook_time into ISO 8601 duration (ex. P1DT1H35M) but am stuck and get different results instead of the right timing. Any suggestions about the conversion or even if you know of a function that can smarter convert minutes to human readable D:H:M ?