Skip to content

Instantly share code, notes, and snippets.

@bkralik
Last active November 25, 2015 23:11
Show Gist options
  • Select an option

  • Save bkralik/78be5b1b9056ecd80053 to your computer and use it in GitHub Desktop.

Select an option

Save bkralik/78be5b1b9056ecd80053 to your computer and use it in GitHub Desktop.
Mikrotik RouterOS time interval parser
<?php
function RouterOSparseInterval($in) {
$pattern = "/(\d+)([wdhms])/";
$multipliers = array(
"w" => 604800,
"d" => 86400,
"h" => 3600,
"m" => 60,
"s" => 1
);
preg_match_all($pattern, $in, $matches, PREG_SET_ORDER);
$total = 0;
foreach($matches as $m) {
$total = $total + $m[1] * $multipliers[$m[2]];
}
if(count($matches) == 0) {
$total = -1;
}
return($total);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment