Last active
February 12, 2018 17:08
-
-
Save claudiohilario/fa888ebd0a2c70734ca55c9868bb5818 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Date { | |
protected $CI; | |
private $db_default_timezone; | |
public function __construct() | |
{ | |
$this->CI =& get_instance(); | |
$this->_getDefaultTimestamp(); | |
} | |
/** | |
* Converte data vinda da base de dados em timestamp | |
* | |
* @param $date data no formato Y-m-d H:i:s | |
* @return int Timestamp | |
*/ | |
public function dateDbToTimestamp($date){ | |
$date = new DateTime($date, new DateTimeZone($this->db_default_timezone)); | |
return $date->getTimestamp(); | |
} | |
/** | |
* Converte timestamp para Base de Dados | |
* | |
* @param $timestamp | |
* @return string data no formato Y-m-d H:i:s | |
*/ | |
public function timestampToDateDb($timestamp){ | |
$date = new DateTime(date('Y-m-d H:i:s',$timestamp), | |
new DateTimeZone($this->db_default_timezone)); | |
return $date->format('Y-m-d H:i:s'); | |
} | |
/** | |
* Coloca na variavel privada $db_default_timezone o Timezone da base de dados | |
*/ | |
private function _getDefaultTimestamp(){ | |
$this->CI->config->load('gfitness'); | |
$this->db_default_timezone = $this->CI->config->item('db_default_timezone'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment