Ver Mensaje Individual
  #9 (permalink)  
Antiguo 04/03/2011, 21:53
leif_sk8er
 
Fecha de Ingreso: junio-2009
Mensajes: 309
Antigüedad: 14 años, 10 meses
Puntos: 5
Respuesta: Calcular desfase horario segun la zona

Por cierto, para detectar la fase horaria usé JS, despues la marco en un select, y cuando guarda la guardo en la base de datos, asi pre-marca en el select la fase horaria de primeras...

JS del auto detect... JQUERY
Código Javascript:
Ver original
  1. // Esta funcion saca la zona horaria oficial del usuario
  2. function timezoneDetect(){
  3.     var dtDate = new Date('1/1/' + (new Date()).getUTCFullYear());
  4.     var intOffset = 10000; //set initial offset high so it is adjusted on the first attempt
  5.     var intMonth;
  6.     var intHoursUtc;
  7.     var intHours;
  8.     var intDaysMultiplyBy;
  9.  
  10.     //go through each month to find the lowest offset to account for DST
  11.     for (intMonth=0;intMonth < 12;intMonth++){
  12.         //go to the next month
  13.         dtDate.setUTCMonth(dtDate.getUTCMonth() + 1);
  14.  
  15.         //To ignore daylight saving time look for the lowest offset.
  16.         //Since, during DST, the clock moves forward, it'll be a bigger number.
  17.         if (intOffset > (dtDate.getTimezoneOffset() * (-1))){
  18.             intOffset = (dtDate.getTimezoneOffset() * (-1));
  19.         }
  20.     }
  21.  
  22.     return intOffset * 60;
  23. }


php para el select
Código PHP:
Ver original
  1. $faseHoraria = array(
  2.                         '-43200' => '(GMT -12:00) Eniwetok, Kwajalein',
  3.                         '-39600' => '(GMT -11:00) Midway Island, Samoa',
  4.                         '-36000' => '(GMT -10:00) Hawaii',
  5.                         '-32400' => '(GMT -9:00) Alaska',
  6.                         '-28800' => '(GMT -8:00) Pacific Time (US & Canada)',
  7.                         '-25200' => '(GMT -7:00) Mountain Time (US & Canada)',
  8.                         '-21600' => '(GMT -6:00) Central Time (US & Canada), Mexico City',
  9.                         '-18000' => '(GMT -5:00) Eastern Time (US & Canada), Bogota, Lima',
  10.                         '-14000' => '(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz',
  11.                         '-7200' => '(GMT -2:00) Mid-Atlantic',
  12.                         '-3600' => '(GMT -1:00) Azores, Cape Verde Islands',
  13.                         '0' => '(GMT 0) Western Europe Time, London, Lisbon, Casablanca',
  14.                         '3600' => '(GMT +1:00) Madrid, Paris, Berlin, Copenhagen',
  15.                         '7200' => '(GMT +2:00) Kaliningrad, South Africa',
  16.                         '10400' => '(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg',
  17.                         '12200' => '(GMT +3:30) Tehran',
  18.                         '14000' => '(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi',
  19.                         '16200' => '(GMT +4:30) Kabul',
  20.                         '18000' => '(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent',
  21.                         '19800' => '(GMT +5:30) Bombay, Calcutta, Madras, New Delhi',
  22.                         '20700' => '(GMT +5:45) Kathmandu',
  23.                         '21600' => '(GMT +6:00) Almaty, Dhaka, Colombo',
  24.                         '25200' => '(GMT +7:00) Bangkok, Hanoi, Jakarta',
  25.                         '28800' => '(GMT +8:00) Beijing, Perth, Singapore, Hong Kong',
  26.                         '32400' => '(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk',
  27.                         '34200' => '(GMT +9:30) Adelaide, Darwin',
  28.                         '36000' => '(GMT +10:00) Eastern Australia, Guam, Vladivostok',
  29.                         '39600' => '(GMT +11:00) Magadan, Solomon Islands, New Caledonia',
  30.                         '43200' => '(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka'
  31.                         );
  32.    
  33.  
  34.    
  35.     // Zona horaria
  36.     echo '<div class="inputTxt"><select name="zonaTxt" style="width:97%;">';
  37.     foreach($faseHoraria as $hora => $nombreFase){
  38.     echo '<option value="'.$hora.'" title="'.$nombreFase.'">'.$nombreFase.'</option>';
  39.     }
  40.     echo '</select></div>';


Pra el premarcado...
Código Javascript:
Ver original
  1. $("select[name='zonaTxt'] option[value='"+faseHoraria+"']").attr("selected","selected");



Incluso como sabes el desfase por js, lo mandas con AJAX y la guardas si quieres para desde el principio saber su fase horaria en el login de la aplicacion...