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

Revision 5592, 1.7 KB checked in by acoutinho, 12 years ago (diff)

Ticket #2434 - Implementacao de compartilhamento de agendas (agendas usuario e agendas publicas)

  • Property svn:executable set to *
RevLine 
[5409]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*/
[5468]6
7var objTime = DataLayer.dispatch( "timezones" );
[5592]8
[5409]9Timezone = {
[5592]10        currentOffset : new Date().getUTCOffset(),
11        daylightSaving: isNaN(parseInt( objTime.isDaylightSaving )) ? 0 : parseInt( objTime.isDaylightSaving ),
[5409]12
[5468]13        timezones: objTime.timezones,     
[5409]14        timezone: function( tzId ){
15
[5468]16                return this.timezones[ tzId || User.preferences.timezone ];
[5409]17
18        },
19       
[5592]20        getDateCalendar: function(date, tzId, isDay){
[5409]21                var timezone = this.timezone( tzId );
22
23                if(!timezone)
24                        return date;
25
[5592]26                date = this.normalizeDate(date, false, true);
[5409]27
[5592]28                return date.add({hours: parseInt(timezone.charAt(0) + timezone.charAt(2))  +  parseInt(isDay) });
[5409]29        },
30       
[5592]31        getDateEvent: function(date, tzId, idCalendar, isDay, type){
32                var timezone = this.timezone( tzId );
33                var timezoneCurrent = this.timezone(DataLayer.get('calendar', idCalendar).timezone);
[5409]34
[5592]35                if(timezone == timezoneCurrent)
36                        return date;
[5409]37               
[5592]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)) ;
[5409]43                else
[5592]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) )});
[5409]52        }
53}
Note: See TracBrowser for help on using the repository browser.