diff options
| author | Michael Save <savetheinternet@tinyboard.org> | 2012-03-31 10:59:20 +1100 |
|---|---|---|
| committer | Michael Save <savetheinternet@tinyboard.org> | 2012-03-31 10:59:20 +1100 |
| commit | fef9a3ca82144348924852f68aee35ff4bf6ca25 (patch) | |
| tree | 2eb7dd277177fcbd572884d15ed3ce100aa61c7c /js/local-time.js | |
| parent | 52443d3da98e992953d8214b7848350f70d02336 (diff) | |
| parent | 2df1ebd88c266d984cbaa6c26917c2ea89c2ae0e (diff) | |
Merge branch 'master' of github.com:savetheinternet/Tinyboard-Tools into tools
Conflicts:
README.md
Diffstat (limited to 'js/local-time.js')
| -rw-r--r-- | js/local-time.js | 42 |
1 files changed, 42 insertions, 0 deletions
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) + ); + }); +}); + |
