/** * Returns false if the dueDateExpression is illegal * IMPORTANT: it stores dates using GTM time * * The dueDateExpression can have these formats: * _ extended (24-09-2009 or different according to date-format setting) * _ tomorrow * _ tom * _ today * _ tod * _ in 1 day * _ in X days (where X is a number) * _ in 1 week * _ in X weeks (where X is a number) * _ in 1 month * _ in X months (where X is a number) * _ in 1 year * _ in X years (where X is a number) * * @param string $dueDateExpression (see method description) * @param string $incomingDateFormat (='') the date format to use (PHP date() format), rather than the user's one * @return PcTask|false */ public function setDueDate($dueDateExpression, $incomingDateFormat = '') { if (!$dueDateExpression) { return parent::setDueDate($dueDateExpression); } $dueDateExpression = trim($dueDateExpression); $dueDateValue = ''; $timestamp = false; // let's look for extended format $dateFormat = DateFormat::getInstance(); $dateBits = $dateFormat->getDateBits($dueDateExpression, $incomingDateFormat); $loggedInUser = PcUserPeer::getLoggedInUser(); if (count($dateBits)) { list($day, $month, $year) = $dateBits; if ($day) { return parent::setDueDate("{$year}-{$month}-{$day}"); } } else { if ($dueDateExpression == 'today' || $dueDateExpression == 'tod') { $timestamp = $loggedInUser->getTime(); } else { if ($dueDateExpression == 'tomorrow' || $dueDateExpression == 'tom') { $timestamp = $loggedInUser->getTime() + 86400; } else { // let's look for the other expressions $dueDateExpression = str_replace('in ', '+', $dueDateExpression); // we do this so we can use strtotime // the strtotime function is a bit lenient: it accepts date shortcuts such as 'in 1 mondddth' // returning today's date (???) // Thus we need some filtering: the dueDateExpression has to contain at least one of the following words: $legalWords = array('next', 'day', 'days', 'week', 'weeks', 'month', 'months', 'year', 'years', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'); $dueDateExpressionWords = explode(' ', $dueDateExpression); if (!count(array_intersect($legalWords, $dueDateExpressionWords))) { return false; } $timestamp = strtotime($dueDateExpression, $loggedInUser->getTime()); } } } if ($timestamp) { return parent::setDueDate(date('Y-m-d', $timestamp)); } return false; }