2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * @package phpMyAdmin-Transformation
11 function PMA_transformation_text_plain__dateformat($buffer, $options = array(), $meta = '') {
12 // possibly use a global transform and feed it with special options:
13 // include './libraries/transformations/global.inc.php';
15 // further operations on $buffer using the $options[] array.
16 if (empty($options[0])) {
20 if (empty($options[2])) {
21 $options[2] = 'local';
23 $options[2] = strtolower($options[2]);
26 if (empty($options[1])) {
27 if ($options[2] == 'local') {
28 $options[1] = $GLOBALS['datefmt'];
30 $options[1] = 'Y-m-d H:i:s';
36 // INT columns will be treated as UNIX timestamps
37 // and need to be detected before the verification for
39 if ($meta->type
== 'int') {
42 // Detect TIMESTAMP(6 | 8 | 10 | 12 | 14)
43 // TIMESTAMP (2 | 4) not supported here.
44 // (Note: prior to MySQL 4.1, TIMESTAMP has a display size, for example
45 // TIMESTAMP(8) means YYYYMMDD)
46 } else if (preg_match('/^(\d{2}){3,7}$/', $buffer)) {
48 if (strlen($buffer) == 14 ||
strlen($buffer) == 8) {
55 $d['year'] = substr($buffer, 0, $offset);
56 $d['month'] = substr($buffer, $offset, 2);
57 $d['day'] = substr($buffer, $offset +
2, 2);
58 $d['hour'] = substr($buffer, $offset +
4, 2);
59 $d['minute'] = substr($buffer, $offset +
6, 2);
60 $d['second'] = substr($buffer, $offset +
8, 2);
62 if (checkdate($d['month'], $d['day'], $d['year'])) {
63 $timestamp = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']);
65 // If all fails, assume one of the dozens of valid strtime() syntaxes (http://www.gnu.org/manual/tar-1.12/html_chapter/tar_7.html)
67 if (preg_match('/^[0-9]\d{1,9}$/', $buffer)) {
68 $timestamp = (int)$buffer;
70 $timestamp = strtotime($buffer);
74 // If all above failed, maybe it's a Unix timestamp already?
75 if ($timestamp < 0 && preg_match('/^[1-9]\d{1,9}$/', $buffer)) {
79 // Reformat a valid timestamp
80 if ($timestamp >= 0) {
81 $timestamp -= $options[0] * 60 * 60;
83 if ($options[2] == 'local') {
84 $text = PMA_localisedDate($timestamp, $options[1]);
85 } elseif ($options[2] == 'utc') {
86 $text = gmdate($options[1], $timestamp);
88 $text = 'INVALID DATE TYPE';
90 $buffer = '<dfn onclick="alert(\'' . $source . '\');" title="' . $source . '">' . $text . '</dfn>';