本文整理汇总了PHP中Date_Calc::compareDates方法的典型用法代码示例。如果您正苦于以下问题:PHP Date_Calc::compareDates方法的具体用法?PHP Date_Calc::compareDates怎么用?PHP Date_Calc::compareDates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Date_Calc
的用法示例。
在下文中一共展示了Date_Calc::compareDates方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isbatchingmaintenancecurrent
function isbatchingmaintenancecurrent($batching_expiration_date)
{
$bedate = $batching_expiration_date ? new CDate($batching_expiration_date) : null;
$now = new CDate();
if (Date_Calc::compareDates($bedate->day, $bedate->month, $bedate->year, $now->day, $now->month, $now->year) < 0) {
return "No";
} else {
return "Yes";
}
}
示例2: getAgo
public static function getAgo($timestamp)
{
if ($timestamp === null) {
return '';
}
$diffdays = Date_Calc::dateDiff(date('j', $timestamp), date('n', $timestamp), date('Y', $timestamp), date('j'), date('n'), date('Y'));
/* An error occured. */
if ($diffdays == -1) {
return;
}
$ago = $diffdays * Date_Calc::compareDates(date('j', $timestamp), date('n', $timestamp), date('Y', $timestamp), date('j'), date('n'), date('Y'));
if ($ago < -1) {
return sprintf(Horde_Model_Translation::t(" (%s days ago)"), $diffdays);
} elseif ($ago == -1) {
return Horde_Model_Translation::t(" (yesterday)");
} elseif ($ago == 0) {
return Horde_Model_Translation::t(" (today)");
} elseif ($ago == 1) {
return Horde_Model_Translation::t(" (tomorrow)");
} else {
return sprintf(Horde_Model_Translation::t(" (in %s days)"), $diffdays);
}
}
示例3: date
//.........这里部分代码省略.........
if ($day < 1 || $day > 31) {
return false;
}
break;
case 'm':
case 'n':
if ($next == 'm') {
$month = (int) Validate::_substr($date, 0, 2);
} else {
$month = (int) Validate::_substr($date, 1, 2);
}
if ($month < 1 || $month > 12) {
return false;
}
break;
case 'Y':
case 'y':
if ($next == 'Y') {
$year = Validate::_substr($date, 4);
$year = (int) $year ? $year : '';
} else {
$year = (int) (substr(date('Y'), 0, 2) . Validate::_substr($date, 2));
}
if (strlen($year) != 4 || $year < 0 || $year > 9999) {
return false;
}
break;
case 'g':
case 'h':
if ($next == 'g') {
$hour = Validate::_substr($date, 1, 2);
} else {
$hour = Validate::_substr($date, 2);
}
if (!preg_match('/^\\d+$/', $hour) || $hour < 0 || $hour > 12) {
return false;
}
break;
case 'G':
case 'H':
if ($next == 'G') {
$hour = Validate::_substr($date, 1, 2);
} else {
$hour = Validate::_substr($date, 2);
}
if (!preg_match('/^\\d+$/', $hour) || $hour < 0 || $hour > 24) {
return false;
}
break;
case 's':
case 'i':
$t = Validate::_substr($date, 2);
if (!preg_match('/^\\d+$/', $t) || $t < 0 || $t > 59) {
return false;
}
break;
default:
trigger_error("Not supported char `{$next}' after % in offset " . ($i + 2), E_USER_WARNING);
}
$i++;
} else {
//literal
if (Validate::_substr($date, 1) != $c) {
return false;
}
}
}
}
// there is remaing data, we don't want it
if (strlen($date) && strtolower($format) != 'rfc822_compliant') {
return false;
}
if (isset($day) && isset($month) && isset($year)) {
if (!checkdate($month, $day, $year)) {
return false;
}
if (strtolower($format) == 'rfc822_compliant') {
if ($weekday != date("D", mktime(0, 0, 0, $month, $day, $year))) {
return false;
}
}
if ($min) {
include_once 'Date/Calc.php';
if (is_a($min, 'Date') && Date_Calc::compareDates($day, $month, $year, $min->getDay(), $min->getMonth(), $min->getYear()) < 0) {
return false;
} elseif (is_array($min) && Date_Calc::compareDates($day, $month, $year, $min[0], $min[1], $min[2]) < 0) {
return false;
}
}
if ($max) {
include_once 'Date/Calc.php';
if (is_a($max, 'Date') && Date_Calc::compareDates($day, $month, $year, $max->getDay(), $max->getMonth(), $max->getYear()) > 0) {
return false;
} elseif (is_array($max) && Date_Calc::compareDates($day, $month, $year, $max[0], $max[1], $max[2]) > 0) {
return false;
}
}
}
return true;
}
示例4: date
//.........这里部分代码省略.........
$date_len = strlen($format);
for ($i = 0; $i < strlen($format); $i++) {
$c = $format[$i];
if ($c == '%') {
$next = $format[$i + 1];
switch ($next) {
case 'j':
case 'd':
if ($next == 'j') {
$day = (int) Validate::_substr($date, 1, 2);
} else {
$day = (int) Validate::_substr($date, 2);
}
if ($day < 1 || $day > 31) {
return false;
}
break;
case 'm':
case 'n':
if ($next == 'm') {
$month = (int) Validate::_substr($date, 2);
} else {
$month = (int) Validate::_substr($date, 1, 2);
}
if ($month < 1 || $month > 12) {
return false;
}
break;
case 'Y':
case 'y':
if ($next == 'Y') {
$year = Validate::_substr($date, 4);
$year = (int) $year ? $year : '';
} else {
$year = (int) (substr(date('Y'), 0, 2) . Validate::_substr($date, 2));
}
if (strlen($year) != 4 || $year < 0 || $year > 9999) {
return false;
}
break;
case 'g':
case 'h':
if ($next == 'g') {
$hour = Validate::_substr($date, 1, 2);
} else {
$hour = Validate::_substr($date, 2);
}
if ($hour < 0 || $hour > 12) {
return false;
}
break;
case 'G':
case 'H':
if ($next == 'G') {
$hour = Validate::_substr($date, 1, 2);
} else {
$hour = Validate::_substr($date, 2);
}
if ($hour < 0 || $hour > 24) {
return false;
}
break;
case 's':
case 'i':
$t = Validate::_substr($date, 2);
if ($t < 0 || $t > 59) {
return false;
}
break;
default:
trigger_error("Not supported char `{$next}' after % in offset " . ($i + 2), E_USER_WARNING);
}
$i++;
} else {
//literal
if (Validate::_substr($date, 1) != $c) {
return false;
}
}
}
// there is remaing data, we don't want it
if (strlen($date)) {
return false;
}
if (isset($day) && isset($month) && isset($year)) {
if (!checkdate($month, $day, $year)) {
return false;
}
if ($min || $max) {
include_once 'Date/Calc.php';
if ($min && Date_Calc::compareDates($day, $month, $year, $min[0], $min[1], $min[2]) < 0) {
return false;
}
if ($max && Date_Calc::compareDates($day, $month, $year, $max[0], $max[1], $max[2]) > 0) {
return false;
}
}
}
return true;
}
示例5: compare
compare('20050125', Date_Calc::NWeekdayOfMonth('last', 2, 1, 2005), 'NWeekdayOfMonth l21');
compare('20050331', Date_Calc::NWeekdayOfMonth('last', 4, 3, 2005), 'NWeekdayOfMonth l43');
compare('20050330', Date_Calc::NWeekdayOfMonth('last', 3, 3, 2005), 'NWeekdayOfMonth l33');
compare('20050329', Date_Calc::NWeekdayOfMonth('last', 2, 3, 2005), 'NWeekdayOfMonth l23');
compare('20050328', Date_Calc::NWeekdayOfMonth('last', 1, 3, 2005), 'NWeekdayOfMonth l13');
compare('20050327', Date_Calc::NWeekdayOfMonth('last', 0, 3, 2005), 'NWeekdayOfMonth l03');
compare('20050326', Date_Calc::NWeekdayOfMonth('last', 6, 3, 2005), 'NWeekdayOfMonth l63');
compare('20050325', Date_Calc::NWeekdayOfMonth('last', 5, 3, 2005), 'NWeekdayOfMonth l53');
compare(false, Date_Calc::isValidDate(29, 2, 1900), 'isValidDate 1');
compare(true, Date_Calc::isValidDate(29, 2, 2000), 'isValidDate 2');
compare(true, Date_Calc::isValidDate('29', '02', '2000'), 'isValidDate 2 str');
compare(false, Date_Calc::isLeapYear(1900), 'isLeapYear 1');
compare(true, Date_Calc::isLeapYear(1996), 'isLeapYear 2');
compare(true, Date_Calc::isLeapYear(2000), 'isLeapYear 3');
compare(false, Date_Calc::isLeapYear(2001), 'isLeapYear 4');
compare(false, Date_Calc::isLeapYear('2001'), 'isLeapYear 4 str');
compare(false, Date_Calc::isFutureDate('22', '11', '2000'), 'isFutureDate 1 str');
compare(false, Date_Calc::isFutureDate(22, 11, 2000), 'isFutureDate 1');
compare(true, Date_Calc::isFutureDate(22, 11, date('Y') + 1), 'isFutureDate 2');
compare(false, Date_Calc::isPastDate(22, 11, date('Y') + 1), 'isPastDate 1');
compare(true, Date_Calc::isPastDate(22, 11, 2000), 'isPastDate 2');
compare(true, Date_Calc::isPastDate('22', '11', '2000'), 'isPastDate 2 str');
compare(10, Date_Calc::dateDiff(22, 11, 2000, 12, 11, 2000), 'dateDiff 1');
compare(10, Date_Calc::dateDiff(12, 11, 2000, 22, 11, 2000), 'dateDiff 2');
compare(61, Date_Calc::dateDiff(22, 11, 2000, 22, 1, 2001), 'dateDiff 3');
compare(61, Date_Calc::dateDiff('22', '11', '2000', '22', '01', '2001'), 'dateDiff 3 str');
compare(-1, Date_Calc::compareDates(12, 11, 2000, 22, 11, 2000), 'compareDates 1');
compare(0, Date_Calc::compareDates(22, 11, 2000, 22, 11, 2000), 'compareDates 2');
compare(1, Date_Calc::compareDates(22, 11, 2000, 12, 11, 2000), 'compareDates 3');
compare(1, Date_Calc::compareDates('22', '11', '2000', '12', '11', '2000'), 'compareDates 3 str');