|
| 1 | + |
| 2 | +define( function() { |
| 3 | +var GlobalizeDate = function( date, timeZonedata ) { |
| 4 | + this.date = new Date( date.getTime() ); |
| 5 | + this.timeZoneData = timeZonedata; |
| 6 | + this.setTime( this.date.getTime() - this.getTimeZoneAdjustment() * 60 * 1000 ); |
| 7 | +}; |
| 8 | + |
| 9 | +GlobalizeDate.prototype.getFullYear = function() { |
| 10 | + return this.date.getUTCFullYear(); |
| 11 | +}; |
| 12 | + |
| 13 | +GlobalizeDate.prototype.getMonth = function() { |
| 14 | + return this.date.getUTCMonth(); |
| 15 | +}; |
| 16 | + |
| 17 | +GlobalizeDate.prototype.getDay = function() { |
| 18 | + return this.date.getUTCDay(); |
| 19 | +}; |
| 20 | + |
| 21 | +GlobalizeDate.prototype.getDate = function() { |
| 22 | + return this.date.getUTCDate(); |
| 23 | +}; |
| 24 | + |
| 25 | +GlobalizeDate.prototype.getMinutes = function() { |
| 26 | + return this.date.getUTCMinutes(); |
| 27 | +}; |
| 28 | + |
| 29 | +GlobalizeDate.prototype.getSeconds = function() { |
| 30 | + return this.date.getUTCSeconds(); |
| 31 | +}; |
| 32 | + |
| 33 | +GlobalizeDate.prototype.getHours = function() { |
| 34 | + return this.date.getUTCHours(); |
| 35 | +}; |
| 36 | + |
| 37 | +GlobalizeDate.prototype.getMinutes = function() { |
| 38 | + return this.date.getUTCMinutes(); |
| 39 | +}; |
| 40 | + |
| 41 | +GlobalizeDate.prototype.getSeconds = function() { |
| 42 | + return this.date.getUTCSeconds(); |
| 43 | +}; |
| 44 | + |
| 45 | +GlobalizeDate.prototype.getMilliseconds = function() { |
| 46 | + return this.date.getUTCMilliseconds(); |
| 47 | +}; |
| 48 | + |
| 49 | +GlobalizeDate.prototype.getTime = function() { |
| 50 | + return this.date.getTime(); |
| 51 | +}; |
| 52 | + |
| 53 | +GlobalizeDate.prototype.setFullYear = function( year ) { |
| 54 | + return this.date.setUTCFullYear( year ); |
| 55 | +}; |
| 56 | + |
| 57 | +GlobalizeDate.prototype.setMonth = function( month ) { |
| 58 | + return this.date.setUTCMonth( month ); |
| 59 | +}; |
| 60 | + |
| 61 | +GlobalizeDate.prototype.setDay = function( date ) { |
| 62 | + return this.date.setUTCDay( date ); |
| 63 | +}; |
| 64 | + |
| 65 | +GlobalizeDate.prototype.setDate = function( date ) { |
| 66 | + return this.date.setUTCDate( date ); |
| 67 | +}; |
| 68 | + |
| 69 | +GlobalizeDate.prototype.setMinutes = function( minutes ) { |
| 70 | + return this.date.setUTCMinutes( minutes ); |
| 71 | +}; |
| 72 | + |
| 73 | +GlobalizeDate.prototype.setSeconds = function( seconds ) { |
| 74 | + return this.date.setUTCSeconds( seconds ); |
| 75 | +}; |
| 76 | + |
| 77 | +GlobalizeDate.prototype.setHours = function( hour ) { |
| 78 | + return this.date.setUTCHours( hour ); |
| 79 | +}; |
| 80 | + |
| 81 | +GlobalizeDate.prototype.setMinutes = function( minutes ) { |
| 82 | + return this.date.setUTCMinutes( minutes ); |
| 83 | +}; |
| 84 | + |
| 85 | +GlobalizeDate.prototype.setSeconds = function( seconds ) { |
| 86 | + return this.date.setUTCSeconds( seconds ); |
| 87 | +}; |
| 88 | + |
| 89 | +GlobalizeDate.prototype.setMilliseconds = function( milliseconds ) { |
| 90 | + return this.date.setUTCMilliseconds( milliseconds ); |
| 91 | +}; |
| 92 | + |
| 93 | +GlobalizeDate.prototype.setTime = function( time ) { |
| 94 | + return this.date.setTime( time ); |
| 95 | +}; |
| 96 | + |
| 97 | +GlobalizeDate.prototype.isDST = function() { |
| 98 | + return this.getStdOffset() !== -this.getTimeZoneAdjustment(); |
| 99 | +}; |
| 100 | + |
| 101 | +GlobalizeDate.prototype.getTimezoneOffset = function() { |
| 102 | + return this.getTimeZoneAdjustment(); |
| 103 | +}; |
| 104 | + |
| 105 | +GlobalizeDate.prototype.getStdOffset = function() { |
| 106 | + var stdOffset = -1; |
| 107 | + if ( this.timeZoneData.offsets > 1 ) { |
| 108 | + stdOffset *= Math.max( |
| 109 | + this.timeZoneData.offsets[ this.timeZoneData.offsets.length - 1 ], |
| 110 | + this.timeZoneData.offsets[ this.timeZoneData.offsets.length - 2 ] |
| 111 | + ); |
| 112 | + } else { |
| 113 | + stdOffset *= this.timeZoneData.offsets[ this.timeZoneData.offsets.length - 1 ]; |
| 114 | + } |
| 115 | + return stdOffset; |
| 116 | +}; |
| 117 | + |
| 118 | +GlobalizeDate.prototype.getTimeZoneAdjustment = function() { |
| 119 | + var index = 0; |
| 120 | + while ( index < this.timeZoneData.untils.length - 1 && |
| 121 | + this.date.getTime() >= this.timeZoneData.untils[ index ] ) { |
| 122 | + index++; |
| 123 | + } |
| 124 | + return index === 0 ? 0 : this.timeZoneData.offsets[ index ]; |
| 125 | +}; |
| 126 | + |
| 127 | +return GlobalizeDate; |
| 128 | +}); |
0 commit comments