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.

43 lines
1.6 KiB

13 years ago
13 years ago
13 years ago
13 years ago
  1. var tz_list;
  2. var original = true;
  3. var operators = {
  4. '+': function(a, b) { return a + b },
  5. '-': function(a, b) { return a - b },
  6. };
  7. function update(elt){
  8. if (elt.selectedIndex == -1)
  9. return null;
  10. //Get the offset from the selected option
  11. text = elt.options[elt.selectedIndex].text;
  12. //Determine if it is a positive or negative offset
  13. sign = text.indexOf("+") > -1 ? "+" : "-";
  14. //Seperate hours and minutes and get the offset in ms
  15. h_m = text.split(sign)[1].split(")")[0].split(":");
  16. tzOffset = parseInt(h_m[0]) * 3600000 + parseInt(h_m[1]) * 60000;
  17. //Get the offset between your computer and UTC
  18. pcOffset = new Date().getTimezoneOffset() * 60000;
  19. return new Date(operators[sign]((new Date().getTime() + pcOffset), tzOffset));
  20. }
  21. movim_add_onload(function()
  22. {
  23. tz_list = document.querySelector("#timezone");
  24. tz_list.onchange = function(e){
  25. newTime = update(tz_list);
  26. formatDate(newTime);
  27. }
  28. setInterval(
  29. function(){ //increment time each second
  30. date = new Date(document.querySelector(".dTimezone").innerHTML).getTime() + 1000;
  31. date = formatDate(new Date(date));
  32. }
  33. ,1000);
  34. formatDate = function (newTime){
  35. h = newTime.getHours()<10 ? "0" + newTime.getHours() : newTime.getHours();
  36. m = newTime.getMinutes()<10 ? "0" + newTime.getMinutes() : newTime.getMinutes();
  37. s = newTime.getSeconds()<10 ? "0" + newTime.getSeconds() : newTime.getSeconds();
  38. document.querySelector(".dTimezone").innerHTML = newTime.toDateString() + " " + h+ ":" + m + ":" + s;
  39. }
  40. });