summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorMichael Save <savetheinternet@tinyboard.org>2012-03-15 16:19:26 +1100
committerMichael Save <savetheinternet@tinyboard.org>2012-03-15 16:19:26 +1100
commit34301da174acd3cfb326f03693657aeacd58be27 (patch)
treebb17f12e2b9098463734939dc772b188a4188d4e /js
parentee54df825a71dab1bfb03fdf91138240f3110a9d (diff)
local-time.js: convert times into user's timezone
Diffstat (limited to 'js')
-rw-r--r--js/auto-reload.js3
-rw-r--r--js/forced-anon.js4
-rw-r--r--js/local-time.js42
-rw-r--r--js/quick-reply.js4
4 files changed, 48 insertions, 5 deletions
diff --git a/js/auto-reload.js b/js/auto-reload.js
index 3789a136..70b4acc3 100644
--- a/js/auto-reload.js
+++ b/js/auto-reload.js
@@ -8,7 +8,8 @@
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
*
* Usage:
- * $config['additional_javascript'][] = $config['root'] . 'auto-reload.js';
+ * $config['additional_javascript'][] = 'js/jquery.min.js';
+ * $config['additional_javascript'][] = 'js/auto-reload.js';
*
*/
diff --git a/js/forced-anon.js b/js/forced-anon.js
index 86af4063..6949769d 100644
--- a/js/forced-anon.js
+++ b/js/forced-anon.js
@@ -6,8 +6,8 @@
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
*
* Usage:
- * $config['additional_javascript'][] = $config['root'] . 'jquery.min.js';
- * $config['additional_javascript'][] = $config['root'] . 'forced-anon.js';
+ * $config['additional_javascript'][] = 'js/jquery.min.js';
+ * $config['additional_javascript'][] = 'js/forced-anon.js';
*
*/
diff --git a/js/local-time.js b/js/local-time.js
new file mode 100644
index 00000000..6d0a163a
--- /dev/null
+++ b/js/local-time.js
@@ -0,0 +1,42 @@
+/*
+ * local-time.js
+ * https://github.com/savetheinternet/Tinyboard-Tools/blob/master/js/local-time.js
+ *
+ * Released under the MIT license
+ * Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
+ *
+ * Usage:
+ * $config['quick_reply'] = true;
+ * $config['additional_javascript'][] = 'js/jquery.min.js';
+ * $config['additional_javascript'][] = 'js/local-time.js';
+ *
+ */
+
+$(document).ready(function(){
+ 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);
+ };
+
+ $('time').each(function() {
+ if(!$(this).text().match(/^\d+\/\d+\/\d+ \(\w+\) \d+:\d+:\d+$/))
+ return;
+
+ var t = iso8601($(this).attr('datetime'));
+
+ $(this).text(
+ // 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
+ zeropad(t.getHours(), 2) + ":" + zeropad(t.getMinutes(), 2) + ":" + zeropad(t.getSeconds(), 2)
+ );
+ });
+});
+
diff --git a/js/quick-reply.js b/js/quick-reply.js
index 0062cd1e..cc1a45a2 100644
--- a/js/quick-reply.js
+++ b/js/quick-reply.js
@@ -7,8 +7,8 @@
*
* Usage:
* $config['quick_reply'] = true;
- * $config['additional_javascript'][] = $config['root'] . 'jquery.min.js';
- * $config['additional_javascript'][] = $config['root'] . 'quick-reply.js';
+ * $config['additional_javascript'][] = 'js/jquery.min.js';
+ * $config['additional_javascript'][] = 'js/quick-reply.js';
*
*/