text_plain__dateformat.inc.php supports DATETIME and TIMESTAMP(14) only. Missing column types: DATE, TIMESTAMP(12/10/8/6), INT (Unix timestamp).
Possible new version follows (I hope Garvin Hicking find this helpfull).
<?php
/* $Id: text_plain__dateformat.inc.php,v 1.1 2003/03/18 15:30:25 garvinhicking Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Plugin function TEMPLATE (Garvin Hicking).
* -----------------------------------------
*
* For instructions, read the libraries/transformations/README file.
*
* The string ENTER_FILENAME_HERE shall be substituted with the filename without the '.inc.php'
* extension. For further information regarding naming conventions see the README file.
*/
if (!defined('PMA_TRANSFORMATION_TEXT_PLAIN__DATEFORMAT')){
define('PMA_TRANSFORMATION_TEXT_PLAIN__DATEFORMAT', 1);
function PMA_transformation_text_plain__dateformat($buffer, $options = array()) {
// possibly use a global transform and feed it with special options:
// include('./libraries/transformations/global.inc.php');
// further operations on $buffer using the $options[] array.
if (!isset($options[0]) || $options[0] == '') {
$options[0] = 0;
}
if (!isset($options[1]) || $options[1] == '') {
$options[1] = $GLOBALS['datefmt'];
}
$timestamp = -1;
// Detect DATE = 'YYYY-MM-DD' and DATETIME = 'YYYY-MM-DD HH:MM:SS'.
if (strpos($buffer, "-"))
{
$timestamp = strtotime($buffer);
}
// Detect TIMESTAMP(6 | 8 | 10 | 12 | 14), (2 | 4) not supported here.
elseif (preg_match('/^(\d{2}){3,7}$/', $buffer))
{
// TIMESTAMP(8 | 14) = YYYYMMDD..., (6 | 10 | 12) = YYMMDD...
if (strlen($buffer) == 14 || strlen($buffer) == 8) $offset = 4;
else $offset = 2;
$d = array();
$d['year'] = substr($buffer, 0, $offset);
$d['month'] = substr($buffer, $offset, 2);
$d['day'] = substr($buffer, $offset + 2, 2);
$d['hour'] = substr($buffer, $offset + 4, 2);
$d['minute'] = substr($buffer, $offset + 6, 2);
$d['second'] = substr($buffer, $offset + 8, 2);
if (checkdate($d['month'], $d['day'], $d['year']))
{
$timestamp = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']);
}
}
// If all above failed, maybe it's a Unix timestamp already?
if ($timestamp < 0 && preg_match('/^[1-9]\d{1,9}$/', $buffer))
{
$timestamp = $buffer;
}
if ($timestamp != -1) {
$timestamp -= $options[0] * 60 * 60;
$buffer = PMA_localisedDate($timestamp, $options[1]);
}
return $buffer;
}
}
?>
Logged In: YES
user_id=473563
Thanks for that patch. I will merge it into CVS.
Logged In: YES
user_id=473563
Merged into CVS with minor modifications.
Thanks for your patch!
Logged In: YES
user_id=356859
You're welcome. (Finally, I participated in PMA, the most useful tool ever.) Your modifications are very good.
I'm not sure if the last preg_match() is realy needed? As far as I can see it does nothing. The $timestamp never become a value that fails /^[1-9]\d{1,9}$/.
Additional question: The plugin interface doesn't provide the field type. Why? Wouldn't it be easier if PMA_transformation_text_plain__dateformat() knows the buffer came from a TIMESTAMP(10), INT etc.?
Logged In: YES
user_id=473563
I used the last preg_match to make sure, that the
strtotime() function didn't produce any invalid timestamps...
Regarding your question about why the fieldtype is not
propagated: Yes, that's a good idea. We will try to
implement that along with the MySQL 4.1 support, which will
also implement charsets etc, which should also be passed to
the MIME-Transformations. So we will most probably turn
$buffer into an array containing verbose information...
Thanks for that hint!
Regards,
Garvin.
Logged In: YES
user_id=473563
As it was just a quick hack to propagate the meta-field
information, I have just included this to CVS.
Maybe you want to try it out and adjust the
dateformat-thingie accordingly? :-)))
Regards,
Garvin.