Time Format Api Call

Hi,

I’m doing a php program to read and write some Mikrotik fileds.

I’m using API calls from boen.robot.

One of the fields I want to read and update is /ip/hotspot/user/profile mac-cookie-timeout

In mikrotik we store this time as “xxxd hh:mm:ss” like “999d 01:00:10” but when I read it we get “42w5d1h10s”.

I prefere to create an input data like xxxd hh:mm:ss to write the info into router.

If someone have donne it what is the suggestion ?

How to convert this time interval to works correctly ?

Thanks,

You can still safely write “999d01:00:10”. Just notice the lack of a space there. This is because the timeout is written as the scripting type “time”, which supports this. You’ll still get “42w5d1h10s” when you read it, but in terms of writing, it’s fine.

If you’d like to also read the Router’s value as “999d01:00:10”, you’d have to call RouterOS\Script::parseValueToDateInterval() and format the resulting object accordingly, e.g.:

echo RouterOS\Script::parseValueToDateInterval(
    $util->setMenu('/ip/hotspot/user/profile')->get('default', 'mac-cookie-timeout')
)->format('%dd%H:%I:%S');

As always excelent help boen.

Many thanks!