本文整理匯總了PHP中DateHelper::strToTime方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateHelper::strToTime方法的具體用法?PHP DateHelper::strToTime怎麽用?PHP DateHelper::strToTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DateHelper
的用法示例。
在下文中一共展示了DateHelper::strToTime方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: updateDayOdometer
/**
* Функция высчитывает данные о пройденном расстоянии от выбранной даты или за все время
*
* @param int $carID
* @param string $date
*/
protected static function updateDayOdometer($carID = null, $date = null)
{
$dateHelper = new DateHelper();
$arResult = array();
if (is_null($carID)) {
$carID = MyCar::getDefaultCarID();
}
if (is_null($date)) {
//TODO: Проверить работу кода
$arRes = Tables\RoutsTable::getList(array('select' => array('ID', 'DATE', 'ODO'), 'filter' => array('MY_CAR_ID' => $carID, '>ODO' => 0), 'order' => array('DATE' => 'ASC', 'ID' => 'ASC')));
$arResult['BUY_ODO'] = MyCar::getBuyCarOdo($carID);
$arResult['MAX_DATE_ODO'] = array();
$bFirst = true;
foreach ($arRes as $ar_res) {
if ($bFirst) {
$bFirst = false;
$arResult['FIRST_DAY'] = $ar_res['DATE'];
}
$arResult['ROUTS'][$ar_res['ID']]['DATE'] = $ar_res['DATE'];
$arResult['ROUTS'][$ar_res['ID']]['ODO'] = $ar_res['ODO'];
if (!isset($arResult['MAX_DATE_ODO'][$ar_res['DATE']]) || $ar_res['ODO'] > $arResult['MAX_DATE_ODO'][$ar_res['DATE']]) {
$arResult['MAX_DATE_ODO'][$ar_res['DATE']] = $ar_res['ODO'];
}
}
$arResult['LAST_DAY'] = date('d.m.Y');
$lastOdo = $arResult['BUY_ODO'];
$arResult['DAY_ODO'] = array();
foreach ($arResult['MAX_DATE_ODO'] as $day => $odo) {
$arResult['DAY_ODO'][$day] = round($odo - $lastOdo, 1);
$lastOdo = $odo;
}
$arResult['ODO_ALL_DAYS'] = array();
$now_day = $arResult['FIRST_DAY'];
while ($now_day !== $arResult['LAST_DAY']) {
if (isset($arResult['DAY_ODO'][$now_day])) {
$arResult['ODO_ALL_DAYS'][$now_day] = $arResult['DAY_ODO'][$now_day];
} else {
$arResult['ODO_ALL_DAYS'][$now_day] = 0;
}
$now_day = $dateHelper->strToTime($now_day, '+1 day', 'site');
}
} else {
$arResult['FIRST_DAY'] = $date;
$arResult['LAST_DAY'] = date('d.m.Y');
$arResult['BUY_ODO'] = MyCar::getBuyCarOdo($carID);
//TODO: Проверить работу кода
$arRes = Tables\RoutsTable::getList(array('select' => array('ID', 'DATE', 'ODO'), 'filter' => array('MY_CAR_ID' => $carID, '>=DATE' => $date, '>ODO' => 0), 'order' => array('DATE' => 'ASC', 'ID' => 'ASC')));
$arResult['MAX_DATE_ODO'] = array();
foreach ($arRes as $ar_res) {
$arResult['ROUTS'][$ar_res['ID']]['DATE'] = $ar_res['DATE'];
$arResult['ROUTS'][$ar_res['ID']]['ODO'] = $ar_res['ODO'];
if (!isset($arResult['MAX_DATE_ODO'][$ar_res['DATE']]) || $ar_res['ODO'] > $arResult['MAX_DATE_ODO'][$ar_res['DATE']]) {
$arResult['MAX_DATE_ODO'][$ar_res['DATE']] = $ar_res['ODO'];
}
}
//TODO: Проверить работу кода
$arRes2 = Tables\RoutsTable::getList(array('select' => array('ID', 'DATE', 'ODO'), 'filter' => array('MY_CAR_ID' => $carID, '<DATE' => $date, '>ODO' => 0), 'order' => array('DATE' => 'DESC', 'ID' => 'DESC')));
if ($arRes2) {
$lastOdo = $arRes2[0]['ODO'];
$arResult['LAST_RES'] = $arRes2[0];
} else {
$lastOdo = $arResult['BUY_ODO'];
}
$arResult['LAST_ODO'] = $lastOdo;
$arResult['DAY_ODO'] = array();
foreach ($arResult['MAX_DATE_ODO'] as $day => $odo) {
$arResult['DAY_ODO'][$day] = round($odo - $lastOdo, 1);
$lastOdo = $odo;
}
$arResult['ODO_ALL_DAYS'] = array();
$now_day = $arResult['FIRST_DAY'];
while ($now_day !== $arResult['LAST_DAY']) {
if (isset($arResult['DAY_ODO'][$now_day])) {
$arResult['ODO_ALL_DAYS'][$now_day] = $arResult['DAY_ODO'][$now_day];
} else {
$arResult['ODO_ALL_DAYS'][$now_day] = 0;
}
$now_day = $dateHelper->strToTime($now_day, '+1 day', 'site');
}
}
//TODO: Проверить работу кода
$arRes2 = Tables\OdoTable::getList(array('select' => array('ID', 'DATE', 'ODO'), 'filter' => array('MY_CAR_ID' => $carID, '>=DATE' => $arResult['FIRST_DAY']), 'order' => array('DATE' => 'ASC')));
$arResult['ODO_TABLE'] = array();
foreach ($arRes2 as $ar_res) {
$arResult['ODO_TABLE'][$ar_res['DATE']] = array('ID' => $ar_res['ID'], 'ODO' => $ar_res['ODO']);
}
$arResult['UPDATED'] = $arResult['INSERTED'] = array();
foreach ($arResult['ODO_ALL_DAYS'] as $day => $odo) {
if (isset($arResult['ODO_TABLE'][$day])) {
if ($odo != $arResult['ODO_TABLE'][$day]['ODO']) {
$query = new Query('update');
$query->setUpdateParams(array('ODO' => $odo), $arResult['ODO_TABLE'][$day]['ID'], Tables\OdoTable::getTableName(), Tables\OdoTable::getMapArray());
$res = $query->exec();
$arResult['UPDATED'][$day] = $res->getResult();
//.........這裏部分代碼省略.........