本文整理汇总了PHP中TimeExpressionParser::parseDate方法的典型用法代码示例。如果您正苦于以下问题:PHP TimeExpressionParser::parseDate方法的具体用法?PHP TimeExpressionParser::parseDate怎么用?PHP TimeExpressionParser::parseDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeExpressionParser
的用法示例。
在下文中一共展示了TimeExpressionParser::parseDate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
/**
* Set field value(s) for the table row represented by this object
*
* @param string|array string $pa_fields representation of a field name
* or array of string representations of field names
* @param mixed $pm_value value to set the given field(s) to
* @param array $pa_options associative array of options
* possible options (keys):
* when dealing with date/time fields:
* - SET_DIRECT_DATE
* - SET_DIRECT_TIME
* - SET_DIRECT_TIMES
*
* for media/files fields:
* - original_filename : (note that it is lower case) optional parameter which enables you to pass the original filename of a file, in addition to the representation in the temporary, global _FILES array;
*
* for text fields:
* - purify : if set then text input is run through HTML Purifier before being set
*
* for parent_id field:
* - treatParentIDAsIdno: force parent_id value to be used as idno lookup rather than a primary key value
*/
public function set($pa_fields, $pm_value = "", $pa_options = null)
{
$this->errors = array();
if (!is_array($pa_fields)) {
$pa_fields = array($pa_fields => $pm_value);
}
foreach ($pa_fields as $vs_field => $vm_value) {
if (array_key_exists($vs_field, $this->FIELDS)) {
$pa_fields_type = $this->getFieldInfo($vs_field, "FIELD_TYPE");
$pb_need_reload = false;
if (!$this->verifyFieldValue($vs_field, $vm_value, $pb_need_reload)) {
return false;
}
if ($pb_need_reload) {
return true;
}
// was set to default
if ($vs_field == $this->primaryKey()) {
$vm_value = preg_replace("/[\"']/", "", $vm_value);
}
$vs_cur_value = isset($this->_FIELD_VALUES[$vs_field]) ? $this->_FIELD_VALUES[$vs_field] : null;
switch ($pa_fields_type) {
case FT_NUMBER:
if ($vs_cur_value != $vm_value) {
$this->_FIELD_VALUE_CHANGED[$vs_field] = true;
}
if ($vs_field == $this->HIERARCHY_PARENT_ID_FLD && (strlen($vm_value) > 0 && (!is_numeric($vm_value) || caGetOption('treatParentIDAsIdno', $pa_options, false)))) {
if (is_array($va_ids = call_user_func_array($this->tableName() . "::find", array(array('idno' => $vm_value, 'deleted' => 0), array('returnAs' => 'ids', 'transaction' => $this->getTransaction()))))) {
$vm_value = array_shift($va_ids);
}
}
if ($vm_value !== "" || $this->getFieldInfo($vs_field, "IS_NULL") && $vm_value == "") {
if ($vm_value) {
if (($vs_list_code = $this->getFieldInfo($vs_field, "LIST_CODE")) && !is_numeric($vm_value)) {
// translate ca_list_item idno's into item_ids if necessary
if ($vn_id = ca_lists::getItemID($vs_list_code, $vm_value)) {
$vm_value = $vn_id;
} else {
$this->postError(1103, _t('Value %1 is not in list %2', $vm_value, $vs_list_code), 'BaseModel->set()', $this->tableName() . '.' . $vs_field);
return false;
}
} else {
$vm_orig_value = $vm_value;
$vm_value = preg_replace("/[^\\d-.]+/", "", $vm_value);
# strip non-numeric characters
if (!preg_match("/^[\\-]{0,1}[\\d.]+\$/", $vm_value)) {
$this->postError(1100, _t("'%1' for %2 is not numeric", $vm_orig_value, $vs_field), "BaseModel->set()", $this->tableName() . '.' . $vs_field);
return false;
}
}
}
$this->_FIELD_VALUES[$vs_field] = $vm_value;
}
break;
case FT_BIT:
if ($vs_cur_value != $vm_value) {
$this->_FIELD_VALUE_CHANGED[$vs_field] = true;
}
$this->_FIELD_VALUES[$vs_field] = $vm_value ? 1 : 0;
break;
case FT_DATETIME:
case FT_HISTORIC_DATETIME:
case FT_DATE:
case FT_HISTORIC_DATE:
if ($this->DIRECT_DATETIMES || $pa_options["SET_DIRECT_DATE"]) {
$this->_FIELD_VALUES[$vs_field] = $vm_value;
$this->_FIELD_VALUE_CHANGED[$vs_field] = true;
} else {
if (!$vm_value && $this->FIELDS[$vs_field]["IS_NULL"]) {
if ($vs_cur_value) {
$this->_FIELD_VALUE_CHANGED[$vs_field] = true;
}
$this->_FIELD_VALUES[$vs_field] = null;
} else {
$o_tep = new TimeExpressionParser();
if ($pa_fields_type == FT_DATE || $pa_fields_type == FT_HISTORIC_DATE) {
$va_timestamps = $o_tep->parseDate($vm_value);
} else {
//.........这里部分代码省略.........
示例2: set
/**
* Set field value(s) for the table row represented by this object
*
* @param string|array string $pa_fields representation of a field name
* or array of string representations of field names
* @param mixed $pm_value value to set the given field(s) to
* @param array $pa_options associative array of options
* possible options (keys):
* when dealing with date/time fields:
* - SET_DIRECT_DATE
* - SET_DIRECT_TIME
* - SET_DIRECT_TIMES
*
* for media/files fields:
* - original_filename : (note that it is lower case) optional parameter which enables you to pass the original filename of a file, in addition to the representation in the temporary, global _FILES array;
*
* for text fields:
* - purify : if set then text input is run through HTML Purifier before being set
*/
public function set($pa_fields, $pm_value = "", $pa_options = null)
{
$this->errors = array();
if (!is_array($pa_fields)) {
$pa_fields = array($pa_fields => $pm_value);
}
foreach ($pa_fields as $vs_field => $vm_value) {
if (array_key_exists($vs_field, $this->FIELDS)) {
$pa_fields_type = $this->getFieldInfo($vs_field, "FIELD_TYPE");
$pb_need_reload = false;
if (!$this->verifyFieldValue($vs_field, $vm_value, $pb_need_reload)) {
return false;
}
if ($pb_need_reload) {
return true;
}
// was set to default
if ($vs_field == $this->primaryKey()) {
$vm_value = preg_replace("/[\"']/", "", $vm_value);
}
// what markup is supported for text fields?
$vs_markup_type = $this->getFieldInfo($vs_field, "MARKUP_TYPE");
// if markup is non-HTML then strip out HTML special chars for safety
if (!($vs_markup_type == __CA_MT_HTML__)) {
$vm_value = htmlspecialchars($vm_value, ENT_QUOTES, 'UTF-8');
}
$vs_cur_value = isset($this->_FIELD_VALUES[$vs_field]) ? $this->_FIELD_VALUES[$vs_field] : null;
switch ($pa_fields_type) {
case FT_NUMBER:
if ($vs_cur_value != $vm_value) {
$this->_FIELD_VALUE_CHANGED[$vs_field] = true;
}
if ($vm_value !== "" || $this->getFieldInfo($vs_field, "IS_NULL") && $vm_value == "") {
if ($vm_value) {
if (($vs_list_code = $this->getFieldInfo($vs_field, "LIST_CODE")) && !is_numeric($vm_value)) {
// translate ca_list_item idno's into item_ids if necessary
if ($vn_id = ca_lists::getItemID($vs_list_code, $vm_value)) {
$vm_value = $vn_id;
}
} else {
$vm_orig_value = $vm_value;
$vm_value = preg_replace("/[^\\d-.]+/", "", $vm_value);
# strip non-numeric characters
if (!preg_match("/^[\\-]{0,1}[\\d.]+\$/", $vm_value)) {
$this->postError(1100, _t("'%1' for %2 is not numeric", $vm_orig_value, $vs_field), "BaseModel->set()");
return "";
}
}
}
$this->_FIELD_VALUES[$vs_field] = $vm_value;
}
break;
case FT_BIT:
if ($vs_cur_value != $vm_value) {
$this->_FIELD_VALUE_CHANGED[$vs_field] = true;
}
$this->_FIELD_VALUES[$vs_field] = $vm_value ? 1 : 0;
break;
case FT_DATETIME:
case FT_HISTORIC_DATETIME:
case FT_DATE:
case FT_HISTORIC_DATE:
if ($this->DIRECT_DATETIMES || $pa_options["SET_DIRECT_DATE"]) {
$this->_FIELD_VALUES[$vs_field] = $vm_value;
$this->_FIELD_VALUE_CHANGED[$vs_field] = true;
} else {
if (!$vm_value && $this->FIELDS[$vs_field]["IS_NULL"]) {
if ($vs_cur_value) {
$this->_FIELD_VALUE_CHANGED[$vs_field] = true;
}
$this->_FIELD_VALUES[$vs_field] = null;
} else {
$o_tep = new TimeExpressionParser();
if ($pa_fields_type == FT_DATE || $pa_fields_type == FT_HISTORIC_DATE) {
$va_timestamps = $o_tep->parseDate($vm_value);
} else {
$va_timestamps = $o_tep->parseDatetime($vm_value);
}
if (!$va_timestamps) {
$this->postError(1805, $o_tep->getParseErrorMessage(), 'BaseModel->set()');
return false;
//.........这里部分代码省略.........