function getDateTime($time, $zone = null) { if (is_a($time, 'DateTime')) { return $time; } $zone = $this->getZone($zone); if (Tool::isInt($time)) { $Date = new \DateTime(null, $zone); $Date->setTimestamp($time); return $Date; } return new \DateTime($time, $zone); }
static function age($value, $min = null, $max = null) { $time = new Time($value); $age = $time->diff(new Time('now')); if (Tool::isInt($max) && $age->y > $max) { Debug::toss(['type' => 'age_max', 'detail' => $max], 'InputException'); } if (Tool::isInt($min) && $age->y < $min) { Debug::toss(['type' => 'age_min', 'detail' => $min], 'InputException'); } }
/** @param dict dictionary to update on query */ protected function namedId($table, $name, &$dict = null) { if (Tool::isInt($name)) { return $name; } $id = $this->value($table, ['name' => $name], 'id'); if ($dict !== null) { $dict[$name] = $id; } return $id; }
function int($v) { if (!Tool::isInt($v)) { self::error(); } return $v; }
/** @param location location to relocate to @param type type of relocation; head for header relocation, js for javascript relocation @param code the http status code. Note, generally this function is used after a post request is parsed, so 303 is the default */ static function redirect($location = null, $type = 'head', $code = null) { if ($type == 'head') { if (!$location) { $location = $_SERVER['REQUEST_URI']; } $code = $code ? $code : 303; header('Location: ' . $location, true, $code); } elseif ($type == 'js') { echo '<script type="text/javascript">'; if (Tool::isInt($location)) { if ($location == 0) { $location = $_SERVER['REQUEST_URI']; echo 'window.location = ' . $_SERVER['REQUEST_URI'] . ';'; } else { echo 'javascript:history.go(' . $location . ');'; } } else { echo 'document.location="' . $location . '";'; } echo '</script>'; } exit; }