PHP API Parse Date from address-list timeout

I have been searching for parser for the address-list timeout duration
I use @boen_robot 's script. but still havent found the solution
use PEAR2\Net\RouterOS;
require_once ‘PEAR2_Net_RouterOS-1.0.0b5.phar’;After i query the router, i got reply:

2d23h42m4s

or

2d3h2m45s

I am wondering how do i get the end date from those results?
for example

Beginning Date: 2017-May-19 00:20:45
Timeout Duration: 1d1h1m1s
End Result: 2017-May-20 01:21:46

or at least give me the variables of the duration(by n hours, n minutes, etc)

The latest version, 1.0.0b6 (which I released just now…) can now parse this. I mean, even 1.0.0b5 includes said function, but the letter notation was not recognized with it.

The method in question:

$duration = RouterOS\Script::parseValue('1d1h1m1s');//Returns a DateInterval object
$startDate = new DateTimeImmutable('2017-May-19 00:20:45');
$endDate = $startDate->add($duration);//$endDate Should be equal to 2017-May-20 01:21:46   

(though of course, instead of a literal, you’d supply the value you get out of RouterOS; the same function can also parse date and datetime like strings into DateTime objects)

Wow, thats quick @boen_robot . will try the feature.
also worth noting that mikrotik API will return timeout with no leading zero. is your script can handle it?

Well, not really… The feature has been there for a few months, if not a year. It’s just that the version having it wasn’t released. And I did it now not just because of your post, but also because of other recent issues that others have been having and were already addressed (your post was merely the last straw that made me go “ugh… fine!!! I’ll release it ASAP.”).

It should be able to handle any variant that’s valid to put into a RouterOS variable value.

e.g.

1w1d1h1m1s
1d1h1m1s
1h1m1s
1m1s
1s
0w0d0h0m0s
1w2h
1d10000h
999m888s77777ms
1:

That last one means “1 hour”… Did you know that? Because I certainly didn’t until I analyzed edge cases of my parsing regex, and to my surprise, RouterOS accepts this edge case as well. :laughing: So yeah, I think I have it covered.

If you find any case that doesn’t match between RouterOS and Script::parseValue(), do tell.

Huh… after a few minutes playing around with seemingly ridiculous cases, I found RouterOS actually accepts each time fragment type to occur multiple times, in any order, and sums them up…

e.g.

1s2w3h4s5:6ms7m

(equals 2w08:07:05.006)

Script::parseValue() doesn’t support that yet. It supports only time fragments that are in descendant order, one per type, each type being skippable. That’s enough to support any value that you read from RouterOS though.