/** * Check a qCal_Date object to see if it falls within the rules specified * when this object was created (or added later actually). * @param qCal_Date The date that you want to check * @return boolean True if the date falls within the ruleset * @access public */ public function checkDate(qCal_Date $date) { $byDay = $this->getValues(); foreach ($byDay as $wday) { $char1 = substr($wday, 0, 1); $cwday = strtoupper(substr($date->getWeekDayName(), 0, 2)); if (ctype_digit($char1) || $char1 == "-" || $char1 == "+") { // if the first character is a digit or a plus or minus, we // need to check that date is a specific weekday of the month if (preg_match('/([+-]?)([0-9]+)([a-z]+)/i', $wday, $matches)) { list($whole, $sign, $dig, $wd) = $matches; // find out if this day matches the specific weekday of month $xth = (int) ($sign . $dig); // @todo Make sure that getXthWeekDayOfMonth doesn't need // to be passed any month or date here... $dtWdSpecific = $date->getXthWeekdayOfMonth($xth, $wd); if ($dtWdSpecific->__toString() == $date->__toString()) { return true; } } } else { if ($wday == $cwday) { return true; } } } return false; }
/** * Calling __toString will output the date in the format specified by calling setFormat() * You can use any of the date-related meta characters from php's date() function. Time-related * formatting will not work. */ public function testToString() { $date = new qCal_Date(2009, 12, 7); // format defaults to m/d/Y $this->assertEqual($date->__toString(), '12/07/2009'); // european format $date->setFormat('d/m/Y'); $this->assertEqual($date->__toString(), '07/12/2009'); // no leading zeros $date->setFormat('n/j/Y'); $this->assertEqual($date->__toString(), '12/7/2009'); // two-digit year $date->setFormat('n/j/y'); $this->assertEqual($date->__toString(), '12/7/09'); // time-related date meta-characters do not work $date->setFormat('m/d/Y h:i:sa'); $this->assertEqual($date->__toString(), '12/07/2009 h:i:sa'); // you can escape meta-characters with a backslash $date->setFormat('\\m\\d\\ymdy'); $this->assertEqual($date->__toString(), 'mdy120709'); }
public function testDateConvertToString() { $date = new qCal_Date(2010, 1, 10); $this->assertEqual($date->__toString(), "01/10/2010"); // will output "01/10/2010" }