2012-03-15 01:19:26 -04:00
|
|
|
/*
|
|
|
|
* local-time.js
|
2012-03-30 20:13:11 -04:00
|
|
|
* https://github.com/savetheinternet/Tinyboard/blob/master/js/local-time.js
|
2012-03-15 01:19:26 -04:00
|
|
|
*
|
|
|
|
* Released under the MIT license
|
|
|
|
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* $config['additional_javascript'][] = 'js/local-time.js';
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-03-31 04:37:31 -04:00
|
|
|
onready(function(){
|
2012-03-15 01:19:26 -04:00
|
|
|
var iso8601 = function(s) {
|
|
|
|
s = s.replace(/\.\d\d\d+/,""); // remove milliseconds
|
|
|
|
s = s.replace(/-/,"/").replace(/-/,"/");
|
|
|
|
s = s.replace(/T/," ").replace(/Z/," UTC");
|
|
|
|
s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
|
|
|
|
return new Date(s);
|
|
|
|
};
|
|
|
|
var zeropad = function(num, count) {
|
|
|
|
return [Math.pow(10, count - num.toString().length), num].join('').substr(1);
|
|
|
|
};
|
|
|
|
|
2012-03-31 04:12:08 -04:00
|
|
|
var times = document.getElementsByTagName('time');
|
|
|
|
|
|
|
|
for(var i = 0; i < times.length; i++) {
|
|
|
|
if(!times[i].innerHTML.match(/^\d+\/\d+\/\d+ \(\w+\) \d+:\d+:\d+$/))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
var t = iso8601(times[i].getAttribute('datetime'));
|
2012-03-15 01:19:26 -04:00
|
|
|
|
|
|
|
|
2012-03-31 04:12:08 -04:00
|
|
|
|
|
|
|
times[i].innerHTML =
|
2012-03-15 01:19:26 -04:00
|
|
|
// date
|
|
|
|
zeropad(t.getMonth() + 1, 2) + "/" + zeropad(t.getDate(), 2) + "/" + t.getFullYear().toString().substring(2) +
|
|
|
|
" (" + ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][t.getDay()] + ") " +
|
|
|
|
// time
|
2012-03-31 04:12:08 -04:00
|
|
|
zeropad(t.getHours(), 2) + ":" + zeropad(t.getMinutes(), 2) + ":" + zeropad(t.getSeconds(), 2);
|
|
|
|
};
|
2012-03-15 01:19:26 -04:00
|
|
|
});
|
|
|
|
|