本文整理汇总了PHP中QDateTime::IsDateNull方法的典型用法代码示例。如果您正苦于以下问题:PHP QDateTime::IsDateNull方法的具体用法?PHP QDateTime::IsDateNull怎么用?PHP QDateTime::IsDateNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDateTime
的用法示例。
在下文中一共展示了QDateTime::IsDateNull方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Validate
public function Validate()
{
if (!parent::Validate()) {
return false;
}
if ($this->strText != '') {
$dttDateTime = new QDateTime($this->strText);
if ($dttDateTime->IsDateNull()) {
$this->strValidationError = QApplication::Translate("invalid date");
return false;
}
if (!is_null($this->Minimum)) {
if ($dttDateTime->IsEarlierThan($this->Minimum)) {
$this->strValidationError = QApplication::Translate("date is earlier than minimum allowed");
return false;
}
}
if (!is_null($this->Maximum)) {
if ($dttDateTime->IsLaterThan($this->Maximum)) {
$this->strValidationError = QApplication::Translate("date is later than maximum allowed");
return false;
}
}
}
$this->strValidationError = '';
return true;
}
示例2: Validate
/**
* Validate the control.
* @return bool
*/
public function Validate()
{
if (!parent::Validate()) {
return false;
}
if ($this->strText != '') {
$dttDateTime = new QDateTime($this->strText, null, QDateTime::DateOnlyType);
if ($dttDateTime->IsDateNull()) {
$this->ValidationError = QApplication::Translate("Invalid date");
return false;
}
if (!is_null($this->Minimum)) {
if ($dttDateTime->IsEarlierThan($this->Minimum)) {
if ($this->strMinDateErrorMsg) {
$this->ValidationError = $this->strMinDateErrorMsg;
} else {
$this->ValidationError = QApplication::Translate("Date is earlier than minimum allowed");
}
return false;
}
}
if (!is_null($this->Maximum)) {
if ($dttDateTime->IsLaterThan($this->Maximum)) {
if ($this->strMaxDateErrorMsg) {
$this->ValidationError = $this->strMaxDateErrorMsg;
} else {
$this->ValidationError = QApplication::Translate("Date is later than maximum allowed");
}
return false;
}
}
}
return true;
}
示例3: testIncompleteDates
public function testIncompleteDates()
{
$obj1 = new QDateTime("Feb 12");
$this->assertFalse($obj1->IsNull());
$this->assertFalse($obj1->IsDateNull());
$this->assertTrue($obj1->IsTimeNull());
$obj2 = new QDateTime("March 2003");
$this->assertFalse($obj2->IsNull());
$this->assertFalse($obj2->IsDateNull());
$this->assertTrue($obj2->IsTimeNull());
}
示例4: ParseForDateTimeValue
public static function ParseForDateTimeValue($strText)
{
// Trim and Clean
$strText = strtolower(trim($strText));
while (strpos($strText, ' ') !== false) {
$strText = str_replace(' ', ' ', $strText);
}
$strText = str_replace('.', '', $strText);
$strText = str_replace('@', ' ', $strText);
// Are we ATTEMPTING to parse a Time value?
if (strpos($strText, ':') === false && strpos($strText, 'am') === false && strpos($strText, 'pm') === false) {
// There is NO TIME VALUE
$dttToReturn = new QDateTime($strText);
if ($dttToReturn->IsDateNull()) {
return null;
} else {
return $dttToReturn;
}
}
// Add ':00' if it doesn't exist AND if 'am' or 'pm' exists
if (strpos($strText, 'pm') !== false && strpos($strText, ':') === false) {
$strText = str_replace(' pm', ':00 pm', $strText, $intCount);
if (!$intCount) {
$strText = str_replace('pm', ':00 pm', $strText, $intCount);
}
} else {
if (strpos($strText, 'am') !== false && strpos($strText, ':') === false) {
$strText = str_replace(' am', ':00 am', $strText, $intCount);
if (!$intCount) {
$strText = str_replace('am', ':00 am', $strText, $intCount);
}
}
}
$dttToReturn = new QDateTime($strText);
if ($dttToReturn->IsDateNull()) {
return null;
} else {
return $dttToReturn;
}
}
示例5: GetControlHtml
protected function GetControlHtml()
{
// Ignore Class
$strCssClass = $this->strCssClass;
$this->strCssClass = '';
$strAttributes = $this->GetAttributes();
$this->strCssClass = $strCssClass;
$strStyle = $this->GetStyleAttributes();
if ($strStyle) {
$strAttributes .= sprintf(' style="%s"', $strStyle);
}
$strCommand = sprintf(' onchange="Qcodo__DateTimePicker_Change(\'%s\', this);"', $this->strControlId);
if ($this->dttDateTime) {
$dttDateTime = $this->dttDateTime;
} else {
$dttDateTime = new QDateTime();
}
$strToReturn = '';
// Generate Date-portion
switch ($this->strDateTimePickerType) {
case QDateTimePickerType::Date:
case QDateTimePickerType::DateTime:
case QDateTimePickerType::DateTimeSeconds:
// Month
$strMonthListbox = sprintf('<select name="%s_lstMonth" id="%s_lstMonth" class="month" %s%s>', $this->strControlId, $this->strControlId, $strAttributes, $strCommand);
if (!$this->blnRequired || $dttDateTime->IsDateNull()) {
$strMonthListbox .= '<option value="">--</option>';
}
$dttMonth = new QDateTime('2000-01-01');
for ($intMonth = 1; $intMonth <= 12; $intMonth++) {
if (!$dttDateTime->IsDateNull() && $dttDateTime->Month == $intMonth || $this->intSelectedMonth == $intMonth) {
$strSelected = ' selected="selected"';
} else {
$strSelected = '';
}
$dttMonth->Month = $intMonth;
$strMonthListbox .= sprintf('<option value="%s"%s>%s</option>', $intMonth, $strSelected, $dttMonth->ToString('MMM'));
}
$strMonthListbox .= '</select>';
// Day
$strDayListbox = sprintf('<select name="%s_lstDay" id="%s_lstDay" class="day" %s%s>', $this->strControlId, $this->strControlId, $strAttributes, $strCommand);
if (!$this->blnRequired || $dttDateTime->IsDateNull()) {
$strDayListbox .= '<option value="">--</option>';
}
if ($dttDateTime->IsDateNull()) {
if ($this->blnRequired) {
// New DateTime, but we are required -- therefore, let's assume January is preselected
for ($intDay = 1; $intDay <= 31; $intDay++) {
$strDayListbox .= sprintf('<option value="%s">%s</option>', $intDay, $intDay);
}
} else {
// New DateTime -- but we are NOT required
// See if a month has been selected yet.
if ($this->intSelectedMonth) {
$intSelectedYear = $this->intSelectedYear ? $this->intSelectedYear : 2000;
$intDaysInMonth = date('t', mktime(0, 0, 0, $this->intSelectedMonth, 1, $intSelectedYear));
for ($intDay = 1; $intDay <= $intDaysInMonth; $intDay++) {
if ($dttDateTime->Day == $intDay || $this->intSelectedDay == $intDay) {
$strSelected = ' selected="selected"';
} else {
$strSelected = '';
}
$strDayListbox .= sprintf('<option value="%s"%s>%s</option>', $intDay, $strSelected, $intDay);
}
} else {
// It's ok just to have the "--" marks and nothing else
}
}
} else {
$intDaysInMonth = $dttDateTime->PHPDate('t');
for ($intDay = 1; $intDay <= $intDaysInMonth; $intDay++) {
if ($dttDateTime->Day == $intDay || $this->intSelectedDay == $intDay) {
$strSelected = ' selected="selected"';
} else {
$strSelected = '';
}
$strDayListbox .= sprintf('<option value="%s"%s>%s</option>', $intDay, $strSelected, $intDay);
}
}
$strDayListbox .= '</select>';
// Year
$strYearListbox = sprintf('<select name="%s_lstYear" id="%s_lstYear" class="year" %s%s>', $this->strControlId, $this->strControlId, $strAttributes, $strCommand);
if (!$this->blnRequired || $dttDateTime->IsDateNull()) {
$strYearListbox .= '<option value="">--</option>';
}
for ($intYear = $this->intMinimumYear; $intYear <= $this->intMaximumYear; $intYear++) {
if ($dttDateTime->Year == $intYear || $this->intSelectedYear == $intYear) {
$strSelected = ' selected="selected"';
} else {
$strSelected = '';
}
$strYearListbox .= sprintf('<option value="%s"%s>%s</option>', $intYear, $strSelected, $intYear);
}
$strYearListbox .= '</select>';
// Put it all together
switch ($this->strDateTimePickerFormat) {
case QDateTimePickerFormat::MonthDayYear:
$strToReturn .= $strMonthListbox . $strDayListbox . $strYearListbox;
break;
case QDateTimePickerFormat::DayMonthYear:
//.........这里部分代码省略.........
示例6: testSetProperties
public function testSetProperties()
{
$obj1 = new QDateTime();
$obj1->setDate(2002, 3, 15);
$this->assertTrue($obj1->IsTimeNull(), "Setting only a date after null constructor keeps time null");
$obj2 = new QDateTime("2002-03-15");
$obj3 = new QDateTime("2002-03-15 13:15");
$obj4 = new QDateTime("2002-03-16");
$this->assertTrue($obj1->IsEqualTo($obj2));
$this->assertTrue($obj1->IsEqualTo($obj3));
// dates are the same!
$this->assertFalse($obj3->IsEqualTo($obj4));
// dates are different!
$obj5 = new QDateTime('13:15:02', null, QDateTime::TimeOnlyType);
$this->assertTrue($obj5->IsDateNull(), "Setting only a date after null constructor keeps time null");
$obj6 = new QDateTime('2002-03-15 13:15:02');
$obj1->SetTime($obj5);
$this->assertFalse($obj1->IsTimeNull(), "Setting a time with object results in a change in null time status");
$this->assertTrue($obj1->IsEqualTo($obj6), "SetTime correctly combines date only and time only values");
}
示例7: __construct
/**
* Construct a QDateTime. Does a few things differently than the php version:
* - Always stores timestamps in local or given timezone, so time extraction is easy
* - Has settings to determine if you want a date only or time only type
* - Will NOT throw exceptions. Errors simply result in a null datetime.
*
* @param null|integer|string|QDateTime|DateTime $mixValue
* @param DateTimeZone $objTimeZone
* @param int $intType
*
* @throws QCallerException
*/
public function __construct($mixValue = null, DateTimeZone $objTimeZone = null, $intType = QDateTime::UnknownType)
{
if ($mixValue instanceof QDateTime) {
// Cloning from another QDateTime object
if ($objTimeZone) {
throw new QCallerException('QDateTime cloning cannot take in a DateTimeZone parameter');
}
parent::__construct($mixValue->format('Y-m-d H:i:s'), $mixValue->GetTimeZone());
$this->blnDateNull = $mixValue->IsDateNull();
$this->blnTimeNull = $mixValue->IsTimeNull();
$this->ReinforceNullProperties();
} else {
if ($mixValue instanceof DateTime) {
// Subclassing from a PHP DateTime object
if ($objTimeZone) {
throw new QCallerException('QDateTime subclassing of a DateTime object cannot take in a DateTimeZone parameter');
}
parent::__construct($mixValue->format('Y-m-d H:i:s'), $mixValue->getTimezone());
// By definition, a DateTime object doesn't have anything nulled
$this->blnDateNull = false;
$this->blnTimeNull = false;
} else {
if (!$mixValue) {
// Set to "null date"
// And Do Nothing Else -- Default Values are already set to Nulled out
parent::__construct('2000-01-01 00:00:00', $objTimeZone);
} else {
if (strtolower($mixValue) == QDateTime::Now) {
// very common, so quickly deal with now string
parent::__construct('now', $objTimeZone);
$this->blnDateNull = false;
$this->blnTimeNull = false;
} else {
if (substr($mixValue, 0, 1) == '@') {
// unix timestamp. PHP superclass will always store ts in UTC. Our class will store in given timezone, or local tz
parent::__construct(date('Y-m-d H:i:s', substr($mixValue, 1)), $objTimeZone);
$this->blnDateNull = false;
$this->blnTimeNull = false;
} else {
// string relative date or time
if ($intTime = strtotime($mixValue)) {
// The documentation states that:
// The valid range of a timestamp is typically from
// Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.
// (These are the dates that correspond to the minimum and maximum values
// for a 32-bit signed integer).
//
// But experimentally, 0000-01-01 00:00:00 is the least date displayed correctly
if ($intTime < -62167241486) {
// Set to "null date"
// And Do Nothing Else -- Default Values are already set to Nulled out
parent::__construct('2000-01-01 00:00:00', $objTimeZone);
} else {
parent::__construct(date('Y-m-d H:i:s', $intTime), $objTimeZone);
$this->blnDateNull = false;
$this->blnTimeNull = false;
}
} else {
// error
parent::__construct();
$this->blnDateNull = true;
$this->blnTimeNull = true;
}
}
}
}
}
}
// User is requesting to force a particular type.
switch ($intType) {
case QDateTime::DateOnlyType:
$this->blnTimeNull = true;
$this->ReinforceNullProperties();
return;
case QDateTime::TimeOnlyType:
$this->blnDateNull = true;
$this->ReinforceNullProperties();
return;
case QDateTime::DateAndTimeType:
// forcing both a date and time type to not be null
$this->blnDateNull = false;
$this->blnTimeNull = false;
break;
default:
break;
}
}