×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
1
Language: Javascript
Posted by: Vlad Krasovsky
Added: Oct 22, 2014 10:11 PM
Views: 13
Tags: no tags
фыв
  1. timeConverter = new Object();
  2. timeConverter.serverZone = "America/Los_Angeles";
  3. timeConverter.format = 'hh:mm a';
  4.  
  5. timeConverter.loadTimeZone = function (obj) {
  6.     var timeZone = unescape(fuzzUtils.getCookie('client-timezone-offset'));
  7.     //console.log(timeZone);
  8.    
  9.     if (timeZone == "false") {
  10.         timeZone = timeConverter.setTimeZone();
  11.     }
  12.    
  13.     var format = 'hh:mm a';
  14.     //var date = new Date();
  15.     $("span[name=cityvibeUtils_timestamp]").each(function(){
  16.         var date = $(this).text();
  17.         var obj = new Object();
  18.         obj.timeZone = timeZone;
  19.         obj.parseFormat = timeConverter.format;
  20.         obj.format = timeConverter.format;
  21.         var t = timeConverter.convertDateTime(date,obj);
  22.         $(this).text(t);
  23.     });
  24.  
  25. }
  26.  
  27. timeConverter.dateTime = function () {
  28.     var timeZone = unescape(fuzzUtils.getCookie('client-timezone-offset'));
  29.     var date = moment();
  30.     var obj = new Object();
  31.     obj.format = "hh:mm a";
  32.     obj.timeZone = timeZone;
  33.     var t = timeConverter.convertDateTime(date,obj);
  34.    
  35.     var tMoment = moment(t,"hh:mm a");
  36.    
  37.     //var tDate = new Date(t);
  38.     //console.log(temp.hour());
  39.     //console.log(t.duration().asMinutes());
  40.     return tMoment;
  41. }
  42.  
  43. timeConverter.convertDateTime = function (date,obj) {
  44.    
  45.     var timeZone = timeConverter.serverZone;
  46.     var parseFormat = null;
  47.     var format = timeConverter.format;
  48.    
  49.     if(typeof obj != 'undefined'){
  50.         if(typeof obj.timeZone != 'undefined'){
  51.             timeZone = obj.timeZone;
  52.         }
  53.         if(typeof obj.parseFormat != 'undefined'){
  54.             parseFormat = obj.timeZone;
  55.         }
  56.         if(typeof obj.format != 'undefined'){
  57.             format = obj.format;
  58.         }
  59.        
  60.     }
  61.     if(parseFormat !== null){
  62.         var t = moment.tz(date,format, timeConverter.serverZone).tz(timeZone).format(format);
  63.     }
  64.     else{
  65.         var t = moment.tz(date, timeConverter.serverZone).tz(timeZone).format(format);
  66.     }
  67.     return t;
  68. }
  69.  
  70.  
  71. timeConverter.setTimeZone = function (obj) {
  72.  
  73.     var tz = jstz.determine(); // Determines the time zone of the browser client
  74.     var tzone = tz.name();
  75.  
  76.     timeConverter.setCookie('client-timezone-offset', tzone, 30);
  77.     return tzone;
  78.  
  79. }
  80.  
  81. timeConverter.setCookie = function (name, value, exdays) {
  82.     var d = new Date();
  83.     d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  84.     var expires = "expires=" + d.toUTCString();
  85.     document.cookie = name + "=" + value + "; " + expires + ";domain=.cityvibe.com;path =/";
  86. }
  87.  
  88. // call the init method
  89. $(document).ready(function () {
  90.     timeConverter.loadTimeZone();
  91. });