| 84 | | return getDateTimeString(true, true, true, true); |
|---|
| 85 | | } |
|---|
| 86 | | |
|---|
| 87 | | /* |
|---|
| 88 | | Returns the Year the W3CDateTime represents in the following format: |
|---|
| 89 | | YYYY |
|---|
| 90 | | */ |
|---|
| 91 | | public function getW3CYear(Void):String |
|---|
| 92 | | { |
|---|
| 93 | | return getFullYear().toString(); |
|---|
| 94 | | } |
|---|
| 95 | | |
|---|
| 96 | | /* |
|---|
| 97 | | Returns the Month the W3CDateTime represents in the following format: |
|---|
| 98 | | MM |
|---|
| 99 | | |
|---|
| 100 | | where 1 = January |
|---|
| 101 | | */ |
|---|
| 102 | | public function getW3CMonth(Void):String |
|---|
| 103 | | { |
|---|
| 104 | | return (getMonth() + 1).toString(); |
|---|
| 105 | | } |
|---|
| 106 | | |
|---|
| 107 | | /* |
|---|
| 108 | | Returns the day of the month the W3CDateTime represents in the |
|---|
| 109 | | following format: |
|---|
| 110 | | dd |
|---|
| 111 | | */ |
|---|
| 112 | | public function getW3CDate(Void):String |
|---|
| 113 | | { |
|---|
| 114 | | return getDate().toString(); |
|---|
| 115 | | } |
|---|
| 116 | | |
|---|
| 117 | | /* |
|---|
| 118 | | Returns the hour the W3CDateTime represents in the |
|---|
| 119 | | following format: |
|---|
| 120 | | hh |
|---|
| 121 | | */ |
|---|
| 122 | | public function getW3CHours(Void):String |
|---|
| 123 | | { |
|---|
| 124 | | //adjust for utc? |
|---|
| 125 | | return getHours().toString(); |
|---|
| 126 | | } |
|---|
| 127 | | |
|---|
| 128 | | /* |
|---|
| 129 | | Returns the minutes the W3CDateTime represents in the |
|---|
| 130 | | following format: |
|---|
| 131 | | mm |
|---|
| 132 | | */ |
|---|
| 133 | | public function getW3CMinutes(Void):String |
|---|
| 134 | | { |
|---|
| 135 | | return getMinutes().toString(); |
|---|
| 136 | | } |
|---|
| 137 | | |
|---|
| 138 | | /* |
|---|
| 139 | | Returns the seconds the W3CDateTime represents in the |
|---|
| 140 | | following format: |
|---|
| 141 | | ss |
|---|
| 142 | | */ |
|---|
| 143 | | public function getW3CSeconds(Void):String |
|---|
| 144 | | { |
|---|
| 145 | | return getMinutes().toString(); |
|---|
| 146 | | } |
|---|
| 147 | | |
|---|
| 148 | | /* |
|---|
| 149 | | Returns the UTC offset the W3CDateTime represents in the |
|---|
| 150 | | following format: |
|---|
| 151 | | +/-hh:mm |
|---|
| 152 | | |
|---|
| 153 | | Note, if there is no offset, it will return |
|---|
| 154 | | Z |
|---|
| 155 | | */ |
|---|
| 156 | | public function getW3CUTCOffset(Void):String |
|---|
| 157 | | { |
|---|
| 158 | | return W3CDateTime.formatTimezoneOffset(this); |
|---|
| 159 | | } |
|---|
| 160 | | |
|---|
| 161 | | /* |
|---|
| 162 | | Static functions that takes a String representation of a number and adds |
|---|
| 163 | | a leading 0 if it is a single digit. |
|---|
| 164 | | */ |
|---|
| 165 | | public static function padDigit(digit:String):String |
|---|
| 166 | | { |
|---|
| 167 | | if(digit.length < 2) |
|---|
| 168 | | { |
|---|
| 169 | | return "0" + digit; |
|---|
| 170 | | } |
|---|
| 171 | | |
|---|
| 172 | | return digit; |
|---|
| 173 | | } |
|---|
| 174 | | |
|---|
| 175 | | /* |
|---|
| 176 | | Static function that takes an ActionScript Date object and returns |
|---|
| 177 | | a well formed W3CDateTime String that represents the specified date. |
|---|
| 178 | | |
|---|
| 179 | | Takes 4 additional optional arguments which specifies the format of |
|---|
| 180 | | the string: |
|---|
| 181 | | |
|---|
| 182 | | incMonth : Whether the month should be included. |
|---|
| 183 | | |
|---|
| 184 | | incDay : Whether the day of the month should be included. |
|---|
| 185 | | |
|---|
| 186 | | incHours : Whether the hours and minutes should be included. |
|---|
| 187 | | |
|---|
| 188 | | incSeconds : Whether the seconds should be included. |
|---|
| 189 | | |
|---|
| 190 | | Note, that all output will be a valid W3CDataTime item. |
|---|
| 191 | | */ |
|---|
| 192 | | public static function parseDate(inDate:Date, |
|---|
| 193 | | incMonth:Boolean, |
|---|
| 194 | | incDay:Boolean, |
|---|
| 195 | | incHours:Boolean, |
|---|
| 196 | | incSeconds:Boolean):String |
|---|
| 197 | | { |
|---|
| 198 | | if(inDate == undefined) |
|---|
| 199 | | { |
|---|
| 200 | | return undefined; |
|---|
| 201 | | } |
|---|
| 202 | | |
|---|
| 203 | | if(incMonth == undefined) |
|---|
| 204 | | { |
|---|
| 205 | | incMonth = false; |
|---|
| 206 | | } |
|---|
| 207 | | |
|---|
| 208 | | if(incDay == undefined) |
|---|
| 209 | | { |
|---|
| 210 | | incDay = false; |
|---|
| 211 | | } |
|---|
| 212 | | |
|---|
| 213 | | if(incHours == undefined) |
|---|
| 214 | | { |
|---|
| 215 | | incHours = false; |
|---|
| 216 | | } |
|---|
| 217 | | |
|---|
| 218 | | if(incSeconds == undefined) |
|---|
| 219 | | { |
|---|
| 220 | | incSeconds = false; |
|---|
| 221 | | } |
|---|
| 222 | | |
|---|
| 223 | | var now:Date = new Date(); |
|---|
| 224 | | |
|---|
| 225 | | var w3cString:String = now.getFullYear().toString(); |
|---|
| 226 | | |
|---|
| 227 | | if(!incMonth) |
|---|
| 228 | | { |
|---|
| 229 | | return w3cString; |
|---|
| 230 | | } |
|---|
| 231 | | |
|---|
| 232 | | w3cString += "-" + W3CDateTime.padDigit((now.getMonth() + 1).toString()); |
|---|
| 233 | | |
|---|
| 234 | | if(!incDay) |
|---|
| 235 | | { |
|---|
| 236 | | return w3cString; |
|---|
| 237 | | } |
|---|
| 238 | | |
|---|
| 239 | | w3cString += "-" + W3CDateTime.padDigit(now.getDate().toString()); |
|---|
| 240 | | |
|---|
| 241 | | if(!incHours) |
|---|
| 242 | | { |
|---|
| 243 | | return w3cString; |
|---|
| 244 | | } |
|---|
| 245 | | |
|---|
| 246 | | w3cString += "T" + W3CDateTime.padDigit(now.getHours().toString()) + |
|---|
| 247 | | ":" + W3CDateTime.padDigit(now.getMinutes().toString()); |
|---|
| 248 | | |
|---|
| 249 | | if(!incSeconds) |
|---|
| 250 | | { |
|---|
| 251 | | //need to format the timeset appropriately |
|---|
| 252 | | return w3cString + W3CDateTime.formatTimezoneOffset(now); |
|---|
| 253 | | } |
|---|
| 254 | | |
|---|
| 255 | | return w3cString + ":" + W3CDateTime.padDigit(now.getSeconds().toString()) + |
|---|
| 256 | | W3CDateTime.formatTimezoneOffset(now); |
|---|
| 257 | | } |
|---|
| 258 | | |
|---|
| 259 | | /* |
|---|
| 260 | | Static methods that takes an ActionScript date instance, and returns |
|---|
| 261 | | the UTC offset in the format used in a W3CDateTime string. |
|---|
| 262 | | |
|---|
| 263 | | The format is: |
|---|
| 264 | | |
|---|
| 265 | | +/-hh:mm |
|---|
| 266 | | |
|---|
| 267 | | If the offset is 0, then method will return |
|---|
| 268 | | Z |
|---|
| 269 | | */ |
|---|
| 270 | | public static function formatTimezoneOffset(d:Date):String |
|---|
| 271 | | { |
|---|
| 272 | | var timezoneOffset:Number = d.getTimezoneOffset(); |
|---|
| 273 | | |
|---|
| 274 | | if(timezoneOffset == 0) |
|---|
| 275 | | { |
|---|
| 276 | | return "Z"; |
|---|
| 277 | | } |
|---|
| 278 | | |
|---|
| 279 | | var operator:String = (timezoneOffset > -1)? "+" : "-"; |
|---|
| 280 | | |
|---|
| 281 | | if(timezoneOffset < 0) |
|---|
| 282 | | { |
|---|
| 283 | | timezoneOffset *= -1; |
|---|
| 284 | | } |
|---|
| 285 | | |
|---|
| 286 | | //what if offset if 0 or less |
|---|
| 287 | | var hours_i:Number = (timezoneOffset / 60); |
|---|
| 288 | | var seconds:String = (timezoneOffset - (hours_i * 60)).toString(); |
|---|
| 289 | | |
|---|
| 290 | | return operator + W3CDateTime.padDigit(hours_i.toString()) + |
|---|
| 291 | | ":" + W3CDateTime.padDigit(seconds); |
|---|
| 292 | | } |
|---|
| 293 | | |
|---|
| 294 | | /* |
|---|
| 295 | | Static method that takes a W3CDateTime string and returns an |
|---|
| 296 | | ActionScript Date object that represents the string passed in. |
|---|
| 297 | | */ |
|---|
| | 84 | return getDateTimeString(true, true, true, true); |
|---|
| | 85 | } |
|---|
| | 86 | |
|---|
| | 87 | /* |
|---|
| | 88 | Returns the Year the W3CDateTime represents in the following format: |
|---|
| | 89 | YYYY |
|---|
| | 90 | */ |
|---|
| | 91 | public function getW3CYear(Void):String |
|---|
| | 92 | { |
|---|
| | 93 | return getFullYear().toString(); |
|---|
| | 94 | } |
|---|
| | 95 | |
|---|
| | 96 | /* |
|---|
| | 97 | Returns the Month the W3CDateTime represents in the following format: |
|---|
| | 98 | MM |
|---|
| | 99 | |
|---|
| | 100 | where 1 = January |
|---|
| | 101 | */ |
|---|
| | 102 | public function getW3CMonth(Void):String |
|---|
| | 103 | { |
|---|
| | 104 | return (getMonth() + 1).toString(); |
|---|
| | 105 | } |
|---|
| | 106 | |
|---|
| | 107 | /* |
|---|
| | 108 | Returns the day of the month the W3CDateTime represents in the |
|---|
| | 109 | following format: |
|---|
| | 110 | dd |
|---|
| | 111 | */ |
|---|
| | 112 | public function getW3CDate(Void):String |
|---|
| | 113 | { |
|---|
| | 114 | return getDate().toString(); |
|---|
| | 115 | } |
|---|
| | 116 | |
|---|
| | 117 | /* |
|---|
| | 118 | Returns the hour the W3CDateTime represents in the |
|---|
| | 119 | following format: |
|---|
| | 120 | hh |
|---|
| | 121 | */ |
|---|
| | 122 | public function getW3CHours(Void):String |
|---|
| | 123 | { |
|---|
| | 124 | //adjust for utc? |
|---|
| | 125 | return getHours().toString(); |
|---|
| | 126 | } |
|---|
| | 127 | |
|---|
| | 128 | /* |
|---|
| | 129 | Returns the minutes the W3CDateTime represents in the |
|---|
| | 130 | following format: |
|---|
| | 131 | mm |
|---|
| | 132 | */ |
|---|
| | 133 | public function getW3CMinutes(Void):String |
|---|
| | 134 | { |
|---|
| | 135 | return getMinutes().toString(); |
|---|
| | 136 | } |
|---|
| | 137 | |
|---|
| | 138 | /* |
|---|
| | 139 | Returns the seconds the W3CDateTime represents in the |
|---|
| | 140 | following format: |
|---|
| | 141 | ss |
|---|
| | 142 | */ |
|---|
| | 143 | public function getW3CSeconds(Void):String |
|---|
| | 144 | { |
|---|
| | 145 | return getMinutes().toString(); |
|---|
| | 146 | } |
|---|
| | 147 | |
|---|
| | 148 | /* |
|---|
| | 149 | Returns the UTC offset the W3CDateTime represents in the |
|---|
| | 150 | following format: |
|---|
| | 151 | +/-hh:mm |
|---|
| | 152 | |
|---|
| | 153 | Note, if there is no offset, it will return |
|---|
| | 154 | Z |
|---|
| | 155 | */ |
|---|
| | 156 | public function getW3CUTCOffset(Void):String |
|---|
| | 157 | { |
|---|
| | 158 | return W3CDateTime.formatTimezoneOffset(this); |
|---|
| | 159 | } |
|---|
| | 160 | |
|---|
| | 161 | /* |
|---|
| | 162 | Static functions that takes a String representation of a number and adds |
|---|
| | 163 | a leading 0 if it is a single digit. |
|---|
| | 164 | */ |
|---|
| | 165 | public static function padDigit(digit:String):String |
|---|
| | 166 | { |
|---|
| | 167 | if(digit.length < 2) |
|---|
| | 168 | { |
|---|
| | 169 | return "0" + digit; |
|---|
| | 170 | } |
|---|
| | 171 | |
|---|
| | 172 | return digit; |
|---|
| | 173 | } |
|---|
| | 174 | |
|---|
| | 175 | /* |
|---|
| | 176 | Static function that takes an ActionScript Date object and returns |
|---|
| | 177 | a well formed W3CDateTime String that represents the specified date. |
|---|
| | 178 | |
|---|
| | 179 | Takes 4 additional optional arguments which specifies the format of |
|---|
| | 180 | the string: |
|---|
| | 181 | |
|---|
| | 182 | incMonth : Whether the month should be included. |
|---|
| | 183 | |
|---|
| | 184 | incDay : Whether the day of the month should be included. |
|---|
| | 185 | |
|---|
| | 186 | incHours : Whether the hours and minutes should be included. |
|---|
| | 187 | |
|---|
| | 188 | incSeconds : Whether the seconds should be included. |
|---|
| | 189 | |
|---|
| | 190 | Note, that all output will be a valid W3CDataTime item. |
|---|
| | 191 | */ |
|---|
| | 192 | public static function parseDate(inDate:Date, |
|---|
| | 193 | incMonth:Boolean, |
|---|
| | 194 | incDay:Boolean, |
|---|
| | 195 | incHours:Boolean, |
|---|
| | 196 | incSeconds:Boolean):String |
|---|
| | 197 | { |
|---|
| | 198 | if(inDate == undefined) |
|---|
| | 199 | { |
|---|
| | 200 | return undefined; |
|---|
| | 201 | } |
|---|
| | 202 | |
|---|
| | 203 | if(incMonth == undefined) |
|---|
| | 204 | { |
|---|
| | 205 | incMonth = false; |
|---|
| | 206 | } |
|---|
| | 207 | |
|---|
| | 208 | if(incDay == undefined) |
|---|
| | 209 | { |
|---|
| | 210 | incDay = false; |
|---|
| | 211 | } |
|---|
| | 212 | |
|---|
| | 213 | if(incHours == undefined) |
|---|
| | 214 | { |
|---|
| | 215 | incHours = false; |
|---|
| | 216 | } |
|---|
| | 217 | |
|---|
| | 218 | if(incSeconds == undefined) |
|---|
| | 219 | { |
|---|
| | 220 | incSeconds = false; |
|---|
| | 221 | } |
|---|
| | 222 | |
|---|
| | 223 | var now:Date = new Date(); |
|---|
| | 224 | |
|---|
| | 225 | var w3cString:String = now.getFullYear().toString(); |
|---|
| | 226 | |
|---|
| | 227 | if(!incMonth) |
|---|
| | 228 | { |
|---|
| | 229 | return w3cString; |
|---|
| | 230 | } |
|---|
| | 231 | |
|---|
| | 232 | w3cString += "-" + W3CDateTime.padDigit((now.getMonth() + 1).toString()); |
|---|
| | 233 | |
|---|
| | 234 | if(!incDay) |
|---|
| | 235 | { |
|---|
| | 236 | return w3cString; |
|---|
| | 237 | } |
|---|
| | 238 | |
|---|
| | 239 | w3cString += "-" + W3CDateTime.padDigit(now.getDate().toString()); |
|---|
| | 240 | |
|---|
| | 241 | if(!incHours) |
|---|
| | 242 | { |
|---|
| | 243 | return w3cString; |
|---|
| | 244 | } |
|---|
| | 245 | |
|---|
| | 246 | w3cString += "T" + W3CDateTime.padDigit(now.getHours().toString()) + |
|---|
| | 247 | ":" + W3CDateTime.padDigit(now.getMinutes().toString()); |
|---|
| | 248 | |
|---|
| | 249 | if(!incSeconds) |
|---|
| | 250 | { |
|---|
| | 251 | //need to format the timeset appropriately |
|---|
| | 252 | return w3cString + W3CDateTime.formatTimezoneOffset(now); |
|---|
| | 253 | } |
|---|
| | 254 | |
|---|
| | 255 | return w3cString + ":" + W3CDateTime.padDigit(now.getSeconds().toString()) + |
|---|
| | 256 | W3CDateTime.formatTimezoneOffset(now); |
|---|
| | 257 | } |
|---|
| | 258 | |
|---|
| | 259 | /* |
|---|
| | 260 | Static methods that takes an ActionScript date instance, and returns |
|---|
| | 261 | the UTC offset in the format used in a W3CDateTime string. |
|---|
| | 262 | |
|---|
| | 263 | The format is: |
|---|
| | 264 | |
|---|
| | 265 | +/-hh:mm |
|---|
| | 266 | |
|---|
| | 267 | If the offset is 0, then method will return |
|---|
| | 268 | Z |
|---|
| | 269 | */ |
|---|
| | 270 | public static function formatTimezoneOffset(d:Date):String |
|---|
| | 271 | { |
|---|
| | 272 | var timezoneOffset:Number = d.getTimezoneOffset(); |
|---|
| | 273 | |
|---|
| | 274 | if(timezoneOffset == 0) |
|---|
| | 275 | { |
|---|
| | 276 | return "Z"; |
|---|
| | 277 | } |
|---|
| | 278 | |
|---|
| | 279 | var operator:String = (timezoneOffset > -1)? "+" : "-"; |
|---|
| | 280 | |
|---|
| | 281 | if(timezoneOffset < 0) |
|---|
| | 282 | { |
|---|
| | 283 | timezoneOffset *= -1; |
|---|
| | 284 | } |
|---|
| | 285 | |
|---|
| | 286 | //what if offset if 0 or less |
|---|
| | 287 | var hours_i:Number = (timezoneOffset / 60); |
|---|
| | 288 | var seconds:String = (timezoneOffset - (hours_i * 60)).toString(); |
|---|
| | 289 | |
|---|
| | 290 | return operator + W3CDateTime.padDigit(hours_i.toString()) + |
|---|
| | 291 | ":" + W3CDateTime.padDigit(seconds); |
|---|
| | 292 | } |
|---|
| | 293 | |
|---|
| | 294 | /* |
|---|
| | 295 | Static method that takes a W3CDateTime string and returns an |
|---|
| | 296 | ActionScript Date object that represents the string passed in. |
|---|
| | 297 | */ |
|---|
| 300 | | if(dateString == undefined || dateString.length < 1) |
|---|
| 301 | | { |
|---|
| 302 | | return undefined; |
|---|
| 303 | | } |
|---|
| 304 | | |
|---|
| 305 | | var YYYY:String = dateString.substr(0, 4); |
|---|
| 306 | | var MM:String = dateString.substr(5, 2); |
|---|
| 307 | | var DD:String = dateString.substr(8, 2); |
|---|
| 308 | | var hh:String = dateString.substr(11, 2); |
|---|
| 309 | | var mm:String = dateString.substr(14, 2); |
|---|
| 310 | | var ss:String = dateString.substr(17, 2); |
|---|
| 311 | | var s:String = ""; |
|---|
| 312 | | |
|---|
| 313 | | var offsetOperator:String; |
|---|
| 314 | | var offsetHours:String; |
|---|
| 315 | | var offsetMinutes:String; |
|---|
| 316 | | |
|---|
| 317 | | var offset:Number = 0; |
|---|
| 318 | | var operator:Number; |
|---|
| 319 | | var indexBump:Number = 0; |
|---|
| 320 | | |
|---|
| 321 | | if(dateString.substr(19, 1) == ".") |
|---|
| 322 | | { |
|---|
| 323 | | //they have a decimal second |
|---|
| 324 | | s = dateString.substr(20, 2); |
|---|
| 325 | | |
|---|
| 326 | | indexBump = 3; |
|---|
| 327 | | } |
|---|
| 328 | | else if (ss == "") { //can have tz offset with no seconds |
|---|
| 329 | | indexBump = -2; |
|---|
| 330 | | } |
|---|
| 331 | | else |
|---|
| 332 | | { |
|---|
| 333 | | indexBump = 0; |
|---|
| 334 | | //they dont have a decimal second |
|---|
| 335 | | } |
|---|
| 336 | | |
|---|
| 337 | | offsetOperator = dateString.substr(19 + indexBump,1); |
|---|
| 338 | | offsetHours = dateString.substr(20 + indexBump,2); |
|---|
| 339 | | offsetMinutes = dateString.substr(23 + indexBump,2); |
|---|
| 340 | | |
|---|
| 341 | | //this could be wrong if there is no operator |
|---|
| 342 | | operator = ((offsetOperator == "-") || (offsetOperator == undefined))? 1 : -1; |
|---|
| 343 | | |
|---|
| 344 | | //this could be wrong if offsethours or offsetminutes is undefined |
|---|
| 345 | | offset = operator * (Number(offsetHours) * 60) + Number(offsetMinutes); |
|---|
| 346 | | |
|---|
| 347 | | if(isNaN(offset)) |
|---|
| 348 | | { |
|---|
| 349 | | offset = 0; |
|---|
| 350 | | } |
|---|
| 351 | | |
|---|
| 352 | | var minutes:Number; |
|---|
| 353 | | if(mm != "") |
|---|
| 354 | | { |
|---|
| 355 | | minutes = Number(mm) + offset; |
|---|
| 356 | | } |
|---|
| 357 | | |
|---|
| 358 | | var month:Number; |
|---|
| 359 | | if(MM != "") |
|---|
| 360 | | { |
|---|
| 361 | | month = Number(MM) - 1; |
|---|
| 362 | | } |
|---|
| 363 | | |
|---|
| 364 | | var year:Number; |
|---|
| 365 | | if(YYYY != "") |
|---|
| 366 | | { |
|---|
| 367 | | year = Number(YYYY); |
|---|
| 368 | | } |
|---|
| 369 | | |
|---|
| 370 | | var day:Number; |
|---|
| 371 | | if(DD != "") |
|---|
| 372 | | { |
|---|
| 373 | | day = Number(DD); |
|---|
| 374 | | } |
|---|
| 375 | | |
|---|
| 376 | | var hours:Number; |
|---|
| 377 | | if(hh != "") |
|---|
| 378 | | { |
|---|
| 379 | | hours = Number(hh); |
|---|
| 380 | | } |
|---|
| 381 | | |
|---|
| 382 | | var seconds:Number; |
|---|
| 383 | | if(ss != "") |
|---|
| 384 | | { |
|---|
| 385 | | seconds = Number(ss); |
|---|
| 386 | | } |
|---|
| 387 | | |
|---|
| 388 | | var utcTimeMS = Date.UTC( |
|---|
| 389 | | year, |
|---|
| 390 | | month, |
|---|
| 391 | | day, |
|---|
| 392 | | hours, |
|---|
| 393 | | minutes, |
|---|
| 394 | | seconds); |
|---|
| 395 | | |
|---|
| 396 | | return new Date(utcTimeMS);; |
|---|
| | 300 | if(dateString == undefined || dateString.length < 1) |
|---|
| | 301 | { |
|---|
| | 302 | return undefined; |
|---|
| | 303 | } |
|---|
| | 304 | |
|---|
| | 305 | var YYYY:String = dateString.substr(0, 4); |
|---|
| | 306 | var MM:String = dateString.substr(5, 2); |
|---|
| | 307 | var DD:String = dateString.substr(8, 2); |
|---|
| | 308 | var hh:String = dateString.substr(11, 2); |
|---|
| | 309 | var mm:String = dateString.substr(14, 2); |
|---|
| | 310 | var ss:String = dateString.substr(17, 2); |
|---|
| | 311 | var s:String = ""; |
|---|
| | 312 | |
|---|
| | 313 | var offsetOperator:String; |
|---|
| | 314 | var offsetHours:String; |
|---|
| | 315 | var offsetMinutes:String; |
|---|
| | 316 | |
|---|
| | 317 | var offset:Number = 0; |
|---|
| | 318 | var operator:Number; |
|---|
| | 319 | var indexBump:Number = 0; |
|---|
| | 320 | |
|---|
| | 321 | if(dateString.substr(19, 1) == ".") |
|---|
| | 322 | { |
|---|
| | 323 | //they have a decimal second |
|---|
| | 324 | s = dateString.substr(20, 2); |
|---|
| | 325 | |
|---|
| | 326 | indexBump = 3; |
|---|
| | 327 | } |
|---|
| | 328 | else if (ss == "") { //can have tz offset with no seconds |
|---|
| | 329 | indexBump = -2; |
|---|
| | 330 | } |
|---|
| | 331 | else |
|---|
| | 332 | { |
|---|
| | 333 | indexBump = 0; |
|---|
| | 334 | //they dont have a decimal second |
|---|
| | 335 | } |
|---|
| | 336 | |
|---|
| | 337 | offsetOperator = dateString.substr(19 + indexBump,1); |
|---|
| | 338 | offsetHours = dateString.substr(20 + indexBump,2); |
|---|
| | 339 | offsetMinutes = dateString.substr(23 + indexBump,2); |
|---|
| | 340 | |
|---|
| | 341 | //this could be wrong if there is no operator |
|---|
| | 342 | operator = ((offsetOperator == "-") || (offsetOperator == undefined))? 1 : -1; |
|---|
| | 343 | |
|---|
| | 344 | //this could be wrong if offsethours or offsetminutes is undefined |
|---|
| | 345 | offset = operator * (Number(offsetHours) * 60) + Number(offsetMinutes); |
|---|
| | 346 | |
|---|
| | 347 | if(isNaN(offset)) |
|---|
| | 348 | { |
|---|
| | 349 | offset = 0; |
|---|
| | 350 | } |
|---|
| | 351 | |
|---|
| | 352 | var minutes:Number; |
|---|
| | 353 | if(mm != "") |
|---|
| | 354 | { |
|---|
| | 355 | minutes = Number(mm) + offset; |
|---|
| | 356 | } |
|---|
| | 357 | |
|---|
| | 358 | var month:Number; |
|---|
| | 359 | if(MM != "") |
|---|
| | 360 | { |
|---|
| | 361 | month = Number(MM) - 1; |
|---|
| | 362 | } |
|---|
| | 363 | |
|---|
| | 364 | var year:Number; |
|---|
| | 365 | if(YYYY != "") |
|---|
| | 366 | { |
|---|
| | 367 | year = Number(YYYY); |
|---|
| | 368 | } |
|---|
| | 369 | |
|---|
| | 370 | var day:Number; |
|---|
| | 371 | if(DD != "") |
|---|
| | 372 | { |
|---|
| | 373 | day = Number(DD); |
|---|
| | 374 | } |
|---|
| | 375 | |
|---|
| | 376 | var hours:Number; |
|---|
| | 377 | if(hh != "") |
|---|
| | 378 | { |
|---|
| | 379 | hours = Number(hh); |
|---|
| | 380 | } |
|---|
| | 381 | |
|---|
| | 382 | var seconds:Number; |
|---|
| | 383 | if(ss != "") |
|---|
| | 384 | { |
|---|
| | 385 | seconds = Number(ss); |
|---|
| | 386 | } |
|---|
| | 387 | |
|---|
| | 388 | var utcTimeMS = Date.UTC( |
|---|
| | 389 | year, |
|---|
| | 390 | month, |
|---|
| | 391 | day, |
|---|
| | 392 | hours, |
|---|
| | 393 | minutes, |
|---|
| | 394 | seconds); |
|---|
| | 395 | |
|---|
| | 396 | return new Date(utcTimeMS);; |
|---|