Compare commits

..

No commits in common. "df4cc74feaf454f131d11c60d916d02e709df9c9" and "11b67c53b31f705489c5271bcd35f41259769f73" have entirely different histories.

3 changed files with 10 additions and 28 deletions

View file

@ -86,20 +86,12 @@ class Date {
* @return \DateTime * @return \DateTime
*/ */
public static function from_timestamp($value, $timezone=null) { public static function from_timestamp($value, $timezone=null) {
$date = \DateTime::createFromFormat("U.u", number_format($value, 6, ".", "")); $date = new \DateTime();
$date -> setTimestamp($value);
$date -> setTimezone(self :: timezone($timezone)); $date -> setTimezone(self :: timezone($timezone));
return $date; return $date;
} }
/**
* Convert \DateTime object to timestamp as float with microsecond
* @param \DateTime $value The \DateTime object to convert
* @return float
*/
public static function to_timestamp($value) {
return floatval($value->format("U.u"));
}
/** /**
* Create \DateTime object * Create \DateTime object
* @param int|null $timezone The expected timezone (optional, default: system one) * @param int|null $timezone The expected timezone (optional, default: system one)

View file

@ -18,11 +18,11 @@ class AttrTimestamp extends Attr {
* The export format * The export format
* @var string * @var string
*/ */
protected $export_format = 'Y/m/d H:i:s.u'; protected $export_format = 'Y/m/d H:i:s';
/** /**
* Compute attribute value from DB * Compute attribute value from DB
* @param int|float|null $value The value as retrieved from debug * @param int|null $value The value as retrieved from debug
* @return \DateTime|null The attribute value * @return \DateTime|null The attribute value
*/ */
public function from_db($value) { public function from_db($value) {
@ -33,14 +33,14 @@ class AttrTimestamp extends Attr {
/** /**
* Compute attribute value for DB * Compute attribute value for DB
* @param \DateTime|int|float|null $value The value as handled in PHP * @param \DateTime|int|null $value The value as handled in PHP
* @return float|null The attribute value as stored in DB * @return int|null The attribute value as stored in DB
*/ */
public function to_db($value) { public function to_db($value) {
$value = parent::from_db($value); $value = parent::from_db($value);
if (is_null($value)) return null; if (is_null($value)) return null;
$value = $value instanceof \DateTime?$value:Date :: from_timestamp($value); $value = $value instanceof \DateTime?$value:Date :: from_timestamp($value);
return Date :: to_timestamp($value); return $value->getTimestamp();
} }
/** /**
@ -61,7 +61,7 @@ class AttrTimestamp extends Attr {
/** /**
* Compute attribute value to string * Compute attribute value to string
* @param \DateTime|int|float|null $value The input value as handled in PHP * @param \DateTime|int|null $value The input value as handled in PHP
* @return string The attribute value as string * @return string The attribute value as string
*/ */
public function to_string($value) { public function to_string($value) {

View file

@ -201,14 +201,6 @@ class Url {
http_response_code($error_code); http_response_code($error_code);
if (Tpl :: initialized()) { if (Tpl :: initialized()) {
if (self :: api_mode())
Tpl :: display_ajax_return(
[
"success" => false,
"error" => $error['message'],
],
$error_code
);
Tpl :: assign('message', $error['message']); Tpl :: assign('message', $error['message']);
Tpl :: display('error_page.tpl', $error['pagetitle']); Tpl :: display('error_page.tpl', $error['pagetitle']);
exit(); exit();
@ -454,10 +446,8 @@ class Url {
Tpl :: assign('request', self :: $request ); Tpl :: assign('request', self :: $request );
// Check authentication (if need) // Check authentication (if need)
if(self :: $request -> authenticated && !Auth::login(true)) { if(self :: $request -> authenticated && !Auth::login(true))
Log :: error(I18n::_("Authentication required but fail to authenticate you.")); Log :: fatal(I18n::_("Authentication required but fail to authenticate you."));
self :: error_page(null, 401);
}
Hook::trigger('before_handling_request', array('request' => self :: $request)); Hook::trigger('before_handling_request', array('request' => self :: $request));
$success = false; $success = false;