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 | |
---|
7 | var objTime = DataLayer.dispatch( "timezones" ); |
---|
8 | |
---|
9 | Timezone = { |
---|
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 | } |
---|