Skip to content

Commit

Permalink
Database: factorized jdate()
Browse files Browse the repository at this point in the history
  • Loading branch information
rdoursenaud committed Mar 15, 2014
1 parent 1d268c2 commit eb86abf
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 88 deletions.
19 changes: 17 additions & 2 deletions htdocs/core/db/DoliDB.class.php
Expand Up @@ -64,8 +64,6 @@ abstract class DoliDB implements Database
public $ok;
public $error;



/**
* Define sort criteria of request
*
Expand Down Expand Up @@ -94,5 +92,22 @@ function order($sortfield=0,$sortorder=0)
return '';
}
}

/**
* Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
* 19700101020000 -> 3600 with TZ+1 and gmt=0
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @param int $gm 1=Input informations are GMT values, otherwise local to server TZ
* @return date Date TMS
*/
function jdate($string, $gm=false)
{
$string=preg_replace('/([^0-9])/i','',$string);
$tmp=$string.'000000';
$date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),$gm);
return $date;
}
}

17 changes: 0 additions & 17 deletions htdocs/core/db/mssql.class.php
Expand Up @@ -553,23 +553,6 @@ function idate($param)
return dol_print_date($param,"%Y-%m-%d %H:%M:%S");
}

/**
* Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
* 19700101020000 -> 3600 with TZ+1 and gmt=0
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @param int $gm 1=Input informations are GMT values, otherwise local to server TZ
* @return date Date TMS
*/
function jdate($string, $gm=false)
{
$string=preg_replace('/([^0-9])/i','',$string);
$tmp=$string.'000000';
$date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),$gm);
return $date;
}

/**
* Format a SQL IF
*
Expand Down
17 changes: 0 additions & 17 deletions htdocs/core/db/mysql.class.php
Expand Up @@ -531,23 +531,6 @@ function idate($param)
return dol_print_date($param,"%Y%m%d%H%M%S");
}

/**
* Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
* 19700101020000 -> 3600 with TZ+1 and gmt=0
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @param int $gm 1=Input informations are GMT values, otherwise local to server TZ
* @return date Date TMS
*/
function jdate($string, $gm=false)
{
$string=preg_replace('/([^0-9])/i','',$string);
$tmp=$string.'000000';
$date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),$gm);
return $date;
}

/**
* Format a SQL IF
*
Expand Down
17 changes: 0 additions & 17 deletions htdocs/core/db/mysqli.class.php
Expand Up @@ -541,23 +541,6 @@ function idate($param)
return dol_print_date($param,"%Y%m%d%H%M%S");
}

/**
* Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
* 19700101020000 -> 3600 with TZ+1 and gmt=0
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @param int $gm 1=Input informations are GMT values, otherwise local to server TZ
* @return date Date TMS
*/
function jdate($string, $gm=false)
{
$string=preg_replace('/([^0-9])/i','',$string);
$tmp=$string.'000000';
$date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),$gm);
return $date;
}

/**
* Format a SQL IF
*
Expand Down
17 changes: 0 additions & 17 deletions htdocs/core/db/pgsql.class.php
Expand Up @@ -752,23 +752,6 @@ function idate($param)
return dol_print_date($param,"%Y-%m-%d %H:%M:%S");
}

/**
* Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
* 19700101020000 -> 3600 with TZ+1 and gmt=0
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @param int $gm 1=Input informations are GMT values, otherwise local to server TZ
* @return date Date TMS
*/
function jdate($string, $gm=false)
{
$string=preg_replace('/([^0-9])/i','',$string);
$tmp=$string.'000000';
$date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),$gm);
return $date;
}

/**
* Format a SQL IF
*
Expand Down
18 changes: 0 additions & 18 deletions htdocs/core/db/sqlite.class.php
Expand Up @@ -674,24 +674,6 @@ function idate($param)
return dol_print_date($param,"%Y%m%d%H%M%S");
}

/**
* Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true)
* 19700101020000 -> 3600 with TZ+1 and gmt=0
* 19700101020000 -> 7200 whaterver is TZ if gmt=1
*
* @param string $string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @param int $gm 1=Input informations are GMT values, otherwise local to server TZ
* @return date Date TMS
*/
function jdate($string, $gm=false)
{
$string=preg_replace('/([^0-9])/i','',$string);
$tmp=$string.'000000';
$date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),$gm);
return $date;
}


/**
* Format a SQL IF
*
Expand Down

0 comments on commit eb86abf

Please sign in to comment.