Пример #1
0
function CCDateAdd($date, $value)
{
    if (CCValidateDate($date)) {
        $FormatArray = array("yyyy", "-", "mm", "-", "dd", " ", "HH", ":", "nn", ":", "ss");
        $value = strtolower($value);
        preg_match_all("/([-+]?)(\\d+)\\s*(year(s?)|month(s?)|day(s?)|hour(s?)|minute(s?)|second(s?)|week(s?)|[ymdwhns])/", $value, $pieces);
        for ($i = 0; $i < count($pieces[0]); $i++) {
            $rel = $pieces[1][$i] == "-" ? -$pieces[2][$i] : $pieces[2][$i];
            $BackMonth = false;
            switch ($pieces[3][$i]) {
                case "years":
                case "year":
                case "y":
                    $date[ccsYear] += $rel;
                    $BackMonth = true;
                    break;
                case "months":
                case "month":
                case "m":
                    $date[ccsMonth] += $rel;
                    $BackMonth = true;
                    break;
                case "weeks":
                case "week":
                case "w":
                    $date[ccsDay] += $rel * 7;
                    break;
                case "days":
                case "day":
                case "d":
                    $date[ccsDay] += $rel;
                    break;
                case "hours":
                case "hour":
                case "h":
                    $date[ccsHour] += $rel;
                    break;
                case "minutes":
                case "minute":
                case "min":
                case "n":
                    $date[ccsMinute] += $rel;
                    break;
                case "seconds":
                case "second":
                case "sec":
                case "s":
                    $date[ccsSecond] += $rel;
                    break;
            }
            if ($date[ccsSecond] >= 60) {
                $date[ccsMinute] += floor($date[ccsSecond] / 60);
                $date[ccsSecond] = $date[ccsSecond] % 60;
            } elseif ($date[ccsSecond] < 0) {
                $date[ccsMinute] += floor($date[ccsSecond] / 60);
                $date[ccsSecond] = ($date[ccsSecond] % 60 + 60) % 60;
            }
            if ($date[ccsMinute] >= 60) {
                $date[ccsHour] += floor($date[ccsMinute] / 60);
                $date[ccsMinute] = $date[ccsMinute] % 60;
            } elseif ($date[ccsMinute] < 0) {
                $date[ccsHour] += floor($date[ccsMinute] / 60);
                $date[ccsMinute] = ($date[ccsMinute] % 60 + 60) % 60;
            }
            if ($date[ccsHour] >= 24) {
                $date[ccsDay] += floor($date[ccsHour] / 24);
                $date[ccsHour] = $date[ccsHour] % 24;
            } elseif ($date[ccsHour] < 0) {
                $date[ccsDay] += floor($date[ccsHour] / 24);
                $date[ccsHour] = ($date[ccsHour] % 24 + 24) % 24;
            }
            if ($date[ccsMonth] > 12) {
                $date[ccsYear] += floor(($date[ccsMonth] - 1) / 12);
                $date[ccsMonth] = ($date[ccsMonth] - 1) % 12 + 1;
            } elseif ($date[ccsMonth] < 1) {
                $date[ccsYear] += floor(($date[ccsMonth] - 1) / 12);
                $date[ccsMonth] = (($date[ccsMonth] - 1) % 12 + 12) % 12 + 1;
            }
            $days = CCDaysInMonth($date[ccsYear], $date[ccsMonth]);
            if ($BackMonth && $date[ccsDay] > $days) {
                $date[ccsDay] = $days;
            } else {
                while ($date[ccsDay] > $days) {
                    $date[ccsMonth] += 1;
                    if ($date[ccsMonth] > 12) {
                        $date[ccsYear] += 1;
                        $date[ccsMonth] = 1;
                    }
                    $date[ccsDay] = $date[ccsDay] - $days;
                    $days = CCDaysInMonth($date[ccsYear], $date[ccsMonth]);
                }
            }
            if ($BackMonth && $date[ccsDay] < 1) {
                $date[ccsDay] = 1;
            } else {
                $tmpDate = "";
                while ($date[ccsDay] < 1) {
                    if ($tmpDate == "") {
                        $tmpDate = CCParseDate(CCFormatDate($date, array("yyyy", "-", "mm", "-01")), array("yyyy", "-", "mm", "-", "dd"));
                    }
                    $tmpDate = CCDateAdd($tmpDate, "-1month");
                    $days = CCDaysInMonth($tmpDate[ccsYear], $tmpDate[ccsMonth]);
                    $date[ccsMonth] -= 1;
                    if ($date[ccsMonth] == 0) {
                        $date[ccsYear] -= 1;
                        $date[ccsMonth] = 12;
                    }
                    $date[ccsDay] = $date[ccsDay] + $days;
                }
            }
        }
        $date[ccsTimestamp] = @mktime($date[ccsHour], $date[ccsMinute], $date[ccsSecond], $date[ccsMonth], $date[ccsDay], $date[ccsYear]);
        return $date;
    }
    return false;
}
Пример #2
0
 function GetParsedValue()
 {
     $varResult = "";
     if (strlen($this->DBValue)) {
         switch ($this->DataType) {
             case ccsDate:
                 if (CCValidateDate($this->DBValue, $this->DBFormat)) {
                     $varResult = CCParseDate($this->DBValue, $this->DBFormat);
                 } else {
                     if (is_array($this->DBFormat)) {
                         $this->Errors->addError("The value in field " . $this->Name . " is not valid. Use the following format: " . join("", $this->DBFormat) . "");
                     } else {
                         $this->Errors->addError("The value in field " . $this->Name . " is not valid.");
                     }
                 }
                 break;
             case ccsBoolean:
                 if (CCValidateBoolean($this->DBValue, $this->DBFormat)) {
                     $varResult = CCParseBoolean($this->DBValue, $this->DBFormat);
                 } else {
                     $this->Errors->addError("The value in field " . $this->Caption . " is not valid.");
                 }
                 break;
             case ccsInteger:
                 if (CCValidateNumber($this->DBValue, $this->DBFormat)) {
                     $varResult = CCParseInteger($this->DBValue, $this->DBFormat);
                 } else {
                     $this->Errors->addError("The value in field " . $this->Name . " is not valid.");
                 }
                 break;
             case ccsFloat:
                 if (CCValidateNumber($this->DBValue, $this->DBFormat)) {
                     $varResult = CCParseFloat($this->DBValue, $this->DBFormat);
                 } else {
                     $this->Errors->addError("The value in field " . $this->Name . " is not valid.");
                 }
                 break;
             case ccsText:
             case ccsMemo:
                 $varResult = strval($this->DBValue);
                 break;
         }
     }
     return $varResult;
 }
