Skip to content

Instantly share code, notes, and snippets.

@claudiohilario
Last active February 12, 2018 17:08
Show Gist options
  • Save claudiohilario/fa888ebd0a2c70734ca55c9868bb5818 to your computer and use it in GitHub Desktop.
Save claudiohilario/fa888ebd0a2c70734ca55c9868bb5818 to your computer and use it in GitHub Desktop.
<?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