diff --git a/macro.inc.php b/macro.inc.php index 460a527..ee18476 100644 --- a/macro.inc.php +++ b/macro.inc.php @@ -31,6 +31,52 @@ function macro_INTERVAL($proc, $spec) 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 */