New WEEK_DATE macro

This commit is contained in:
wrenge 2023-07-06 10:02:58 +03:00
parent e4faacae82
commit 4c4d1af1a5
1 changed files with 46 additions and 0 deletions

View File

@ -31,6 +31,52 @@ function macro_INTERVAL($proc, $spec)
return $sec; return $sec;
} }
/**
* @global
*/
function macro_WEEK_DATE($proc, $spec)
{
$parts = explode(" ", $spec);
$dow_str = $parts[0];
$time_str = $parts[1];
$day = 0;
switch ($dow_str) {
case 'MONDAY':
$day = 0;
break;
case 'TUESDAY':
$day = 1;
break;
case 'WEDNESDAY':
$day = 2;
break;
case 'THURSDAY':
$day = 3;
break;
case 'FRIDAY':
$day = 4;
break;
case 'SATURDAY':
$day = 5;
break;
case 'SUNDAY':
$day = 6;
break;
default:
throw new Exception("Bad day of week: $spec");
break;
}
$stamp = strtotime($time_str);
if($stamp === false)
throw new Exception("Bad time: $spec");
$stamp += $day * 24 * 60 * 60;
return $stamp;
}
/** /**
* @global * @global
*/ */