2012-03-15 06:19:26 +01:00
|
|
|
/*
|
|
|
|
* local-time.js
|
2012-03-31 02:13:11 +02:00
|
|
|
* https://github.com/savetheinternet/Tinyboard/blob/master/js/local-time.js
|
2012-03-15 06:19:26 +01:00
|
|
|
*
|
|
|
|
* Released under the MIT license
|
|
|
|
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
|
2014-01-19 14:27:24 +01:00
|
|
|
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
2012-03-15 06:19:26 +01:00
|
|
|
*
|
|
|
|
* Usage:
|
2013-07-31 10:37:07 +02:00
|
|
|
* // $config['additional_javascript'][] = 'js/jquery.min.js';
|
2012-03-15 06:19:26 +01:00
|
|
|
* $config['additional_javascript'][] = 'js/local-time.js';
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-03-31 10:37:31 +02:00
|
|
|
onready(function(){
|
2012-03-15 06:19:26 +01: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);
|
|
|
|
};
|
2013-07-03 03:09:05 +02:00
|
|
|
|
|
|
|
var do_localtime = function(elem) {
|
|
|
|
var times = elem.getElementsByTagName('time');
|
2012-03-15 06:19:26 +01:00
|
|
|
|
2013-07-03 03:09:05 +02:00
|
|
|
for(var i = 0; i < times.length; i++) {
|
|
|
|
if(typeof times[i].getAttribute('data-local') == 'undefined')
|
|
|
|
continue;
|
2012-03-31 10:12:08 +02:00
|
|
|
|
2013-07-03 03:09:05 +02:00
|
|
|
var t = iso8601(times[i].getAttribute('datetime'));
|
2012-03-15 06:19:26 +01:00
|
|
|
|
|
|
|
|
2013-07-03 03:09:05 +02:00
|
|
|
times[i].setAttribute('data-local', 'true');
|
|
|
|
times[i].innerHTML =
|
|
|
|
// date
|
|
|
|
zeropad(t.getMonth() + 1, 2) + "/" + zeropad(t.getDate(), 2) + "/" + t.getFullYear().toString().substring(2) +
|
2013-07-03 07:27:09 +02:00
|
|
|
" (" + [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun")][t.getDay()] + ") " +
|
2013-07-03 03:09:05 +02:00
|
|
|
// time
|
|
|
|
zeropad(t.getHours(), 2) + ":" + zeropad(t.getMinutes(), 2) + ":" + zeropad(t.getSeconds(), 2);
|
|
|
|
};
|
2012-03-31 10:12:08 +02:00
|
|
|
};
|
2013-07-03 03:09:05 +02:00
|
|
|
|
|
|
|
do_localtime(document);
|
2013-07-31 10:37:07 +02:00
|
|
|
|
|
|
|
if (window.jQuery) {
|
|
|
|
// allow to work with auto-reload.js, etc.
|
2014-01-21 19:25:11 +01:00
|
|
|
$(document).on('new_post', function(e, post) {
|
2013-07-31 10:37:07 +02:00
|
|
|
do_localtime(post);
|
|
|
|
});
|
|
|
|
}
|
2012-03-15 06:19:26 +01:00
|
|
|
});
|
|
|
|
|