The version of vichan running on lainchan.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.7KB

  1. /*
  2. * local-time.js
  3. * https://github.com/savetheinternet/Tinyboard/blob/master/js/local-time.js
  4. *
  5. * Released under the MIT license
  6. * Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
  7. * Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
  8. *
  9. * Usage:
  10. * // $config['additional_javascript'][] = 'js/jquery.min.js';
  11. * $config['additional_javascript'][] = 'js/local-time.js';
  12. *
  13. */
  14. onready(function(){
  15. var iso8601 = function(s) {
  16. s = s.replace(/\.\d\d\d+/,""); // remove milliseconds
  17. s = s.replace(/-/,"/").replace(/-/,"/");
  18. s = s.replace(/T/," ").replace(/Z/," UTC");
  19. s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
  20. return new Date(s);
  21. };
  22. var zeropad = function(num, count) {
  23. return [Math.pow(10, count - num.toString().length), num].join('').substr(1);
  24. };
  25. var do_localtime = function(elem) {
  26. var times = elem.getElementsByTagName('time');
  27. for(var i = 0; i < times.length; i++) {
  28. if(typeof times[i].getAttribute('data-local') == 'undefined')
  29. continue;
  30. var t = iso8601(times[i].getAttribute('datetime'));
  31. times[i].setAttribute('data-local', 'true');
  32. times[i].innerHTML =
  33. // date
  34. zeropad(t.getMonth() + 1, 2) + "/" + zeropad(t.getDate(), 2) + "/" + t.getFullYear().toString().substring(2) +
  35. " (" + [_("Sun"), _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun")][t.getDay()] + ") " +
  36. // time
  37. zeropad(t.getHours(), 2) + ":" + zeropad(t.getMinutes(), 2) + ":" + zeropad(t.getSeconds(), 2);
  38. };
  39. };
  40. do_localtime(document);
  41. if (window.jQuery) {
  42. // allow to work with auto-reload.js, etc.
  43. $(document).on('new_post', function(e, post) {
  44. do_localtime(post);
  45. });
  46. }
  47. });