0byt3m1n1-V2
Path:
/
home
/
nlpacade
/
www.OLD
/
arcaneoverseas.com
/
application
/
helpers
/
[
Home
]
File: datetime_helper.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); /** * Convert MySQL's DATE (YYYY-MM-DD) or DATETIME (YYYY-MM-DD hh:mm:ss) to timestamp * * Returns the timestamp equivalent of a given DATE/DATETIME * * @todo add regex to validate given datetime * @author Clemens Kofler <clemens.kofler@chello.at> * @access public * @return integer */ function mysqldatetime_to_timestamp($datetime = "") { // function is only applicable for valid MySQL DATETIME (19 characters) and DATE (10 characters) $l = strlen($datetime); if (!($l == 10 || $l == 19)) return 0; // $date = $datetime; $hours = 0; $minutes = 0; $seconds = 0; // DATETIME only if ($l == 19) { list($date, $time) = explode(" ", $datetime); list($hours, $minutes, $seconds) = explode(":", $time); } list($year, $month, $day) = explode("-", $date); return mktime($hours, $minutes, $seconds, $month, $day, $year); } /** * Convert MySQL's DATE (YYYY-MM-DD) or DATETIME (YYYY-MM-DD hh:mm:ss) to date using given format string * * Returns the date (format according to given string) of a given DATE/DATETIME * * @author Clemens Kofler <clemens.kofler@chello.at> * @access public * @return integer */ function mysqldatetime_to_date($datetime = "", $format = "d.m.Y, H:i:s") { return date($format, mysqldatetime_to_timestamp($datetime)); } /** * Convert timestamp to MySQL's DATE or DATETIME (YYYY-MM-DD hh:mm:ss) * * Returns the DATE or DATETIME equivalent of a given timestamp * * @author Clemens Kofler <clemens.kofler@chello.at> * @access public * @return string */ function timestamp_to_mysqldatetime($timestamp = "", $datetime = true) { if (empty($timestamp) || !is_numeric($timestamp)) $timestamp = time(); return ($datetime) ? date("Y-m-d H:i:s", $timestamp) : date("Y-m-d", $timestamp); } /** * Convert timestamp to Human Date * * Returns the date (format according to given string) of a given timestamp * * @author Cleiton Francisco V. Gomes <http://www.cleiton.net/> * @access public * @param string * @param string * @return string */ function timestamp_to_date($timestamp = "", $format = "d/m/Y H:i:s") { if (empty($timestamp) || !is_numeric($timestamp)) $timestamp = time(); return date($format, $timestamp); } /** * Convert Human Date to Timestamp * * Returns the timestamp equivalent of a given HUMAN DATE/DATETIME * * @author Cleiton Francisco V. Gomes <http://www.cleiton.net/> * @access public * @param string * @return integer */ function date_to_timestamp($datetime = "") { if (!preg_match("/^(\d{1,2})[.\- \/](\d{1,2})[.\- \/](\d{2}(\d{2})?)( (\d{1,2}):(\d{1,2})(:(\d{1,2}))?)?$/", $datetime, $date)) return FALSE; $day = $date[1]; $month = $date[2]; $year = $date[3]; $hour = (empty($date[6])) ? 0 : $date[6]; $min = (empty($date[7])) ? 0 : $date[7]; $sec = (empty($date[9])) ? 0 : $date[9]; return mktime($hour, $min, $sec, $month, $day, $year); } /** * Convert HUMAN DATE to MySQL's DATE or DATETIME (YYYY-MM-DD hh:mm:ss) * * Returns the DATE or DATETIME equivalent of a given HUMAN DATE/DATETIME * * @author Cleiton Francisco V. Gomes <http://www.cleiton.net/> * @access public * @param string * @param boolean * @return string */ function date_to_mysqldate($date) { $d = date("y-m-d", strtotime($date)); return $d; } /** * * * */ /* * * * return true si l'abonnement est expirées sinon */ function VerifExpiationDate($date) { $datejour = date('d/m/Y'); //la date du fin est stocké dans une base de données //on extracte la date du fin depuis la bdd et on la met dans une variable $datefin $datefin = $date; //explode pour mettre la date du fin en format numerique: 12/05/2006 -> 12052006 $dfin = explode("/", $datefin); //explode pour mettre la date du jour en format numerique: 31/05/2009 -> 31052009 $djour = explode("/", $datejour); // concaténation pour inverser l'ordre: 12052006 -> 20060512 $finab = $dfin[2] . $dfin[1] . $dfin[0]; // concaténation pour inverser l'ordre: 31052009 -> 20090531 $auj = $djour[2] . $djour[1] . $djour[0]; // Ensuite il suffit de comparer les deux valeurs if ($auj > $finab) { return true; } else { //-------Abonnement en cours----- return false; } } ////supprimer les éléments vide d'auntabelay function filled($var) { return (strlen($var) > 1); } function odd($var) { // retourne lorsque l'entrée est impaire return($var & 1); } function even($var) { // retourne lorsque l'entrée est paire return(!($var & 1)); } /** * Comparaison entre deux jours * */ function date_diffrent($date1, $date2) { echo strtotime($date1) . "<br>"; echo strtotime($date2) . "<br>"; //return round((strtotime($date1) - strtotime($date2))/(60*60*24)-1); } /* * * * Convertir date en format fr * */ function dateFR($time) { //setlocale(LC_TIME, "fr"); return str_replace(":", "H",date("d/m/Y h:i", strtotime($time)));//utf8_encode(strftime("d/m/Y %Hh%M", strtotime($time))); //strftime("", 1207742661) } function dateFR2($time) { //setlocale(LC_TIME, "fr"); return date("d/m/Y", strtotime($time));//utf8_encode(strftime("d/m/Y %Hh%M", strtotime($time))); //strftime("", 1207742661) } function month($m) { /* Traduction mois */ /* ------------ */ if ($m == "1") { $mois = "Janvier"; } elseif ($m == "2") { $mois = "Février"; } elseif ($m == "3") { $mois = "Mars"; } elseif ($m == "4") { $mois = "Avril"; } elseif ($m == "5") { $mois = "Mai"; } elseif ($m == "6") { $mois = "Juin"; } elseif ($m == "7") { $mois = "Juillet"; } elseif ($m == "8") { $mois = "Aout"; } elseif ($m == "9") { $mois = "Septembre"; } elseif ($m == "10") { $mois = "Octobre"; } elseif ($m == "11") { $mois = "Novembre"; } elseif ($m == "12") { $mois = "Décembre"; } return $mois; } function TotalHt($array = array()){ $totalht = ""; if(is_array($array)){ foreach($array as $number ){ if(is_array($number)){ foreach($number as $num){ $totalht += $num; } }else{ $totalht += $number; } } if($totalht != "") return number_format($totalht, 2, ',', ' '); } } /**********/ function getAppTitre(){ return "Gabriel Laurent"; } function getAdmin(){ return "Gabriel Laurent"; } function getAppEmail(){ //return "gabriel.Laurent@admin.com"; return "gabrielaurent2012@gmail.com"; } function getAppEmail_no_repley(){ return "no-repley-gabriel.Laurent@admin.com"; } function AddTime($time1,$time2) { list( $hr1, $min1, $sec1 ) = split( ":", $time1); $UTime1 = mktime(1,$min1,$sec1,01,01,1970); list( $hr2, $min2, $sec2 ) = split( ":", $time2); $UTime2 = mktime(1,$min2,$sec2,01,01,1970); $UTimeTotal = $UTime1 + $UTime2; $UTimeTotal = $UTimeTotal - 3600; $timeTotal = date ("H:i:s",$UTimeTotal); list( $hr3, $min3, $sec3 ) = split( ":", $timeTotal); $hrTotal = $hr1 + $hr2; if ($hr3 >= 1) $hrTotal = $hrTotal + $hr3; $timeTotal = $hrTotal.":".$min3.":".$sec3; return $timeTotal; } /** * Tranque chaine * */ function coupe($chaine ,$max=50){ if(strlen($chaine)>=$max) { // Met la portion de chaine dans $chaine $chaine=substr($chaine,0,$max); // position du dernier espace $espace=strrpos($chaine," "); // test si il ya un espace if($espace) // si ya 1 espace, coupe de nouveau la chaine $chaine=substr($chaine,0,$espace); // Ajoute ... à la chaine $chaine .= '...'; } return $chaine; } function coupe2($chaine ,$max=50){ if(strlen($chaine)>=$max) { // Met la portion de chaine dans $chaine $chaine=substr($chaine,0,$max); // position du dernier espace $espace=strrpos($chaine," "); // test si il ya un espace if($espace) // si ya 1 espace, coupe de nouveau la chaine $chaine=substr($chaine,0,$espace); } return $chaine; } function price($price){ return (is_string($price)) ? $price : number_format($price, 2, ',', ' ')." €"; } /** * * */ function diffBetweenDate($date1,$date2){ $date1 = new DateTime($date1); $date2 = new DateTime($date2); $diff = $date2->diff($date1); $hours = $diff->h; $hours = $hours + ($diff->d*24); return $hours; } function Pourcentage($Nombre, $Total) { return number_format($Nombre * 100 / $Total, 2, '.', ' '); } function formater_url($url){ $url = utf8_decode($url); $url = strtolower(strtr($url, utf8_decode('ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ()[]\'"~$&%*@ç!?;,:/\^¨€{}<>|+.- '), 'aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn -- c --- e --')); $url = str_replace(' ', '', $url); $url = str_replace('---', '-', $url); $url = str_replace('--', '-', $url); $url = trim($url,'-'); return $url; } function combineCss(){ $this->load->driver('minify'); $file = FCPATH . 'themes/css/reset.css'; $file2 = FCPATH . 'themes/css/style.css'; $file3 = FCPATH . 'themes/css/superfish.css'; $file4 = FCPATH . 'themes/css/jquery.jscrollpane.css'; $file5 = FCPATH . 'themes/css/colorbox.css'; $fileCombine = $this->minify->combine_files(array($file, $file2, $file3, $file4, $file5), 'css'); $this->minify->save_file($fileCombine, FCPATH. 'themes/css/all.css'); } /** * */ function valide_link($link){ if (preg_match('|^https*://|', $link) === 0) { $link = 'http://' . $link . '/'; } return $link; } //Utilisation echo AddTime("12:04:12","02:11:49");
©
2018.