Translation update done using Pootle.
[phpmyadmin-themes.git] / libraries / transformations / text_plain__dateformat.inc.php
blob42a19a96d9f853b3994dd7ceb8b39a46d38a4f65
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @package phpMyAdmin-Transformation
5 */
7 function PMA_transformation_text_plain__dateformat_info() {
8 return array(
9 'info' => __('Displays a TIME, TIMESTAMP, DATETIME or numeric unix timestamp column as formatted date. The first option is the offset (in hours) which will be added to the timestamp (Default: 0). Use second option to specify a different date/time format string. Third option determines whether you want to see local date or UTC one (use "local" or "utc" strings) for that. According to that, date format has different value - for "local" see the documentation for PHP\'s strftime() function and for "utc" it is done using gmdate() function.'),
13 /**
16 function PMA_transformation_text_plain__dateformat($buffer, $options = array(), $meta = '') {
17 // possibly use a global transform and feed it with special options:
18 // include './libraries/transformations/global.inc.php';
20 // further operations on $buffer using the $options[] array.
21 if (empty($options[0])) {
22 $options[0] = 0;
25 if (empty($options[2])) {
26 $options[2] = 'local';
27 } else {
28 $options[2] = strtolower($options[2]);
31 if (empty($options[1])) {
32 if ($options[2] == 'local') {
33 $options[1] = __('%B %d, %Y at %I:%M %p');
34 } else {
35 $options[1] = 'Y-m-d H:i:s';
39 $timestamp = -1;
41 // INT columns will be treated as UNIX timestamps
42 // and need to be detected before the verification for
43 // MySQL TIMESTAMP
44 if ($meta->type == 'int') {
45 $timestamp = $buffer;
47 // Detect TIMESTAMP(6 | 8 | 10 | 12 | 14)
48 // TIMESTAMP (2 | 4) not supported here.
49 // (Note: prior to MySQL 4.1, TIMESTAMP has a display size, for example
50 // TIMESTAMP(8) means YYYYMMDD)
51 } else if (preg_match('/^(\d{2}){3,7}$/', $buffer)) {
53 if (strlen($buffer) == 14 || strlen($buffer) == 8) {
54 $offset = 4;
55 } else {
56 $offset = 2;
59 $d = array();
60 $d['year'] = substr($buffer, 0, $offset);
61 $d['month'] = substr($buffer, $offset, 2);
62 $d['day'] = substr($buffer, $offset + 2, 2);
63 $d['hour'] = substr($buffer, $offset + 4, 2);
64 $d['minute'] = substr($buffer, $offset + 6, 2);
65 $d['second'] = substr($buffer, $offset + 8, 2);
67 if (checkdate($d['month'], $d['day'], $d['year'])) {
68 $timestamp = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']);
70 // 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)
71 } else {
72 if (preg_match('/^[0-9]\d{1,9}$/', $buffer)) {
73 $timestamp = (int)$buffer;
74 } else {
75 $timestamp = strtotime($buffer);
79 // If all above failed, maybe it's a Unix timestamp already?
80 if ($timestamp < 0 && preg_match('/^[1-9]\d{1,9}$/', $buffer)) {
81 $timestamp = $buffer;
84 // Reformat a valid timestamp
85 if ($timestamp >= 0) {
86 $timestamp -= $options[0] * 60 * 60;
87 $source = $buffer;
88 if ($options[2] == 'local') {
89 $text = PMA_localisedDate($timestamp, $options[1]);
90 } elseif ($options[2] == 'utc') {
91 $text = gmdate($options[1], $timestamp);
92 } else {
93 $text = 'INVALID DATE TYPE';
95 $buffer = '<dfn onclick="alert(\'' . $source . '\');" title="' . $source . '">' . $text . '</dfn>';
98 return $buffer;