/** * Escapes a timestamp for use in SQL, includes surrounding quotes * * A `NULL` or invalid value will be returned as `'NULL'` * * @param string $value The timestamp to escape * @return string The escaped timestamp */ private function escapeTimestamp($value) { if ($value === NULL) { return 'NULL'; } try { $value = new fTimestamp($value); return "'" . $value->format('Y-m-d H:i:s') . "'"; } catch (fValidationException $e) { return 'NULL'; } }
/** * Formats the time * * @throws fValidationException When a non-time formatting character is included in `$format` * * @param string $format The [http://php.net/date date()] function compatible formatting string, or a format name from fTimestamp::defineFormat() * @return string The formatted time */ public function format($format) { $format = fTimestamp::translateFormat($format); $restricted_formats = 'cdDeFIjlLmMnNoOPrStTUwWyYzZ'; if (preg_match('#(?!\\\\).[' . $restricted_formats . ']#', $format)) { throw new fProgrammerException('The formatting string, %1$s, contains one of the following non-time formatting characters: %2$s', $format, join(', ', str_split($restricted_formats))); } return fTimestamp::callFormatCallback(date($format, $this->time)); }
public function getElapsedRatio() { $st = $this->getStartDatetime()->format('U'); $et = $this->getEndDatetime()->format('U'); $ts = new fTimestamp(); $now = min($ts->format('U'), $et); return max(round(100 * ($now - $st + 1) / ($et - $st + 1)), 0); }
/** * Resets the configuration of the class * * @internal * * @return void */ public static function reset() { self::$formats = array(); self::$format_callback = NULL; }
/** * Validates all timestamp/timezone columns * * @internal * * @param fActiveRecord $object The fActiveRecord instance * @param array &$values The current values * @param array &$old_values The old values * @param array &$related_records Any records related to this record * @param array &$cache The cache array for the record * @param array &$validation_messages An array of ordered validation messages * @return void */ public static function validateTimezoneColumns($object, &$values, &$old_values, &$related_records, &$cache, &$validation_messages) { $class = get_class($object); if (empty(self::$timezone_columns[$class])) { return; } foreach (self::$timezone_columns[$class] as $timezone_column => $timestamp_column) { if ($values[$timestamp_column] instanceof fTimestamp || $values[$timestamp_column] === NULL) { continue; } if (!fTimestamp::isValidTimezone($values[$timezone_column])) { $validation_messages[$timezone_column] = self::compose('%sThe timezone specified is invalid', fValidationException::formatField(fORM::getColumnName($class, $timezone_column))); } else { $validation_messages[$timestamp_column] = self::compose('%sPlease enter a date/time', fValidationException::formatField(fORM::getColumnName($class, $timestamp_column))); } } }
/** * @dataProvider lteProvider */ public function testLte($primary, $secondary, $result) { $timestamp = new fTimestamp($primary); $this->assertEquals($result, $timestamp->lte($secondary)); }
<?php define('DOC_ROOT', realpath(dirname(__FILE__) . '/../')); define('URL_ROOT', path_fix(substr(DOC_ROOT, strlen(realpath($_SERVER['DOCUMENT_ROOT'])))) . '/'); define('URL_ROOT_TRIM', ltrim(URL_ROOT, "\\")); error_reporting(E_STRICT | E_ALL); fCore::enableErrorHandling('html'); fCore::enableExceptionHandling('html'); fTimestamp::setDefaultTimezone('Asia/Kuala_Lumpur'); fAuthorization::setLoginPage(URL_ROOT . 'authentication.php'); fAuthorization::setAuthLevels(array('super' => 1000, 'admin' => 100, 'user' => 50, 'guest' => 25)); // This prevents cross-site session transfer fSession::setPath(DOC_ROOT . '/session/'); include DOC_ROOT . '/resources/library/flourish/constructor_functions.php'; /** * Configuration Settings * */ $config = array("db" => array("dbName" => "umw_mms", "dbHost" => "localhost", "dbUsername" => "useradmin", "password" => "test0"), "title" => "Material Management System", "version" => "v2.00b"); /** * Automatically includes classes * * @throws Exception * * @param string $class Name of the class to load * @return void */ function __autoload($class) { $flourish_file = DOC_ROOT . '/resources/library/flourish/' . $class . '.php'; if (file_exists($flourish_file)) {
<?php define('DOC_ROOT', realpath(dirname(__FILE__) . '/../')); define('URL_ROOT', substr(DOC_ROOT, strlen(realpath($_SERVER['DOCUMENT_ROOT']))) . '/'); error_reporting(E_STRICT | E_ALL); fCore::enableErrorHandling('html'); fCore::enableExceptionHandling('html'); fCore::disableContext(); fTimestamp::setDefaultTimezone('America/New_York'); fAuthorization::setLoginPage(URL_ROOT . 'log_in'); include DOC_ROOT . '/inc/constructor_functions.php'; /** * Automatically includes classes * * @throws Exception * * @param string $class Name of the class to load * @return void */ function __autoload($class) { $flourish_file = DOC_ROOT . '/inc/flourish/' . $class . '.php'; if (file_exists($flourish_file)) { return require $flourish_file; } $file = DOC_ROOT . '/inc/classes/' . $class . '.php'; if (file_exists($file)) { return require $file; } throw new Exception('The class ' . $class . ' could not be loaded'); }
$config_error .= "<br/>Tattle Error <br />" . "Flourishlib Session path is not write-able. Path at : " . $GLOBALS['SESSION_FILES']; $config_error = true; } if ($config_exit) { print $config_error; exit; } $status_array = array('0' => 'OK', '1' => 'Error', '2' => 'Warning'); $visibility_array = array('0' => 'Public', '1' => 'Private'); $over_under_array = array('0' => 'Over', '1' => 'Under'); $breadcrumbs = array(); $breadcrumbs[] = array('name' => 'Home', 'url' => '#', 'active' => false); error_reporting(E_STRICT | E_ALL); fCore::enableErrorHandling('html'); fCore::enableExceptionHandling('html'); fTimestamp::setDefaultTimezone($GLOBALS['TIMEZONE']); fAuthorization::setLoginPage(User::makeURL('login')); fAuthorization::setAuthLevels(array('admin' => 100, 'user' => 50, 'guest' => 25)); // This prevents cross-site session transfer fSession::setPath($GLOBALS['SESSION_FILES']); if (!fAuthorization::checkLoggedIn()) { if ($GLOBALS['ALLOW_HTTP_AUTH'] && (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']))) { unset($_SERVER['PHP_AUTH_PW']); //no need for a clear text password hanging around. try { $user = new User(array('username' => $_SERVER['PHP_AUTH_USER'])); // Auto Register User fAuthorization::setUserToken($user->getEmail()); fAuthorization::setUserAuthLevel($user->getRole()); fSession::set('user_id', $user->getUserId()); fSession::set('user_name', $user->getUsername());
/** * @dataProvider timezoneRelativeProvider */ public function testTimezoneRelative($time, $timezone, $other_time, $other_timezone) { $timestamp = new fTimestamp($time, $timezone); $other_timestamp = new fTimestamp($other_time, $other_timezone); $this->assertEquals($other_timestamp->adjust($timezone)->__toString(), $timestamp->__toString()); }