[795] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * -------------------------------------------- * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \**************************************************************************/ |
---|
| 11 | |
---|
| 12 | require_once 'class.JobDate.inc.php'; |
---|
| 13 | |
---|
| 14 | /** |
---|
| 15 | * Classe para datas absolutas e com repetições comuns |
---|
| 16 | * @author Sidnei Augusto Drovetto Junior - drovetto@gmail.com |
---|
| 17 | * @version 1.0 |
---|
| 18 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 19 | * @package Workflow |
---|
| 20 | * @subpackage Job |
---|
| 21 | */ |
---|
| 22 | class AbsoluteDate extends JobDate |
---|
| 23 | { |
---|
| 24 | /** |
---|
| 25 | * Verifica se um Job será executado na data fornecida |
---|
| 26 | * @param object $checkDate A data que será verificada |
---|
| 27 | * @return bool True caso o Job deva ser executado e false caso contrário |
---|
| 28 | * @access public |
---|
| 29 | */ |
---|
| 30 | public function checkMatchesInterval($checkDate) |
---|
| 31 | { |
---|
| 32 | $preCheck = array(); |
---|
| 33 | |
---|
| 34 | switch($this->interval['unity']) |
---|
| 35 | { |
---|
| 36 | case DateUnity::NONE: |
---|
| 37 | $preCheck[] = 'Y'; |
---|
| 38 | case DateUnity::YEAR: |
---|
| 39 | $preCheck[] = 'n'; |
---|
| 40 | case DateUnity::MONTH: |
---|
| 41 | $preCheck[] = 'j'; |
---|
| 42 | case DateUnity::DAY: |
---|
| 43 | $preCheck[] = 'G'; |
---|
| 44 | case DateUnity::HOUR: |
---|
| 45 | $preCheck[] = 'i'; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | $preCheck = implode(':', $preCheck); |
---|
| 49 | if ($checkDate->format($preCheck) !== $this->startDate->format($preCheck)) |
---|
| 50 | return false; |
---|
| 51 | |
---|
| 52 | if ($this->interval['unity'] == DateUnity::NONE) |
---|
| 53 | return true; |
---|
| 54 | |
---|
| 55 | if ($this->interval['unity'] == DateUnity::MINUTE) |
---|
| 56 | { |
---|
| 57 | $start = $this->startDate->format('U') / 60; |
---|
| 58 | $check = $checkDate->format('U') / 60; |
---|
| 59 | return (((($check - $start) % $this->interval['value']) === 0) && ($check >= $start)); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | if ($this->interval['unity'] == DateUnity::HOUR) |
---|
| 63 | { |
---|
| 64 | $start = $this->startDate->format('U') / 3600; |
---|
| 65 | $check = $checkDate->format('U') / 3600; |
---|
| 66 | return (((($check - $start) % $this->interval['value']) === 0) && ($check >= $start)); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | if ($this->interval['unity'] == DateUnity::DAY) |
---|
| 70 | { |
---|
| 71 | $start = $this->startDate->format('U') / 86400; |
---|
| 72 | $check = $checkDate->format('U') / 86400; |
---|
| 73 | return (((($check - $start) % $this->interval['value']) === 0) && ($check >= $start)); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | if ($this->interval['unity'] == DateUnity::MONTH) |
---|
| 77 | { |
---|
| 78 | $start = ($this->startDate->format('Y') * 12) + $this->startDate->format('n'); |
---|
| 79 | $check = ($checkDate->format('Y') * 12) + $checkDate->format('n'); |
---|
| 80 | return (((($check - $start) % $this->interval['value']) === 0) && ($check >= $start)); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | if ($this->interval['unity'] == DateUnity::YEAR) |
---|
| 84 | { |
---|
| 85 | $start = $this->startDate->format('Y'); |
---|
| 86 | $check = $checkDate->format('Y'); |
---|
| 87 | return (((($check - $start) % $this->interval['value']) === 0) && ($check >= $start)); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | return false; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | ?> |
---|