source: trunk/prototype/modules/calendar/js/timezone.js @ 6069

Revision 6069, 1.8 KB checked in by douglasz, 12 years ago (diff)

Ticket #2673 - Problemas com o mapa de disponibilidade.

  • Property svn:executable set to *
Line 
1/*
2        Todo Otimizar caulculo de timezone
3        Objeto Date.toString() retorna a data com inserção do offset
4        Objeto Date.getTime() retorna a data sem inserção do offset
5*/
6
7var objTime = DataLayer.dispatch( "timezones" );
8
9Timezone = {
10        currentOffset : new Date().getUTCOffset(),
11        daylightSaving: isNaN(parseInt( objTime.isDaylightSaving )) ? 0 : parseInt( objTime.isDaylightSaving ),
12
13        timezones: objTime.timezones,     
14        timezone: function( tzId ){
15
16                return this.timezones[ tzId || User.preferences.timezone ];
17
18        },
19       
20        getDateCalendar: function(date, tzId, isDay){
21                var timezone = this.timezone( tzId );
22
23                if(!timezone)
24                        return date;
25
26                date = this.normalizeDate(date, false, true);
27
28                return date.add({hours: parseInt(timezone.charAt(0) + timezone.charAt(2))  +  parseInt(isDay) });
29        },
30       
31        getDateEvent: function(date, tzId, idCalendar, isDay, type){
32                var timezone = this.timezone( tzId );
33                var timezoneCurrent = this.timezone(DataLayer.get('calendar', idCalendar).timezone);
34
35                if(timezone == timezoneCurrent)
36                        return date;
37               
38                var to = parseInt(timezone.charAt(0) + timezone.charAt(2)) + parseInt(isDay.event[type]);
39                var current = parseInt(timezoneCurrent.charAt(0) + timezoneCurrent.charAt(2)) + parseInt(isDay.calendar[type]);
40               
41                if(timezone.charAt(0) == timezoneCurrent.charAt(0))
42                        hours =   (  to + (current * - 1)) ;
43                else
44                        hours =  to + (( current ) * (timezone.charAt(0) ==  '+'  ? -1 : 1)) ;
45               
46                return date.add({hours: hours});
47        },
48       
49        normalizeDate: function(date, current, inverse){
50                var offsetDate = !!current ? this.currentOffset : date.getUTCOffset();
51                return date.add({hours: (parseInt(offsetDate.charAt(0) + offsetDate.charAt(2)) * (!!inverse ? -1 : 1) )});
52        },
53       
54        getDateMapDisponibility: function(date){
55                return this.normalizeDate(date, false, true);
56        }
57}
Note: See TracBrowser for help on using the repository browser.