MetaDate::IsValid PHP Method

IsValid() public static method

public static IsValid ( $p_value )
    public static function IsValid($p_value)
    {
        $p_value = trim($p_value);
        // curdate() is an value which have to be computed
        if (preg_match('/now\\(\\)|curdate\\(\\)|curtime\\(\\)/i', $p_value)) {
            return true;
        }
        if (preg_match('/^[\\d]{4,4}-[\\d]{1,2}-[\\d]{1,2}$/', $p_value) == 0) {
            return false;
        }
        list($year, $month, $monthDay) = preg_split('/-/', $p_value);
        if ($month < 1 || $month > 12) {
            return false;
        }
        $lastMonthDay = strftime('%d', mktime(0, 0, 0, $month + 1, 0, $year));
        if ($monthDay < 1 || $monthDay > $lastMonthDay) {
            return false;
        }
        return true;
    }

Usage Example

Ejemplo n.º 1
0
 public function setValue($p_value)
 {
     if (!MetaDate::IsValid($p_value)) {
         throw new InvalidValueException($p_value, MetaDate::GetTypeName());
     }
     $this->m_value = trim($p_value);
     list($this->m_year, $this->m_month, $this->m_monthDay) = preg_split('/-/', $this->m_value);
     $timestamp = strtotime($this->m_value);
     $date_time = getdate($timestamp);
     $this->m_weekDay = $date_time['wday'];
 }
All Usage Examples Of MetaDate::IsValid