├── README.md ├── es6-promise.js ├── forecast.io.js ├── index.html ├── manifest ├── moment.js ├── proxy.php ├── require.js └── ti.forecast.io.js /README.md: -------------------------------------------------------------------------------- 1 | Pull Requests welcome, if you have used this script in a project let me know, I'd like to start a directory. Have fun. 2 | 3 | forecast.io-javascript-api 4 | ========================== 5 | 6 | forecast.io JavaScript API 7 | 8 | ## Getting Started 9 | PHP is required for proxy to work. This is a cross domain policy workaround. 10 | 11 | Forecast.io.js is configured to work with both [AMD](https://en.wikipedia.org/wiki/Asynchronous_module_definition) and [CJS](https://en.wikipedia.org/wiki/CommonJS) applications. When the module is loaded it will return a constructor that, once run, will provide the necessary interface functions, namely: 12 | 13 | * `getCurrentConditions` 14 | * `getForecastToday` 15 | * `getForecastWeek` 16 | 17 | Use of the above is demonstrated within index.html. 18 | 19 | If you're using [Require.JS](http://requirejs.org/) use the example configuration in index.html as a reference. 20 | 21 | If you're using [Webpack](http://webpack.github.io/), [Browserify](http://browserify.org/) or some other CJS module loader simply require the module like so 22 | 23 | `var ForecastIO = require('forecast.io');` 24 | 25 | and use the `ForecastIO` constructor as per the demo on the index page. 26 | 27 | ## Location data 28 | 29 | Forecast.io.js can handle multiple location requests. Any request _must_ be supplied as an array of objects as per the example in index.html. 30 | 31 | ## Dependencies 32 | 33 | Forecast.io.js uses [moment.js](http://momentjs.com/) to handle date/time data and an [ES6 Promises Polyfill](https://github.com/jakearchibald/es6-promise) to handle the requests via promises. 34 | 35 | If you're using Require.JS be sure to load include these two libraries somewhere in your application. 36 | 37 | If you're using a CJS module loader be sure to install these two libraries using npm: 38 | 39 | `npm install moment` 40 | 41 | Ref: [https://www.npmjs.com/package/moment](https://www.npmjs.com/package/moment) 42 | 43 | `npm install es6-promise` 44 | 45 | Ref: [https://www.npmjs.com/package/es6-promise](https://www.npmjs.com/package/es6-promise) 46 | 47 | 48 | ti.forecast.io-javascript-api 49 | ============================= 50 | 51 | ti.forecast.io Javascript API 52 | 53 | The Titanium version works a little differently. Callbacks help with data manipulation over the standard javascript API, 54 | there is also no need for a proxy. 55 | 56 | require("ti.forecast.io"); 57 | var forecast = new ForecastIO({ 58 | API_KEY: 'API_KEY' 59 | }); 60 | 61 | var condition = forecast.getCurrentConditions(lat, lon, onSuccessCallback, onErrorCallback); 62 | 63 | function onSuccessCallback(weather) { 64 | weather.getSummary(); 65 | }; 66 | 67 | function onErrorCallback(e) { 68 | // Handle your errors in here 69 | }; 70 | 71 | There are also more returns which will be added into the plain Javascript in due course. 72 | 73 | The MIT License (MIT) 74 | 75 | Copyright (c) 2013 Ian Tearle @iantearle 76 | 77 | Permission is hereby granted, free of charge, to any person obtaining a copy 78 | of this software and associated documentation files (the "Software"), to deal 79 | in the Software without restriction, including without limitation the rights 80 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 81 | copies of the Software, and to permit persons to whom the Software is 82 | furnished to do so, subject to the following conditions: 83 | 84 | The above copyright notice and this permission notice shall be included in 85 | all copies or substantial portions of the Software. 86 | 87 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 88 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 89 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 90 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 91 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 92 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 93 | THE SOFTWARE. 94 | -------------------------------------------------------------------------------- /es6-promise.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * @overview es6-promise - a tiny implementation of Promises/A+. 3 | * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald) 4 | * @license Licensed under MIT license 5 | * See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE 6 | * @version 3.0.2 7 | */ 8 | 9 | (function() { 10 | "use strict"; 11 | function lib$es6$promise$utils$$objectOrFunction(x) { 12 | return typeof x === 'function' || (typeof x === 'object' && x !== null); 13 | } 14 | 15 | function lib$es6$promise$utils$$isFunction(x) { 16 | return typeof x === 'function'; 17 | } 18 | 19 | function lib$es6$promise$utils$$isMaybeThenable(x) { 20 | return typeof x === 'object' && x !== null; 21 | } 22 | 23 | var lib$es6$promise$utils$$_isArray; 24 | if (!Array.isArray) { 25 | lib$es6$promise$utils$$_isArray = function (x) { 26 | return Object.prototype.toString.call(x) === '[object Array]'; 27 | }; 28 | } else { 29 | lib$es6$promise$utils$$_isArray = Array.isArray; 30 | } 31 | 32 | var lib$es6$promise$utils$$isArray = lib$es6$promise$utils$$_isArray; 33 | var lib$es6$promise$asap$$len = 0; 34 | var lib$es6$promise$asap$$toString = {}.toString; 35 | var lib$es6$promise$asap$$vertxNext; 36 | var lib$es6$promise$asap$$customSchedulerFn; 37 | 38 | var lib$es6$promise$asap$$asap = function asap(callback, arg) { 39 | lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len] = callback; 40 | lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len + 1] = arg; 41 | lib$es6$promise$asap$$len += 2; 42 | if (lib$es6$promise$asap$$len === 2) { 43 | // If len is 2, that means that we need to schedule an async flush. 44 | // If additional callbacks are queued before the queue is flushed, they 45 | // will be processed by this flush that we are scheduling. 46 | if (lib$es6$promise$asap$$customSchedulerFn) { 47 | lib$es6$promise$asap$$customSchedulerFn(lib$es6$promise$asap$$flush); 48 | } else { 49 | lib$es6$promise$asap$$scheduleFlush(); 50 | } 51 | } 52 | } 53 | 54 | function lib$es6$promise$asap$$setScheduler(scheduleFn) { 55 | lib$es6$promise$asap$$customSchedulerFn = scheduleFn; 56 | } 57 | 58 | function lib$es6$promise$asap$$setAsap(asapFn) { 59 | lib$es6$promise$asap$$asap = asapFn; 60 | } 61 | 62 | var lib$es6$promise$asap$$browserWindow = (typeof window !== 'undefined') ? window : undefined; 63 | var lib$es6$promise$asap$$browserGlobal = lib$es6$promise$asap$$browserWindow || {}; 64 | var lib$es6$promise$asap$$BrowserMutationObserver = lib$es6$promise$asap$$browserGlobal.MutationObserver || lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver; 65 | var lib$es6$promise$asap$$isNode = typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; 66 | 67 | // test for web worker but not in IE10 68 | var lib$es6$promise$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' && 69 | typeof importScripts !== 'undefined' && 70 | typeof MessageChannel !== 'undefined'; 71 | 72 | // node 73 | function lib$es6$promise$asap$$useNextTick() { 74 | // node version 0.10.x displays a deprecation warning when nextTick is used recursively 75 | // see https://github.com/cujojs/when/issues/410 for details 76 | return function() { 77 | process.nextTick(lib$es6$promise$asap$$flush); 78 | }; 79 | } 80 | 81 | // vertx 82 | function lib$es6$promise$asap$$useVertxTimer() { 83 | return function() { 84 | lib$es6$promise$asap$$vertxNext(lib$es6$promise$asap$$flush); 85 | }; 86 | } 87 | 88 | function lib$es6$promise$asap$$useMutationObserver() { 89 | var iterations = 0; 90 | var observer = new lib$es6$promise$asap$$BrowserMutationObserver(lib$es6$promise$asap$$flush); 91 | var node = document.createTextNode(''); 92 | observer.observe(node, { characterData: true }); 93 | 94 | return function() { 95 | node.data = (iterations = ++iterations % 2); 96 | }; 97 | } 98 | 99 | // web worker 100 | function lib$es6$promise$asap$$useMessageChannel() { 101 | var channel = new MessageChannel(); 102 | channel.port1.onmessage = lib$es6$promise$asap$$flush; 103 | return function () { 104 | channel.port2.postMessage(0); 105 | }; 106 | } 107 | 108 | function lib$es6$promise$asap$$useSetTimeout() { 109 | return function() { 110 | setTimeout(lib$es6$promise$asap$$flush, 1); 111 | }; 112 | } 113 | 114 | var lib$es6$promise$asap$$queue = new Array(1000); 115 | function lib$es6$promise$asap$$flush() { 116 | for (var i = 0; i < lib$es6$promise$asap$$len; i+=2) { 117 | var callback = lib$es6$promise$asap$$queue[i]; 118 | var arg = lib$es6$promise$asap$$queue[i+1]; 119 | 120 | callback(arg); 121 | 122 | lib$es6$promise$asap$$queue[i] = undefined; 123 | lib$es6$promise$asap$$queue[i+1] = undefined; 124 | } 125 | 126 | lib$es6$promise$asap$$len = 0; 127 | } 128 | 129 | function lib$es6$promise$asap$$attemptVertx() { 130 | try { 131 | var r = require; 132 | var vertx = r('vertx'); 133 | lib$es6$promise$asap$$vertxNext = vertx.runOnLoop || vertx.runOnContext; 134 | return lib$es6$promise$asap$$useVertxTimer(); 135 | } catch(e) { 136 | return lib$es6$promise$asap$$useSetTimeout(); 137 | } 138 | } 139 | 140 | var lib$es6$promise$asap$$scheduleFlush; 141 | // Decide what async method to use to triggering processing of queued callbacks: 142 | if (lib$es6$promise$asap$$isNode) { 143 | lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useNextTick(); 144 | } else if (lib$es6$promise$asap$$BrowserMutationObserver) { 145 | lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMutationObserver(); 146 | } else if (lib$es6$promise$asap$$isWorker) { 147 | lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMessageChannel(); 148 | } else if (lib$es6$promise$asap$$browserWindow === undefined && typeof require === 'function') { 149 | lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$attemptVertx(); 150 | } else { 151 | lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useSetTimeout(); 152 | } 153 | 154 | function lib$es6$promise$$internal$$noop() {} 155 | 156 | var lib$es6$promise$$internal$$PENDING = void 0; 157 | var lib$es6$promise$$internal$$FULFILLED = 1; 158 | var lib$es6$promise$$internal$$REJECTED = 2; 159 | 160 | var lib$es6$promise$$internal$$GET_THEN_ERROR = new lib$es6$promise$$internal$$ErrorObject(); 161 | 162 | function lib$es6$promise$$internal$$selfFulfillment() { 163 | return new TypeError("You cannot resolve a promise with itself"); 164 | } 165 | 166 | function lib$es6$promise$$internal$$cannotReturnOwn() { 167 | return new TypeError('A promises callback cannot return that same promise.'); 168 | } 169 | 170 | function lib$es6$promise$$internal$$getThen(promise) { 171 | try { 172 | return promise.then; 173 | } catch(error) { 174 | lib$es6$promise$$internal$$GET_THEN_ERROR.error = error; 175 | return lib$es6$promise$$internal$$GET_THEN_ERROR; 176 | } 177 | } 178 | 179 | function lib$es6$promise$$internal$$tryThen(then, value, fulfillmentHandler, rejectionHandler) { 180 | try { 181 | then.call(value, fulfillmentHandler, rejectionHandler); 182 | } catch(e) { 183 | return e; 184 | } 185 | } 186 | 187 | function lib$es6$promise$$internal$$handleForeignThenable(promise, thenable, then) { 188 | lib$es6$promise$asap$$asap(function(promise) { 189 | var sealed = false; 190 | var error = lib$es6$promise$$internal$$tryThen(then, thenable, function(value) { 191 | if (sealed) { return; } 192 | sealed = true; 193 | if (thenable !== value) { 194 | lib$es6$promise$$internal$$resolve(promise, value); 195 | } else { 196 | lib$es6$promise$$internal$$fulfill(promise, value); 197 | } 198 | }, function(reason) { 199 | if (sealed) { return; } 200 | sealed = true; 201 | 202 | lib$es6$promise$$internal$$reject(promise, reason); 203 | }, 'Settle: ' + (promise._label || ' unknown promise')); 204 | 205 | if (!sealed && error) { 206 | sealed = true; 207 | lib$es6$promise$$internal$$reject(promise, error); 208 | } 209 | }, promise); 210 | } 211 | 212 | function lib$es6$promise$$internal$$handleOwnThenable(promise, thenable) { 213 | if (thenable._state === lib$es6$promise$$internal$$FULFILLED) { 214 | lib$es6$promise$$internal$$fulfill(promise, thenable._result); 215 | } else if (thenable._state === lib$es6$promise$$internal$$REJECTED) { 216 | lib$es6$promise$$internal$$reject(promise, thenable._result); 217 | } else { 218 | lib$es6$promise$$internal$$subscribe(thenable, undefined, function(value) { 219 | lib$es6$promise$$internal$$resolve(promise, value); 220 | }, function(reason) { 221 | lib$es6$promise$$internal$$reject(promise, reason); 222 | }); 223 | } 224 | } 225 | 226 | function lib$es6$promise$$internal$$handleMaybeThenable(promise, maybeThenable) { 227 | if (maybeThenable.constructor === promise.constructor) { 228 | lib$es6$promise$$internal$$handleOwnThenable(promise, maybeThenable); 229 | } else { 230 | var then = lib$es6$promise$$internal$$getThen(maybeThenable); 231 | 232 | if (then === lib$es6$promise$$internal$$GET_THEN_ERROR) { 233 | lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$GET_THEN_ERROR.error); 234 | } else if (then === undefined) { 235 | lib$es6$promise$$internal$$fulfill(promise, maybeThenable); 236 | } else if (lib$es6$promise$utils$$isFunction(then)) { 237 | lib$es6$promise$$internal$$handleForeignThenable(promise, maybeThenable, then); 238 | } else { 239 | lib$es6$promise$$internal$$fulfill(promise, maybeThenable); 240 | } 241 | } 242 | } 243 | 244 | function lib$es6$promise$$internal$$resolve(promise, value) { 245 | if (promise === value) { 246 | lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$selfFulfillment()); 247 | } else if (lib$es6$promise$utils$$objectOrFunction(value)) { 248 | lib$es6$promise$$internal$$handleMaybeThenable(promise, value); 249 | } else { 250 | lib$es6$promise$$internal$$fulfill(promise, value); 251 | } 252 | } 253 | 254 | function lib$es6$promise$$internal$$publishRejection(promise) { 255 | if (promise._onerror) { 256 | promise._onerror(promise._result); 257 | } 258 | 259 | lib$es6$promise$$internal$$publish(promise); 260 | } 261 | 262 | function lib$es6$promise$$internal$$fulfill(promise, value) { 263 | if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; } 264 | 265 | promise._result = value; 266 | promise._state = lib$es6$promise$$internal$$FULFILLED; 267 | 268 | if (promise._subscribers.length !== 0) { 269 | lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, promise); 270 | } 271 | } 272 | 273 | function lib$es6$promise$$internal$$reject(promise, reason) { 274 | if (promise._state !== lib$es6$promise$$internal$$PENDING) { return; } 275 | promise._state = lib$es6$promise$$internal$$REJECTED; 276 | promise._result = reason; 277 | 278 | lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publishRejection, promise); 279 | } 280 | 281 | function lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection) { 282 | var subscribers = parent._subscribers; 283 | var length = subscribers.length; 284 | 285 | parent._onerror = null; 286 | 287 | subscribers[length] = child; 288 | subscribers[length + lib$es6$promise$$internal$$FULFILLED] = onFulfillment; 289 | subscribers[length + lib$es6$promise$$internal$$REJECTED] = onRejection; 290 | 291 | if (length === 0 && parent._state) { 292 | lib$es6$promise$asap$$asap(lib$es6$promise$$internal$$publish, parent); 293 | } 294 | } 295 | 296 | function lib$es6$promise$$internal$$publish(promise) { 297 | var subscribers = promise._subscribers; 298 | var settled = promise._state; 299 | 300 | if (subscribers.length === 0) { return; } 301 | 302 | var child, callback, detail = promise._result; 303 | 304 | for (var i = 0; i < subscribers.length; i += 3) { 305 | child = subscribers[i]; 306 | callback = subscribers[i + settled]; 307 | 308 | if (child) { 309 | lib$es6$promise$$internal$$invokeCallback(settled, child, callback, detail); 310 | } else { 311 | callback(detail); 312 | } 313 | } 314 | 315 | promise._subscribers.length = 0; 316 | } 317 | 318 | function lib$es6$promise$$internal$$ErrorObject() { 319 | this.error = null; 320 | } 321 | 322 | var lib$es6$promise$$internal$$TRY_CATCH_ERROR = new lib$es6$promise$$internal$$ErrorObject(); 323 | 324 | function lib$es6$promise$$internal$$tryCatch(callback, detail) { 325 | try { 326 | return callback(detail); 327 | } catch(e) { 328 | lib$es6$promise$$internal$$TRY_CATCH_ERROR.error = e; 329 | return lib$es6$promise$$internal$$TRY_CATCH_ERROR; 330 | } 331 | } 332 | 333 | function lib$es6$promise$$internal$$invokeCallback(settled, promise, callback, detail) { 334 | var hasCallback = lib$es6$promise$utils$$isFunction(callback), 335 | value, error, succeeded, failed; 336 | 337 | if (hasCallback) { 338 | value = lib$es6$promise$$internal$$tryCatch(callback, detail); 339 | 340 | if (value === lib$es6$promise$$internal$$TRY_CATCH_ERROR) { 341 | failed = true; 342 | error = value.error; 343 | value = null; 344 | } else { 345 | succeeded = true; 346 | } 347 | 348 | if (promise === value) { 349 | lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$cannotReturnOwn()); 350 | return; 351 | } 352 | 353 | } else { 354 | value = detail; 355 | succeeded = true; 356 | } 357 | 358 | if (promise._state !== lib$es6$promise$$internal$$PENDING) { 359 | // noop 360 | } else if (hasCallback && succeeded) { 361 | lib$es6$promise$$internal$$resolve(promise, value); 362 | } else if (failed) { 363 | lib$es6$promise$$internal$$reject(promise, error); 364 | } else if (settled === lib$es6$promise$$internal$$FULFILLED) { 365 | lib$es6$promise$$internal$$fulfill(promise, value); 366 | } else if (settled === lib$es6$promise$$internal$$REJECTED) { 367 | lib$es6$promise$$internal$$reject(promise, value); 368 | } 369 | } 370 | 371 | function lib$es6$promise$$internal$$initializePromise(promise, resolver) { 372 | try { 373 | resolver(function resolvePromise(value){ 374 | lib$es6$promise$$internal$$resolve(promise, value); 375 | }, function rejectPromise(reason) { 376 | lib$es6$promise$$internal$$reject(promise, reason); 377 | }); 378 | } catch(e) { 379 | lib$es6$promise$$internal$$reject(promise, e); 380 | } 381 | } 382 | 383 | function lib$es6$promise$enumerator$$Enumerator(Constructor, input) { 384 | var enumerator = this; 385 | 386 | enumerator._instanceConstructor = Constructor; 387 | enumerator.promise = new Constructor(lib$es6$promise$$internal$$noop); 388 | 389 | if (enumerator._validateInput(input)) { 390 | enumerator._input = input; 391 | enumerator.length = input.length; 392 | enumerator._remaining = input.length; 393 | 394 | enumerator._init(); 395 | 396 | if (enumerator.length === 0) { 397 | lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result); 398 | } else { 399 | enumerator.length = enumerator.length || 0; 400 | enumerator._enumerate(); 401 | if (enumerator._remaining === 0) { 402 | lib$es6$promise$$internal$$fulfill(enumerator.promise, enumerator._result); 403 | } 404 | } 405 | } else { 406 | lib$es6$promise$$internal$$reject(enumerator.promise, enumerator._validationError()); 407 | } 408 | } 409 | 410 | lib$es6$promise$enumerator$$Enumerator.prototype._validateInput = function(input) { 411 | return lib$es6$promise$utils$$isArray(input); 412 | }; 413 | 414 | lib$es6$promise$enumerator$$Enumerator.prototype._validationError = function() { 415 | return new Error('Array Methods must be provided an Array'); 416 | }; 417 | 418 | lib$es6$promise$enumerator$$Enumerator.prototype._init = function() { 419 | this._result = new Array(this.length); 420 | }; 421 | 422 | var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator; 423 | 424 | lib$es6$promise$enumerator$$Enumerator.prototype._enumerate = function() { 425 | var enumerator = this; 426 | 427 | var length = enumerator.length; 428 | var promise = enumerator.promise; 429 | var input = enumerator._input; 430 | 431 | for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) { 432 | enumerator._eachEntry(input[i], i); 433 | } 434 | }; 435 | 436 | lib$es6$promise$enumerator$$Enumerator.prototype._eachEntry = function(entry, i) { 437 | var enumerator = this; 438 | var c = enumerator._instanceConstructor; 439 | 440 | if (lib$es6$promise$utils$$isMaybeThenable(entry)) { 441 | if (entry.constructor === c && entry._state !== lib$es6$promise$$internal$$PENDING) { 442 | entry._onerror = null; 443 | enumerator._settledAt(entry._state, i, entry._result); 444 | } else { 445 | enumerator._willSettleAt(c.resolve(entry), i); 446 | } 447 | } else { 448 | enumerator._remaining--; 449 | enumerator._result[i] = entry; 450 | } 451 | }; 452 | 453 | lib$es6$promise$enumerator$$Enumerator.prototype._settledAt = function(state, i, value) { 454 | var enumerator = this; 455 | var promise = enumerator.promise; 456 | 457 | if (promise._state === lib$es6$promise$$internal$$PENDING) { 458 | enumerator._remaining--; 459 | 460 | if (state === lib$es6$promise$$internal$$REJECTED) { 461 | lib$es6$promise$$internal$$reject(promise, value); 462 | } else { 463 | enumerator._result[i] = value; 464 | } 465 | } 466 | 467 | if (enumerator._remaining === 0) { 468 | lib$es6$promise$$internal$$fulfill(promise, enumerator._result); 469 | } 470 | }; 471 | 472 | lib$es6$promise$enumerator$$Enumerator.prototype._willSettleAt = function(promise, i) { 473 | var enumerator = this; 474 | 475 | lib$es6$promise$$internal$$subscribe(promise, undefined, function(value) { 476 | enumerator._settledAt(lib$es6$promise$$internal$$FULFILLED, i, value); 477 | }, function(reason) { 478 | enumerator._settledAt(lib$es6$promise$$internal$$REJECTED, i, reason); 479 | }); 480 | }; 481 | function lib$es6$promise$promise$all$$all(entries) { 482 | return new lib$es6$promise$enumerator$$default(this, entries).promise; 483 | } 484 | var lib$es6$promise$promise$all$$default = lib$es6$promise$promise$all$$all; 485 | function lib$es6$promise$promise$race$$race(entries) { 486 | /*jshint validthis:true */ 487 | var Constructor = this; 488 | 489 | var promise = new Constructor(lib$es6$promise$$internal$$noop); 490 | 491 | if (!lib$es6$promise$utils$$isArray(entries)) { 492 | lib$es6$promise$$internal$$reject(promise, new TypeError('You must pass an array to race.')); 493 | return promise; 494 | } 495 | 496 | var length = entries.length; 497 | 498 | function onFulfillment(value) { 499 | lib$es6$promise$$internal$$resolve(promise, value); 500 | } 501 | 502 | function onRejection(reason) { 503 | lib$es6$promise$$internal$$reject(promise, reason); 504 | } 505 | 506 | for (var i = 0; promise._state === lib$es6$promise$$internal$$PENDING && i < length; i++) { 507 | lib$es6$promise$$internal$$subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection); 508 | } 509 | 510 | return promise; 511 | } 512 | var lib$es6$promise$promise$race$$default = lib$es6$promise$promise$race$$race; 513 | function lib$es6$promise$promise$resolve$$resolve(object) { 514 | /*jshint validthis:true */ 515 | var Constructor = this; 516 | 517 | if (object && typeof object === 'object' && object.constructor === Constructor) { 518 | return object; 519 | } 520 | 521 | var promise = new Constructor(lib$es6$promise$$internal$$noop); 522 | lib$es6$promise$$internal$$resolve(promise, object); 523 | return promise; 524 | } 525 | var lib$es6$promise$promise$resolve$$default = lib$es6$promise$promise$resolve$$resolve; 526 | function lib$es6$promise$promise$reject$$reject(reason) { 527 | /*jshint validthis:true */ 528 | var Constructor = this; 529 | var promise = new Constructor(lib$es6$promise$$internal$$noop); 530 | lib$es6$promise$$internal$$reject(promise, reason); 531 | return promise; 532 | } 533 | var lib$es6$promise$promise$reject$$default = lib$es6$promise$promise$reject$$reject; 534 | 535 | var lib$es6$promise$promise$$counter = 0; 536 | 537 | function lib$es6$promise$promise$$needsResolver() { 538 | throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); 539 | } 540 | 541 | function lib$es6$promise$promise$$needsNew() { 542 | throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function."); 543 | } 544 | 545 | var lib$es6$promise$promise$$default = lib$es6$promise$promise$$Promise; 546 | /** 547 | Promise objects represent the eventual result of an asynchronous operation. The 548 | primary way of interacting with a promise is through its `then` method, which 549 | registers callbacks to receive either a promise's eventual value or the reason 550 | why the promise cannot be fulfilled. 551 | 552 | Terminology 553 | ----------- 554 | 555 | - `promise` is an object or function with a `then` method whose behavior conforms to this specification. 556 | - `thenable` is an object or function that defines a `then` method. 557 | - `value` is any legal JavaScript value (including undefined, a thenable, or a promise). 558 | - `exception` is a value that is thrown using the throw statement. 559 | - `reason` is a value that indicates why a promise was rejected. 560 | - `settled` the final resting state of a promise, fulfilled or rejected. 561 | 562 | A promise can be in one of three states: pending, fulfilled, or rejected. 563 | 564 | Promises that are fulfilled have a fulfillment value and are in the fulfilled 565 | state. Promises that are rejected have a rejection reason and are in the 566 | rejected state. A fulfillment value is never a thenable. 567 | 568 | Promises can also be said to *resolve* a value. If this value is also a 569 | promise, then the original promise's settled state will match the value's 570 | settled state. So a promise that *resolves* a promise that rejects will 571 | itself reject, and a promise that *resolves* a promise that fulfills will 572 | itself fulfill. 573 | 574 | 575 | Basic Usage: 576 | ------------ 577 | 578 | ```js 579 | var promise = new Promise(function(resolve, reject) { 580 | // on success 581 | resolve(value); 582 | 583 | // on failure 584 | reject(reason); 585 | }); 586 | 587 | promise.then(function(value) { 588 | // on fulfillment 589 | }, function(reason) { 590 | // on rejection 591 | }); 592 | ``` 593 | 594 | Advanced Usage: 595 | --------------- 596 | 597 | Promises shine when abstracting away asynchronous interactions such as 598 | `XMLHttpRequest`s. 599 | 600 | ```js 601 | function getJSON(url) { 602 | return new Promise(function(resolve, reject){ 603 | var xhr = new XMLHttpRequest(); 604 | 605 | xhr.open('GET', url); 606 | xhr.onreadystatechange = handler; 607 | xhr.responseType = 'json'; 608 | xhr.setRequestHeader('Accept', 'application/json'); 609 | xhr.send(); 610 | 611 | function handler() { 612 | if (this.readyState === this.DONE) { 613 | if (this.status === 200) { 614 | resolve(this.response); 615 | } else { 616 | reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']')); 617 | } 618 | } 619 | }; 620 | }); 621 | } 622 | 623 | getJSON('/posts.json').then(function(json) { 624 | // on fulfillment 625 | }, function(reason) { 626 | // on rejection 627 | }); 628 | ``` 629 | 630 | Unlike callbacks, promises are great composable primitives. 631 | 632 | ```js 633 | Promise.all([ 634 | getJSON('/posts'), 635 | getJSON('/comments') 636 | ]).then(function(values){ 637 | values[0] // => postsJSON 638 | values[1] // => commentsJSON 639 | 640 | return values; 641 | }); 642 | ``` 643 | 644 | @class Promise 645 | @param {function} resolver 646 | Useful for tooling. 647 | @constructor 648 | */ 649 | function lib$es6$promise$promise$$Promise(resolver) { 650 | this._id = lib$es6$promise$promise$$counter++; 651 | this._state = undefined; 652 | this._result = undefined; 653 | this._subscribers = []; 654 | 655 | if (lib$es6$promise$$internal$$noop !== resolver) { 656 | if (!lib$es6$promise$utils$$isFunction(resolver)) { 657 | lib$es6$promise$promise$$needsResolver(); 658 | } 659 | 660 | if (!(this instanceof lib$es6$promise$promise$$Promise)) { 661 | lib$es6$promise$promise$$needsNew(); 662 | } 663 | 664 | lib$es6$promise$$internal$$initializePromise(this, resolver); 665 | } 666 | } 667 | 668 | lib$es6$promise$promise$$Promise.all = lib$es6$promise$promise$all$$default; 669 | lib$es6$promise$promise$$Promise.race = lib$es6$promise$promise$race$$default; 670 | lib$es6$promise$promise$$Promise.resolve = lib$es6$promise$promise$resolve$$default; 671 | lib$es6$promise$promise$$Promise.reject = lib$es6$promise$promise$reject$$default; 672 | lib$es6$promise$promise$$Promise._setScheduler = lib$es6$promise$asap$$setScheduler; 673 | lib$es6$promise$promise$$Promise._setAsap = lib$es6$promise$asap$$setAsap; 674 | lib$es6$promise$promise$$Promise._asap = lib$es6$promise$asap$$asap; 675 | 676 | lib$es6$promise$promise$$Promise.prototype = { 677 | constructor: lib$es6$promise$promise$$Promise, 678 | 679 | /** 680 | The primary way of interacting with a promise is through its `then` method, 681 | which registers callbacks to receive either a promise's eventual value or the 682 | reason why the promise cannot be fulfilled. 683 | 684 | ```js 685 | findUser().then(function(user){ 686 | // user is available 687 | }, function(reason){ 688 | // user is unavailable, and you are given the reason why 689 | }); 690 | ``` 691 | 692 | Chaining 693 | -------- 694 | 695 | The return value of `then` is itself a promise. This second, 'downstream' 696 | promise is resolved with the return value of the first promise's fulfillment 697 | or rejection handler, or rejected if the handler throws an exception. 698 | 699 | ```js 700 | findUser().then(function (user) { 701 | return user.name; 702 | }, function (reason) { 703 | return 'default name'; 704 | }).then(function (userName) { 705 | // If `findUser` fulfilled, `userName` will be the user's name, otherwise it 706 | // will be `'default name'` 707 | }); 708 | 709 | findUser().then(function (user) { 710 | throw new Error('Found user, but still unhappy'); 711 | }, function (reason) { 712 | throw new Error('`findUser` rejected and we're unhappy'); 713 | }).then(function (value) { 714 | // never reached 715 | }, function (reason) { 716 | // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. 717 | // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. 718 | }); 719 | ``` 720 | If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. 721 | 722 | ```js 723 | findUser().then(function (user) { 724 | throw new PedagogicalException('Upstream error'); 725 | }).then(function (value) { 726 | // never reached 727 | }).then(function (value) { 728 | // never reached 729 | }, function (reason) { 730 | // The `PedgagocialException` is propagated all the way down to here 731 | }); 732 | ``` 733 | 734 | Assimilation 735 | ------------ 736 | 737 | Sometimes the value you want to propagate to a downstream promise can only be 738 | retrieved asynchronously. This can be achieved by returning a promise in the 739 | fulfillment or rejection handler. The downstream promise will then be pending 740 | until the returned promise is settled. This is called *assimilation*. 741 | 742 | ```js 743 | findUser().then(function (user) { 744 | return findCommentsByAuthor(user); 745 | }).then(function (comments) { 746 | // The user's comments are now available 747 | }); 748 | ``` 749 | 750 | If the assimliated promise rejects, then the downstream promise will also reject. 751 | 752 | ```js 753 | findUser().then(function (user) { 754 | return findCommentsByAuthor(user); 755 | }).then(function (comments) { 756 | // If `findCommentsByAuthor` fulfills, we'll have the value here 757 | }, function (reason) { 758 | // If `findCommentsByAuthor` rejects, we'll have the reason here 759 | }); 760 | ``` 761 | 762 | Simple Example 763 | -------------- 764 | 765 | Synchronous Example 766 | 767 | ```javascript 768 | var result; 769 | 770 | try { 771 | result = findResult(); 772 | // success 773 | } catch(reason) { 774 | // failure 775 | } 776 | ``` 777 | 778 | Errback Example 779 | 780 | ```js 781 | findResult(function(result, err){ 782 | if (err) { 783 | // failure 784 | } else { 785 | // success 786 | } 787 | }); 788 | ``` 789 | 790 | Promise Example; 791 | 792 | ```javascript 793 | findResult().then(function(result){ 794 | // success 795 | }, function(reason){ 796 | // failure 797 | }); 798 | ``` 799 | 800 | Advanced Example 801 | -------------- 802 | 803 | Synchronous Example 804 | 805 | ```javascript 806 | var author, books; 807 | 808 | try { 809 | author = findAuthor(); 810 | books = findBooksByAuthor(author); 811 | // success 812 | } catch(reason) { 813 | // failure 814 | } 815 | ``` 816 | 817 | Errback Example 818 | 819 | ```js 820 | 821 | function foundBooks(books) { 822 | 823 | } 824 | 825 | function failure(reason) { 826 | 827 | } 828 | 829 | findAuthor(function(author, err){ 830 | if (err) { 831 | failure(err); 832 | // failure 833 | } else { 834 | try { 835 | findBoooksByAuthor(author, function(books, err) { 836 | if (err) { 837 | failure(err); 838 | } else { 839 | try { 840 | foundBooks(books); 841 | } catch(reason) { 842 | failure(reason); 843 | } 844 | } 845 | }); 846 | } catch(error) { 847 | failure(err); 848 | } 849 | // success 850 | } 851 | }); 852 | ``` 853 | 854 | Promise Example; 855 | 856 | ```javascript 857 | findAuthor(). 858 | then(findBooksByAuthor). 859 | then(function(books){ 860 | // found books 861 | }).catch(function(reason){ 862 | // something went wrong 863 | }); 864 | ``` 865 | 866 | @method then 867 | @param {Function} onFulfilled 868 | @param {Function} onRejected 869 | Useful for tooling. 870 | @return {Promise} 871 | */ 872 | then: function(onFulfillment, onRejection) { 873 | var parent = this; 874 | var state = parent._state; 875 | 876 | if (state === lib$es6$promise$$internal$$FULFILLED && !onFulfillment || state === lib$es6$promise$$internal$$REJECTED && !onRejection) { 877 | return this; 878 | } 879 | 880 | var child = new this.constructor(lib$es6$promise$$internal$$noop); 881 | var result = parent._result; 882 | 883 | if (state) { 884 | var callback = arguments[state - 1]; 885 | lib$es6$promise$asap$$asap(function(){ 886 | lib$es6$promise$$internal$$invokeCallback(state, child, callback, result); 887 | }); 888 | } else { 889 | lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection); 890 | } 891 | 892 | return child; 893 | }, 894 | 895 | /** 896 | `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same 897 | as the catch block of a try/catch statement. 898 | 899 | ```js 900 | function findAuthor(){ 901 | throw new Error('couldn't find that author'); 902 | } 903 | 904 | // synchronous 905 | try { 906 | findAuthor(); 907 | } catch(reason) { 908 | // something went wrong 909 | } 910 | 911 | // async with promises 912 | findAuthor().catch(function(reason){ 913 | // something went wrong 914 | }); 915 | ``` 916 | 917 | @method catch 918 | @param {Function} onRejection 919 | Useful for tooling. 920 | @return {Promise} 921 | */ 922 | 'catch': function(onRejection) { 923 | return this.then(null, onRejection); 924 | } 925 | }; 926 | function lib$es6$promise$polyfill$$polyfill() { 927 | var local; 928 | 929 | if (typeof global !== 'undefined') { 930 | local = global; 931 | } else if (typeof self !== 'undefined') { 932 | local = self; 933 | } else { 934 | try { 935 | local = Function('return this')(); 936 | } catch (e) { 937 | throw new Error('polyfill failed because global object is unavailable in this environment'); 938 | } 939 | } 940 | 941 | var P = local.Promise; 942 | 943 | if (P && Object.prototype.toString.call(P.resolve()) === '[object Promise]' && !P.cast) { 944 | return; 945 | } 946 | 947 | local.Promise = lib$es6$promise$promise$$default; 948 | } 949 | var lib$es6$promise$polyfill$$default = lib$es6$promise$polyfill$$polyfill; 950 | 951 | var lib$es6$promise$umd$$ES6Promise = { 952 | 'Promise': lib$es6$promise$promise$$default, 953 | 'polyfill': lib$es6$promise$polyfill$$default 954 | }; 955 | 956 | /* global define:true module:true window: true */ 957 | if (typeof define === 'function' && define['amd']) { 958 | define(function() { return lib$es6$promise$umd$$ES6Promise; }); 959 | } else if (typeof module !== 'undefined' && module['exports']) { 960 | module['exports'] = lib$es6$promise$umd$$ES6Promise; 961 | } else if (typeof this !== 'undefined') { 962 | this['ES6Promise'] = lib$es6$promise$umd$$ES6Promise; 963 | } 964 | 965 | lib$es6$promise$polyfill$$default(); 966 | }).call(this); 967 | 968 | -------------------------------------------------------------------------------- /forecast.io.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | //Install jQuery and Moment.js using npm or 4 | //if using require.js manage the paths as you see fit 5 | 6 | //Notes 7 | //Could use ES6 promises (and polyfill) 8 | //rather than jQuery 9 | 10 | (function(root, factory) { 11 | if (typeof define === 'function' && define.amd) { 12 | // AMD. Register as an anonymous module. 13 | define(['moment', 'es6-promise'], function(moment) { 14 | return (root.ForecastIO = factory(moment)); 15 | }); 16 | } else if (typeof module === 'object' && module.exports) { 17 | // Node. Does not work with strict CommonJS, but 18 | // only CommonJS-like environments that support module.exports, 19 | // like Node. 20 | module.exports = (root.ForecastIO = factory(require('moment'), require('es6-promise').Promise)); 21 | } else { 22 | // Browser globals (root is window) 23 | root.ForecastIO = factory(root.moment); 24 | } 25 | }(this, function(moment) { 26 | 27 | /* By Ian Tearle 28 | github.com/iantearle 29 | 30 | Other contributors 31 | Richard Bultitude 32 | github.com/rjbultitude 33 | Brandon Love 34 | github.com/brandonlove 35 | */ 36 | 37 | //Error strings 38 | var fioServiceError = 'There was a problem accessing forecast.io. Make sure you have a valid key'; 39 | 40 | //Forecast Class 41 | /** 42 | * Will construct a new ForecastIO object 43 | * 44 | * @param string $config 45 | * @return boolean 46 | */ 47 | function ForecastIO(config) { 48 | //var PROXY_SCRIPT = '/proxy.php'; 49 | if (!config) { 50 | console.log('You must pass ForecastIO configurations'); 51 | } 52 | if (!config.PROXY_SCRIPT) { 53 | if (!config.API_KEY) { 54 | console.log('API_KEY or PROXY_SCRIPT must be set in ForecastIO config'); 55 | } 56 | } 57 | this.API_KEY = config.API_KEY; 58 | this.url = (typeof config.PROXY_SCRIPT !== 'undefined') ? config.PROXY_SCRIPT + '?url=': 'https://api.forecast.io/forecast/' + config.API_KEY + '/'; 59 | } 60 | 61 | function makeRequest(method, url) { 62 | return new Promise(function(resolve, reject) { 63 | var xhr = new XMLHttpRequest(); 64 | xhr.open(method, url); 65 | xhr.onload = function() { 66 | if (this.status >= 200 && this.status < 300) { 67 | resolve(xhr.response); 68 | } else { 69 | reject({ 70 | status: this.status, 71 | statusText: xhr.statusText 72 | }); 73 | } 74 | }; 75 | xhr.onerror = function() { 76 | reject({ 77 | status: this.status, 78 | statusText: xhr.statusText 79 | }); 80 | }; 81 | xhr.send(); 82 | }); 83 | } 84 | 85 | /** 86 | * Checks the location object 87 | * passed into the app 88 | * and wraps it in an array 89 | * if it wasn't one already 90 | * 91 | * @param object $locObject 92 | * @return array 93 | */ 94 | function checkObject(locObject) { 95 | var locationsObjWrap = []; 96 | if (!Array.isArray(locObject)) { 97 | //console.log('locations was not an array'); 98 | locationsObjWrap.push(locObject); 99 | return locationsObjWrap; 100 | } 101 | else { 102 | return locObject; 103 | } 104 | } 105 | 106 | /** 107 | * Will build a url string from the lat long coords 108 | * and return a promise with the json 109 | * 110 | * @param number $latitude 111 | * @param number $longitude 112 | * @return promise object 113 | */ 114 | ForecastIO.prototype.requestData = function requestData(latitude, longitude) { 115 | var requestUrl = this.url + latitude + ',' + longitude; 116 | return makeRequest('GET', requestUrl); 117 | }; 118 | 119 | ForecastIO.prototype.requestAllLocData = function requestAllLocData(locations) { 120 | var locDataArr = []; 121 | for (var i = 0; i < locations.length; i++) { 122 | var content = this.requestData(locations[i].latitude, locations[i].longitude); 123 | locDataArr.push(content); 124 | } 125 | return locDataArr; 126 | }; 127 | 128 | /** 129 | * Will take a locations object and a callback function 130 | * and pass the current conditions into the callback 131 | * 132 | * @param object $locations 133 | * @param function $appFn 134 | * @return boolean 135 | */ 136 | ForecastIO.prototype.getCurrentConditions = function getCurrentConditions(locations, appFn) { 137 | var locationsArr = checkObject(locations); 138 | var allLocDataArr = this.requestAllLocData(locationsArr); 139 | Promise.all(allLocDataArr).then(function(values) { 140 | if (values.length === 0 || values[0] === '' || values[0] === null || values[0] === undefined) { 141 | console.log(fioServiceError); 142 | return; 143 | } 144 | else { 145 | var dataSets = []; 146 | for (var i = 0; i < values.length; i++) { 147 | var jsonData = JSON.parse(values[i]); 148 | var currently = new ForecastIOConditions(jsonData.currently); 149 | dataSets.push(currently); 150 | } 151 | appFn(dataSets); 152 | return dataSets; 153 | } 154 | }, function(rejectObj) { 155 | console.log(rejectObj.status); 156 | console.log(rejectObj.statusText); 157 | }); 158 | }; 159 | 160 | /** 161 | * Will take a locations object and a callback function 162 | * and pass the conditions on hourly basis for today into the callback 163 | * 164 | * @param object $locations 165 | * @param function $appFn 166 | * @return boolean 167 | */ 168 | ForecastIO.prototype.getForecastToday = function getForecastToday(locations, appFn) { 169 | var locationsArr = checkObject(locations); 170 | var allLocDataArr = this.requestAllLocData(locationsArr); 171 | Promise.all(allLocDataArr).then(function(values) { 172 | if (values.length === 0 || values[0] === '' || values[0] === null || values[0] === undefined) { 173 | console.log(fioServiceError); 174 | return; 175 | } 176 | else { 177 | var dataSets = []; 178 | for (var i = 0; i < values.length; i++) { 179 | var today = moment().format('YYYY-MM-DD'); 180 | var jsonData = JSON.parse(values[i]); 181 | for (var j = 0; j < jsonData.hourly.data.length; j++) { 182 | var hourlyData = jsonData.hourly.data[j]; 183 | if (moment.unix(hourlyData.time).format('YYYY-MM-DD') === today) { 184 | dataSets.push(new ForecastIOConditions(hourlyData)); 185 | } 186 | } 187 | } 188 | appFn(dataSets); 189 | return dataSets; 190 | } 191 | }, function(rejectObj) { 192 | console.log(rejectObj.status); 193 | console.log(rejectObj.statusText); 194 | }); 195 | }; 196 | 197 | /** 198 | * Will take a locations object and a callback function 199 | * and pass the daily conditions for next seven days into the callback 200 | * 201 | * @param object $locations 202 | * @param function $appFn 203 | * @return boolean 204 | */ 205 | ForecastIO.prototype.getForecastWeek = function getForecastWeek(locations, appFn) { 206 | var locationsArr = checkObject(locations); 207 | var allLocDataArr = this.requestAllLocData(locationsArr); 208 | Promise.all(allLocDataArr).then(function(values) { 209 | if (values.length === 0 || values[0] === '' || values[0] === null || values[0] === undefined) { 210 | console.log(fioServiceError); 211 | return; 212 | } 213 | else { 214 | var dataSets = []; 215 | for (var i = 0; i < values.length; i++) { 216 | var jsonData = JSON.parse(values[i]); 217 | for (var j = 0; j < jsonData.daily.data.length; j++) { 218 | var dailyData = jsonData.daily.data[j]; 219 | dataSets.push(new ForecastIOConditions(dailyData)); 220 | } 221 | } 222 | appFn(dataSets); 223 | return dataSets; 224 | } 225 | }, function(rejectObj) { 226 | console.log(rejectObj.status); 227 | console.log(rejectObj.statusText); 228 | }); 229 | }; 230 | 231 | function ForecastIOConditions(rawData) { 232 | ForecastIOConditions.prototype = { 233 | rawData: rawData 234 | }; 235 | /** 236 | * Will return the temperature 237 | * 238 | * @return String 239 | */ 240 | this.getTemperature = function() { 241 | return rawData.temperature; 242 | }; 243 | /** 244 | * Will return the apparent temperature 245 | * 246 | * @return String 247 | */ 248 | this.getApparentTemperature = function() { 249 | return rawData.apparentTemperature; 250 | }; 251 | /** 252 | * Get the summary of the conditions 253 | * 254 | * @return String 255 | */ 256 | this.getSummary = function() { 257 | return rawData.summary; 258 | }; 259 | /** 260 | * Get the icon of the conditions 261 | * 262 | * @return String 263 | */ 264 | this.getIcon = function() { 265 | return rawData.icon; 266 | }; 267 | /** 268 | * Get the time, when $format not set timestamp else formatted time 269 | * 270 | * @param String $format 271 | * @return String 272 | */ 273 | this.getTime = function(format) { 274 | if (!format) { 275 | return rawData.time; 276 | } else { 277 | return moment.unix(rawData.time).format(format); 278 | } 279 | }; 280 | /** 281 | * Get the pressure 282 | * 283 | * @return String 284 | */ 285 | this.getPressure = function() { 286 | return rawData.pressure; 287 | }; 288 | /** 289 | * get humidity 290 | * 291 | * @return String 292 | */ 293 | this.getHumidity = function() { 294 | return rawData.humidity; 295 | }; 296 | /** 297 | * Get the wind speed 298 | * 299 | * @return String 300 | */ 301 | this.getWindSpeed = function() { 302 | return rawData.windSpeed; 303 | }; 304 | /** 305 | * Get wind direction 306 | * 307 | * @return type 308 | */ 309 | this.getWindBearing = function() { 310 | return rawData.windBearing; 311 | }; 312 | /** 313 | * get precipitation type 314 | * 315 | * @return type 316 | */ 317 | this.getPrecipitationType = function() { 318 | return rawData.precipType; 319 | }; 320 | /** 321 | * get the probability 0..1 of precipitation type 322 | * 323 | * @return type 324 | */ 325 | this.getPrecipitationProbability = function() { 326 | return rawData.precipProbability; 327 | }; 328 | /** 329 | * Get the cloud cover 330 | * 331 | * @return type 332 | */ 333 | this.getCloudCover = function() { 334 | return rawData.cloudCover; 335 | }; 336 | /** 337 | * get the min temperature 338 | * 339 | * only available for week forecast 340 | * 341 | * @return type 342 | */ 343 | this.getMinTemperature = function() { 344 | return rawData.temperatureMin; 345 | }; 346 | /** 347 | * get max temperature 348 | * 349 | * only available for week forecast 350 | * 351 | * @return type 352 | */ 353 | this.getMaxTemperature = function() { 354 | return rawData.temperatureMax; 355 | }; 356 | /** 357 | * get sunrise time 358 | * 359 | * only available for week forecast 360 | * 361 | * @return type 362 | */ 363 | this.getSunrise = function() { 364 | return rawData.sunriseTime; 365 | }; 366 | /** 367 | * get sunset time 368 | * 369 | * only available for week forecast 370 | * 371 | * @return type 372 | */ 373 | this.getSunset = function() { 374 | return rawData.sunsetTime; 375 | }; 376 | /** 377 | * get precipitation intensity 378 | * 379 | * @return number 380 | */ 381 | this.getPrecipIntensity = function() { 382 | return rawData.precipIntensity; 383 | }; 384 | /** 385 | * get dew point 386 | * 387 | * @return number 388 | */ 389 | this.getDewPoint = function() { 390 | return rawData.dewPoint; 391 | }; 392 | /** 393 | * get the ozone 394 | * 395 | * @return number 396 | */ 397 | this.getOzone = function() { 398 | return rawData.ozone; 399 | }; 400 | } 401 | 402 | return ForecastIO; 403 | })); 404 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |

Forecast.io JS API

16 | 17 |

Current Temperatures

18 | 19 | 20 |
21 | 22 |

Forecast for today

23 | 24 | 25 |
26 | 27 |

Forecast for the week

28 | 29 | 30 | 31 | 32 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /manifest: -------------------------------------------------------------------------------- 1 | version: 0.0.9 2 | description: Forecast.io API Wrapper 3 | author: Ian Tearle <@iantearle> 4 | license: MIT 5 | copyright: Copyright © 2015 Ian Tearle 6 | name: ti.forecast.io-javascript-api 7 | moduleid: ti.forecast.io-javascript-api 8 | guid: 946f6eea-6afd-0508-0954-554899 9 | platform: commonjs 10 | minsdk: 3.2.0.GA 11 | -------------------------------------------------------------------------------- /moment.js: -------------------------------------------------------------------------------- 1 | //! moment.js 2 | //! version : 2.10.6 3 | //! authors : Tim Wood, Iskren Chernev, Moment.js contributors 4 | //! license : MIT 5 | //! momentjs.com 6 | 7 | (function (global, factory) { 8 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 9 | typeof define === 'function' && define.amd ? define(factory) : 10 | global.moment = factory() 11 | }(this, function () { 'use strict'; 12 | 13 | var hookCallback; 14 | 15 | function utils_hooks__hooks () { 16 | return hookCallback.apply(null, arguments); 17 | } 18 | 19 | // This is done to register the method called with moment() 20 | // without creating circular dependencies. 21 | function setHookCallback (callback) { 22 | hookCallback = callback; 23 | } 24 | 25 | function isArray(input) { 26 | return Object.prototype.toString.call(input) === '[object Array]'; 27 | } 28 | 29 | function isDate(input) { 30 | return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]'; 31 | } 32 | 33 | function map(arr, fn) { 34 | var res = [], i; 35 | for (i = 0; i < arr.length; ++i) { 36 | res.push(fn(arr[i], i)); 37 | } 38 | return res; 39 | } 40 | 41 | function hasOwnProp(a, b) { 42 | return Object.prototype.hasOwnProperty.call(a, b); 43 | } 44 | 45 | function extend(a, b) { 46 | for (var i in b) { 47 | if (hasOwnProp(b, i)) { 48 | a[i] = b[i]; 49 | } 50 | } 51 | 52 | if (hasOwnProp(b, 'toString')) { 53 | a.toString = b.toString; 54 | } 55 | 56 | if (hasOwnProp(b, 'valueOf')) { 57 | a.valueOf = b.valueOf; 58 | } 59 | 60 | return a; 61 | } 62 | 63 | function create_utc__createUTC (input, format, locale, strict) { 64 | return createLocalOrUTC(input, format, locale, strict, true).utc(); 65 | } 66 | 67 | function defaultParsingFlags() { 68 | // We need to deep clone this object. 69 | return { 70 | empty : false, 71 | unusedTokens : [], 72 | unusedInput : [], 73 | overflow : -2, 74 | charsLeftOver : 0, 75 | nullInput : false, 76 | invalidMonth : null, 77 | invalidFormat : false, 78 | userInvalidated : false, 79 | iso : false 80 | }; 81 | } 82 | 83 | function getParsingFlags(m) { 84 | if (m._pf == null) { 85 | m._pf = defaultParsingFlags(); 86 | } 87 | return m._pf; 88 | } 89 | 90 | function valid__isValid(m) { 91 | if (m._isValid == null) { 92 | var flags = getParsingFlags(m); 93 | m._isValid = !isNaN(m._d.getTime()) && 94 | flags.overflow < 0 && 95 | !flags.empty && 96 | !flags.invalidMonth && 97 | !flags.invalidWeekday && 98 | !flags.nullInput && 99 | !flags.invalidFormat && 100 | !flags.userInvalidated; 101 | 102 | if (m._strict) { 103 | m._isValid = m._isValid && 104 | flags.charsLeftOver === 0 && 105 | flags.unusedTokens.length === 0 && 106 | flags.bigHour === undefined; 107 | } 108 | } 109 | return m._isValid; 110 | } 111 | 112 | function valid__createInvalid (flags) { 113 | var m = create_utc__createUTC(NaN); 114 | if (flags != null) { 115 | extend(getParsingFlags(m), flags); 116 | } 117 | else { 118 | getParsingFlags(m).userInvalidated = true; 119 | } 120 | 121 | return m; 122 | } 123 | 124 | var momentProperties = utils_hooks__hooks.momentProperties = []; 125 | 126 | function copyConfig(to, from) { 127 | var i, prop, val; 128 | 129 | if (typeof from._isAMomentObject !== 'undefined') { 130 | to._isAMomentObject = from._isAMomentObject; 131 | } 132 | if (typeof from._i !== 'undefined') { 133 | to._i = from._i; 134 | } 135 | if (typeof from._f !== 'undefined') { 136 | to._f = from._f; 137 | } 138 | if (typeof from._l !== 'undefined') { 139 | to._l = from._l; 140 | } 141 | if (typeof from._strict !== 'undefined') { 142 | to._strict = from._strict; 143 | } 144 | if (typeof from._tzm !== 'undefined') { 145 | to._tzm = from._tzm; 146 | } 147 | if (typeof from._isUTC !== 'undefined') { 148 | to._isUTC = from._isUTC; 149 | } 150 | if (typeof from._offset !== 'undefined') { 151 | to._offset = from._offset; 152 | } 153 | if (typeof from._pf !== 'undefined') { 154 | to._pf = getParsingFlags(from); 155 | } 156 | if (typeof from._locale !== 'undefined') { 157 | to._locale = from._locale; 158 | } 159 | 160 | if (momentProperties.length > 0) { 161 | for (i in momentProperties) { 162 | prop = momentProperties[i]; 163 | val = from[prop]; 164 | if (typeof val !== 'undefined') { 165 | to[prop] = val; 166 | } 167 | } 168 | } 169 | 170 | return to; 171 | } 172 | 173 | var updateInProgress = false; 174 | 175 | // Moment prototype object 176 | function Moment(config) { 177 | copyConfig(this, config); 178 | this._d = new Date(config._d != null ? config._d.getTime() : NaN); 179 | // Prevent infinite loop in case updateOffset creates new moment 180 | // objects. 181 | if (updateInProgress === false) { 182 | updateInProgress = true; 183 | utils_hooks__hooks.updateOffset(this); 184 | updateInProgress = false; 185 | } 186 | } 187 | 188 | function isMoment (obj) { 189 | return obj instanceof Moment || (obj != null && obj._isAMomentObject != null); 190 | } 191 | 192 | function absFloor (number) { 193 | if (number < 0) { 194 | return Math.ceil(number); 195 | } else { 196 | return Math.floor(number); 197 | } 198 | } 199 | 200 | function toInt(argumentForCoercion) { 201 | var coercedNumber = +argumentForCoercion, 202 | value = 0; 203 | 204 | if (coercedNumber !== 0 && isFinite(coercedNumber)) { 205 | value = absFloor(coercedNumber); 206 | } 207 | 208 | return value; 209 | } 210 | 211 | function compareArrays(array1, array2, dontConvert) { 212 | var len = Math.min(array1.length, array2.length), 213 | lengthDiff = Math.abs(array1.length - array2.length), 214 | diffs = 0, 215 | i; 216 | for (i = 0; i < len; i++) { 217 | if ((dontConvert && array1[i] !== array2[i]) || 218 | (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) { 219 | diffs++; 220 | } 221 | } 222 | return diffs + lengthDiff; 223 | } 224 | 225 | function Locale() { 226 | } 227 | 228 | var locales = {}; 229 | var globalLocale; 230 | 231 | function normalizeLocale(key) { 232 | return key ? key.toLowerCase().replace('_', '-') : key; 233 | } 234 | 235 | // pick the locale from the array 236 | // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each 237 | // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root 238 | function chooseLocale(names) { 239 | var i = 0, j, next, locale, split; 240 | 241 | while (i < names.length) { 242 | split = normalizeLocale(names[i]).split('-'); 243 | j = split.length; 244 | next = normalizeLocale(names[i + 1]); 245 | next = next ? next.split('-') : null; 246 | while (j > 0) { 247 | locale = loadLocale(split.slice(0, j).join('-')); 248 | if (locale) { 249 | return locale; 250 | } 251 | if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) { 252 | //the next array item is better than a shallower substring of this one 253 | break; 254 | } 255 | j--; 256 | } 257 | i++; 258 | } 259 | return null; 260 | } 261 | 262 | function loadLocale(name) { 263 | var oldLocale = null; 264 | // TODO: Find a better way to register and load all the locales in Node 265 | if (!locales[name] && typeof module !== 'undefined' && 266 | module && module.exports) { 267 | try { 268 | oldLocale = globalLocale._abbr; 269 | require('./locale/' + name); 270 | // because defineLocale currently also sets the global locale, we 271 | // want to undo that for lazy loaded locales 272 | locale_locales__getSetGlobalLocale(oldLocale); 273 | } catch (e) { } 274 | } 275 | return locales[name]; 276 | } 277 | 278 | // This function will load locale and then set the global locale. If 279 | // no arguments are passed in, it will simply return the current global 280 | // locale key. 281 | function locale_locales__getSetGlobalLocale (key, values) { 282 | var data; 283 | if (key) { 284 | if (typeof values === 'undefined') { 285 | data = locale_locales__getLocale(key); 286 | } 287 | else { 288 | data = defineLocale(key, values); 289 | } 290 | 291 | if (data) { 292 | // moment.duration._locale = moment._locale = data; 293 | globalLocale = data; 294 | } 295 | } 296 | 297 | return globalLocale._abbr; 298 | } 299 | 300 | function defineLocale (name, values) { 301 | if (values !== null) { 302 | values.abbr = name; 303 | locales[name] = locales[name] || new Locale(); 304 | locales[name].set(values); 305 | 306 | // backwards compat for now: also set the locale 307 | locale_locales__getSetGlobalLocale(name); 308 | 309 | return locales[name]; 310 | } else { 311 | // useful for testing 312 | delete locales[name]; 313 | return null; 314 | } 315 | } 316 | 317 | // returns locale data 318 | function locale_locales__getLocale (key) { 319 | var locale; 320 | 321 | if (key && key._locale && key._locale._abbr) { 322 | key = key._locale._abbr; 323 | } 324 | 325 | if (!key) { 326 | return globalLocale; 327 | } 328 | 329 | if (!isArray(key)) { 330 | //short-circuit everything else 331 | locale = loadLocale(key); 332 | if (locale) { 333 | return locale; 334 | } 335 | key = [key]; 336 | } 337 | 338 | return chooseLocale(key); 339 | } 340 | 341 | var aliases = {}; 342 | 343 | function addUnitAlias (unit, shorthand) { 344 | var lowerCase = unit.toLowerCase(); 345 | aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit; 346 | } 347 | 348 | function normalizeUnits(units) { 349 | return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined; 350 | } 351 | 352 | function normalizeObjectUnits(inputObject) { 353 | var normalizedInput = {}, 354 | normalizedProp, 355 | prop; 356 | 357 | for (prop in inputObject) { 358 | if (hasOwnProp(inputObject, prop)) { 359 | normalizedProp = normalizeUnits(prop); 360 | if (normalizedProp) { 361 | normalizedInput[normalizedProp] = inputObject[prop]; 362 | } 363 | } 364 | } 365 | 366 | return normalizedInput; 367 | } 368 | 369 | function makeGetSet (unit, keepTime) { 370 | return function (value) { 371 | if (value != null) { 372 | get_set__set(this, unit, value); 373 | utils_hooks__hooks.updateOffset(this, keepTime); 374 | return this; 375 | } else { 376 | return get_set__get(this, unit); 377 | } 378 | }; 379 | } 380 | 381 | function get_set__get (mom, unit) { 382 | return mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit](); 383 | } 384 | 385 | function get_set__set (mom, unit, value) { 386 | return mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value); 387 | } 388 | 389 | // MOMENTS 390 | 391 | function getSet (units, value) { 392 | var unit; 393 | if (typeof units === 'object') { 394 | for (unit in units) { 395 | this.set(unit, units[unit]); 396 | } 397 | } else { 398 | units = normalizeUnits(units); 399 | if (typeof this[units] === 'function') { 400 | return this[units](value); 401 | } 402 | } 403 | return this; 404 | } 405 | 406 | function zeroFill(number, targetLength, forceSign) { 407 | var absNumber = '' + Math.abs(number), 408 | zerosToFill = targetLength - absNumber.length, 409 | sign = number >= 0; 410 | return (sign ? (forceSign ? '+' : '') : '-') + 411 | Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber; 412 | } 413 | 414 | var formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Q|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g; 415 | 416 | var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g; 417 | 418 | var formatFunctions = {}; 419 | 420 | var formatTokenFunctions = {}; 421 | 422 | // token: 'M' 423 | // padded: ['MM', 2] 424 | // ordinal: 'Mo' 425 | // callback: function () { this.month() + 1 } 426 | function addFormatToken (token, padded, ordinal, callback) { 427 | var func = callback; 428 | if (typeof callback === 'string') { 429 | func = function () { 430 | return this[callback](); 431 | }; 432 | } 433 | if (token) { 434 | formatTokenFunctions[token] = func; 435 | } 436 | if (padded) { 437 | formatTokenFunctions[padded[0]] = function () { 438 | return zeroFill(func.apply(this, arguments), padded[1], padded[2]); 439 | }; 440 | } 441 | if (ordinal) { 442 | formatTokenFunctions[ordinal] = function () { 443 | return this.localeData().ordinal(func.apply(this, arguments), token); 444 | }; 445 | } 446 | } 447 | 448 | function removeFormattingTokens(input) { 449 | if (input.match(/\[[\s\S]/)) { 450 | return input.replace(/^\[|\]$/g, ''); 451 | } 452 | return input.replace(/\\/g, ''); 453 | } 454 | 455 | function makeFormatFunction(format) { 456 | var array = format.match(formattingTokens), i, length; 457 | 458 | for (i = 0, length = array.length; i < length; i++) { 459 | if (formatTokenFunctions[array[i]]) { 460 | array[i] = formatTokenFunctions[array[i]]; 461 | } else { 462 | array[i] = removeFormattingTokens(array[i]); 463 | } 464 | } 465 | 466 | return function (mom) { 467 | var output = ''; 468 | for (i = 0; i < length; i++) { 469 | output += array[i] instanceof Function ? array[i].call(mom, format) : array[i]; 470 | } 471 | return output; 472 | }; 473 | } 474 | 475 | // format date using native date object 476 | function formatMoment(m, format) { 477 | if (!m.isValid()) { 478 | return m.localeData().invalidDate(); 479 | } 480 | 481 | format = expandFormat(format, m.localeData()); 482 | formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format); 483 | 484 | return formatFunctions[format](m); 485 | } 486 | 487 | function expandFormat(format, locale) { 488 | var i = 5; 489 | 490 | function replaceLongDateFormatTokens(input) { 491 | return locale.longDateFormat(input) || input; 492 | } 493 | 494 | localFormattingTokens.lastIndex = 0; 495 | while (i >= 0 && localFormattingTokens.test(format)) { 496 | format = format.replace(localFormattingTokens, replaceLongDateFormatTokens); 497 | localFormattingTokens.lastIndex = 0; 498 | i -= 1; 499 | } 500 | 501 | return format; 502 | } 503 | 504 | var match1 = /\d/; // 0 - 9 505 | var match2 = /\d\d/; // 00 - 99 506 | var match3 = /\d{3}/; // 000 - 999 507 | var match4 = /\d{4}/; // 0000 - 9999 508 | var match6 = /[+-]?\d{6}/; // -999999 - 999999 509 | var match1to2 = /\d\d?/; // 0 - 99 510 | var match1to3 = /\d{1,3}/; // 0 - 999 511 | var match1to4 = /\d{1,4}/; // 0 - 9999 512 | var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999 513 | 514 | var matchUnsigned = /\d+/; // 0 - inf 515 | var matchSigned = /[+-]?\d+/; // -inf - inf 516 | 517 | var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z 518 | 519 | var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123 520 | 521 | // any word (or two) characters or numbers including two/three word month in arabic. 522 | var matchWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i; 523 | 524 | var regexes = {}; 525 | 526 | function isFunction (sth) { 527 | // https://github.com/moment/moment/issues/2325 528 | return typeof sth === 'function' && 529 | Object.prototype.toString.call(sth) === '[object Function]'; 530 | } 531 | 532 | 533 | function addRegexToken (token, regex, strictRegex) { 534 | regexes[token] = isFunction(regex) ? regex : function (isStrict) { 535 | return (isStrict && strictRegex) ? strictRegex : regex; 536 | }; 537 | } 538 | 539 | function getParseRegexForToken (token, config) { 540 | if (!hasOwnProp(regexes, token)) { 541 | return new RegExp(unescapeFormat(token)); 542 | } 543 | 544 | return regexes[token](config._strict, config._locale); 545 | } 546 | 547 | // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript 548 | function unescapeFormat(s) { 549 | return s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) { 550 | return p1 || p2 || p3 || p4; 551 | }).replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); 552 | } 553 | 554 | var tokens = {}; 555 | 556 | function addParseToken (token, callback) { 557 | var i, func = callback; 558 | if (typeof token === 'string') { 559 | token = [token]; 560 | } 561 | if (typeof callback === 'number') { 562 | func = function (input, array) { 563 | array[callback] = toInt(input); 564 | }; 565 | } 566 | for (i = 0; i < token.length; i++) { 567 | tokens[token[i]] = func; 568 | } 569 | } 570 | 571 | function addWeekParseToken (token, callback) { 572 | addParseToken(token, function (input, array, config, token) { 573 | config._w = config._w || {}; 574 | callback(input, config._w, config, token); 575 | }); 576 | } 577 | 578 | function addTimeToArrayFromToken(token, input, config) { 579 | if (input != null && hasOwnProp(tokens, token)) { 580 | tokens[token](input, config._a, config, token); 581 | } 582 | } 583 | 584 | var YEAR = 0; 585 | var MONTH = 1; 586 | var DATE = 2; 587 | var HOUR = 3; 588 | var MINUTE = 4; 589 | var SECOND = 5; 590 | var MILLISECOND = 6; 591 | 592 | function daysInMonth(year, month) { 593 | return new Date(Date.UTC(year, month + 1, 0)).getUTCDate(); 594 | } 595 | 596 | // FORMATTING 597 | 598 | addFormatToken('M', ['MM', 2], 'Mo', function () { 599 | return this.month() + 1; 600 | }); 601 | 602 | addFormatToken('MMM', 0, 0, function (format) { 603 | return this.localeData().monthsShort(this, format); 604 | }); 605 | 606 | addFormatToken('MMMM', 0, 0, function (format) { 607 | return this.localeData().months(this, format); 608 | }); 609 | 610 | // ALIASES 611 | 612 | addUnitAlias('month', 'M'); 613 | 614 | // PARSING 615 | 616 | addRegexToken('M', match1to2); 617 | addRegexToken('MM', match1to2, match2); 618 | addRegexToken('MMM', matchWord); 619 | addRegexToken('MMMM', matchWord); 620 | 621 | addParseToken(['M', 'MM'], function (input, array) { 622 | array[MONTH] = toInt(input) - 1; 623 | }); 624 | 625 | addParseToken(['MMM', 'MMMM'], function (input, array, config, token) { 626 | var month = config._locale.monthsParse(input, token, config._strict); 627 | // if we didn't find a month name, mark the date as invalid. 628 | if (month != null) { 629 | array[MONTH] = month; 630 | } else { 631 | getParsingFlags(config).invalidMonth = input; 632 | } 633 | }); 634 | 635 | // LOCALES 636 | 637 | var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'); 638 | function localeMonths (m) { 639 | return this._months[m.month()]; 640 | } 641 | 642 | var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'); 643 | function localeMonthsShort (m) { 644 | return this._monthsShort[m.month()]; 645 | } 646 | 647 | function localeMonthsParse (monthName, format, strict) { 648 | var i, mom, regex; 649 | 650 | if (!this._monthsParse) { 651 | this._monthsParse = []; 652 | this._longMonthsParse = []; 653 | this._shortMonthsParse = []; 654 | } 655 | 656 | for (i = 0; i < 12; i++) { 657 | // make the regex if we don't have it already 658 | mom = create_utc__createUTC([2000, i]); 659 | if (strict && !this._longMonthsParse[i]) { 660 | this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i'); 661 | this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i'); 662 | } 663 | if (!strict && !this._monthsParse[i]) { 664 | regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, ''); 665 | this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i'); 666 | } 667 | // test the regex 668 | if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) { 669 | return i; 670 | } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) { 671 | return i; 672 | } else if (!strict && this._monthsParse[i].test(monthName)) { 673 | return i; 674 | } 675 | } 676 | } 677 | 678 | // MOMENTS 679 | 680 | function setMonth (mom, value) { 681 | var dayOfMonth; 682 | 683 | // TODO: Move this out of here! 684 | if (typeof value === 'string') { 685 | value = mom.localeData().monthsParse(value); 686 | // TODO: Another silent failure? 687 | if (typeof value !== 'number') { 688 | return mom; 689 | } 690 | } 691 | 692 | dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value)); 693 | mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth); 694 | return mom; 695 | } 696 | 697 | function getSetMonth (value) { 698 | if (value != null) { 699 | setMonth(this, value); 700 | utils_hooks__hooks.updateOffset(this, true); 701 | return this; 702 | } else { 703 | return get_set__get(this, 'Month'); 704 | } 705 | } 706 | 707 | function getDaysInMonth () { 708 | return daysInMonth(this.year(), this.month()); 709 | } 710 | 711 | function checkOverflow (m) { 712 | var overflow; 713 | var a = m._a; 714 | 715 | if (a && getParsingFlags(m).overflow === -2) { 716 | overflow = 717 | a[MONTH] < 0 || a[MONTH] > 11 ? MONTH : 718 | a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE : 719 | a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR : 720 | a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE : 721 | a[SECOND] < 0 || a[SECOND] > 59 ? SECOND : 722 | a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND : 723 | -1; 724 | 725 | if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) { 726 | overflow = DATE; 727 | } 728 | 729 | getParsingFlags(m).overflow = overflow; 730 | } 731 | 732 | return m; 733 | } 734 | 735 | function warn(msg) { 736 | if (utils_hooks__hooks.suppressDeprecationWarnings === false && typeof console !== 'undefined' && console.warn) { 737 | console.warn('Deprecation warning: ' + msg); 738 | } 739 | } 740 | 741 | function deprecate(msg, fn) { 742 | var firstTime = true; 743 | 744 | return extend(function () { 745 | if (firstTime) { 746 | warn(msg + '\n' + (new Error()).stack); 747 | firstTime = false; 748 | } 749 | return fn.apply(this, arguments); 750 | }, fn); 751 | } 752 | 753 | var deprecations = {}; 754 | 755 | function deprecateSimple(name, msg) { 756 | if (!deprecations[name]) { 757 | warn(msg); 758 | deprecations[name] = true; 759 | } 760 | } 761 | 762 | utils_hooks__hooks.suppressDeprecationWarnings = false; 763 | 764 | var from_string__isoRegex = /^\s*(?:[+-]\d{6}|\d{4})-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/; 765 | 766 | var isoDates = [ 767 | ['YYYYYY-MM-DD', /[+-]\d{6}-\d{2}-\d{2}/], 768 | ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/], 769 | ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/], 770 | ['GGGG-[W]WW', /\d{4}-W\d{2}/], 771 | ['YYYY-DDD', /\d{4}-\d{3}/] 772 | ]; 773 | 774 | // iso time formats and regexes 775 | var isoTimes = [ 776 | ['HH:mm:ss.SSSS', /(T| )\d\d:\d\d:\d\d\.\d+/], 777 | ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/], 778 | ['HH:mm', /(T| )\d\d:\d\d/], 779 | ['HH', /(T| )\d\d/] 780 | ]; 781 | 782 | var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i; 783 | 784 | // date from iso format 785 | function configFromISO(config) { 786 | var i, l, 787 | string = config._i, 788 | match = from_string__isoRegex.exec(string); 789 | 790 | if (match) { 791 | getParsingFlags(config).iso = true; 792 | for (i = 0, l = isoDates.length; i < l; i++) { 793 | if (isoDates[i][1].exec(string)) { 794 | config._f = isoDates[i][0]; 795 | break; 796 | } 797 | } 798 | for (i = 0, l = isoTimes.length; i < l; i++) { 799 | if (isoTimes[i][1].exec(string)) { 800 | // match[6] should be 'T' or space 801 | config._f += (match[6] || ' ') + isoTimes[i][0]; 802 | break; 803 | } 804 | } 805 | if (string.match(matchOffset)) { 806 | config._f += 'Z'; 807 | } 808 | configFromStringAndFormat(config); 809 | } else { 810 | config._isValid = false; 811 | } 812 | } 813 | 814 | // date from iso format or fallback 815 | function configFromString(config) { 816 | var matched = aspNetJsonRegex.exec(config._i); 817 | 818 | if (matched !== null) { 819 | config._d = new Date(+matched[1]); 820 | return; 821 | } 822 | 823 | configFromISO(config); 824 | if (config._isValid === false) { 825 | delete config._isValid; 826 | utils_hooks__hooks.createFromInputFallback(config); 827 | } 828 | } 829 | 830 | utils_hooks__hooks.createFromInputFallback = deprecate( 831 | 'moment construction falls back to js Date. This is ' + 832 | 'discouraged and will be removed in upcoming major ' + 833 | 'release. Please refer to ' + 834 | 'https://github.com/moment/moment/issues/1407 for more info.', 835 | function (config) { 836 | config._d = new Date(config._i + (config._useUTC ? ' UTC' : '')); 837 | } 838 | ); 839 | 840 | function createDate (y, m, d, h, M, s, ms) { 841 | //can't just apply() to create a date: 842 | //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply 843 | var date = new Date(y, m, d, h, M, s, ms); 844 | 845 | //the date constructor doesn't accept years < 1970 846 | if (y < 1970) { 847 | date.setFullYear(y); 848 | } 849 | return date; 850 | } 851 | 852 | function createUTCDate (y) { 853 | var date = new Date(Date.UTC.apply(null, arguments)); 854 | if (y < 1970) { 855 | date.setUTCFullYear(y); 856 | } 857 | return date; 858 | } 859 | 860 | addFormatToken(0, ['YY', 2], 0, function () { 861 | return this.year() % 100; 862 | }); 863 | 864 | addFormatToken(0, ['YYYY', 4], 0, 'year'); 865 | addFormatToken(0, ['YYYYY', 5], 0, 'year'); 866 | addFormatToken(0, ['YYYYYY', 6, true], 0, 'year'); 867 | 868 | // ALIASES 869 | 870 | addUnitAlias('year', 'y'); 871 | 872 | // PARSING 873 | 874 | addRegexToken('Y', matchSigned); 875 | addRegexToken('YY', match1to2, match2); 876 | addRegexToken('YYYY', match1to4, match4); 877 | addRegexToken('YYYYY', match1to6, match6); 878 | addRegexToken('YYYYYY', match1to6, match6); 879 | 880 | addParseToken(['YYYYY', 'YYYYYY'], YEAR); 881 | addParseToken('YYYY', function (input, array) { 882 | array[YEAR] = input.length === 2 ? utils_hooks__hooks.parseTwoDigitYear(input) : toInt(input); 883 | }); 884 | addParseToken('YY', function (input, array) { 885 | array[YEAR] = utils_hooks__hooks.parseTwoDigitYear(input); 886 | }); 887 | 888 | // HELPERS 889 | 890 | function daysInYear(year) { 891 | return isLeapYear(year) ? 366 : 365; 892 | } 893 | 894 | function isLeapYear(year) { 895 | return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; 896 | } 897 | 898 | // HOOKS 899 | 900 | utils_hooks__hooks.parseTwoDigitYear = function (input) { 901 | return toInt(input) + (toInt(input) > 68 ? 1900 : 2000); 902 | }; 903 | 904 | // MOMENTS 905 | 906 | var getSetYear = makeGetSet('FullYear', false); 907 | 908 | function getIsLeapYear () { 909 | return isLeapYear(this.year()); 910 | } 911 | 912 | addFormatToken('w', ['ww', 2], 'wo', 'week'); 913 | addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek'); 914 | 915 | // ALIASES 916 | 917 | addUnitAlias('week', 'w'); 918 | addUnitAlias('isoWeek', 'W'); 919 | 920 | // PARSING 921 | 922 | addRegexToken('w', match1to2); 923 | addRegexToken('ww', match1to2, match2); 924 | addRegexToken('W', match1to2); 925 | addRegexToken('WW', match1to2, match2); 926 | 927 | addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) { 928 | week[token.substr(0, 1)] = toInt(input); 929 | }); 930 | 931 | // HELPERS 932 | 933 | // firstDayOfWeek 0 = sun, 6 = sat 934 | // the day of the week that starts the week 935 | // (usually sunday or monday) 936 | // firstDayOfWeekOfYear 0 = sun, 6 = sat 937 | // the first week is the week that contains the first 938 | // of this day of the week 939 | // (eg. ISO weeks use thursday (4)) 940 | function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) { 941 | var end = firstDayOfWeekOfYear - firstDayOfWeek, 942 | daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(), 943 | adjustedMoment; 944 | 945 | 946 | if (daysToDayOfWeek > end) { 947 | daysToDayOfWeek -= 7; 948 | } 949 | 950 | if (daysToDayOfWeek < end - 7) { 951 | daysToDayOfWeek += 7; 952 | } 953 | 954 | adjustedMoment = local__createLocal(mom).add(daysToDayOfWeek, 'd'); 955 | return { 956 | week: Math.ceil(adjustedMoment.dayOfYear() / 7), 957 | year: adjustedMoment.year() 958 | }; 959 | } 960 | 961 | // LOCALES 962 | 963 | function localeWeek (mom) { 964 | return weekOfYear(mom, this._week.dow, this._week.doy).week; 965 | } 966 | 967 | var defaultLocaleWeek = { 968 | dow : 0, // Sunday is the first day of the week. 969 | doy : 6 // The week that contains Jan 1st is the first week of the year. 970 | }; 971 | 972 | function localeFirstDayOfWeek () { 973 | return this._week.dow; 974 | } 975 | 976 | function localeFirstDayOfYear () { 977 | return this._week.doy; 978 | } 979 | 980 | // MOMENTS 981 | 982 | function getSetWeek (input) { 983 | var week = this.localeData().week(this); 984 | return input == null ? week : this.add((input - week) * 7, 'd'); 985 | } 986 | 987 | function getSetISOWeek (input) { 988 | var week = weekOfYear(this, 1, 4).week; 989 | return input == null ? week : this.add((input - week) * 7, 'd'); 990 | } 991 | 992 | addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear'); 993 | 994 | // ALIASES 995 | 996 | addUnitAlias('dayOfYear', 'DDD'); 997 | 998 | // PARSING 999 | 1000 | addRegexToken('DDD', match1to3); 1001 | addRegexToken('DDDD', match3); 1002 | addParseToken(['DDD', 'DDDD'], function (input, array, config) { 1003 | config._dayOfYear = toInt(input); 1004 | }); 1005 | 1006 | // HELPERS 1007 | 1008 | //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday 1009 | function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) { 1010 | var week1Jan = 6 + firstDayOfWeek - firstDayOfWeekOfYear, janX = createUTCDate(year, 0, 1 + week1Jan), d = janX.getUTCDay(), dayOfYear; 1011 | if (d < firstDayOfWeek) { 1012 | d += 7; 1013 | } 1014 | 1015 | weekday = weekday != null ? 1 * weekday : firstDayOfWeek; 1016 | 1017 | dayOfYear = 1 + week1Jan + 7 * (week - 1) - d + weekday; 1018 | 1019 | return { 1020 | year: dayOfYear > 0 ? year : year - 1, 1021 | dayOfYear: dayOfYear > 0 ? dayOfYear : daysInYear(year - 1) + dayOfYear 1022 | }; 1023 | } 1024 | 1025 | // MOMENTS 1026 | 1027 | function getSetDayOfYear (input) { 1028 | var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1; 1029 | return input == null ? dayOfYear : this.add((input - dayOfYear), 'd'); 1030 | } 1031 | 1032 | // Pick the first defined of two or three arguments. 1033 | function defaults(a, b, c) { 1034 | if (a != null) { 1035 | return a; 1036 | } 1037 | if (b != null) { 1038 | return b; 1039 | } 1040 | return c; 1041 | } 1042 | 1043 | function currentDateArray(config) { 1044 | var now = new Date(); 1045 | if (config._useUTC) { 1046 | return [now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()]; 1047 | } 1048 | return [now.getFullYear(), now.getMonth(), now.getDate()]; 1049 | } 1050 | 1051 | // convert an array to a date. 1052 | // the array should mirror the parameters below 1053 | // note: all values past the year are optional and will default to the lowest possible value. 1054 | // [year, month, day , hour, minute, second, millisecond] 1055 | function configFromArray (config) { 1056 | var i, date, input = [], currentDate, yearToUse; 1057 | 1058 | if (config._d) { 1059 | return; 1060 | } 1061 | 1062 | currentDate = currentDateArray(config); 1063 | 1064 | //compute day of the year from weeks and weekdays 1065 | if (config._w && config._a[DATE] == null && config._a[MONTH] == null) { 1066 | dayOfYearFromWeekInfo(config); 1067 | } 1068 | 1069 | //if the day of the year is set, figure out what it is 1070 | if (config._dayOfYear) { 1071 | yearToUse = defaults(config._a[YEAR], currentDate[YEAR]); 1072 | 1073 | if (config._dayOfYear > daysInYear(yearToUse)) { 1074 | getParsingFlags(config)._overflowDayOfYear = true; 1075 | } 1076 | 1077 | date = createUTCDate(yearToUse, 0, config._dayOfYear); 1078 | config._a[MONTH] = date.getUTCMonth(); 1079 | config._a[DATE] = date.getUTCDate(); 1080 | } 1081 | 1082 | // Default to current date. 1083 | // * if no year, month, day of month are given, default to today 1084 | // * if day of month is given, default month and year 1085 | // * if month is given, default only year 1086 | // * if year is given, don't default anything 1087 | for (i = 0; i < 3 && config._a[i] == null; ++i) { 1088 | config._a[i] = input[i] = currentDate[i]; 1089 | } 1090 | 1091 | // Zero out whatever was not defaulted, including time 1092 | for (; i < 7; i++) { 1093 | config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i]; 1094 | } 1095 | 1096 | // Check for 24:00:00.000 1097 | if (config._a[HOUR] === 24 && 1098 | config._a[MINUTE] === 0 && 1099 | config._a[SECOND] === 0 && 1100 | config._a[MILLISECOND] === 0) { 1101 | config._nextDay = true; 1102 | config._a[HOUR] = 0; 1103 | } 1104 | 1105 | config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input); 1106 | // Apply timezone offset from input. The actual utcOffset can be changed 1107 | // with parseZone. 1108 | if (config._tzm != null) { 1109 | config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm); 1110 | } 1111 | 1112 | if (config._nextDay) { 1113 | config._a[HOUR] = 24; 1114 | } 1115 | } 1116 | 1117 | function dayOfYearFromWeekInfo(config) { 1118 | var w, weekYear, week, weekday, dow, doy, temp; 1119 | 1120 | w = config._w; 1121 | if (w.GG != null || w.W != null || w.E != null) { 1122 | dow = 1; 1123 | doy = 4; 1124 | 1125 | // TODO: We need to take the current isoWeekYear, but that depends on 1126 | // how we interpret now (local, utc, fixed offset). So create 1127 | // a now version of current config (take local/utc/offset flags, and 1128 | // create now). 1129 | weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(local__createLocal(), 1, 4).year); 1130 | week = defaults(w.W, 1); 1131 | weekday = defaults(w.E, 1); 1132 | } else { 1133 | dow = config._locale._week.dow; 1134 | doy = config._locale._week.doy; 1135 | 1136 | weekYear = defaults(w.gg, config._a[YEAR], weekOfYear(local__createLocal(), dow, doy).year); 1137 | week = defaults(w.w, 1); 1138 | 1139 | if (w.d != null) { 1140 | // weekday -- low day numbers are considered next week 1141 | weekday = w.d; 1142 | if (weekday < dow) { 1143 | ++week; 1144 | } 1145 | } else if (w.e != null) { 1146 | // local weekday -- counting starts from begining of week 1147 | weekday = w.e + dow; 1148 | } else { 1149 | // default to begining of week 1150 | weekday = dow; 1151 | } 1152 | } 1153 | temp = dayOfYearFromWeeks(weekYear, week, weekday, doy, dow); 1154 | 1155 | config._a[YEAR] = temp.year; 1156 | config._dayOfYear = temp.dayOfYear; 1157 | } 1158 | 1159 | utils_hooks__hooks.ISO_8601 = function () {}; 1160 | 1161 | // date from string and format string 1162 | function configFromStringAndFormat(config) { 1163 | // TODO: Move this to another part of the creation flow to prevent circular deps 1164 | if (config._f === utils_hooks__hooks.ISO_8601) { 1165 | configFromISO(config); 1166 | return; 1167 | } 1168 | 1169 | config._a = []; 1170 | getParsingFlags(config).empty = true; 1171 | 1172 | // This array is used to make a Date, either with `new Date` or `Date.UTC` 1173 | var string = '' + config._i, 1174 | i, parsedInput, tokens, token, skipped, 1175 | stringLength = string.length, 1176 | totalParsedInputLength = 0; 1177 | 1178 | tokens = expandFormat(config._f, config._locale).match(formattingTokens) || []; 1179 | 1180 | for (i = 0; i < tokens.length; i++) { 1181 | token = tokens[i]; 1182 | parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0]; 1183 | if (parsedInput) { 1184 | skipped = string.substr(0, string.indexOf(parsedInput)); 1185 | if (skipped.length > 0) { 1186 | getParsingFlags(config).unusedInput.push(skipped); 1187 | } 1188 | string = string.slice(string.indexOf(parsedInput) + parsedInput.length); 1189 | totalParsedInputLength += parsedInput.length; 1190 | } 1191 | // don't parse if it's not a known token 1192 | if (formatTokenFunctions[token]) { 1193 | if (parsedInput) { 1194 | getParsingFlags(config).empty = false; 1195 | } 1196 | else { 1197 | getParsingFlags(config).unusedTokens.push(token); 1198 | } 1199 | addTimeToArrayFromToken(token, parsedInput, config); 1200 | } 1201 | else if (config._strict && !parsedInput) { 1202 | getParsingFlags(config).unusedTokens.push(token); 1203 | } 1204 | } 1205 | 1206 | // add remaining unparsed input length to the string 1207 | getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength; 1208 | if (string.length > 0) { 1209 | getParsingFlags(config).unusedInput.push(string); 1210 | } 1211 | 1212 | // clear _12h flag if hour is <= 12 1213 | if (getParsingFlags(config).bigHour === true && 1214 | config._a[HOUR] <= 12 && 1215 | config._a[HOUR] > 0) { 1216 | getParsingFlags(config).bigHour = undefined; 1217 | } 1218 | // handle meridiem 1219 | config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem); 1220 | 1221 | configFromArray(config); 1222 | checkOverflow(config); 1223 | } 1224 | 1225 | 1226 | function meridiemFixWrap (locale, hour, meridiem) { 1227 | var isPm; 1228 | 1229 | if (meridiem == null) { 1230 | // nothing to do 1231 | return hour; 1232 | } 1233 | if (locale.meridiemHour != null) { 1234 | return locale.meridiemHour(hour, meridiem); 1235 | } else if (locale.isPM != null) { 1236 | // Fallback 1237 | isPm = locale.isPM(meridiem); 1238 | if (isPm && hour < 12) { 1239 | hour += 12; 1240 | } 1241 | if (!isPm && hour === 12) { 1242 | hour = 0; 1243 | } 1244 | return hour; 1245 | } else { 1246 | // this is not supposed to happen 1247 | return hour; 1248 | } 1249 | } 1250 | 1251 | function configFromStringAndArray(config) { 1252 | var tempConfig, 1253 | bestMoment, 1254 | 1255 | scoreToBeat, 1256 | i, 1257 | currentScore; 1258 | 1259 | if (config._f.length === 0) { 1260 | getParsingFlags(config).invalidFormat = true; 1261 | config._d = new Date(NaN); 1262 | return; 1263 | } 1264 | 1265 | for (i = 0; i < config._f.length; i++) { 1266 | currentScore = 0; 1267 | tempConfig = copyConfig({}, config); 1268 | if (config._useUTC != null) { 1269 | tempConfig._useUTC = config._useUTC; 1270 | } 1271 | tempConfig._f = config._f[i]; 1272 | configFromStringAndFormat(tempConfig); 1273 | 1274 | if (!valid__isValid(tempConfig)) { 1275 | continue; 1276 | } 1277 | 1278 | // if there is any input that was not parsed add a penalty for that format 1279 | currentScore += getParsingFlags(tempConfig).charsLeftOver; 1280 | 1281 | //or tokens 1282 | currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10; 1283 | 1284 | getParsingFlags(tempConfig).score = currentScore; 1285 | 1286 | if (scoreToBeat == null || currentScore < scoreToBeat) { 1287 | scoreToBeat = currentScore; 1288 | bestMoment = tempConfig; 1289 | } 1290 | } 1291 | 1292 | extend(config, bestMoment || tempConfig); 1293 | } 1294 | 1295 | function configFromObject(config) { 1296 | if (config._d) { 1297 | return; 1298 | } 1299 | 1300 | var i = normalizeObjectUnits(config._i); 1301 | config._a = [i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond]; 1302 | 1303 | configFromArray(config); 1304 | } 1305 | 1306 | function createFromConfig (config) { 1307 | var res = new Moment(checkOverflow(prepareConfig(config))); 1308 | if (res._nextDay) { 1309 | // Adding is smart enough around DST 1310 | res.add(1, 'd'); 1311 | res._nextDay = undefined; 1312 | } 1313 | 1314 | return res; 1315 | } 1316 | 1317 | function prepareConfig (config) { 1318 | var input = config._i, 1319 | format = config._f; 1320 | 1321 | config._locale = config._locale || locale_locales__getLocale(config._l); 1322 | 1323 | if (input === null || (format === undefined && input === '')) { 1324 | return valid__createInvalid({nullInput: true}); 1325 | } 1326 | 1327 | if (typeof input === 'string') { 1328 | config._i = input = config._locale.preparse(input); 1329 | } 1330 | 1331 | if (isMoment(input)) { 1332 | return new Moment(checkOverflow(input)); 1333 | } else if (isArray(format)) { 1334 | configFromStringAndArray(config); 1335 | } else if (format) { 1336 | configFromStringAndFormat(config); 1337 | } else if (isDate(input)) { 1338 | config._d = input; 1339 | } else { 1340 | configFromInput(config); 1341 | } 1342 | 1343 | return config; 1344 | } 1345 | 1346 | function configFromInput(config) { 1347 | var input = config._i; 1348 | if (input === undefined) { 1349 | config._d = new Date(); 1350 | } else if (isDate(input)) { 1351 | config._d = new Date(+input); 1352 | } else if (typeof input === 'string') { 1353 | configFromString(config); 1354 | } else if (isArray(input)) { 1355 | config._a = map(input.slice(0), function (obj) { 1356 | return parseInt(obj, 10); 1357 | }); 1358 | configFromArray(config); 1359 | } else if (typeof(input) === 'object') { 1360 | configFromObject(config); 1361 | } else if (typeof(input) === 'number') { 1362 | // from milliseconds 1363 | config._d = new Date(input); 1364 | } else { 1365 | utils_hooks__hooks.createFromInputFallback(config); 1366 | } 1367 | } 1368 | 1369 | function createLocalOrUTC (input, format, locale, strict, isUTC) { 1370 | var c = {}; 1371 | 1372 | if (typeof(locale) === 'boolean') { 1373 | strict = locale; 1374 | locale = undefined; 1375 | } 1376 | // object construction must be done this way. 1377 | // https://github.com/moment/moment/issues/1423 1378 | c._isAMomentObject = true; 1379 | c._useUTC = c._isUTC = isUTC; 1380 | c._l = locale; 1381 | c._i = input; 1382 | c._f = format; 1383 | c._strict = strict; 1384 | 1385 | return createFromConfig(c); 1386 | } 1387 | 1388 | function local__createLocal (input, format, locale, strict) { 1389 | return createLocalOrUTC(input, format, locale, strict, false); 1390 | } 1391 | 1392 | var prototypeMin = deprecate( 1393 | 'moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548', 1394 | function () { 1395 | var other = local__createLocal.apply(null, arguments); 1396 | return other < this ? this : other; 1397 | } 1398 | ); 1399 | 1400 | var prototypeMax = deprecate( 1401 | 'moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548', 1402 | function () { 1403 | var other = local__createLocal.apply(null, arguments); 1404 | return other > this ? this : other; 1405 | } 1406 | ); 1407 | 1408 | // Pick a moment m from moments so that m[fn](other) is true for all 1409 | // other. This relies on the function fn to be transitive. 1410 | // 1411 | // moments should either be an array of moment objects or an array, whose 1412 | // first element is an array of moment objects. 1413 | function pickBy(fn, moments) { 1414 | var res, i; 1415 | if (moments.length === 1 && isArray(moments[0])) { 1416 | moments = moments[0]; 1417 | } 1418 | if (!moments.length) { 1419 | return local__createLocal(); 1420 | } 1421 | res = moments[0]; 1422 | for (i = 1; i < moments.length; ++i) { 1423 | if (!moments[i].isValid() || moments[i][fn](res)) { 1424 | res = moments[i]; 1425 | } 1426 | } 1427 | return res; 1428 | } 1429 | 1430 | // TODO: Use [].sort instead? 1431 | function min () { 1432 | var args = [].slice.call(arguments, 0); 1433 | 1434 | return pickBy('isBefore', args); 1435 | } 1436 | 1437 | function max () { 1438 | var args = [].slice.call(arguments, 0); 1439 | 1440 | return pickBy('isAfter', args); 1441 | } 1442 | 1443 | function Duration (duration) { 1444 | var normalizedInput = normalizeObjectUnits(duration), 1445 | years = normalizedInput.year || 0, 1446 | quarters = normalizedInput.quarter || 0, 1447 | months = normalizedInput.month || 0, 1448 | weeks = normalizedInput.week || 0, 1449 | days = normalizedInput.day || 0, 1450 | hours = normalizedInput.hour || 0, 1451 | minutes = normalizedInput.minute || 0, 1452 | seconds = normalizedInput.second || 0, 1453 | milliseconds = normalizedInput.millisecond || 0; 1454 | 1455 | // representation for dateAddRemove 1456 | this._milliseconds = +milliseconds + 1457 | seconds * 1e3 + // 1000 1458 | minutes * 6e4 + // 1000 * 60 1459 | hours * 36e5; // 1000 * 60 * 60 1460 | // Because of dateAddRemove treats 24 hours as different from a 1461 | // day when working around DST, we need to store them separately 1462 | this._days = +days + 1463 | weeks * 7; 1464 | // It is impossible translate months into days without knowing 1465 | // which months you are are talking about, so we have to store 1466 | // it separately. 1467 | this._months = +months + 1468 | quarters * 3 + 1469 | years * 12; 1470 | 1471 | this._data = {}; 1472 | 1473 | this._locale = locale_locales__getLocale(); 1474 | 1475 | this._bubble(); 1476 | } 1477 | 1478 | function isDuration (obj) { 1479 | return obj instanceof Duration; 1480 | } 1481 | 1482 | function offset (token, separator) { 1483 | addFormatToken(token, 0, 0, function () { 1484 | var offset = this.utcOffset(); 1485 | var sign = '+'; 1486 | if (offset < 0) { 1487 | offset = -offset; 1488 | sign = '-'; 1489 | } 1490 | return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2); 1491 | }); 1492 | } 1493 | 1494 | offset('Z', ':'); 1495 | offset('ZZ', ''); 1496 | 1497 | // PARSING 1498 | 1499 | addRegexToken('Z', matchOffset); 1500 | addRegexToken('ZZ', matchOffset); 1501 | addParseToken(['Z', 'ZZ'], function (input, array, config) { 1502 | config._useUTC = true; 1503 | config._tzm = offsetFromString(input); 1504 | }); 1505 | 1506 | // HELPERS 1507 | 1508 | // timezone chunker 1509 | // '+10:00' > ['10', '00'] 1510 | // '-1530' > ['-15', '30'] 1511 | var chunkOffset = /([\+\-]|\d\d)/gi; 1512 | 1513 | function offsetFromString(string) { 1514 | var matches = ((string || '').match(matchOffset) || []); 1515 | var chunk = matches[matches.length - 1] || []; 1516 | var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0]; 1517 | var minutes = +(parts[1] * 60) + toInt(parts[2]); 1518 | 1519 | return parts[0] === '+' ? minutes : -minutes; 1520 | } 1521 | 1522 | // Return a moment from input, that is local/utc/zone equivalent to model. 1523 | function cloneWithOffset(input, model) { 1524 | var res, diff; 1525 | if (model._isUTC) { 1526 | res = model.clone(); 1527 | diff = (isMoment(input) || isDate(input) ? +input : +local__createLocal(input)) - (+res); 1528 | // Use low-level api, because this fn is low-level api. 1529 | res._d.setTime(+res._d + diff); 1530 | utils_hooks__hooks.updateOffset(res, false); 1531 | return res; 1532 | } else { 1533 | return local__createLocal(input).local(); 1534 | } 1535 | } 1536 | 1537 | function getDateOffset (m) { 1538 | // On Firefox.24 Date#getTimezoneOffset returns a floating point. 1539 | // https://github.com/moment/moment/pull/1871 1540 | return -Math.round(m._d.getTimezoneOffset() / 15) * 15; 1541 | } 1542 | 1543 | // HOOKS 1544 | 1545 | // This function will be called whenever a moment is mutated. 1546 | // It is intended to keep the offset in sync with the timezone. 1547 | utils_hooks__hooks.updateOffset = function () {}; 1548 | 1549 | // MOMENTS 1550 | 1551 | // keepLocalTime = true means only change the timezone, without 1552 | // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]--> 1553 | // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset 1554 | // +0200, so we adjust the time as needed, to be valid. 1555 | // 1556 | // Keeping the time actually adds/subtracts (one hour) 1557 | // from the actual represented time. That is why we call updateOffset 1558 | // a second time. In case it wants us to change the offset again 1559 | // _changeInProgress == true case, then we have to adjust, because 1560 | // there is no such time in the given timezone. 1561 | function getSetOffset (input, keepLocalTime) { 1562 | var offset = this._offset || 0, 1563 | localAdjust; 1564 | if (input != null) { 1565 | if (typeof input === 'string') { 1566 | input = offsetFromString(input); 1567 | } 1568 | if (Math.abs(input) < 16) { 1569 | input = input * 60; 1570 | } 1571 | if (!this._isUTC && keepLocalTime) { 1572 | localAdjust = getDateOffset(this); 1573 | } 1574 | this._offset = input; 1575 | this._isUTC = true; 1576 | if (localAdjust != null) { 1577 | this.add(localAdjust, 'm'); 1578 | } 1579 | if (offset !== input) { 1580 | if (!keepLocalTime || this._changeInProgress) { 1581 | add_subtract__addSubtract(this, create__createDuration(input - offset, 'm'), 1, false); 1582 | } else if (!this._changeInProgress) { 1583 | this._changeInProgress = true; 1584 | utils_hooks__hooks.updateOffset(this, true); 1585 | this._changeInProgress = null; 1586 | } 1587 | } 1588 | return this; 1589 | } else { 1590 | return this._isUTC ? offset : getDateOffset(this); 1591 | } 1592 | } 1593 | 1594 | function getSetZone (input, keepLocalTime) { 1595 | if (input != null) { 1596 | if (typeof input !== 'string') { 1597 | input = -input; 1598 | } 1599 | 1600 | this.utcOffset(input, keepLocalTime); 1601 | 1602 | return this; 1603 | } else { 1604 | return -this.utcOffset(); 1605 | } 1606 | } 1607 | 1608 | function setOffsetToUTC (keepLocalTime) { 1609 | return this.utcOffset(0, keepLocalTime); 1610 | } 1611 | 1612 | function setOffsetToLocal (keepLocalTime) { 1613 | if (this._isUTC) { 1614 | this.utcOffset(0, keepLocalTime); 1615 | this._isUTC = false; 1616 | 1617 | if (keepLocalTime) { 1618 | this.subtract(getDateOffset(this), 'm'); 1619 | } 1620 | } 1621 | return this; 1622 | } 1623 | 1624 | function setOffsetToParsedOffset () { 1625 | if (this._tzm) { 1626 | this.utcOffset(this._tzm); 1627 | } else if (typeof this._i === 'string') { 1628 | this.utcOffset(offsetFromString(this._i)); 1629 | } 1630 | return this; 1631 | } 1632 | 1633 | function hasAlignedHourOffset (input) { 1634 | input = input ? local__createLocal(input).utcOffset() : 0; 1635 | 1636 | return (this.utcOffset() - input) % 60 === 0; 1637 | } 1638 | 1639 | function isDaylightSavingTime () { 1640 | return ( 1641 | this.utcOffset() > this.clone().month(0).utcOffset() || 1642 | this.utcOffset() > this.clone().month(5).utcOffset() 1643 | ); 1644 | } 1645 | 1646 | function isDaylightSavingTimeShifted () { 1647 | if (typeof this._isDSTShifted !== 'undefined') { 1648 | return this._isDSTShifted; 1649 | } 1650 | 1651 | var c = {}; 1652 | 1653 | copyConfig(c, this); 1654 | c = prepareConfig(c); 1655 | 1656 | if (c._a) { 1657 | var other = c._isUTC ? create_utc__createUTC(c._a) : local__createLocal(c._a); 1658 | this._isDSTShifted = this.isValid() && 1659 | compareArrays(c._a, other.toArray()) > 0; 1660 | } else { 1661 | this._isDSTShifted = false; 1662 | } 1663 | 1664 | return this._isDSTShifted; 1665 | } 1666 | 1667 | function isLocal () { 1668 | return !this._isUTC; 1669 | } 1670 | 1671 | function isUtcOffset () { 1672 | return this._isUTC; 1673 | } 1674 | 1675 | function isUtc () { 1676 | return this._isUTC && this._offset === 0; 1677 | } 1678 | 1679 | var aspNetRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/; 1680 | 1681 | // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html 1682 | // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere 1683 | var create__isoRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/; 1684 | 1685 | function create__createDuration (input, key) { 1686 | var duration = input, 1687 | // matching against regexp is expensive, do it on demand 1688 | match = null, 1689 | sign, 1690 | ret, 1691 | diffRes; 1692 | 1693 | if (isDuration(input)) { 1694 | duration = { 1695 | ms : input._milliseconds, 1696 | d : input._days, 1697 | M : input._months 1698 | }; 1699 | } else if (typeof input === 'number') { 1700 | duration = {}; 1701 | if (key) { 1702 | duration[key] = input; 1703 | } else { 1704 | duration.milliseconds = input; 1705 | } 1706 | } else if (!!(match = aspNetRegex.exec(input))) { 1707 | sign = (match[1] === '-') ? -1 : 1; 1708 | duration = { 1709 | y : 0, 1710 | d : toInt(match[DATE]) * sign, 1711 | h : toInt(match[HOUR]) * sign, 1712 | m : toInt(match[MINUTE]) * sign, 1713 | s : toInt(match[SECOND]) * sign, 1714 | ms : toInt(match[MILLISECOND]) * sign 1715 | }; 1716 | } else if (!!(match = create__isoRegex.exec(input))) { 1717 | sign = (match[1] === '-') ? -1 : 1; 1718 | duration = { 1719 | y : parseIso(match[2], sign), 1720 | M : parseIso(match[3], sign), 1721 | d : parseIso(match[4], sign), 1722 | h : parseIso(match[5], sign), 1723 | m : parseIso(match[6], sign), 1724 | s : parseIso(match[7], sign), 1725 | w : parseIso(match[8], sign) 1726 | }; 1727 | } else if (duration == null) {// checks for null or undefined 1728 | duration = {}; 1729 | } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) { 1730 | diffRes = momentsDifference(local__createLocal(duration.from), local__createLocal(duration.to)); 1731 | 1732 | duration = {}; 1733 | duration.ms = diffRes.milliseconds; 1734 | duration.M = diffRes.months; 1735 | } 1736 | 1737 | ret = new Duration(duration); 1738 | 1739 | if (isDuration(input) && hasOwnProp(input, '_locale')) { 1740 | ret._locale = input._locale; 1741 | } 1742 | 1743 | return ret; 1744 | } 1745 | 1746 | create__createDuration.fn = Duration.prototype; 1747 | 1748 | function parseIso (inp, sign) { 1749 | // We'd normally use ~~inp for this, but unfortunately it also 1750 | // converts floats to ints. 1751 | // inp may be undefined, so careful calling replace on it. 1752 | var res = inp && parseFloat(inp.replace(',', '.')); 1753 | // apply sign while we're at it 1754 | return (isNaN(res) ? 0 : res) * sign; 1755 | } 1756 | 1757 | function positiveMomentsDifference(base, other) { 1758 | var res = {milliseconds: 0, months: 0}; 1759 | 1760 | res.months = other.month() - base.month() + 1761 | (other.year() - base.year()) * 12; 1762 | if (base.clone().add(res.months, 'M').isAfter(other)) { 1763 | --res.months; 1764 | } 1765 | 1766 | res.milliseconds = +other - +(base.clone().add(res.months, 'M')); 1767 | 1768 | return res; 1769 | } 1770 | 1771 | function momentsDifference(base, other) { 1772 | var res; 1773 | other = cloneWithOffset(other, base); 1774 | if (base.isBefore(other)) { 1775 | res = positiveMomentsDifference(base, other); 1776 | } else { 1777 | res = positiveMomentsDifference(other, base); 1778 | res.milliseconds = -res.milliseconds; 1779 | res.months = -res.months; 1780 | } 1781 | 1782 | return res; 1783 | } 1784 | 1785 | function createAdder(direction, name) { 1786 | return function (val, period) { 1787 | var dur, tmp; 1788 | //invert the arguments, but complain about it 1789 | if (period !== null && !isNaN(+period)) { 1790 | deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period).'); 1791 | tmp = val; val = period; period = tmp; 1792 | } 1793 | 1794 | val = typeof val === 'string' ? +val : val; 1795 | dur = create__createDuration(val, period); 1796 | add_subtract__addSubtract(this, dur, direction); 1797 | return this; 1798 | }; 1799 | } 1800 | 1801 | function add_subtract__addSubtract (mom, duration, isAdding, updateOffset) { 1802 | var milliseconds = duration._milliseconds, 1803 | days = duration._days, 1804 | months = duration._months; 1805 | updateOffset = updateOffset == null ? true : updateOffset; 1806 | 1807 | if (milliseconds) { 1808 | mom._d.setTime(+mom._d + milliseconds * isAdding); 1809 | } 1810 | if (days) { 1811 | get_set__set(mom, 'Date', get_set__get(mom, 'Date') + days * isAdding); 1812 | } 1813 | if (months) { 1814 | setMonth(mom, get_set__get(mom, 'Month') + months * isAdding); 1815 | } 1816 | if (updateOffset) { 1817 | utils_hooks__hooks.updateOffset(mom, days || months); 1818 | } 1819 | } 1820 | 1821 | var add_subtract__add = createAdder(1, 'add'); 1822 | var add_subtract__subtract = createAdder(-1, 'subtract'); 1823 | 1824 | function moment_calendar__calendar (time, formats) { 1825 | // We want to compare the start of today, vs this. 1826 | // Getting start-of-today depends on whether we're local/utc/offset or not. 1827 | var now = time || local__createLocal(), 1828 | sod = cloneWithOffset(now, this).startOf('day'), 1829 | diff = this.diff(sod, 'days', true), 1830 | format = diff < -6 ? 'sameElse' : 1831 | diff < -1 ? 'lastWeek' : 1832 | diff < 0 ? 'lastDay' : 1833 | diff < 1 ? 'sameDay' : 1834 | diff < 2 ? 'nextDay' : 1835 | diff < 7 ? 'nextWeek' : 'sameElse'; 1836 | return this.format(formats && formats[format] || this.localeData().calendar(format, this, local__createLocal(now))); 1837 | } 1838 | 1839 | function clone () { 1840 | return new Moment(this); 1841 | } 1842 | 1843 | function isAfter (input, units) { 1844 | var inputMs; 1845 | units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond'); 1846 | if (units === 'millisecond') { 1847 | input = isMoment(input) ? input : local__createLocal(input); 1848 | return +this > +input; 1849 | } else { 1850 | inputMs = isMoment(input) ? +input : +local__createLocal(input); 1851 | return inputMs < +this.clone().startOf(units); 1852 | } 1853 | } 1854 | 1855 | function isBefore (input, units) { 1856 | var inputMs; 1857 | units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond'); 1858 | if (units === 'millisecond') { 1859 | input = isMoment(input) ? input : local__createLocal(input); 1860 | return +this < +input; 1861 | } else { 1862 | inputMs = isMoment(input) ? +input : +local__createLocal(input); 1863 | return +this.clone().endOf(units) < inputMs; 1864 | } 1865 | } 1866 | 1867 | function isBetween (from, to, units) { 1868 | return this.isAfter(from, units) && this.isBefore(to, units); 1869 | } 1870 | 1871 | function isSame (input, units) { 1872 | var inputMs; 1873 | units = normalizeUnits(units || 'millisecond'); 1874 | if (units === 'millisecond') { 1875 | input = isMoment(input) ? input : local__createLocal(input); 1876 | return +this === +input; 1877 | } else { 1878 | inputMs = +local__createLocal(input); 1879 | return +(this.clone().startOf(units)) <= inputMs && inputMs <= +(this.clone().endOf(units)); 1880 | } 1881 | } 1882 | 1883 | function diff (input, units, asFloat) { 1884 | var that = cloneWithOffset(input, this), 1885 | zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4, 1886 | delta, output; 1887 | 1888 | units = normalizeUnits(units); 1889 | 1890 | if (units === 'year' || units === 'month' || units === 'quarter') { 1891 | output = monthDiff(this, that); 1892 | if (units === 'quarter') { 1893 | output = output / 3; 1894 | } else if (units === 'year') { 1895 | output = output / 12; 1896 | } 1897 | } else { 1898 | delta = this - that; 1899 | output = units === 'second' ? delta / 1e3 : // 1000 1900 | units === 'minute' ? delta / 6e4 : // 1000 * 60 1901 | units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60 1902 | units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst 1903 | units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst 1904 | delta; 1905 | } 1906 | return asFloat ? output : absFloor(output); 1907 | } 1908 | 1909 | function monthDiff (a, b) { 1910 | // difference in months 1911 | var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()), 1912 | // b is in (anchor - 1 month, anchor + 1 month) 1913 | anchor = a.clone().add(wholeMonthDiff, 'months'), 1914 | anchor2, adjust; 1915 | 1916 | if (b - anchor < 0) { 1917 | anchor2 = a.clone().add(wholeMonthDiff - 1, 'months'); 1918 | // linear across the month 1919 | adjust = (b - anchor) / (anchor - anchor2); 1920 | } else { 1921 | anchor2 = a.clone().add(wholeMonthDiff + 1, 'months'); 1922 | // linear across the month 1923 | adjust = (b - anchor) / (anchor2 - anchor); 1924 | } 1925 | 1926 | return -(wholeMonthDiff + adjust); 1927 | } 1928 | 1929 | utils_hooks__hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ'; 1930 | 1931 | function toString () { 1932 | return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ'); 1933 | } 1934 | 1935 | function moment_format__toISOString () { 1936 | var m = this.clone().utc(); 1937 | if (0 < m.year() && m.year() <= 9999) { 1938 | if ('function' === typeof Date.prototype.toISOString) { 1939 | // native implementation is ~50x faster, use it when we can 1940 | return this.toDate().toISOString(); 1941 | } else { 1942 | return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]'); 1943 | } 1944 | } else { 1945 | return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]'); 1946 | } 1947 | } 1948 | 1949 | function format (inputString) { 1950 | var output = formatMoment(this, inputString || utils_hooks__hooks.defaultFormat); 1951 | return this.localeData().postformat(output); 1952 | } 1953 | 1954 | function from (time, withoutSuffix) { 1955 | if (!this.isValid()) { 1956 | return this.localeData().invalidDate(); 1957 | } 1958 | return create__createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix); 1959 | } 1960 | 1961 | function fromNow (withoutSuffix) { 1962 | return this.from(local__createLocal(), withoutSuffix); 1963 | } 1964 | 1965 | function to (time, withoutSuffix) { 1966 | if (!this.isValid()) { 1967 | return this.localeData().invalidDate(); 1968 | } 1969 | return create__createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix); 1970 | } 1971 | 1972 | function toNow (withoutSuffix) { 1973 | return this.to(local__createLocal(), withoutSuffix); 1974 | } 1975 | 1976 | function locale (key) { 1977 | var newLocaleData; 1978 | 1979 | if (key === undefined) { 1980 | return this._locale._abbr; 1981 | } else { 1982 | newLocaleData = locale_locales__getLocale(key); 1983 | if (newLocaleData != null) { 1984 | this._locale = newLocaleData; 1985 | } 1986 | return this; 1987 | } 1988 | } 1989 | 1990 | var lang = deprecate( 1991 | 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.', 1992 | function (key) { 1993 | if (key === undefined) { 1994 | return this.localeData(); 1995 | } else { 1996 | return this.locale(key); 1997 | } 1998 | } 1999 | ); 2000 | 2001 | function localeData () { 2002 | return this._locale; 2003 | } 2004 | 2005 | function startOf (units) { 2006 | units = normalizeUnits(units); 2007 | // the following switch intentionally omits break keywords 2008 | // to utilize falling through the cases. 2009 | switch (units) { 2010 | case 'year': 2011 | this.month(0); 2012 | /* falls through */ 2013 | case 'quarter': 2014 | case 'month': 2015 | this.date(1); 2016 | /* falls through */ 2017 | case 'week': 2018 | case 'isoWeek': 2019 | case 'day': 2020 | this.hours(0); 2021 | /* falls through */ 2022 | case 'hour': 2023 | this.minutes(0); 2024 | /* falls through */ 2025 | case 'minute': 2026 | this.seconds(0); 2027 | /* falls through */ 2028 | case 'second': 2029 | this.milliseconds(0); 2030 | } 2031 | 2032 | // weeks are a special case 2033 | if (units === 'week') { 2034 | this.weekday(0); 2035 | } 2036 | if (units === 'isoWeek') { 2037 | this.isoWeekday(1); 2038 | } 2039 | 2040 | // quarters are also special 2041 | if (units === 'quarter') { 2042 | this.month(Math.floor(this.month() / 3) * 3); 2043 | } 2044 | 2045 | return this; 2046 | } 2047 | 2048 | function endOf (units) { 2049 | units = normalizeUnits(units); 2050 | if (units === undefined || units === 'millisecond') { 2051 | return this; 2052 | } 2053 | return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms'); 2054 | } 2055 | 2056 | function to_type__valueOf () { 2057 | return +this._d - ((this._offset || 0) * 60000); 2058 | } 2059 | 2060 | function unix () { 2061 | return Math.floor(+this / 1000); 2062 | } 2063 | 2064 | function toDate () { 2065 | return this._offset ? new Date(+this) : this._d; 2066 | } 2067 | 2068 | function toArray () { 2069 | var m = this; 2070 | return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()]; 2071 | } 2072 | 2073 | function toObject () { 2074 | var m = this; 2075 | return { 2076 | years: m.year(), 2077 | months: m.month(), 2078 | date: m.date(), 2079 | hours: m.hours(), 2080 | minutes: m.minutes(), 2081 | seconds: m.seconds(), 2082 | milliseconds: m.milliseconds() 2083 | }; 2084 | } 2085 | 2086 | function moment_valid__isValid () { 2087 | return valid__isValid(this); 2088 | } 2089 | 2090 | function parsingFlags () { 2091 | return extend({}, getParsingFlags(this)); 2092 | } 2093 | 2094 | function invalidAt () { 2095 | return getParsingFlags(this).overflow; 2096 | } 2097 | 2098 | addFormatToken(0, ['gg', 2], 0, function () { 2099 | return this.weekYear() % 100; 2100 | }); 2101 | 2102 | addFormatToken(0, ['GG', 2], 0, function () { 2103 | return this.isoWeekYear() % 100; 2104 | }); 2105 | 2106 | function addWeekYearFormatToken (token, getter) { 2107 | addFormatToken(0, [token, token.length], 0, getter); 2108 | } 2109 | 2110 | addWeekYearFormatToken('gggg', 'weekYear'); 2111 | addWeekYearFormatToken('ggggg', 'weekYear'); 2112 | addWeekYearFormatToken('GGGG', 'isoWeekYear'); 2113 | addWeekYearFormatToken('GGGGG', 'isoWeekYear'); 2114 | 2115 | // ALIASES 2116 | 2117 | addUnitAlias('weekYear', 'gg'); 2118 | addUnitAlias('isoWeekYear', 'GG'); 2119 | 2120 | // PARSING 2121 | 2122 | addRegexToken('G', matchSigned); 2123 | addRegexToken('g', matchSigned); 2124 | addRegexToken('GG', match1to2, match2); 2125 | addRegexToken('gg', match1to2, match2); 2126 | addRegexToken('GGGG', match1to4, match4); 2127 | addRegexToken('gggg', match1to4, match4); 2128 | addRegexToken('GGGGG', match1to6, match6); 2129 | addRegexToken('ggggg', match1to6, match6); 2130 | 2131 | addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) { 2132 | week[token.substr(0, 2)] = toInt(input); 2133 | }); 2134 | 2135 | addWeekParseToken(['gg', 'GG'], function (input, week, config, token) { 2136 | week[token] = utils_hooks__hooks.parseTwoDigitYear(input); 2137 | }); 2138 | 2139 | // HELPERS 2140 | 2141 | function weeksInYear(year, dow, doy) { 2142 | return weekOfYear(local__createLocal([year, 11, 31 + dow - doy]), dow, doy).week; 2143 | } 2144 | 2145 | // MOMENTS 2146 | 2147 | function getSetWeekYear (input) { 2148 | var year = weekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year; 2149 | return input == null ? year : this.add((input - year), 'y'); 2150 | } 2151 | 2152 | function getSetISOWeekYear (input) { 2153 | var year = weekOfYear(this, 1, 4).year; 2154 | return input == null ? year : this.add((input - year), 'y'); 2155 | } 2156 | 2157 | function getISOWeeksInYear () { 2158 | return weeksInYear(this.year(), 1, 4); 2159 | } 2160 | 2161 | function getWeeksInYear () { 2162 | var weekInfo = this.localeData()._week; 2163 | return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy); 2164 | } 2165 | 2166 | addFormatToken('Q', 0, 0, 'quarter'); 2167 | 2168 | // ALIASES 2169 | 2170 | addUnitAlias('quarter', 'Q'); 2171 | 2172 | // PARSING 2173 | 2174 | addRegexToken('Q', match1); 2175 | addParseToken('Q', function (input, array) { 2176 | array[MONTH] = (toInt(input) - 1) * 3; 2177 | }); 2178 | 2179 | // MOMENTS 2180 | 2181 | function getSetQuarter (input) { 2182 | return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3); 2183 | } 2184 | 2185 | addFormatToken('D', ['DD', 2], 'Do', 'date'); 2186 | 2187 | // ALIASES 2188 | 2189 | addUnitAlias('date', 'D'); 2190 | 2191 | // PARSING 2192 | 2193 | addRegexToken('D', match1to2); 2194 | addRegexToken('DD', match1to2, match2); 2195 | addRegexToken('Do', function (isStrict, locale) { 2196 | return isStrict ? locale._ordinalParse : locale._ordinalParseLenient; 2197 | }); 2198 | 2199 | addParseToken(['D', 'DD'], DATE); 2200 | addParseToken('Do', function (input, array) { 2201 | array[DATE] = toInt(input.match(match1to2)[0], 10); 2202 | }); 2203 | 2204 | // MOMENTS 2205 | 2206 | var getSetDayOfMonth = makeGetSet('Date', true); 2207 | 2208 | addFormatToken('d', 0, 'do', 'day'); 2209 | 2210 | addFormatToken('dd', 0, 0, function (format) { 2211 | return this.localeData().weekdaysMin(this, format); 2212 | }); 2213 | 2214 | addFormatToken('ddd', 0, 0, function (format) { 2215 | return this.localeData().weekdaysShort(this, format); 2216 | }); 2217 | 2218 | addFormatToken('dddd', 0, 0, function (format) { 2219 | return this.localeData().weekdays(this, format); 2220 | }); 2221 | 2222 | addFormatToken('e', 0, 0, 'weekday'); 2223 | addFormatToken('E', 0, 0, 'isoWeekday'); 2224 | 2225 | // ALIASES 2226 | 2227 | addUnitAlias('day', 'd'); 2228 | addUnitAlias('weekday', 'e'); 2229 | addUnitAlias('isoWeekday', 'E'); 2230 | 2231 | // PARSING 2232 | 2233 | addRegexToken('d', match1to2); 2234 | addRegexToken('e', match1to2); 2235 | addRegexToken('E', match1to2); 2236 | addRegexToken('dd', matchWord); 2237 | addRegexToken('ddd', matchWord); 2238 | addRegexToken('dddd', matchWord); 2239 | 2240 | addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config) { 2241 | var weekday = config._locale.weekdaysParse(input); 2242 | // if we didn't get a weekday name, mark the date as invalid 2243 | if (weekday != null) { 2244 | week.d = weekday; 2245 | } else { 2246 | getParsingFlags(config).invalidWeekday = input; 2247 | } 2248 | }); 2249 | 2250 | addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) { 2251 | week[token] = toInt(input); 2252 | }); 2253 | 2254 | // HELPERS 2255 | 2256 | function parseWeekday(input, locale) { 2257 | if (typeof input !== 'string') { 2258 | return input; 2259 | } 2260 | 2261 | if (!isNaN(input)) { 2262 | return parseInt(input, 10); 2263 | } 2264 | 2265 | input = locale.weekdaysParse(input); 2266 | if (typeof input === 'number') { 2267 | return input; 2268 | } 2269 | 2270 | return null; 2271 | } 2272 | 2273 | // LOCALES 2274 | 2275 | var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'); 2276 | function localeWeekdays (m) { 2277 | return this._weekdays[m.day()]; 2278 | } 2279 | 2280 | var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'); 2281 | function localeWeekdaysShort (m) { 2282 | return this._weekdaysShort[m.day()]; 2283 | } 2284 | 2285 | var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'); 2286 | function localeWeekdaysMin (m) { 2287 | return this._weekdaysMin[m.day()]; 2288 | } 2289 | 2290 | function localeWeekdaysParse (weekdayName) { 2291 | var i, mom, regex; 2292 | 2293 | this._weekdaysParse = this._weekdaysParse || []; 2294 | 2295 | for (i = 0; i < 7; i++) { 2296 | // make the regex if we don't have it already 2297 | if (!this._weekdaysParse[i]) { 2298 | mom = local__createLocal([2000, 1]).day(i); 2299 | regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, ''); 2300 | this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i'); 2301 | } 2302 | // test the regex 2303 | if (this._weekdaysParse[i].test(weekdayName)) { 2304 | return i; 2305 | } 2306 | } 2307 | } 2308 | 2309 | // MOMENTS 2310 | 2311 | function getSetDayOfWeek (input) { 2312 | var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay(); 2313 | if (input != null) { 2314 | input = parseWeekday(input, this.localeData()); 2315 | return this.add(input - day, 'd'); 2316 | } else { 2317 | return day; 2318 | } 2319 | } 2320 | 2321 | function getSetLocaleDayOfWeek (input) { 2322 | var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7; 2323 | return input == null ? weekday : this.add(input - weekday, 'd'); 2324 | } 2325 | 2326 | function getSetISODayOfWeek (input) { 2327 | // behaves the same as moment#day except 2328 | // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6) 2329 | // as a setter, sunday should belong to the previous week. 2330 | return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7); 2331 | } 2332 | 2333 | addFormatToken('H', ['HH', 2], 0, 'hour'); 2334 | addFormatToken('h', ['hh', 2], 0, function () { 2335 | return this.hours() % 12 || 12; 2336 | }); 2337 | 2338 | function meridiem (token, lowercase) { 2339 | addFormatToken(token, 0, 0, function () { 2340 | return this.localeData().meridiem(this.hours(), this.minutes(), lowercase); 2341 | }); 2342 | } 2343 | 2344 | meridiem('a', true); 2345 | meridiem('A', false); 2346 | 2347 | // ALIASES 2348 | 2349 | addUnitAlias('hour', 'h'); 2350 | 2351 | // PARSING 2352 | 2353 | function matchMeridiem (isStrict, locale) { 2354 | return locale._meridiemParse; 2355 | } 2356 | 2357 | addRegexToken('a', matchMeridiem); 2358 | addRegexToken('A', matchMeridiem); 2359 | addRegexToken('H', match1to2); 2360 | addRegexToken('h', match1to2); 2361 | addRegexToken('HH', match1to2, match2); 2362 | addRegexToken('hh', match1to2, match2); 2363 | 2364 | addParseToken(['H', 'HH'], HOUR); 2365 | addParseToken(['a', 'A'], function (input, array, config) { 2366 | config._isPm = config._locale.isPM(input); 2367 | config._meridiem = input; 2368 | }); 2369 | addParseToken(['h', 'hh'], function (input, array, config) { 2370 | array[HOUR] = toInt(input); 2371 | getParsingFlags(config).bigHour = true; 2372 | }); 2373 | 2374 | // LOCALES 2375 | 2376 | function localeIsPM (input) { 2377 | // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays 2378 | // Using charAt should be more compatible. 2379 | return ((input + '').toLowerCase().charAt(0) === 'p'); 2380 | } 2381 | 2382 | var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i; 2383 | function localeMeridiem (hours, minutes, isLower) { 2384 | if (hours > 11) { 2385 | return isLower ? 'pm' : 'PM'; 2386 | } else { 2387 | return isLower ? 'am' : 'AM'; 2388 | } 2389 | } 2390 | 2391 | 2392 | // MOMENTS 2393 | 2394 | // Setting the hour should keep the time, because the user explicitly 2395 | // specified which hour he wants. So trying to maintain the same hour (in 2396 | // a new timezone) makes sense. Adding/subtracting hours does not follow 2397 | // this rule. 2398 | var getSetHour = makeGetSet('Hours', true); 2399 | 2400 | addFormatToken('m', ['mm', 2], 0, 'minute'); 2401 | 2402 | // ALIASES 2403 | 2404 | addUnitAlias('minute', 'm'); 2405 | 2406 | // PARSING 2407 | 2408 | addRegexToken('m', match1to2); 2409 | addRegexToken('mm', match1to2, match2); 2410 | addParseToken(['m', 'mm'], MINUTE); 2411 | 2412 | // MOMENTS 2413 | 2414 | var getSetMinute = makeGetSet('Minutes', false); 2415 | 2416 | addFormatToken('s', ['ss', 2], 0, 'second'); 2417 | 2418 | // ALIASES 2419 | 2420 | addUnitAlias('second', 's'); 2421 | 2422 | // PARSING 2423 | 2424 | addRegexToken('s', match1to2); 2425 | addRegexToken('ss', match1to2, match2); 2426 | addParseToken(['s', 'ss'], SECOND); 2427 | 2428 | // MOMENTS 2429 | 2430 | var getSetSecond = makeGetSet('Seconds', false); 2431 | 2432 | addFormatToken('S', 0, 0, function () { 2433 | return ~~(this.millisecond() / 100); 2434 | }); 2435 | 2436 | addFormatToken(0, ['SS', 2], 0, function () { 2437 | return ~~(this.millisecond() / 10); 2438 | }); 2439 | 2440 | addFormatToken(0, ['SSS', 3], 0, 'millisecond'); 2441 | addFormatToken(0, ['SSSS', 4], 0, function () { 2442 | return this.millisecond() * 10; 2443 | }); 2444 | addFormatToken(0, ['SSSSS', 5], 0, function () { 2445 | return this.millisecond() * 100; 2446 | }); 2447 | addFormatToken(0, ['SSSSSS', 6], 0, function () { 2448 | return this.millisecond() * 1000; 2449 | }); 2450 | addFormatToken(0, ['SSSSSSS', 7], 0, function () { 2451 | return this.millisecond() * 10000; 2452 | }); 2453 | addFormatToken(0, ['SSSSSSSS', 8], 0, function () { 2454 | return this.millisecond() * 100000; 2455 | }); 2456 | addFormatToken(0, ['SSSSSSSSS', 9], 0, function () { 2457 | return this.millisecond() * 1000000; 2458 | }); 2459 | 2460 | 2461 | // ALIASES 2462 | 2463 | addUnitAlias('millisecond', 'ms'); 2464 | 2465 | // PARSING 2466 | 2467 | addRegexToken('S', match1to3, match1); 2468 | addRegexToken('SS', match1to3, match2); 2469 | addRegexToken('SSS', match1to3, match3); 2470 | 2471 | var token; 2472 | for (token = 'SSSS'; token.length <= 9; token += 'S') { 2473 | addRegexToken(token, matchUnsigned); 2474 | } 2475 | 2476 | function parseMs(input, array) { 2477 | array[MILLISECOND] = toInt(('0.' + input) * 1000); 2478 | } 2479 | 2480 | for (token = 'S'; token.length <= 9; token += 'S') { 2481 | addParseToken(token, parseMs); 2482 | } 2483 | // MOMENTS 2484 | 2485 | var getSetMillisecond = makeGetSet('Milliseconds', false); 2486 | 2487 | addFormatToken('z', 0, 0, 'zoneAbbr'); 2488 | addFormatToken('zz', 0, 0, 'zoneName'); 2489 | 2490 | // MOMENTS 2491 | 2492 | function getZoneAbbr () { 2493 | return this._isUTC ? 'UTC' : ''; 2494 | } 2495 | 2496 | function getZoneName () { 2497 | return this._isUTC ? 'Coordinated Universal Time' : ''; 2498 | } 2499 | 2500 | var momentPrototype__proto = Moment.prototype; 2501 | 2502 | momentPrototype__proto.add = add_subtract__add; 2503 | momentPrototype__proto.calendar = moment_calendar__calendar; 2504 | momentPrototype__proto.clone = clone; 2505 | momentPrototype__proto.diff = diff; 2506 | momentPrototype__proto.endOf = endOf; 2507 | momentPrototype__proto.format = format; 2508 | momentPrototype__proto.from = from; 2509 | momentPrototype__proto.fromNow = fromNow; 2510 | momentPrototype__proto.to = to; 2511 | momentPrototype__proto.toNow = toNow; 2512 | momentPrototype__proto.get = getSet; 2513 | momentPrototype__proto.invalidAt = invalidAt; 2514 | momentPrototype__proto.isAfter = isAfter; 2515 | momentPrototype__proto.isBefore = isBefore; 2516 | momentPrototype__proto.isBetween = isBetween; 2517 | momentPrototype__proto.isSame = isSame; 2518 | momentPrototype__proto.isValid = moment_valid__isValid; 2519 | momentPrototype__proto.lang = lang; 2520 | momentPrototype__proto.locale = locale; 2521 | momentPrototype__proto.localeData = localeData; 2522 | momentPrototype__proto.max = prototypeMax; 2523 | momentPrototype__proto.min = prototypeMin; 2524 | momentPrototype__proto.parsingFlags = parsingFlags; 2525 | momentPrototype__proto.set = getSet; 2526 | momentPrototype__proto.startOf = startOf; 2527 | momentPrototype__proto.subtract = add_subtract__subtract; 2528 | momentPrototype__proto.toArray = toArray; 2529 | momentPrototype__proto.toObject = toObject; 2530 | momentPrototype__proto.toDate = toDate; 2531 | momentPrototype__proto.toISOString = moment_format__toISOString; 2532 | momentPrototype__proto.toJSON = moment_format__toISOString; 2533 | momentPrototype__proto.toString = toString; 2534 | momentPrototype__proto.unix = unix; 2535 | momentPrototype__proto.valueOf = to_type__valueOf; 2536 | 2537 | // Year 2538 | momentPrototype__proto.year = getSetYear; 2539 | momentPrototype__proto.isLeapYear = getIsLeapYear; 2540 | 2541 | // Week Year 2542 | momentPrototype__proto.weekYear = getSetWeekYear; 2543 | momentPrototype__proto.isoWeekYear = getSetISOWeekYear; 2544 | 2545 | // Quarter 2546 | momentPrototype__proto.quarter = momentPrototype__proto.quarters = getSetQuarter; 2547 | 2548 | // Month 2549 | momentPrototype__proto.month = getSetMonth; 2550 | momentPrototype__proto.daysInMonth = getDaysInMonth; 2551 | 2552 | // Week 2553 | momentPrototype__proto.week = momentPrototype__proto.weeks = getSetWeek; 2554 | momentPrototype__proto.isoWeek = momentPrototype__proto.isoWeeks = getSetISOWeek; 2555 | momentPrototype__proto.weeksInYear = getWeeksInYear; 2556 | momentPrototype__proto.isoWeeksInYear = getISOWeeksInYear; 2557 | 2558 | // Day 2559 | momentPrototype__proto.date = getSetDayOfMonth; 2560 | momentPrototype__proto.day = momentPrototype__proto.days = getSetDayOfWeek; 2561 | momentPrototype__proto.weekday = getSetLocaleDayOfWeek; 2562 | momentPrototype__proto.isoWeekday = getSetISODayOfWeek; 2563 | momentPrototype__proto.dayOfYear = getSetDayOfYear; 2564 | 2565 | // Hour 2566 | momentPrototype__proto.hour = momentPrototype__proto.hours = getSetHour; 2567 | 2568 | // Minute 2569 | momentPrototype__proto.minute = momentPrototype__proto.minutes = getSetMinute; 2570 | 2571 | // Second 2572 | momentPrototype__proto.second = momentPrototype__proto.seconds = getSetSecond; 2573 | 2574 | // Millisecond 2575 | momentPrototype__proto.millisecond = momentPrototype__proto.milliseconds = getSetMillisecond; 2576 | 2577 | // Offset 2578 | momentPrototype__proto.utcOffset = getSetOffset; 2579 | momentPrototype__proto.utc = setOffsetToUTC; 2580 | momentPrototype__proto.local = setOffsetToLocal; 2581 | momentPrototype__proto.parseZone = setOffsetToParsedOffset; 2582 | momentPrototype__proto.hasAlignedHourOffset = hasAlignedHourOffset; 2583 | momentPrototype__proto.isDST = isDaylightSavingTime; 2584 | momentPrototype__proto.isDSTShifted = isDaylightSavingTimeShifted; 2585 | momentPrototype__proto.isLocal = isLocal; 2586 | momentPrototype__proto.isUtcOffset = isUtcOffset; 2587 | momentPrototype__proto.isUtc = isUtc; 2588 | momentPrototype__proto.isUTC = isUtc; 2589 | 2590 | // Timezone 2591 | momentPrototype__proto.zoneAbbr = getZoneAbbr; 2592 | momentPrototype__proto.zoneName = getZoneName; 2593 | 2594 | // Deprecations 2595 | momentPrototype__proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth); 2596 | momentPrototype__proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth); 2597 | momentPrototype__proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear); 2598 | momentPrototype__proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779', getSetZone); 2599 | 2600 | var momentPrototype = momentPrototype__proto; 2601 | 2602 | function moment__createUnix (input) { 2603 | return local__createLocal(input * 1000); 2604 | } 2605 | 2606 | function moment__createInZone () { 2607 | return local__createLocal.apply(null, arguments).parseZone(); 2608 | } 2609 | 2610 | var defaultCalendar = { 2611 | sameDay : '[Today at] LT', 2612 | nextDay : '[Tomorrow at] LT', 2613 | nextWeek : 'dddd [at] LT', 2614 | lastDay : '[Yesterday at] LT', 2615 | lastWeek : '[Last] dddd [at] LT', 2616 | sameElse : 'L' 2617 | }; 2618 | 2619 | function locale_calendar__calendar (key, mom, now) { 2620 | var output = this._calendar[key]; 2621 | return typeof output === 'function' ? output.call(mom, now) : output; 2622 | } 2623 | 2624 | var defaultLongDateFormat = { 2625 | LTS : 'h:mm:ss A', 2626 | LT : 'h:mm A', 2627 | L : 'MM/DD/YYYY', 2628 | LL : 'MMMM D, YYYY', 2629 | LLL : 'MMMM D, YYYY h:mm A', 2630 | LLLL : 'dddd, MMMM D, YYYY h:mm A' 2631 | }; 2632 | 2633 | function longDateFormat (key) { 2634 | var format = this._longDateFormat[key], 2635 | formatUpper = this._longDateFormat[key.toUpperCase()]; 2636 | 2637 | if (format || !formatUpper) { 2638 | return format; 2639 | } 2640 | 2641 | this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) { 2642 | return val.slice(1); 2643 | }); 2644 | 2645 | return this._longDateFormat[key]; 2646 | } 2647 | 2648 | var defaultInvalidDate = 'Invalid date'; 2649 | 2650 | function invalidDate () { 2651 | return this._invalidDate; 2652 | } 2653 | 2654 | var defaultOrdinal = '%d'; 2655 | var defaultOrdinalParse = /\d{1,2}/; 2656 | 2657 | function ordinal (number) { 2658 | return this._ordinal.replace('%d', number); 2659 | } 2660 | 2661 | function preParsePostFormat (string) { 2662 | return string; 2663 | } 2664 | 2665 | var defaultRelativeTime = { 2666 | future : 'in %s', 2667 | past : '%s ago', 2668 | s : 'a few seconds', 2669 | m : 'a minute', 2670 | mm : '%d minutes', 2671 | h : 'an hour', 2672 | hh : '%d hours', 2673 | d : 'a day', 2674 | dd : '%d days', 2675 | M : 'a month', 2676 | MM : '%d months', 2677 | y : 'a year', 2678 | yy : '%d years' 2679 | }; 2680 | 2681 | function relative__relativeTime (number, withoutSuffix, string, isFuture) { 2682 | var output = this._relativeTime[string]; 2683 | return (typeof output === 'function') ? 2684 | output(number, withoutSuffix, string, isFuture) : 2685 | output.replace(/%d/i, number); 2686 | } 2687 | 2688 | function pastFuture (diff, output) { 2689 | var format = this._relativeTime[diff > 0 ? 'future' : 'past']; 2690 | return typeof format === 'function' ? format(output) : format.replace(/%s/i, output); 2691 | } 2692 | 2693 | function locale_set__set (config) { 2694 | var prop, i; 2695 | for (i in config) { 2696 | prop = config[i]; 2697 | if (typeof prop === 'function') { 2698 | this[i] = prop; 2699 | } else { 2700 | this['_' + i] = prop; 2701 | } 2702 | } 2703 | // Lenient ordinal parsing accepts just a number in addition to 2704 | // number + (possibly) stuff coming from _ordinalParseLenient. 2705 | this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + (/\d{1,2}/).source); 2706 | } 2707 | 2708 | var prototype__proto = Locale.prototype; 2709 | 2710 | prototype__proto._calendar = defaultCalendar; 2711 | prototype__proto.calendar = locale_calendar__calendar; 2712 | prototype__proto._longDateFormat = defaultLongDateFormat; 2713 | prototype__proto.longDateFormat = longDateFormat; 2714 | prototype__proto._invalidDate = defaultInvalidDate; 2715 | prototype__proto.invalidDate = invalidDate; 2716 | prototype__proto._ordinal = defaultOrdinal; 2717 | prototype__proto.ordinal = ordinal; 2718 | prototype__proto._ordinalParse = defaultOrdinalParse; 2719 | prototype__proto.preparse = preParsePostFormat; 2720 | prototype__proto.postformat = preParsePostFormat; 2721 | prototype__proto._relativeTime = defaultRelativeTime; 2722 | prototype__proto.relativeTime = relative__relativeTime; 2723 | prototype__proto.pastFuture = pastFuture; 2724 | prototype__proto.set = locale_set__set; 2725 | 2726 | // Month 2727 | prototype__proto.months = localeMonths; 2728 | prototype__proto._months = defaultLocaleMonths; 2729 | prototype__proto.monthsShort = localeMonthsShort; 2730 | prototype__proto._monthsShort = defaultLocaleMonthsShort; 2731 | prototype__proto.monthsParse = localeMonthsParse; 2732 | 2733 | // Week 2734 | prototype__proto.week = localeWeek; 2735 | prototype__proto._week = defaultLocaleWeek; 2736 | prototype__proto.firstDayOfYear = localeFirstDayOfYear; 2737 | prototype__proto.firstDayOfWeek = localeFirstDayOfWeek; 2738 | 2739 | // Day of Week 2740 | prototype__proto.weekdays = localeWeekdays; 2741 | prototype__proto._weekdays = defaultLocaleWeekdays; 2742 | prototype__proto.weekdaysMin = localeWeekdaysMin; 2743 | prototype__proto._weekdaysMin = defaultLocaleWeekdaysMin; 2744 | prototype__proto.weekdaysShort = localeWeekdaysShort; 2745 | prototype__proto._weekdaysShort = defaultLocaleWeekdaysShort; 2746 | prototype__proto.weekdaysParse = localeWeekdaysParse; 2747 | 2748 | // Hours 2749 | prototype__proto.isPM = localeIsPM; 2750 | prototype__proto._meridiemParse = defaultLocaleMeridiemParse; 2751 | prototype__proto.meridiem = localeMeridiem; 2752 | 2753 | function lists__get (format, index, field, setter) { 2754 | var locale = locale_locales__getLocale(); 2755 | var utc = create_utc__createUTC().set(setter, index); 2756 | return locale[field](utc, format); 2757 | } 2758 | 2759 | function list (format, index, field, count, setter) { 2760 | if (typeof format === 'number') { 2761 | index = format; 2762 | format = undefined; 2763 | } 2764 | 2765 | format = format || ''; 2766 | 2767 | if (index != null) { 2768 | return lists__get(format, index, field, setter); 2769 | } 2770 | 2771 | var i; 2772 | var out = []; 2773 | for (i = 0; i < count; i++) { 2774 | out[i] = lists__get(format, i, field, setter); 2775 | } 2776 | return out; 2777 | } 2778 | 2779 | function lists__listMonths (format, index) { 2780 | return list(format, index, 'months', 12, 'month'); 2781 | } 2782 | 2783 | function lists__listMonthsShort (format, index) { 2784 | return list(format, index, 'monthsShort', 12, 'month'); 2785 | } 2786 | 2787 | function lists__listWeekdays (format, index) { 2788 | return list(format, index, 'weekdays', 7, 'day'); 2789 | } 2790 | 2791 | function lists__listWeekdaysShort (format, index) { 2792 | return list(format, index, 'weekdaysShort', 7, 'day'); 2793 | } 2794 | 2795 | function lists__listWeekdaysMin (format, index) { 2796 | return list(format, index, 'weekdaysMin', 7, 'day'); 2797 | } 2798 | 2799 | locale_locales__getSetGlobalLocale('en', { 2800 | ordinalParse: /\d{1,2}(th|st|nd|rd)/, 2801 | ordinal : function (number) { 2802 | var b = number % 10, 2803 | output = (toInt(number % 100 / 10) === 1) ? 'th' : 2804 | (b === 1) ? 'st' : 2805 | (b === 2) ? 'nd' : 2806 | (b === 3) ? 'rd' : 'th'; 2807 | return number + output; 2808 | } 2809 | }); 2810 | 2811 | // Side effect imports 2812 | utils_hooks__hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', locale_locales__getSetGlobalLocale); 2813 | utils_hooks__hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', locale_locales__getLocale); 2814 | 2815 | var mathAbs = Math.abs; 2816 | 2817 | function duration_abs__abs () { 2818 | var data = this._data; 2819 | 2820 | this._milliseconds = mathAbs(this._milliseconds); 2821 | this._days = mathAbs(this._days); 2822 | this._months = mathAbs(this._months); 2823 | 2824 | data.milliseconds = mathAbs(data.milliseconds); 2825 | data.seconds = mathAbs(data.seconds); 2826 | data.minutes = mathAbs(data.minutes); 2827 | data.hours = mathAbs(data.hours); 2828 | data.months = mathAbs(data.months); 2829 | data.years = mathAbs(data.years); 2830 | 2831 | return this; 2832 | } 2833 | 2834 | function duration_add_subtract__addSubtract (duration, input, value, direction) { 2835 | var other = create__createDuration(input, value); 2836 | 2837 | duration._milliseconds += direction * other._milliseconds; 2838 | duration._days += direction * other._days; 2839 | duration._months += direction * other._months; 2840 | 2841 | return duration._bubble(); 2842 | } 2843 | 2844 | // supports only 2.0-style add(1, 's') or add(duration) 2845 | function duration_add_subtract__add (input, value) { 2846 | return duration_add_subtract__addSubtract(this, input, value, 1); 2847 | } 2848 | 2849 | // supports only 2.0-style subtract(1, 's') or subtract(duration) 2850 | function duration_add_subtract__subtract (input, value) { 2851 | return duration_add_subtract__addSubtract(this, input, value, -1); 2852 | } 2853 | 2854 | function absCeil (number) { 2855 | if (number < 0) { 2856 | return Math.floor(number); 2857 | } else { 2858 | return Math.ceil(number); 2859 | } 2860 | } 2861 | 2862 | function bubble () { 2863 | var milliseconds = this._milliseconds; 2864 | var days = this._days; 2865 | var months = this._months; 2866 | var data = this._data; 2867 | var seconds, minutes, hours, years, monthsFromDays; 2868 | 2869 | // if we have a mix of positive and negative values, bubble down first 2870 | // check: https://github.com/moment/moment/issues/2166 2871 | if (!((milliseconds >= 0 && days >= 0 && months >= 0) || 2872 | (milliseconds <= 0 && days <= 0 && months <= 0))) { 2873 | milliseconds += absCeil(monthsToDays(months) + days) * 864e5; 2874 | days = 0; 2875 | months = 0; 2876 | } 2877 | 2878 | // The following code bubbles up values, see the tests for 2879 | // examples of what that means. 2880 | data.milliseconds = milliseconds % 1000; 2881 | 2882 | seconds = absFloor(milliseconds / 1000); 2883 | data.seconds = seconds % 60; 2884 | 2885 | minutes = absFloor(seconds / 60); 2886 | data.minutes = minutes % 60; 2887 | 2888 | hours = absFloor(minutes / 60); 2889 | data.hours = hours % 24; 2890 | 2891 | days += absFloor(hours / 24); 2892 | 2893 | // convert days to months 2894 | monthsFromDays = absFloor(daysToMonths(days)); 2895 | months += monthsFromDays; 2896 | days -= absCeil(monthsToDays(monthsFromDays)); 2897 | 2898 | // 12 months -> 1 year 2899 | years = absFloor(months / 12); 2900 | months %= 12; 2901 | 2902 | data.days = days; 2903 | data.months = months; 2904 | data.years = years; 2905 | 2906 | return this; 2907 | } 2908 | 2909 | function daysToMonths (days) { 2910 | // 400 years have 146097 days (taking into account leap year rules) 2911 | // 400 years have 12 months === 4800 2912 | return days * 4800 / 146097; 2913 | } 2914 | 2915 | function monthsToDays (months) { 2916 | // the reverse of daysToMonths 2917 | return months * 146097 / 4800; 2918 | } 2919 | 2920 | function as (units) { 2921 | var days; 2922 | var months; 2923 | var milliseconds = this._milliseconds; 2924 | 2925 | units = normalizeUnits(units); 2926 | 2927 | if (units === 'month' || units === 'year') { 2928 | days = this._days + milliseconds / 864e5; 2929 | months = this._months + daysToMonths(days); 2930 | return units === 'month' ? months : months / 12; 2931 | } else { 2932 | // handle milliseconds separately because of floating point math errors (issue #1867) 2933 | days = this._days + Math.round(monthsToDays(this._months)); 2934 | switch (units) { 2935 | case 'week' : return days / 7 + milliseconds / 6048e5; 2936 | case 'day' : return days + milliseconds / 864e5; 2937 | case 'hour' : return days * 24 + milliseconds / 36e5; 2938 | case 'minute' : return days * 1440 + milliseconds / 6e4; 2939 | case 'second' : return days * 86400 + milliseconds / 1000; 2940 | // Math.floor prevents floating point math errors here 2941 | case 'millisecond': return Math.floor(days * 864e5) + milliseconds; 2942 | default: throw new Error('Unknown unit ' + units); 2943 | } 2944 | } 2945 | } 2946 | 2947 | // TODO: Use this.as('ms')? 2948 | function duration_as__valueOf () { 2949 | return ( 2950 | this._milliseconds + 2951 | this._days * 864e5 + 2952 | (this._months % 12) * 2592e6 + 2953 | toInt(this._months / 12) * 31536e6 2954 | ); 2955 | } 2956 | 2957 | function makeAs (alias) { 2958 | return function () { 2959 | return this.as(alias); 2960 | }; 2961 | } 2962 | 2963 | var asMilliseconds = makeAs('ms'); 2964 | var asSeconds = makeAs('s'); 2965 | var asMinutes = makeAs('m'); 2966 | var asHours = makeAs('h'); 2967 | var asDays = makeAs('d'); 2968 | var asWeeks = makeAs('w'); 2969 | var asMonths = makeAs('M'); 2970 | var asYears = makeAs('y'); 2971 | 2972 | function duration_get__get (units) { 2973 | units = normalizeUnits(units); 2974 | return this[units + 's'](); 2975 | } 2976 | 2977 | function makeGetter(name) { 2978 | return function () { 2979 | return this._data[name]; 2980 | }; 2981 | } 2982 | 2983 | var milliseconds = makeGetter('milliseconds'); 2984 | var seconds = makeGetter('seconds'); 2985 | var minutes = makeGetter('minutes'); 2986 | var hours = makeGetter('hours'); 2987 | var days = makeGetter('days'); 2988 | var months = makeGetter('months'); 2989 | var years = makeGetter('years'); 2990 | 2991 | function weeks () { 2992 | return absFloor(this.days() / 7); 2993 | } 2994 | 2995 | var round = Math.round; 2996 | var thresholds = { 2997 | s: 45, // seconds to minute 2998 | m: 45, // minutes to hour 2999 | h: 22, // hours to day 3000 | d: 26, // days to month 3001 | M: 11 // months to year 3002 | }; 3003 | 3004 | // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize 3005 | function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) { 3006 | return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture); 3007 | } 3008 | 3009 | function duration_humanize__relativeTime (posNegDuration, withoutSuffix, locale) { 3010 | var duration = create__createDuration(posNegDuration).abs(); 3011 | var seconds = round(duration.as('s')); 3012 | var minutes = round(duration.as('m')); 3013 | var hours = round(duration.as('h')); 3014 | var days = round(duration.as('d')); 3015 | var months = round(duration.as('M')); 3016 | var years = round(duration.as('y')); 3017 | 3018 | var a = seconds < thresholds.s && ['s', seconds] || 3019 | minutes === 1 && ['m'] || 3020 | minutes < thresholds.m && ['mm', minutes] || 3021 | hours === 1 && ['h'] || 3022 | hours < thresholds.h && ['hh', hours] || 3023 | days === 1 && ['d'] || 3024 | days < thresholds.d && ['dd', days] || 3025 | months === 1 && ['M'] || 3026 | months < thresholds.M && ['MM', months] || 3027 | years === 1 && ['y'] || ['yy', years]; 3028 | 3029 | a[2] = withoutSuffix; 3030 | a[3] = +posNegDuration > 0; 3031 | a[4] = locale; 3032 | return substituteTimeAgo.apply(null, a); 3033 | } 3034 | 3035 | // This function allows you to set a threshold for relative time strings 3036 | function duration_humanize__getSetRelativeTimeThreshold (threshold, limit) { 3037 | if (thresholds[threshold] === undefined) { 3038 | return false; 3039 | } 3040 | if (limit === undefined) { 3041 | return thresholds[threshold]; 3042 | } 3043 | thresholds[threshold] = limit; 3044 | return true; 3045 | } 3046 | 3047 | function humanize (withSuffix) { 3048 | var locale = this.localeData(); 3049 | var output = duration_humanize__relativeTime(this, !withSuffix, locale); 3050 | 3051 | if (withSuffix) { 3052 | output = locale.pastFuture(+this, output); 3053 | } 3054 | 3055 | return locale.postformat(output); 3056 | } 3057 | 3058 | var iso_string__abs = Math.abs; 3059 | 3060 | function iso_string__toISOString() { 3061 | // for ISO strings we do not use the normal bubbling rules: 3062 | // * milliseconds bubble up until they become hours 3063 | // * days do not bubble at all 3064 | // * months bubble up until they become years 3065 | // This is because there is no context-free conversion between hours and days 3066 | // (think of clock changes) 3067 | // and also not between days and months (28-31 days per month) 3068 | var seconds = iso_string__abs(this._milliseconds) / 1000; 3069 | var days = iso_string__abs(this._days); 3070 | var months = iso_string__abs(this._months); 3071 | var minutes, hours, years; 3072 | 3073 | // 3600 seconds -> 60 minutes -> 1 hour 3074 | minutes = absFloor(seconds / 60); 3075 | hours = absFloor(minutes / 60); 3076 | seconds %= 60; 3077 | minutes %= 60; 3078 | 3079 | // 12 months -> 1 year 3080 | years = absFloor(months / 12); 3081 | months %= 12; 3082 | 3083 | 3084 | // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js 3085 | var Y = years; 3086 | var M = months; 3087 | var D = days; 3088 | var h = hours; 3089 | var m = minutes; 3090 | var s = seconds; 3091 | var total = this.asSeconds(); 3092 | 3093 | if (!total) { 3094 | // this is the same as C#'s (Noda) and python (isodate)... 3095 | // but not other JS (goog.date) 3096 | return 'P0D'; 3097 | } 3098 | 3099 | return (total < 0 ? '-' : '') + 3100 | 'P' + 3101 | (Y ? Y + 'Y' : '') + 3102 | (M ? M + 'M' : '') + 3103 | (D ? D + 'D' : '') + 3104 | ((h || m || s) ? 'T' : '') + 3105 | (h ? h + 'H' : '') + 3106 | (m ? m + 'M' : '') + 3107 | (s ? s + 'S' : ''); 3108 | } 3109 | 3110 | var duration_prototype__proto = Duration.prototype; 3111 | 3112 | duration_prototype__proto.abs = duration_abs__abs; 3113 | duration_prototype__proto.add = duration_add_subtract__add; 3114 | duration_prototype__proto.subtract = duration_add_subtract__subtract; 3115 | duration_prototype__proto.as = as; 3116 | duration_prototype__proto.asMilliseconds = asMilliseconds; 3117 | duration_prototype__proto.asSeconds = asSeconds; 3118 | duration_prototype__proto.asMinutes = asMinutes; 3119 | duration_prototype__proto.asHours = asHours; 3120 | duration_prototype__proto.asDays = asDays; 3121 | duration_prototype__proto.asWeeks = asWeeks; 3122 | duration_prototype__proto.asMonths = asMonths; 3123 | duration_prototype__proto.asYears = asYears; 3124 | duration_prototype__proto.valueOf = duration_as__valueOf; 3125 | duration_prototype__proto._bubble = bubble; 3126 | duration_prototype__proto.get = duration_get__get; 3127 | duration_prototype__proto.milliseconds = milliseconds; 3128 | duration_prototype__proto.seconds = seconds; 3129 | duration_prototype__proto.minutes = minutes; 3130 | duration_prototype__proto.hours = hours; 3131 | duration_prototype__proto.days = days; 3132 | duration_prototype__proto.weeks = weeks; 3133 | duration_prototype__proto.months = months; 3134 | duration_prototype__proto.years = years; 3135 | duration_prototype__proto.humanize = humanize; 3136 | duration_prototype__proto.toISOString = iso_string__toISOString; 3137 | duration_prototype__proto.toString = iso_string__toISOString; 3138 | duration_prototype__proto.toJSON = iso_string__toISOString; 3139 | duration_prototype__proto.locale = locale; 3140 | duration_prototype__proto.localeData = localeData; 3141 | 3142 | // Deprecations 3143 | duration_prototype__proto.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', iso_string__toISOString); 3144 | duration_prototype__proto.lang = lang; 3145 | 3146 | // Side effect imports 3147 | 3148 | addFormatToken('X', 0, 0, 'unix'); 3149 | addFormatToken('x', 0, 0, 'valueOf'); 3150 | 3151 | // PARSING 3152 | 3153 | addRegexToken('x', matchSigned); 3154 | addRegexToken('X', matchTimestamp); 3155 | addParseToken('X', function (input, array, config) { 3156 | config._d = new Date(parseFloat(input, 10) * 1000); 3157 | }); 3158 | addParseToken('x', function (input, array, config) { 3159 | config._d = new Date(toInt(input)); 3160 | }); 3161 | 3162 | // Side effect imports 3163 | 3164 | 3165 | utils_hooks__hooks.version = '2.10.6'; 3166 | 3167 | setHookCallback(local__createLocal); 3168 | 3169 | utils_hooks__hooks.fn = momentPrototype; 3170 | utils_hooks__hooks.min = min; 3171 | utils_hooks__hooks.max = max; 3172 | utils_hooks__hooks.utc = create_utc__createUTC; 3173 | utils_hooks__hooks.unix = moment__createUnix; 3174 | utils_hooks__hooks.months = lists__listMonths; 3175 | utils_hooks__hooks.isDate = isDate; 3176 | utils_hooks__hooks.locale = locale_locales__getSetGlobalLocale; 3177 | utils_hooks__hooks.invalid = valid__createInvalid; 3178 | utils_hooks__hooks.duration = create__createDuration; 3179 | utils_hooks__hooks.isMoment = isMoment; 3180 | utils_hooks__hooks.weekdays = lists__listWeekdays; 3181 | utils_hooks__hooks.parseZone = moment__createInZone; 3182 | utils_hooks__hooks.localeData = locale_locales__getLocale; 3183 | utils_hooks__hooks.isDuration = isDuration; 3184 | utils_hooks__hooks.monthsShort = lists__listMonthsShort; 3185 | utils_hooks__hooks.weekdaysMin = lists__listWeekdaysMin; 3186 | utils_hooks__hooks.defineLocale = defineLocale; 3187 | utils_hooks__hooks.weekdaysShort = lists__listWeekdaysShort; 3188 | utils_hooks__hooks.normalizeUnits = normalizeUnits; 3189 | utils_hooks__hooks.relativeTimeThreshold = duration_humanize__getSetRelativeTimeThreshold; 3190 | 3191 | var _moment = utils_hooks__hooks; 3192 | 3193 | return _moment; 3194 | 3195 | })); -------------------------------------------------------------------------------- /proxy.php: -------------------------------------------------------------------------------- 1 | this.depCount&&!this.defined){if(G(l)){if(this.events.error&&this.map.isDefine||g.onError!==ca)try{f=i.execCb(c,l,b,f)}catch(d){a=d}else f=i.execCb(c,l,b,f);this.map.isDefine&&void 0===f&&((b=this.module)?f=b.exports:this.usingExports&& 19 | (f=this.exports));if(a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",w(this.error=a)}else f=l;this.exports=f;if(this.map.isDefine&&!this.ignore&&(r[c]=f,g.onResourceLoad))g.onResourceLoad(i,this.map,this.depMaps);y(c);this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}else this.fetch()}},callPlugin:function(){var a= 20 | this.map,b=a.id,d=p(a.prefix);this.depMaps.push(d);q(d,"defined",u(this,function(f){var l,d;d=m(aa,this.map.id);var e=this.map.name,P=this.map.parentMap?this.map.parentMap.name:null,n=i.makeRequire(a.parentMap,{enableBuildCallback:!0});if(this.map.unnormalized){if(f.normalize&&(e=f.normalize(e,function(a){return c(a,P,!0)})||""),f=p(a.prefix+"!"+e,this.map.parentMap),q(f,"defined",u(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),d=m(h,f.id)){this.depMaps.push(f); 21 | if(this.events.error)d.on("error",u(this,function(a){this.emit("error",a)}));d.enable()}}else d?(this.map.url=i.nameToUrl(d),this.load()):(l=u(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),l.error=u(this,function(a){this.inited=!0;this.error=a;a.requireModules=[b];B(h,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&y(a.map.id)});w(a)}),l.fromText=u(this,function(f,c){var d=a.name,e=p(d),P=M;c&&(f=c);P&&(M=!1);s(e);t(j.config,b)&&(j.config[d]=j.config[b]);try{g.exec(f)}catch(h){return w(C("fromtexteval", 22 | "fromText eval for "+b+" failed: "+h,h,[b]))}P&&(M=!0);this.depMaps.push(e);i.completeLoad(d);n([d],l)}),f.load(a.name,n,l,j))}));i.enable(d,this);this.pluginMaps[d.id]=d},enable:function(){V[this.map.id]=this;this.enabling=this.enabled=!0;v(this.depMaps,u(this,function(a,b){var c,f;if("string"===typeof a){a=p(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=m(L,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;q(a,"defined",u(this,function(a){this.defineDep(b, 23 | a);this.check()}));this.errback&&q(a,"error",u(this,this.errback))}c=a.id;f=h[c];!t(L,c)&&(f&&!f.enabled)&&i.enable(a,this)}));B(this.pluginMaps,u(this,function(a){var b=m(h,a.id);b&&!b.enabled&&i.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){v(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}};i={config:j,contextName:b,registry:h,defined:r,urlFetched:S,defQueue:A,Module:Z,makeModuleMap:p, 24 | nextTick:g.nextTick,onError:w,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=j.shim,c={paths:!0,bundles:!0,config:!0,map:!0};B(a,function(a,b){c[b]?(j[b]||(j[b]={}),U(j[b],a,!0,!0)):j[b]=a});a.bundles&&B(a.bundles,function(a,b){v(a,function(a){a!==b&&(aa[a]=b)})});a.shim&&(B(a.shim,function(a,c){H(a)&&(a={deps:a});if((a.exports||a.init)&&!a.exportsFn)a.exportsFn=i.makeShimExports(a);b[c]=a}),j.shim=b);a.packages&&v(a.packages,function(a){var b, 25 | a="string"===typeof a?{name:a}:a;b=a.name;a.location&&(j.paths[b]=a.location);j.pkgs[b]=a.name+"/"+(a.main||"main").replace(ia,"").replace(Q,"")});B(h,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=p(b))});if(a.deps||a.callback)i.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(ba,arguments));return b||a.exports&&da(a.exports)}},makeRequire:function(a,e){function j(c,d,m){var n,q;e.enableBuildCallback&&(d&&G(d))&&(d.__requireJsBuild= 26 | !0);if("string"===typeof c){if(G(d))return w(C("requireargs","Invalid require call"),m);if(a&&t(L,c))return L[c](h[a.id]);if(g.get)return g.get(i,c,a,j);n=p(c,a,!1,!0);n=n.id;return!t(r,n)?w(C("notloaded",'Module name "'+n+'" has not been loaded yet for context: '+b+(a?"":". Use require([])"))):r[n]}J();i.nextTick(function(){J();q=s(p(null,a));q.skipMap=e.skipMap;q.init(c,d,m,{enabled:!0});D()});return j}e=e||{};U(j,{isBrowser:z,toUrl:function(b){var d,e=b.lastIndexOf("."),k=b.split("/")[0];if(-1!== 27 | e&&(!("."===k||".."===k)||1e.attachEvent.toString().indexOf("[native code"))&&!Y?(M=!0,e.attachEvent("onreadystatechange",b.onScriptLoad)): 34 | (e.addEventListener("load",b.onScriptLoad,!1),e.addEventListener("error",b.onScriptError,!1)),e.src=d,J=e,D?y.insertBefore(e,D):y.appendChild(e),J=null,e;if(ea)try{importScripts(d),b.completeLoad(c)}catch(m){b.onError(C("importscripts","importScripts failed for "+c+" at "+d,m,[c]))}};z&&!q.skipDataMain&&T(document.getElementsByTagName("script"),function(b){y||(y=b.parentNode);if(I=b.getAttribute("data-main"))return s=I,q.baseUrl||(E=s.split("/"),s=E.pop(),O=E.length?E.join("/")+"/":"./",q.baseUrl= 35 | O),s=s.replace(Q,""),g.jsExtRegExp.test(s)&&(s=I),q.deps=q.deps?q.deps.concat(s):[s],!0});define=function(b,c,d){var e,g;"string"!==typeof b&&(d=c,c=b,b=null);H(c)||(d=c,c=null);!c&&G(d)&&(c=[],d.length&&(d.toString().replace(ka,"").replace(la,function(b,d){c.push(d)}),c=(1===d.length?["require"]:["require","exports","module"]).concat(c)));if(M){if(!(e=J))N&&"interactive"===N.readyState||T(document.getElementsByTagName("script"),function(b){if("interactive"===b.readyState)return N=b}),e=N;e&&(b|| 36 | (b=e.getAttribute("data-requiremodule")),g=F[e.getAttribute("data-requirecontext")])}(g?g.defQueue:R).push([b,c,d])};define.amd={jQuery:!0};g.exec=function(b){return eval(b)};g(q)}})(this); -------------------------------------------------------------------------------- /ti.forecast.io.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Helper Class for forecast.io webservice 3 | * Including moment.js for date help. 4 | * HTTTClient supports Cross-Domain XHR - no need for callbacks 5 | * 6 | * MIT License (MIT) 7 | * Copyright (c) 2013 Ian Tearle @iantearle 8 | * 9 | */ 10 | var moment = require('alloy/moment'); 11 | 12 | function ForecastIO() { 13 | FORECAST_API = 'API_KEY'; // Sign up at https://developer.forecast.io/ 14 | FORECAST_URL = 'https://api.forecast.io/forecast/'; 15 | 16 | this.requestData = function(latitude, longitude, onSuccess, onError, timestamp) { 17 | var onSuccess = onSuccess || function(){}; 18 | var onError = onError || function(){}; 19 | var timestamp = (timestamp) ? ','+timestamp : ''; 20 | 21 | var request_url = FORECAST_URL + FORECAST_API + '/' + latitude + ',' + longitude + timestamp + '?units=uk'; 22 | 23 | var xhr = Titanium.Network.createHTTPClient({ 24 | enableKeepAlive: false 25 | }); 26 | 27 | // Create the result object 28 | var result = {}; 29 | 30 | // Open the HTTP connection 31 | xhr.open("GET", request_url); 32 | 33 | // When the connection was successful 34 | xhr.onload = function() { 35 | // Check the status of this 36 | result.status = xhr.status == 200 ? "ok" : xhr.status; 37 | result.data = JSON.parse(xhr.responseText); 38 | 39 | onSuccess(result); 40 | }; 41 | 42 | // When there was an error 43 | xhr.onerror = function(e) { 44 | // Check the status of this 45 | result.status = "error"; 46 | result.data = e; 47 | result.code = xhr.status; 48 | onError(result); 49 | }; 50 | 51 | xhr.send(); 52 | } 53 | /** 54 | * Will return the current conditions 55 | * 56 | * @param float $latitude 57 | * @param float $longitude 58 | * @return \ForecastIOConditions|boolean 59 | */ 60 | this.getCurrentConditions = function(latitude, longitude, onSuccess, onError, timestamp) { 61 | var onSuccess = onSuccess || function(){}; 62 | var onError = onError || function(){}; 63 | 64 | this.requestData(latitude, longitude, onSuccessCallback, onErrorCallback, timestamp); 65 | 66 | function onSuccessCallback(e) { 67 | var bigReturn = new ForecastIOConditions(e.data.currently); 68 | onSuccess(bigReturn); 69 | }; 70 | 71 | function onErrorCallback(e) { 72 | // Handle your errors in here 73 | onError("error"); 74 | }; 75 | } 76 | /** 77 | * Will return conditions on hourly basis for today 78 | * 79 | * @param type $latitude 80 | * @param type $longitude 81 | * @return \ForecastIOConditions|boolean 82 | */ 83 | this.getForecastToday = function(latitude, longitude, onSuccess, onError, timestamp) { 84 | var onSuccess = onSuccess || function(){}; 85 | var onError = onError || function(){}; 86 | 87 | this.requestData(latitude, longitude, onSuccessCallback, onErrorCallback, timestamp); 88 | 89 | function onSuccessCallback(e) { 90 | conditions = []; 91 | today = moment().format("YYYY-MM-DD"); 92 | for(i=0; i