Convert transformation descriptions to gettext.
[phpmyadmin/blinky.git] / libraries / transformations / text_plain__dateformat.inc.php
blob3f11fa9025039a1bf1ec3e2966e787dc34281e8f
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @package phpMyAdmin-Transformation
5 * @version $Id$
6 */
8 function PMA_transformation_text_plain__dateformat_info() {
9 return array(
10 'info' => __('Displays a TIME, TIMESTAMP, DATETIME or numeric unix timestamp field 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.'),
14 /**
17 function PMA_transformation_text_plain__dateformat($buffer, $options = array(), $meta = '') {
18 // possibly use a global transform and feed it with special options:
19 // include './libraries/transformations/global.inc.php';
21 // further operations on $buffer using the $options[] array.
22 if (empty($options[0])) {
23 $options[0] = 0;
26 if (empty($options[2])) {
27 $options[2] = 'local';
28 } else {
29 $options[2] = strtolower($options[2]);
32 if (empty($options[1])) {
33 if ($options[2] == 'local') {
34 $options[1] = __('%B %d, %Y at %I:%M %p');
35 } else {
36 $options[1] = 'Y-m-d H:i:s';
40 $timestamp = -1;
42 // INT columns will be treated as UNIX timestamps
43 // and need to be detected before the verification for
44 // MySQL TIMESTAMP
45 if ($meta->type == 'int') {
46 $timestamp = $buffer;
48 // Detect TIMESTAMP(6 | 8 | 10 | 12 | 14)
49 // TIMESTAMP (2 | 4) not supported here.
50 // (Note: prior to MySQL 4.1, TIMESTAMP has a display size, for example
51 // TIMESTAMP(8) means YYYYMMDD)
52 } else if (preg_match('/^(\d{2}){3,7}$/', $buffer)) {
54 if (strlen($buffer) == 14 || strlen($buffer) == 8) {
55 $offset = 4;
56 } else {
57 $offset = 2;
60 $d = array();
61 $d['year'] = substr($buffer, 0, $offset);
62 $d['month'] = substr($buffer, $offset, 2);
63 $d['day'] = substr($buffer, $offset + 2, 2);
64 $d['hour'] = substr($buffer, $offset + 4, 2);
65 $d['minute'] = substr($buffer, $offset + 6, 2);
66 $d['second'] = substr($buffer, $offset + 8, 2);
68 if (checkdate($d['month'], $d['day'], $d['year'])) {
69 $timestamp = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']);
71 // 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)
72 } else {
73 if (preg_match('/^[0-9]\d{1,9}$/', $buffer)) {
74 $timestamp = (int)$buffer;
75 } else {
76 $timestamp = strtotime($buffer);
80 // If all above failed, maybe it's a Unix timestamp already?
81 if ($timestamp < 0 && preg_match('/^[1-9]\d{1,9}$/', $buffer)) {
82 $timestamp = $buffer;
85 // Reformat a valid timestamp
86 if ($timestamp >= 0) {
87 $timestamp -= $options[0] * 60 * 60;
88 $source = $buffer;
89 if ($options[2] == 'local') {
90 $text = PMA_localisedDate($timestamp, $options[1]);
91 } elseif ($options[2] == 'utc') {
92 $text = gmdate($options[1], $timestamp);
93 } else {
94 $text = 'INVALID DATE TYPE';
96 $buffer = '<dfn onclick="alert(\'' . $source . '\');" title="' . $source . '">' . $text . '</dfn>';
99 return $buffer;