Пример #3
0
 function GetParsedValue()
 {
     global $CCSLocales;
     $varResult = "";
     if (strlen($this->DBValue)) {
         switch ($this->DataType) {
             case ccsDate:
                 $DateValidation = true;
                 if (CCValidateDateMask($this->DBValue, $this->DBFormat)) {
                     $varResult = CCParseDate($this->DBValue, $this->DBFormat);
                     if (!$varResult || !CCValidateDate($varResult)) {
                         $DateValidation = false;
                         $varResult = "";
                     }
                 } else {
                     $DateValidation = false;
                 }
                 if (!$DateValidation) {
                     if (is_array($this->DBFormat)) {
                         $FormatString = join("", $this->DBFormat);
                     } else {
                         $FormatString = $this->DBFormat;
                     }
                     $this->Errors->addError($CCSLocales->GetText('CCS_IncorrectFieldFormat', array($this->Name, $FormatString)));
                 }
                 break;
             case ccsBoolean:
                 if (CCValidateBoolean($this->DBValue, $this->DBFormat)) {
                     $varResult = CCParseBoolean($this->DBValue, $this->DBFormat);
                 } else {
                     if (is_array($this->DBFormat)) {
                         $FormatString = CCGetBooleanFormat($this->DBFormat);
                     } else {
                         $FormatString = $this->DBFormat;
                     }
                     $this->Errors->addError($CCSLocales->GetText('CCS_IncorrectFieldFormat', array($this->Name, $FormatString)));
                 }
                 break;
             case ccsInteger:
                 if (CCValidateNumber($this->DBValue, $this->DBFormat, true)) {
                     $varResult = CCParseInteger($this->DBValue, $this->DBFormat, true);
                 } else {
                     $this->Errors->addError($CCSLocales->GetText('CCS_IncorrectFieldFormat', array($this->Name, $this->DBFormat)));
                 }
                 break;
             case ccsFloat:
                 if (CCValidateNumber($this->DBValue, $this->DBFormat, true)) {
                     $varResult = CCParseFloat($this->DBValue, $this->DBFormat, true);
                 } else {
                     $this->Errors->addError($CCSLocales->GetText('CCS_IncorrectFieldFormat', array($this->Name, $this->DBFormat)));
                 }
                 break;
             case ccsText:
             case ccsMemo:
                 $varResult = strval($this->DBValue);
                 break;
         }
     }
     return $varResult;
 }