Created
April 10, 2017 15:58
-
-
Save anonymous/7e9b5e9f4ddcf8a91f2bb4281a51604e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** This plugin replaces UNIX timestamps with human-readable dates in your local format. | |
* Mouse click on the date field reveals timestamp back. | |
* | |
* @link https://www.adminer.org/plugins/#use | |
* @author Anonymous | |
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 | |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) | |
*/ | |
class AdminerReadableDates { | |
/** @access protected */ | |
var $prepend; | |
function __construct() { | |
$this->prepend = <<<EOT | |
<script> | |
document.addEventListener('DOMContentLoaded', function(event) { | |
var date = new Date(); | |
var tds = document.querySelectorAll('td[id^="val"]'); | |
for (var i = 0; i < tds.length; i++) { | |
var text = tds[i].innerHTML.trim(); | |
if (text.match(/^\d{10}$/)) { | |
date.setTime(parseInt(text) * 1000); | |
tds[i].oldDate = text; | |
// tds[i].newDate = date.toUTCString().substr(5); // UTC format | |
tds[i].newDate = date.toLocaleString(); // Local format | |
// tds[i].newDate = date.toLocaleFormat('%e %b %Y %H:%M:%S'); // Custom format - works in Firefox only | |
tds[i].newDate = '<span style="color: #009900">' + tds[i].newDate + '</span>'; | |
tds[i].innerHTML = tds[i].newDate; | |
tds[i].dateIsNew = true; | |
tds[i].addEventListener('click', function(event) { | |
this.innerHTML = (this.dateIsNew ? this.oldDate : this.newDate); | |
this.dateIsNew = !this.dateIsNew; | |
}); | |
} | |
} | |
}); | |
</script> | |
EOT; | |
} | |
function head() { | |
echo $this->prepend; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment