Converting number of Excel column names no longer limited
[phpmyadmin/arisferyanto.git] / libraries / transformations / text_plain__dateformat.inc.php
blob282cb16bfa75de57a07834dc91a9adac12b0feda
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @package phpMyAdmin-Transformation
5 * @version $Id$
6 */
8 /**
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])) {
17 $options[0] = 0;
20 if (empty($options[2])) {
21 $options[2] = 'local';
22 } else {
23 $options[2] = strtolower($options[2]);
26 if (empty($options[1])) {
27 if ($options[2] == 'local') {
28 $options[1] = $GLOBALS['datefmt'];
29 } else {
30 $options[1] = 'Y-m-d H:i:s';
34 $timestamp = -1;
36 // INT columns will be treated as UNIX timestamps
37 // and need to be detected before the verification for
38 // MySQL TIMESTAMP
39 if ($meta->type == 'int') {
40 $timestamp = $buffer;
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) {
49 $offset = 4;
50 } else {
51 $offset = 2;
54 $d = array();
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)
66 } else {
67 if (preg_match('/^[0-9]\d{1,9}$/', $buffer)) {
68 $timestamp = (int)$buffer;
69 } else {
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)) {
76 $timestamp = $buffer;
79 // Reformat a valid timestamp
80 if ($timestamp >= 0) {
81 $timestamp -= $options[0] * 60 * 60;
82 $source = $buffer;
83 if ($options[2] == 'local') {
84 $text = PMA_localisedDate($timestamp, $options[1]);
85 } elseif ($options[2] == 'utc') {
86 $text = gmdate($options[1], $timestamp);
87 } else {
88 $text = 'INVALID DATE TYPE';
90 $buffer = '<dfn onclick="alert(\'' . $source . '\');" title="' . $source . '">' . $text . '</dfn>';
93 return $buffer;