1/** 2 * angular-input-masks 3 * Personalized input masks for AngularJS 4 * @version v2.5.0 5 * @link http://github.com/assisrafael/angular-input-masks 6 * @license MIT 7 */ 8require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 9/** 10 * br-validations 11 * A library of validations applicable to several Brazilian data like I.E., CNPJ, CPF and others 12 * @version v0.2.4 13 * @link http://github.com/the-darc/br-validations 14 * @license MIT 15 */ 16(function (root, factory) { 17 if (typeof define === 'function' && define.amd) { 18 // AMD. Register as an anonymous module. 19 define([], factory); 20 } else if (typeof exports === 'object') { 21 // Node. Does not work with strict CommonJS, but 22 // only CommonJS-like environments that support module.exports, 23 // like Node. 24 module.exports = factory(); 25 } else { 26 // Browser globals (root is window) 27 root.BrV = factory(); 28 } 29}(this, function () { 30var CNPJ = {}; 31 32CNPJ.validate = function(c) { 33 var b = [6,5,4,3,2,9,8,7,6,5,4,3,2]; 34 c = c.replace(/[^\d]/g,''); 35 36 var r = /^(0{14}|1{14}|2{14}|3{14}|4{14}|5{14}|6{14}|7{14}|8{14}|9{14})$/; 37 if (!c || c.length !== 14 || r.test(c)) { 38 return false; 39 } 40 c = c.split(''); 41 42 for (var i = 0, n = 0; i < 12; i++) { 43 n += c[i] * b[i+1]; 44 } 45 n = 11 - n%11; 46 n = n >= 10 ? 0 : n; 47 if (parseInt(c[12]) !== n) { 48 return false; 49 } 50 51 for (i = 0, n = 0; i <= 12; i++) { 52 n += c[i] * b[i]; 53 } 54 n = 11 - n%11; 55 n = n >= 10 ? 0 : n; 56 if (parseInt(c[13]) !== n) { 57 return false; 58 } 59 return true; 60}; 61 62 63var CPF = {}; 64 65CPF.validate = function(cpf) { 66 cpf = cpf.replace(/[^\d]+/g,''); 67 var r = /^(0{11}|1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11})$/; 68 if (!cpf || cpf.length !== 11 || r.test(cpf)) { 69 return false; 70 } 71 function validateDigit(digit) { 72 var add = 0; 73 var init = digit - 9; 74 for (var i = 0; i < 9; i ++) { 75 add += parseInt(cpf.charAt(i + init)) * (i+1); 76 } 77 return (add%11)%10 === parseInt(cpf.charAt(digit)); 78 } 79 return validateDigit(9) && validateDigit(10); 80}; 81 82var IE = function(uf) { 83 if (!(this instanceof IE)) { 84 return new IE(uf); 85 } 86 87 this.rules = IErules[uf] || []; 88 this.rule; 89 IE.prototype._defineRule = function(value) { 90 this.rule = undefined; 91 for (var r = 0; r < this.rules.length && this.rule === undefined; r++) { 92 var str = value.replace(/[^\d]/g,''); 93 var ruleCandidate = this.rules[r]; 94 if (str.length === ruleCandidate.chars && (!ruleCandidate.match || ruleCandidate.match.test(value))) { 95 this.rule = ruleCandidate; 96 } 97 } 98 return !!this.rule; 99 }; 100 101 IE.prototype.validate = function(value) { 102 if (!value || !this._defineRule(value)) { 103 return false; 104 } 105 return this.rule.validate(value); 106 }; 107}; 108 109var IErules = {}; 110 111var algorithmSteps = { 112 handleStr: { 113 onlyNumbers: function(str) { 114 return str.replace(/[^\d]/g,'').split(''); 115 }, 116 mgSpec: function(str) { 117 var s = str.replace(/[^\d]/g,''); 118 s = s.substr(0,3)+'0'+s.substr(3, s.length); 119 return s.split(''); 120 } 121 }, 122 sum: { 123 normalSum: function(handledStr, pesos) { 124 var nums = handledStr; 125 var sum = 0; 126 for (var i = 0; i < pesos.length; i++) { 127 sum += parseInt(nums[i]) * pesos[i]; 128 } 129 return sum; 130 }, 131 individualSum: function(handledStr, pesos) { 132 var nums = handledStr; 133 var sum = 0; 134 for (var i = 0; i < pesos.length; i++) { 135 var mult = parseInt(nums[i]) * pesos[i]; 136 sum += mult%10 + parseInt(mult/10); 137 } 138 return sum; 139 }, 140 apSpec: function(handledStr, pesos) { 141 var sum = this.normalSum(handledStr, pesos); 142 var ref = handledStr.join(''); 143 if (ref >= '030000010' && ref <= '030170009') { 144 return sum + 5; 145 } 146 if (ref >= '030170010' && ref <= '030190229') { 147 return sum + 9; 148 } 149 return sum; 150 } 151 }, 152 rest: { 153 mod11: function(sum) { 154 return sum%11; 155 }, 156 mod10: function(sum) { 157 return sum%10; 158 }, 159 mod9: function(sum) { 160 return sum%9; 161 } 162 }, 163 expectedDV: { 164 minusRestOf11: function(rest) { 165 return rest < 2 ? 0 : 11 - rest; 166 }, 167 minusRestOf11v2: function(rest) { 168 return rest < 2 ? 11 - rest - 10 : 11 - rest; 169 }, 170 minusRestOf10: function(rest) { 171 return rest < 1 ? 0 : 10 - rest; 172 }, 173 mod10: function(rest) { 174 return rest%10; 175 }, 176 goSpec: function(rest, handledStr) { 177 var ref = handledStr.join(''); 178 if (rest === 1) { 179 return ref >= '101031050' && ref <= '101199979' ? 1 : 0; 180 } 181 return rest === 0 ? 0 : 11 - rest; 182 }, 183 apSpec: function(rest, handledStr) { 184 var ref = handledStr.join(''); 185 if (rest === 0) { 186 return ref >= '030170010' && ref <= '030190229' ? 1 : 0; 187 } 188 return rest === 1 ? 0 : 11 - rest; 189 }, 190 voidFn: function(rest) { 191 return rest; 192 } 193 } 194}; 195 196 197/** 198 * options { 199 * pesos: Array of values used to operate in sum step 200 * dvPos: Position of the DV to validate considering the handledStr 201 * algorithmSteps: The four DV's validation algorithm steps names 202 * } 203 */ 204function validateDV(value, options) { 205 var steps = options.algorithmSteps; 206 207 // Step 01: Handle String 208 var handledStr = algorithmSteps.handleStr[steps[0]](value); 209 210 // Step 02: Sum chars 211 var sum = algorithmSteps.sum[steps[1]](handledStr, options.pesos); 212 213 // Step 03: Rest calculation 214 var rest = algorithmSteps.rest[steps[2]](sum); 215 216 // Fixed Step: Get current DV 217 var currentDV = parseInt(handledStr[options.dvpos]); 218 219 // Step 04: Expected DV calculation 220 var expectedDV = algorithmSteps.expectedDV[steps[3]](rest, handledStr); 221 222 // Fixed step: DV verification 223 return currentDV === expectedDV; 224} 225 226function validateIE(value, rule) { 227 if (rule.match && !rule.match.test(value)) { 228 return false;
229 } 230 for (var i = 0; i < rule.dvs.length; i++) { 231 // console.log('>> >> dv'+i); 232 if (!validateDV(value, rule.dvs[i])) { 233 return false; 234 } 235 } 236 return true; 237} 238 239IErules.PE = [{ 240 //mask: new StringMask('0000000-00'), 241 chars: 9, 242 dvs: [{ 243 dvpos: 7, 244 pesos: [8,7,6,5,4,3,2], 245 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 246 },{ 247 dvpos: 8, 248 pesos: [9,8,7,6,5,4,3,2], 249 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 250 }], 251 validate: function(value) { return validateIE(value, this); } 252},{ 253 // mask: new StringMask('00.0.000.0000000-0'), 254 chars: 14, 255 pesos: [[1,2,3,4,5,9,8,7,6,5,4,3,2]], 256 dvs: [{ 257 dvpos: 13, 258 pesos: [5,4,3,2,1,9,8,7,6,5,4,3,2], 259 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11v2'] 260 }], 261 validate: function(value) { return validateIE(value, this); } 262}]; 263 264IErules.RS = [{ 265 // mask: new StringMask('000/0000000'), 266 chars: 10, 267 dvs: [{ 268 dvpos: 9, 269 pesos: [2,9,8,7,6,5,4,3,2], 270 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 271 }], 272 validate: function(value) { return validateIE(value, this); } 273}]; 274 275IErules.AC = [{ 276 // mask: new StringMask('00.000.000/000-00'), 277 chars: 13, 278 match: /^01/, 279 dvs: [{ 280 dvpos: 11, 281 pesos: [4,3,2,9,8,7,6,5,4,3,2], 282 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 283 },{ 284 dvpos: 12, 285 pesos: [5,4,3,2,9,8,7,6,5,4,3,2], 286 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 287 }], 288 validate: function(value) { return validateIE(value, this); } 289}]; 290 291IErules.MG = [{ 292 // mask: new StringMask('000.000.000/0000'), 293 chars: 13, 294 dvs: [{ 295 dvpos: 12, 296 pesos: [1,2,1,2,1,2,1,2,1,2,1,2], 297 algorithmSteps: ['mgSpec', 'individualSum', 'mod10', 'minusRestOf10'] 298 },{ 299 dvpos: 12, 300 pesos: [3,2,11,10,9,8,7,6,5,4,3,2], 301 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 302 }], 303 validate: function(value) { return validateIE(value, this); } 304}]; 305 306IErules.SP = [{ 307 // mask: new StringMask('000.000.000.000'), 308 chars: 12, 309 match: /^[0-9]/, 310 dvs: [{ 311 dvpos: 8, 312 pesos: [1,3,4,5,6,7,8,10], 313 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'mod10'] 314 },{ 315 dvpos: 11, 316 pesos: [3,2,10,9,8,7,6,5,4,3,2], 317 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'mod10'] 318 }], 319 validate: function(value) { return validateIE(value, this); } 320},{ 321 // mask: new StringMask('P-00000000.0/000') 322 chars: 12, 323 match: /^P/i, 324 dvs: [{ 325 dvpos: 8, 326 pesos: [1,3,4,5,6,7,8,10], 327 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'mod10'] 328 }], 329 validate: function(value) { return validateIE(value, this); } 330}]; 331 332IErules.DF = [{ 333 // mask: new StringMask('00000000000-00'), 334 chars: 13, 335 dvs: [{ 336 dvpos: 11, 337 pesos: [4,3,2,9,8,7,6,5,4,3,2], 338 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 339 },{ 340 dvpos: 12, 341 pesos: [5,4,3,2,9,8,7,6,5,4,3,2], 342 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 343 }], 344 validate: function(value) { return validateIE(value, this); } 345}]; 346 347IErules.ES = [{ 348 // mask: new StringMask('000.000.00-0') 349 chars: 9, 350 dvs: [{ 351 dvpos: 8, 352 pesos: [9,8,7,6,5,4,3,2], 353 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 354 }], 355 validate: function(value) { return validateIE(value, this); } 356}]; 357 358IErules.BA = [{ 359 // mask: new StringMask('000000-00') 360 chars: 8, 361 match: /^[0123458]/, 362 dvs: [{ 363 dvpos: 7, 364 pesos: [7,6,5,4,3,2], 365 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod10', 'minusRestOf10'] 366 },{ 367 dvpos: 6, 368 pesos: [8,7,6,5,4,3,0,2], 369 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod10', 'minusRestOf10'] 370 }], 371 validate: function(value) { return validateIE(value, this); } 372},{ 373 chars: 8, 374 match: /^[679]/, 375 dvs: [{ 376 dvpos: 7, 377 pesos: [7,6,5,4,3,2], 378 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 379 },{ 380 dvpos: 6, 381 pesos: [8,7,6,5,4,3,0,2], 382 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 383 }], 384 validate: function(value) { return validateIE(value, this); } 385},{ 386 // mask: new StringMask('0000000-00') 387 chars: 9, 388 match: /^[0-9][0123458]/, 389 dvs: [{ 390 dvpos: 8, 391 pesos: [8,7,6,5,4,3,2], 392 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod10', 'minusRestOf10'] 393 },{ 394 dvpos: 7, 395 pesos: [9,8,7,6,5,4,3,0,2], 396 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod10', 'minusRestOf10'] 397 }], 398 validate: function(value) { return validateIE(value, this); } 399},{ 400 chars: 9, 401 match: /^[0-9][679]/, 402 dvs: [{ 403 dvpos: 8, 404 pesos: [8,7,6,5,4,3,2], 405 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 406 },{ 407 dvpos: 7, 408 pesos: [9,8,7,6,5,4,3,0,2], 409 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 410 }], 411 validate: function(value) { return validateIE(value, this); } 412}]; 413 414IErules.AM = [{ 415 //mask: new StringMask('00.000.000-0') 416 chars: 9, 417 dvs: [{ 418 dvpos: 8, 419 pesos: [9,8,7,6,5,4,3,2], 420 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 421 }], 422 validate: function(value) { return validateIE(value, this); } 423}]; 424 425IErules.RN = [{ 426 // {mask: new StringMask('00.000.000-0') 427 chars: 9, 428 match: /^20/, 429 dvs: [{ 430 dvpos: 8, 431 pesos: [9,8,7,6,5,4,3,2], 432 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 433 }], 434 validate: function(value) { return validateIE(value, this); } 435},{ 436 // {mask: new StringMask('00.0.000.000-0'), chars: 10} 437 chars: 10, 438 match: /^20/, 439 dvs: [{ 440 dvpos: 8, 441 pesos: [10,9,8,7,6,5,4,3,2], 442 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 443 }], 444 validate: function(value) { return validateIE(value, this); } 445}]; 446 447IErules.RO = [{ 448 // mask: new StringMask('0000000000000-0') 449 chars: 14, 450 dvs: [{ 451 dvpos: 13, 452 pesos: [6,5,4,3,2,9,8,7,6,5,4,3,2], 453 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 454 }], 455 validate: function(value) { return validateIE(value, this); } 456}]; 457 458IErules.PR = [{ 459 // mask: new StringMask('00000000-00') 460 chars: 10, 461 dvs: [{ 462 dvpos: 8, 463 pesos: [3,2,7,6,5,4,3,2], 464 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 465 },{ 466 dvpos: 9, 467 pesos: [4,3,2,7,6,5,4,3,2], 468 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 469 }], 470 validate: function(value) { return validateIE(value, this); } 471}]; 472 473IErules.SC = [{ 474 // {mask: new StringMask('000.000.000'), uf: 'SANTA CATARINA'} 475 chars: 9, 476 dvs: [{ 477 dvpos: 8, 478 pesos: [9,8,7,6,5,4,3,2], 479 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 480 }], 481 validate: function(value) { return validateIE(value, this); } 482}]; 483 484IErules.RJ = [{ 485 // {mask: new StringMask('00.000.00-0'), uf: 'RIO DE JANEIRO'} 486 chars: 8, 487 dvs: [{ 488 dvpos: 7, 489 pesos: [2,7,6,5,4,3,2], 490 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 491 }], 492 validate: function(value) { return validateIE(value, this); } 493}]; 494 495IErules.PA = [{ 496 // {mask: new StringMask('00-000000-0') 497 chars: 9, 498 match: /^15/, 499 dvs: [{ 500 dvpos: 8, 501 pesos: [9,8,7,6,5,4,3,2], 502 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 503 }], 504 validate: function(value) { return validateIE(value, this); } 505}]; 506 507IErules.SE = [{ 508 // {mask: new StringMask('00000000-0') 509 chars: 9, 510 dvs: [{ 511 dvpos: 8, 512 pesos: [9,8,7,6,5,4,3,2], 513 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 514 }], 515 validate: function(value) { return validateIE(value, this); } 516}]; 517 518IErules.PB = [{ 519 // {mask: new StringMask('00000000-0') 520 chars: 9, 521 dvs: [{ 522 dvpos: 8, 523 pesos: [9,8,7,6,5,4,3,2], 524 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 525 }], 526 validate: function(value) { return validateIE(value, this); } 527}]; 528
529IErules.CE = [{ 530 // {mask: new StringMask('00000000-0') 531 chars: 9, 532 dvs: [{ 533 dvpos: 8, 534 pesos: [9,8,7,6,5,4,3,2], 535 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 536 }], 537 validate: function(value) { return validateIE(value, this); } 538}]; 539 540IErules.PI = [{ 541 // {mask: new StringMask('000000000') 542 chars: 9, 543 dvs: [{ 544 dvpos: 8, 545 pesos: [9,8,7,6,5,4,3,2], 546 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 547 }], 548 validate: function(value) { return validateIE(value, this); } 549}]; 550 551IErules.MA = [{ 552 // {mask: new StringMask('000000000') 553 chars: 9, 554 match: /^12/, 555 dvs: [{ 556 dvpos: 8, 557 pesos: [9,8,7,6,5,4,3,2], 558 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 559 }], 560 validate: function(value) { return validateIE(value, this); } 561}]; 562 563IErules.MT = [{ 564 // {mask: new StringMask('0000000000-0') 565 chars: 11, 566 dvs: [{ 567 dvpos: 10, 568 pesos: [3,2,9,8,7,6,5,4,3,2], 569 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 570 }], 571 validate: function(value) { return validateIE(value, this); } 572}]; 573 574IErules.MS = [{ 575 // {mask: new StringMask('000000000') 576 chars: 9, 577 match: /^28/, 578 dvs: [{ 579 dvpos: 8, 580 pesos: [9,8,7,6,5,4,3,2], 581 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 582 }], 583 validate: function(value) { return validateIE(value, this); } 584}]; 585 586IErules.TO = [{ 587 // {mask: new StringMask('00000000000'), 588 chars: 11, 589 match: /^[0-9]{2}((0[123])|(99))/, 590 dvs: [{ 591 dvpos: 10, 592 pesos: [9,8,0,0,7,6,5,4,3,2], 593 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 594 }], 595 validate: function(value) { return validateIE(value, this); } 596}]; 597 598IErules.AL = [{ 599 // {mask: new StringMask('000000000') 600 chars: 9, 601 match: /^24[03578]/, 602 dvs: [{ 603 dvpos: 8, 604 pesos: [9,8,7,6,5,4,3,2], 605 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'minusRestOf11'] 606 }], 607 validate: function(value) { return validateIE(value, this); } 608}]; 609 610IErules.RR = [{ 611 // {mask: new StringMask('00000000-0') 612 chars: 9, 613 match: /^24/, 614 dvs: [{ 615 dvpos: 8, 616 pesos: [1,2,3,4,5,6,7,8], 617 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod9', 'voidFn'] 618 }], 619 validate: function(value) { return validateIE(value, this); } 620}]; 621 622IErules.GO = [{ 623 // {mask: new StringMask('00.000.000-0') 624 chars: 9, 625 match: /^1[015]/, 626 dvs: [{ 627 dvpos: 8, 628 pesos: [9,8,7,6,5,4,3,2], 629 algorithmSteps: ['onlyNumbers', 'normalSum', 'mod11', 'goSpec'] 630 }], 631 validate: function(value) { return validateIE(value, this); } 632}]; 633 634IErules.AP = [{ 635 // {mask: new StringMask('000000000') 636 chars: 9, 637 match: /^03/, 638 dvs: [{ 639 dvpos: 8, 640 pesos: [9,8,7,6,5,4,3,2], 641 algorithmSteps: ['onlyNumbers', 'apSpec', 'mod11', 'apSpec'] 642 }], 643 validate: function(value) { return validateIE(value, this); } 644}]; 645 646 return { 647 ie: IE, 648 cpf: CPF, 649 cnpj: CNPJ 650 }; 651})); 652},{}],2:[function(require,module,exports){ 653//! moment.js 654//! version : 2.14.1 655//! authors : Tim Wood, Iskren Chernev, Moment.js contributors 656//! license : MIT 657//! momentjs.com 658 659;(function (global, factory) { 660 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 661 typeof define === 'function' && define.amd ? define(factory) : 662 global.moment = factory() 663}(this, function () { 'use strict'; 664 665 var hookCallback; 666 667 function utils_hooks__hooks () { 668 return hookCallback.apply(null, arguments); 669 } 670 671 // This is done to register the method called with moment() 672 // without creating circular dependencies. 673 function setHookCallback (callback) { 674 hookCallback = callback; 675 } 676 677 function isArray(input) { 678 return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]'; 679 } 680 681 function isObject(input) { 682 return Object.prototype.toString.call(input) === '[object Object]'; 683 } 684 685 function isObjectEmpty(obj) { 686 var k; 687 for (k in obj) { 688 // even if its not own property I'd still call it non-empty 689 return false; 690 } 691 return true; 692 } 693 694 function isDate(input) { 695 return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]'; 696 } 697 698 function map(arr, fn) { 699 var res = [], i; 700 for (i = 0; i < arr.length; ++i) { 701 res.push(fn(arr[i], i)); 702 } 703 return res; 704 } 705 706 function hasOwnProp(a, b) { 707 return Object.prototype.hasOwnProperty.call(a, b); 708 } 709 710 function extend(a, b) { 711 for (var i in b) { 712 if (hasOwnProp(b, i)) { 713 a[i] = b[i]; 714 } 715 } 716 717 if (hasOwnProp(b, 'toString')) { 718 a.toString = b.toString; 719 } 720 721 if (hasOwnProp(b, 'valueOf')) { 722 a.valueOf = b.valueOf; 723 } 724 725 return a; 726 } 727 728 function create_utc__createUTC (input, format, locale, strict) {
vendor: 9,979 bytes, lines 729-1066
729 return createLocalOrUTC(input, format, locale, strict, true).utc(); 730 } 731 732 function defaultParsingFlags() { 733 // We need to deep clone this object. 734 return { 735 empty : false, 736 unusedTokens : [], 737 unusedInput : [], 738 overflow : -2, 739 charsLeftOver : 0, 740 nullInput : false, 741 invalidMonth : null, 742 invalidFormat : false, 743 userInvalidated : false, 744 iso : false, 745 parsedDateParts : [], 746 meridiem : null 747 }; 748 } 749 750 function getParsingFlags(m) { 751 if (m._pf == null) { 752 m._pf = defaultParsingFlags(); 753 } 754 return m._pf; 755 } 756 757 var some; 758 if (Array.prototype.some) { 759 some = Array.prototype.some; 760 } else { 761 some = function (fun) { 762 var t = Object(this); 763 var len = t.length >>> 0; 764 765 for (var i = 0; i < len; i++) { 766 if (i in t && fun.call(this, t[i], i, t)) { 767 return true; 768 } 769 } 770 771 return false; 772 }; 773 } 774 775 function valid__isValid(m) { 776 if (m._isValid == null) { 777 var flags = getParsingFlags(m); 778 var parsedParts = some.call(flags.parsedDateParts, function (i) { 779 return i != null; 780 }); 781 m._isValid = !isNaN(m._d.getTime()) && 782 flags.overflow < 0 && 783 !flags.empty && 784 !flags.invalidMonth && 785 !flags.invalidWeekday && 786 !flags.nullInput && 787 !flags.invalidFormat && 788 !flags.userInvalidated && 789 (!flags.meridiem || (flags.meridiem && parsedParts)); 790 791 if (m._strict) { 792 m._isValid = m._isValid && 793 flags.charsLeftOver === 0 && 794 flags.unusedTokens.length === 0 && 795 flags.bigHour === undefined; 796 } 797 } 798 return m._isValid; 799 } 800 801 function valid__createInvalid (flags) { 802 var m = create_utc__createUTC(NaN); 803 if (flags != null) { 804 extend(getParsingFlags(m), flags); 805 } 806 else { 807 getParsingFlags(m).userInvalidated = true; 808 } 809 810 return m; 811 } 812 813 function isUndefined(input) { 814 return input === void 0; 815 } 816 817 // Plugins that add properties should also add the key here (null value), 818 // so we can properly clone ourselves. 819 var momentProperties = utils_hooks__hooks.momentProperties = []; 820 821 function copyConfig(to, from) { 822 var i, prop, val; 823 824 if (!isUndefined(from._isAMomentObject)) { 825 to._isAMomentObject = from._isAMomentObject; 826 } 827 if (!isUndefined(from._i)) { 828 to._i = from._i; 829 } 830 if (!isUndefined(from._f)) { 831 to._f = from._f; 832 } 833 if (!isUndefined(from._l)) { 834 to._l = from._l; 835 } 836 if (!isUndefined(from._strict)) { 837 to._strict = from._strict; 838 } 839 if (!isUndefined(from._tzm)) { 840 to._tzm = from._tzm; 841 } 842 if (!isUndefined(from._isUTC)) { 843 to._isUTC = from._isUTC; 844 } 845 if (!isUndefined(from._offset)) { 846 to._offset = from._offset; 847 } 848 if (!isUndefined(from._pf)) { 849 to._pf = getParsingFlags(from); 850 } 851 if (!isUndefined(from._locale)) { 852 to._locale = from._locale; 853 } 854 855 if (momentProperties.length > 0) { 856 for (i in momentProperties) { 857 prop = momentProperties[i]; 858 val = from[prop]; 859 if (!isUndefined(val)) { 860 to[prop] = val; 861 } 862 } 863 } 864 865 return to; 866 } 867 868 var updateInProgress = false; 869 870 // Moment prototype object 871 function Moment(config) { 872 copyConfig(this, config); 873 this._d = new Date(config._d != null ? config._d.getTime() : NaN); 874 // Prevent infinite loop in case updateOffset creates new moment 875 // objects. 876 if (updateInProgress === false) { 877 updateInProgress = true; 878 utils_hooks__hooks.updateOffset(this); 879 updateInProgress = false; 880 } 881 } 882 883 function isMoment (obj) { 884 return obj instanceof Moment || (obj != null && obj._isAMomentObject != null); 885 } 886 887 function absFloor (number) { 888 if (number < 0) { 889 // -0 -> 0 890 return Math.ceil(number) || 0; 891 } else { 892 return Math.floor(number); 893 } 894 } 895 896 function toInt(argumentForCoercion) { 897 var coercedNumber = +argumentForCoercion, 898 value = 0; 899 900 if (coercedNumber !== 0 && isFinite(coercedNumber)) { 901 value = absFloor(coercedNumber); 902 } 903 904 return value; 905 } 906 907 // compare two arrays, return the number of differences 908 function compareArrays(array1, array2, dontConvert) { 909 var len = Math.min(array1.length, array2.length), 910 lengthDiff = Math.abs(array1.length - array2.length), 911 diffs = 0, 912 i; 913 for (i = 0; i < len; i++) { 914 if ((dontConvert && array1[i] !== array2[i]) || 915 (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) { 916 diffs++; 917 } 918 } 919 return diffs + lengthDiff; 920 } 921 922 function warn(msg) { 923 if (utils_hooks__hooks.suppressDeprecationWarnings === false && 924 (typeof console !== 'undefined') && console.warn) { 925 console.warn('Deprecation warning: ' + msg); 926 } 927 } 928 929 function deprecate(msg, fn) { 930 var firstTime = true; 931 932 return extend(function () { 933 if (utils_hooks__hooks.deprecationHandler != null) { 934 utils_hooks__hooks.deprecationHandler(null, msg); 935 } 936 if (firstTime) { 937 warn(msg + '\nArguments: ' + Array.prototype.slice.call(arguments).join(', ') + '\n' + (new Error()).stack); 938 firstTime = false; 939 } 940 return fn.apply(this, arguments); 941 }, fn); 942 } 943 944 var deprecations = {}; 945 946 function deprecateSimple(name, msg) { 947 if (utils_hooks__hooks.deprecationHandler != null) { 948 utils_hooks__hooks.deprecationHandler(name, msg); 949 } 950 if (!deprecations[name]) { 951 warn(msg); 952 deprecations[name] = true; 953 } 954 } 955 956 utils_hooks__hooks.suppressDeprecationWarnings = false; 957 utils_hooks__hooks.deprecationHandler = null; 958 959 function isFunction(input) { 960 return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]'; 961 } 962 963 function locale_set__set (config) { 964 var prop, i; 965 for (i in config) { 966 prop = config[i]; 967 if (isFunction(prop)) { 968 this[i] = prop; 969 } else { 970 this['_' + i] = prop; 971 } 972 } 973 this._config = config; 974 // Lenient ordinal parsing accepts just a number in addition to 975 // number + (possibly) stuff coming from _ordinalParseLenient. 976 this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + (/\d{1,2}/).source); 977 } 978 979 function mergeConfigs(parentConfig, childConfig) { 980 var res = extend({}, parentConfig), prop; 981 for (prop in childConfig) { 982 if (hasOwnProp(childConfig, prop)) { 983 if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) { 984 res[prop] = {}; 985 extend(res[prop], parentConfig[prop]); 986 extend(res[prop], childConfig[prop]); 987 } else if (childConfig[prop] != null) { 988 res[prop] = childConfig[prop]; 989 } else { 990 delete res[prop]; 991 } 992 } 993 } 994 for (prop in parentConfig) { 995 if (hasOwnProp(parentConfig, prop) && 996 !hasOwnProp(childConfig, prop) && 997 isObject(parentConfig[prop])) { 998 // make sure changes to properties don't modify parent config 999 res[prop] = extend({}, res[prop]); 1000 } 1001 } 1002 return res; 1003 } 1004 1005 function Locale(config) { 1006 if (config != null) { 1007 this.set(config); 1008 } 1009 } 1010 1011 var keys; 1012 1013 if (Object.keys) { 1014 keys = Object.keys; 1015 } else { 1016 keys = function (obj) { 1017 var i, res = []; 1018 for (i in obj) { 1019 if (hasOwnProp(obj, i)) { 1020 res.push(i); 1021 } 1022 } 1023 return res; 1024 }; 1025 } 1026 1027 var defaultCalendar = { 1028 sameDay : '[Today at] LT', 1029 nextDay : '[Tomorrow at] LT', 1030 nextWeek : 'dddd [at] LT', 1031 lastDay : '[Yesterday at] LT', 1032 lastWeek : '[Last] dddd [at] LT', 1033 sameElse : 'L' 1034 }; 1035 1036 function locale_calendar__calendar (key, mom, now) { 1037 var output = this._calendar[key] || this._calendar['sameElse']; 1038 return isFunction(output) ? output.call(mom, now) : output; 1039 } 1040 1041 var defaultLongDateFormat = { 1042 LTS : 'h:mm:ss A', 1043 LT : 'h:mm A', 1044 L : 'MM/DD/YYYY', 1045 LL : 'MMMM D, YYYY', 1046 LLL : 'MMMM D, YYYY h:mm A', 1047 LLLL : 'dddd, MMMM D, YYYY h:mm A' 1048 }; 1049 1050 function longDateFormat (key) { 1051 var format = this._longDateFormat[key], 1052 formatUpper = this._longDateFormat[key.toUpperCase()]; 1053 1054 if (format || !formatUpper) { 1055 return format; 1056 } 1057 1058 this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) { 1059 return val.slice(1); 1060 }); 1061 1062 return this._longDateFormat[key]; 1063 } 1064 1065 var defaultInvalidDate = 'Invalid date'; 1066
1067 function invalidDate () { 1068 return this._invalidDate; 1069 } 1070 1071 var defaultOrdinal = '%d'; 1072 var defaultOrdinalParse = /\d{1,2}/; 1073 1074 function ordinal (number) { 1075 return this._ordinal.replace('%d', number); 1076 } 1077 1078 var defaultRelativeTime = { 1079 future : 'in %s', 1080 past : '%s ago', 1081 s : 'a few seconds', 1082 m : 'a minute', 1083 mm : '%d minutes', 1084 h : 'an hour', 1085 hh : '%d hours', 1086 d : 'a day', 1087 dd : '%d days', 1088 M : 'a month', 1089 MM : '%d months', 1090 y : 'a year', 1091 yy : '%d years' 1092 }; 1093 1094 function relative__relativeTime (number, withoutSuffix, string, isFuture) { 1095 var output = this._relativeTime[string]; 1096 return (isFunction(output)) ? 1097 output(number, withoutSuffix, string, isFuture) : 1098 output.replace(/%d/i, number); 1099 } 1100 1101 function pastFuture (diff, output) { 1102 var format = this._relativeTime[diff > 0 ? 'future' : 'past']; 1103 return isFunction(format) ? format(output) : format.replace(/%s/i, output); 1104 } 1105 1106 var aliases = {}; 1107 1108 function addUnitAlias (unit, shorthand) { 1109 var lowerCase = unit.toLowerCase(); 1110 aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit; 1111 } 1112 1113 function normalizeUnits(units) { 1114 return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined; 1115 } 1116 1117 function normalizeObjectUnits(inputObject) { 1118 var normalizedInput = {}, 1119 normalizedProp, 1120 prop; 1121 1122 for (prop in inputObject) { 1123 if (hasOwnProp(inputObject, prop)) { 1124 normalizedProp = normalizeUnits(prop); 1125 if (normalizedProp) { 1126 normalizedInput[normalizedProp] = inputObject[prop]; 1127 } 1128 } 1129 } 1130 1131 return normalizedInput; 1132 } 1133 1134 var priorities = {}; 1135 1136 function addUnitPriority(unit, priority) { 1137 priorities[unit] = priority; 1138 } 1139 1140 function getPrioritizedUnits(unitsObj) { 1141 var units = []; 1142 for (var u in unitsObj) { 1143 units.push({unit: u, priority: priorities[u]}); 1144 } 1145 units.sort(function (a, b) { 1146 return a.priority - b.priority; 1147 }); 1148 return units; 1149 } 1150 1151 function makeGetSet (unit, keepTime) { 1152 return function (value) { 1153 if (value != null) { 1154 get_set__set(this, unit, value); 1155 utils_hooks__hooks.updateOffset(this, keepTime); 1156 return this; 1157 } else { 1158 return get_set__get(this, unit); 1159 } 1160 }; 1161 } 1162 1163 function get_set__get (mom, unit) { 1164 return mom.isValid() ? 1165 mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() : NaN; 1166 } 1167 1168 function get_set__set (mom, unit, value) { 1169 if (mom.isValid()) { 1170 mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value); 1171 } 1172 } 1173 1174 // MOMENTS 1175 1176 function stringGet (units) { 1177 units = normalizeUnits(units); 1178 if (isFunction(this[units])) { 1179 return this[units](); 1180 } 1181 return this; 1182 } 1183 1184 1185 function stringSet (units, value) { 1186 if (typeof units === 'object') { 1187 units = normalizeObjectUnits(units); 1188 var prioritized = getPrioritizedUnits(units); 1189 for (var i = 0; i < prioritized.length; i++) { 1190 this[prioritized[i].unit](units[prioritized[i].unit]); 1191 } 1192 } else { 1193 units = normalizeUnits(units); 1194 if (isFunction(this[units])) { 1195 return this[units](value); 1196 } 1197 } 1198 return this; 1199 } 1200 1201 function zeroFill(number, targetLength, forceSign) { 1202 var absNumber = '' + Math.abs(number), 1203 zerosToFill = targetLength - absNumber.length, 1204 sign = number >= 0; 1205 return (sign ? (forceSign ? '+' : '') : '-') + 1206 Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber; 1207 } 1208 1209 var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}
vendor: 79,654 bytes, lines 1209-3562
1209|x|X|zz?|ZZ?|.)/g; 1210 1211 var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g; 1212 1213 var formatFunctions = {}; 1214 1215 var formatTokenFunctions = {}; 1216 1217 // token: 'M' 1218 // padded: ['MM', 2] 1219 // ordinal: 'Mo' 1220 // callback: function () { this.month() + 1 } 1221 function addFormatToken (token, padded, ordinal, callback) { 1222 var func = callback; 1223 if (typeof callback === 'string') { 1224 func = function () { 1225 return this[callback](); 1226 }; 1227 } 1228 if (token) { 1229 formatTokenFunctions[token] = func; 1230 } 1231 if (padded) { 1232 formatTokenFunctions[padded[0]] = function () { 1233 return zeroFill(func.apply(this, arguments), padded[1], padded[2]); 1234 }; 1235 } 1236 if (ordinal) { 1237 formatTokenFunctions[ordinal] = function () { 1238 return this.localeData().ordinal(func.apply(this, arguments), token); 1239 }; 1240 } 1241 } 1242 1243 function removeFormattingTokens(input) { 1244 if (input.match(/\[[\s\S]/)) { 1245 return input.replace(/^\[|\]$/g, ''); 1246 } 1247 return input.replace(/\\/g, ''); 1248 } 1249 1250 function makeFormatFunction(format) { 1251 var array = format.match(formattingTokens), i, length; 1252 1253 for (i = 0, length = array.length; i < length; i++) { 1254 if (formatTokenFunctions[array[i]]) { 1255 array[i] = formatTokenFunctions[array[i]]; 1256 } else { 1257 array[i] = removeFormattingTokens(array[i]); 1258 } 1259 } 1260 1261 return function (mom) { 1262 var output = '', i; 1263 for (i = 0; i < length; i++) { 1264 output += array[i] instanceof Function ? array[i].call(mom, format) : array[i]; 1265 } 1266 return output; 1267 }; 1268 } 1269 1270 // format date using native date object 1271 function formatMoment(m, format) { 1272 if (!m.isValid()) { 1273 return m.localeData().invalidDate(); 1274 } 1275 1276 format = expandFormat(format, m.localeData()); 1277 formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format); 1278 1279 return formatFunctions[format](m); 1280 } 1281 1282 function expandFormat(format, locale) { 1283 var i = 5; 1284 1285 function replaceLongDateFormatTokens(input) { 1286 return locale.longDateFormat(input) || input; 1287 } 1288 1289 localFormattingTokens.lastIndex = 0; 1290 while (i >= 0 && localFormattingTokens.test(format)) { 1291 format = format.replace(localFormattingTokens, replaceLongDateFormatTokens); 1292 localFormattingTokens.lastIndex = 0; 1293 i -= 1; 1294 } 1295 1296 return format; 1297 } 1298 1299 var match1 = /\d/; // 0 - 9 1300 var match2 = /\d\d/; // 00 - 99 1301 var match3 = /\d{3}/; // 000 - 999 1302 var match4 = /\d{4}/; // 0000 - 9999 1303 var match6 = /[+-]?\d{6}/; // -999999 - 999999 1304 var match1to2 = /\d\d?/; // 0 - 99 1305 var match3to4 = /\d\d\d\d?/; // 999 - 9999 1306 var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999 1307 var match1to3 = /\d{1,3}/; // 0 - 999 1308 var match1to4 = /\d{1,4}/; // 0 - 9999 1309 var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999 1310 1311 var matchUnsigned = /\d+/; // 0 - inf 1312 var matchSigned = /[+-]?\d+/; // -inf - inf 1313 1314 var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z 1315 var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z 1316 1317 var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123 1318 1319 // any word (or two) characters or numbers including two/three word month in arabic. 1320 // includes scottish gaelic two word and hyphenated months 1321 var matchWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i; 1322 1323 1324 var regexes = {}; 1325 1326 function addRegexToken (token, regex, strictRegex) { 1327 regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) { 1328 return (isStrict && strictRegex) ? strictRegex : regex; 1329 }; 1330 } 1331 1332 function getParseRegexForToken (token, config) { 1333 if (!hasOwnProp(regexes, token)) { 1334 return new RegExp(unescapeFormat(token)); 1335 } 1336 1337 return regexes[token](config._strict, config._locale); 1338 } 1339 1340 // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript 1341 function unescapeFormat(s) { 1342 return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) { 1343 return p1 || p2 || p3 || p4; 1344 })); 1345 } 1346 1347 function regexEscape(s) { 1348 return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); 1349 } 1350 1351 var tokens = {}; 1352 1353 function addParseToken (token, callback) { 1354 var i, func = callback; 1355 if (typeof token === 'string') { 1356 token = [token]; 1357 } 1358 if (typeof callback === 'number') { 1359 func = function (input, array) { 1360 array[callback] = toInt(input); 1361 }; 1362 } 1363 for (i = 0; i < token.length; i++) { 1364 tokens[token[i]] = func; 1365 } 1366 } 1367 1368 function addWeekParseToken (token, callback) { 1369 addParseToken(token, function (input, array, config, token) { 1370 config._w = config._w || {}; 1371 callback(input, config._w, config, token); 1372 }); 1373 } 1374 1375 function addTimeToArrayFromToken(token, input, config) { 1376 if (input != null && hasOwnProp(tokens, token)) { 1377 tokens[token](input, config._a, config, token); 1378 } 1379 } 1380 1381 var YEAR = 0; 1382 var MONTH = 1; 1383 var DATE = 2; 1384 var HOUR = 3; 1385 var MINUTE = 4; 1386 var SECOND = 5; 1387 var MILLISECOND = 6; 1388 var WEEK = 7; 1389 var WEEKDAY = 8; 1390 1391 var indexOf; 1392 1393 if (Array.prototype.indexOf) { 1394 indexOf = Array.prototype.indexOf; 1395 } else { 1396 indexOf = function (o) { 1397 // I know 1398 var i; 1399 for (i = 0; i < this.length; ++i) { 1400 if (this[i] === o) { 1401 return i; 1402 } 1403 } 1404 return -1; 1405 }; 1406 } 1407 1408 function daysInMonth(year, month) { 1409 return new Date(Date.UTC(year, month + 1, 0)).getUTCDate(); 1410 } 1411 1412 // FORMATTING 1413 1414 addFormatToken('M', ['MM', 2], 'Mo', function () { 1415 return this.month() + 1; 1416 }); 1417 1418 addFormatToken('MMM', 0, 0, function (format) { 1419 return this.localeData().monthsShort(this, format); 1420 }); 1421 1422 addFormatToken('MMMM', 0, 0, function (format) { 1423 return this.localeData().months(this, format); 1424 }); 1425 1426 // ALIASES 1427 1428 addUnitAlias('month', 'M'); 1429 1430 // PRIORITY 1431 1432 addUnitPriority('month', 8); 1433 1434 // PARSING 1435 1436 addRegexToken('M', match1to2); 1437 addRegexToken('MM', match1to2, match2); 1438 addRegexToken('MMM', function (isStrict, locale) { 1439 return locale.monthsShortRegex(isStrict); 1440 }); 1441 addRegexToken('MMMM', function (isStrict, locale) { 1442 return locale.monthsRegex(isStrict); 1443 }); 1444 1445 addParseToken(['M', 'MM'], function (input, array) { 1446 array[MONTH] = toInt(input) - 1; 1447 }); 1448 1449 addParseToken(['MMM', 'MMMM'], function (input, array, config, token) { 1450 var month = config._locale.monthsParse(input, token, config._strict); 1451 // if we didn't find a month name, mark the date as invalid. 1452 if (month != null) { 1453 array[MONTH] = month; 1454 } else { 1455 getParsingFlags(config).invalidMonth = input; 1456 } 1457 }); 1458 1459 // LOCALES 1460 1461 var MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/; 1462 var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'); 1463 function localeMonths (m, format) { 1464 return isArray(this._months) ? this._months[m.month()] : 1465 this._months[(this._months.isFormat || MONTHS_IN_FORMAT).test(format) ? 'format' : 'standalone'][m.month()]; 1466 } 1467 1468 var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'); 1469 function localeMonthsShort (m, format) { 1470 return isArray(this._monthsShort) ? this._monthsShort[m.month()] : 1471 this._monthsShort[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()]; 1472 } 1473 1474 function units_month__handleStrictParse(monthName, format, strict) { 1475 var i, ii, mom, llc = monthName.toLocaleLowerCase(); 1476 if (!this._monthsParse) { 1477 // this is not used 1478 this._monthsParse = []; 1479 this._longMonthsParse = []; 1480 this._shortMonthsParse = []; 1481 for (i = 0; i < 12; ++i) { 1482 mom = create_utc__createUTC([2000, i]); 1483 this._shortMonthsParse[i] = this.monthsShort(mom, '').toLocaleLowerCase(); 1484 this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase(); 1485 } 1486 } 1487 1488 if (strict) { 1489 if (format === 'MMM') { 1490 ii = indexOf.call(this._shortMonthsParse, llc); 1491 return ii !== -1 ? ii : null; 1492 } else { 1493 ii = indexOf.call(this._longMonthsParse, llc); 1494 return ii !== -1 ? ii : null; 1495 } 1496 } else { 1497 if (format === 'MMM') { 1498 ii = indexOf.call(this._shortMonthsParse, llc); 1499 if (ii !== -1) { 1500 return ii; 1501 } 1502 ii = indexOf.call(this._longMonthsParse, llc); 1503 return ii !== -1 ? ii : null; 1504 } else { 1505 ii = indexOf.call(this._longMonthsParse, llc); 1506 if (ii !== -1) { 1507 return ii; 1508 } 1509 ii = indexOf.call(this._shortMonthsParse, llc); 1510 return ii !== -1 ? ii : null; 1511 } 1512 } 1513 } 1514 1515 function localeMonthsParse (monthName, format, strict) { 1516 var i, mom, regex; 1517 1518 if (this._monthsParseExact) { 1519 return units_month__handleStrictParse.call(this, monthName, format, strict); 1520 } 1521 1522 if (!this._monthsParse) { 1523 this._monthsParse = []; 1524 this._longMonthsParse = []; 1525 this._shortMonthsParse = []; 1526 } 1527 1528 // TODO: add sorting 1529 // Sorting makes sure if one month (or abbr) is a prefix of another 1530 // see sorting in computeMonthsParse 1531 for (i = 0; i < 12; i++) { 1532 // make the regex if we don't have it already 1533 mom = create_utc__createUTC([2000, i]); 1534 if (strict && !this._longMonthsParse[i]) { 1535 this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i'); 1536 this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i'); 1537 } 1538 if (!strict && !this._monthsParse[i]) { 1539 regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, ''); 1540 this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i'); 1541 } 1542 // test the regex 1543 if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) { 1544 return i; 1545 } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) { 1546 return i; 1547 } else if (!strict && this._monthsParse[i].test(monthName)) { 1548 return i; 1549 } 1550 } 1551 } 1552 1553 // MOMENTS 1554 1555 function setMonth (mom, value) { 1556 var dayOfMonth; 1557 1558 if (!mom.isValid()) { 1559 // No op 1560 return mom; 1561 } 1562 1563 if (typeof value === 'string') { 1564 if (/^\d+$/.test(value)) { 1565 value = toInt(value); 1566 } else { 1567 value = mom.localeData().monthsParse(value); 1568 // TODO: Another silent failure? 1569 if (typeof value !== 'number') { 1570 return mom; 1571 } 1572 } 1573 } 1574 1575 dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value)); 1576 mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth); 1577 return mom; 1578 } 1579 1580 function getSetMonth (value) { 1581 if (value != null) { 1582 setMonth(this, value); 1583 utils_hooks__hooks.updateOffset(this, true); 1584 return this; 1585 } else { 1586 return get_set__get(this, 'Month'); 1587 } 1588 } 1589 1590 function getDaysInMonth () { 1591 return daysInMonth(this.year(), this.month()); 1592 } 1593 1594 var defaultMonthsShortRegex = matchWord; 1595 function monthsShortRegex (isStrict) { 1596 if (this._monthsParseExact) { 1597 if (!hasOwnProp(this, '_monthsRegex')) { 1598 computeMonthsParse.call(this); 1599 } 1600 if (isStrict) { 1601 return this._monthsShortStrictRegex; 1602 } else { 1603 return this._monthsShortRegex; 1604 } 1605 } else { 1606 if (!hasOwnProp(this, '_monthsShortRegex')) { 1607 this._monthsShortRegex = defaultMonthsShortRegex; 1608 } 1609 return this._monthsShortStrictRegex && isStrict ? 1610 this._monthsShortStrictRegex : this._monthsShortRegex; 1611 } 1612 } 1613 1614 var defaultMonthsRegex = matchWord; 1615 function monthsRegex (isStrict) { 1616 if (this._monthsParseExact) { 1617 if (!hasOwnProp(this, '_monthsRegex')) { 1618 computeMonthsParse.call(this); 1619 } 1620 if (isStrict) { 1621 return this._monthsStrictRegex; 1622 } else { 1623 return this._monthsRegex; 1624 } 1625 } else { 1626 if (!hasOwnProp(this, '_monthsRegex')) { 1627 this._monthsRegex = defaultMonthsRegex; 1628 } 1629 return this._monthsStrictRegex && isStrict ? 1630 this._monthsStrictRegex : this._monthsRegex; 1631 } 1632 } 1633 1634 function computeMonthsParse () { 1635 function cmpLenRev(a, b) { 1636 return b.length - a.length; 1637 } 1638 1639 var shortPieces = [], longPieces = [], mixedPieces = [], 1640 i, mom; 1641 for (i = 0; i < 12; i++) { 1642 // make the regex if we don't have it already 1643 mom = create_utc__createUTC([2000, i]); 1644 shortPieces.push(this.monthsShort(mom, '')); 1645 longPieces.push(this.months(mom, '')); 1646 mixedPieces.push(this.months(mom, '')); 1647 mixedPieces.push(this.monthsShort(mom, '')); 1648 } 1649 // Sorting makes sure if one month (or abbr) is a prefix of another it 1650 // will match the longer piece. 1651 shortPieces.sort(cmpLenRev); 1652 longPieces.sort(cmpLenRev); 1653 mixedPieces.sort(cmpLenRev); 1654 for (i = 0; i < 12; i++) { 1655 shortPieces[i] = regexEscape(shortPieces[i]); 1656 longPieces[i] = regexEscape(longPieces[i]); 1657 } 1658 for (i = 0; i < 24; i++) { 1659 mixedPieces[i] = regexEscape(mixedPieces[i]); 1660 } 1661 1662 this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i'); 1663 this._monthsShortRegex = this._monthsRegex; 1664 this._monthsStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i'); 1665 this._monthsShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i'); 1666 } 1667 1668 // FORMATTING 1669 1670 addFormatToken('Y', 0, 0, function () { 1671 var y = this.year(); 1672 return y <= 9999 ? '' + y : '+' + y; 1673 }); 1674 1675 addFormatToken(0, ['YY', 2], 0, function () { 1676 return this.year() % 100; 1677 }); 1678 1679 addFormatToken(0, ['YYYY', 4], 0, 'year'); 1680 addFormatToken(0, ['YYYYY', 5], 0, 'year'); 1681 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year'); 1682 1683 // ALIASES 1684 1685 addUnitAlias('year', 'y'); 1686 1687 // PRIORITIES 1688 1689 addUnitPriority('year', 1); 1690 1691 // PARSING 1692 1693 addRegexToken('Y', matchSigned); 1694 addRegexToken('YY', match1to2, match2); 1695 addRegexToken('YYYY', match1to4, match4); 1696 addRegexToken('YYYYY', match1to6, match6); 1697 addRegexToken('YYYYYY', match1to6, match6); 1698 1699 addParseToken(['YYYYY', 'YYYYYY'], YEAR); 1700 addParseToken('YYYY', function (input, array) { 1701 array[YEAR] = input.length === 2 ? utils_hooks__hooks.parseTwoDigitYear(input) : toInt(input); 1702 }); 1703 addParseToken('YY', function (input, array) { 1704 array[YEAR] = utils_hooks__hooks.parseTwoDigitYear(input); 1705 }); 1706 addParseToken('Y', function (input, array) { 1707 array[YEAR] = parseInt(input, 10); 1708 }); 1709 1710 // HELPERS 1711 1712 function daysInYear(year) { 1713 return isLeapYear(year) ? 366 : 365; 1714 } 1715 1716 function isLeapYear(year) { 1717 return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; 1718 } 1719 1720 // HOOKS 1721 1722 utils_hooks__hooks.parseTwoDigitYear = function (input) { 1723 return toInt(input) + (toInt(input) > 68 ? 1900 : 2000); 1724 }; 1725 1726 // MOMENTS 1727 1728 var getSetYear = makeGetSet('FullYear', true); 1729 1730 function getIsLeapYear () { 1731 return isLeapYear(this.year()); 1732 } 1733 1734 function createDate (y, m, d, h, M, s, ms) { 1735 //can't just apply() to create a date: 1736 //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply 1737 var date = new Date(y, m, d, h, M, s, ms); 1738 1739 //the date constructor remaps years 0-99 to 1900-1999 1740 if (y < 100 && y >= 0 && isFinite(date.getFullYear())) { 1741 date.setFullYear(y); 1742 } 1743 return date; 1744 } 1745 1746 function createUTCDate (y) { 1747 var date = new Date(Date.UTC.apply(null, arguments)); 1748 1749 //the Date.UTC function remaps years 0-99 to 1900-1999 1750 if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) { 1751 date.setUTCFullYear(y); 1752 } 1753 return date; 1754 } 1755 1756 // start-of-first-week - start-of-year 1757 function firstWeekOffset(year, dow, doy) { 1758 var // first-week day -- which january is always in the first week (4 for iso, 1 for other) 1759 fwd = 7 + dow - doy, 1760 // first-week day local weekday -- which local weekday is fwd 1761 fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7; 1762 1763 return -fwdlw + fwd - 1; 1764 } 1765 1766 //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday 1767 function dayOfYearFromWeeks(year, week, weekday, dow, doy) { 1768 var localWeekday = (7 + weekday - dow) % 7, 1769 weekOffset = firstWeekOffset(year, dow, doy), 1770 dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset, 1771 resYear, resDayOfYear; 1772 1773 if (dayOfYear <= 0) { 1774 resYear = year - 1; 1775 resDayOfYear = daysInYear(resYear) + dayOfYear; 1776 } else if (dayOfYear > daysInYear(year)) { 1777 resYear = year + 1; 1778 resDayOfYear = dayOfYear - daysInYear(year); 1779 } else { 1780 resYear = year; 1781 resDayOfYear = dayOfYear; 1782 } 1783 1784 return { 1785 year: resYear, 1786 dayOfYear: resDayOfYear 1787 }; 1788 } 1789 1790 function weekOfYear(mom, dow, doy) { 1791 var weekOffset = firstWeekOffset(mom.year(), dow, doy), 1792 week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1, 1793 resWeek, resYear; 1794 1795 if (week < 1) { 1796 resYear = mom.year() - 1; 1797 resWeek = week + weeksInYear(resYear, dow, doy); 1798 } else if (week > weeksInYear(mom.year(), dow, doy)) { 1799 resWeek = week - weeksInYear(mom.year(), dow, doy); 1800 resYear = mom.year() + 1; 1801 } else { 1802 resYear = mom.year(); 1803 resWeek = week; 1804 } 1805 1806 return { 1807 week: resWeek, 1808 year: resYear 1809 }; 1810 } 1811 1812 function weeksInYear(year, dow, doy) { 1813 var weekOffset = firstWeekOffset(year, dow, doy), 1814 weekOffsetNext = firstWeekOffset(year + 1, dow, doy); 1815 return (daysInYear(year) - weekOffset + weekOffsetNext) / 7; 1816 } 1817 1818 // FORMATTING 1819 1820 addFormatToken('w', ['ww', 2], 'wo', 'week'); 1821 addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek'); 1822 1823 // ALIASES 1824 1825 addUnitAlias('week', 'w'); 1826 addUnitAlias('isoWeek', 'W'); 1827 1828 // PRIORITIES 1829 1830 addUnitPriority('week', 5); 1831 addUnitPriority('isoWeek', 5); 1832 1833 // PARSING 1834 1835 addRegexToken('w', match1to2); 1836 addRegexToken('ww', match1to2, match2); 1837 addRegexToken('W', match1to2); 1838 addRegexToken('WW', match1to2, match2); 1839 1840 addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) { 1841 week[token.substr(0, 1)] = toInt(input); 1842 }); 1843 1844 // HELPERS 1845 1846 // LOCALES 1847 1848 function localeWeek (mom) { 1849 return weekOfYear(mom, this._week.dow, this._week.doy).week; 1850 } 1851 1852 var defaultLocaleWeek = { 1853 dow : 0, // Sunday is the first day of the week. 1854 doy : 6 // The week that contains Jan 1st is the first week of the year. 1855 }; 1856 1857 function localeFirstDayOfWeek () { 1858 return this._week.dow; 1859 } 1860 1861 function localeFirstDayOfYear () { 1862 return this._week.doy; 1863 } 1864 1865 // MOMENTS 1866 1867 function getSetWeek (input) { 1868 var week = this.localeData().week(this); 1869 return input == null ? week : this.add((input - week) * 7, 'd'); 1870 } 1871 1872 function getSetISOWeek (input) { 1873 var week = weekOfYear(this, 1, 4).week; 1874 return input == null ? week : this.add((input - week) * 7, 'd'); 1875 } 1876 1877 // FORMATTING 1878 1879 addFormatToken('d', 0, 'do', 'day'); 1880 1881 addFormatToken('dd', 0, 0, function (format) { 1882 return this.localeData().weekdaysMin(this, format); 1883 }); 1884 1885 addFormatToken('ddd', 0, 0, function (format) { 1886 return this.localeData().weekdaysShort(this, format); 1887 }); 1888 1889 addFormatToken('dddd', 0, 0, function (format) { 1890 return this.localeData().weekdays(this, format); 1891 }); 1892 1893 addFormatToken('e', 0, 0, 'weekday'); 1894 addFormatToken('E', 0, 0, 'isoWeekday'); 1895 1896 // ALIASES 1897 1898 addUnitAlias('day', 'd'); 1899 addUnitAlias('weekday', 'e'); 1900 addUnitAlias('isoWeekday', 'E'); 1901 1902 // PRIORITY 1903 addUnitPriority('day', 11); 1904 addUnitPriority('weekday', 11); 1905 addUnitPriority('isoWeekday', 11); 1906 1907 // PARSING 1908 1909 addRegexToken('d', match1to2); 1910 addRegexToken('e', match1to2); 1911 addRegexToken('E', match1to2); 1912 addRegexToken('dd', function (isStrict, locale) { 1913 return locale.weekdaysMinRegex(isStrict); 1914 }); 1915 addRegexToken('ddd', function (isStrict, locale) { 1916 return locale.weekdaysShortRegex(isStrict); 1917 }); 1918 addRegexToken('dddd', function (isStrict, locale) { 1919 return locale.weekdaysRegex(isStrict); 1920 }); 1921 1922 addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) { 1923 var weekday = config._locale.weekdaysParse(input, token, config._strict); 1924 // if we didn't get a weekday name, mark the date as invalid 1925 if (weekday != null) { 1926 week.d = weekday; 1927 } else { 1928 getParsingFlags(config).invalidWeekday = input; 1929 } 1930 }); 1931 1932 addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) { 1933 week[token] = toInt(input); 1934 }); 1935 1936 // HELPERS 1937 1938 function parseWeekday(input, locale) { 1939 if (typeof input !== 'string') { 1940 return input; 1941 } 1942 1943 if (!isNaN(input)) { 1944 return parseInt(input, 10); 1945 } 1946 1947 input = locale.weekdaysParse(input); 1948 if (typeof input === 'number') { 1949 return input; 1950 } 1951 1952 return null; 1953 } 1954 1955 function parseIsoWeekday(input, locale) { 1956 if (typeof input === 'string') { 1957 return locale.weekdaysParse(input) % 7 || 7; 1958 } 1959 return isNaN(input) ? null : input; 1960 } 1961 1962 // LOCALES 1963 1964 var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'); 1965 function localeWeekdays (m, format) { 1966 return isArray(this._weekdays) ? this._weekdays[m.day()] : 1967 this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()]; 1968 } 1969 1970 var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'); 1971 function localeWeekdaysShort (m) { 1972 return this._weekdaysShort[m.day()]; 1973 } 1974 1975 var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'); 1976 function localeWeekdaysMin (m) { 1977 return this._weekdaysMin[m.day()]; 1978 } 1979 1980 function day_of_week__handleStrictParse(weekdayName, format, strict) { 1981 var i, ii, mom, llc = weekdayName.toLocaleLowerCase(); 1982 if (!this._weekdaysParse) { 1983 this._weekdaysParse = []; 1984 this._shortWeekdaysParse = []; 1985 this._minWeekdaysParse = []; 1986 1987 for (i = 0; i < 7; ++i) { 1988 mom = create_utc__createUTC([2000, 1]).day(i); 1989 this._minWeekdaysParse[i] = this.weekdaysMin(mom, '').toLocaleLowerCase(); 1990 this._shortWeekdaysParse[i] = this.weekdaysShort(mom, '').toLocaleLowerCase(); 1991 this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase(); 1992 } 1993 } 1994 1995 if (strict) { 1996 if (format === 'dddd') { 1997 ii = indexOf.call(this._weekdaysParse, llc); 1998 return ii !== -1 ? ii : null; 1999 } else if (format === 'ddd') { 2000 ii = indexOf.call(this._shortWeekdaysParse, llc); 2001 return ii !== -1 ? ii : null; 2002 } else { 2003 ii = indexOf.call(this._minWeekdaysParse, llc); 2004 return ii !== -1 ? ii : null; 2005 } 2006 } else { 2007 if (format === 'dddd') { 2008 ii = indexOf.call(this._weekdaysParse, llc); 2009 if (ii !== -1) { 2010 return ii; 2011 } 2012 ii = indexOf.call(this._shortWeekdaysParse, llc); 2013 if (ii !== -1) { 2014 return ii; 2015 } 2016 ii = indexOf.call(this._minWeekdaysParse, llc); 2017 return ii !== -1 ? ii : null; 2018 } else if (format === 'ddd') { 2019 ii = indexOf.call(this._shortWeekdaysParse, llc); 2020 if (ii !== -1) { 2021 return ii; 2022 } 2023 ii = indexOf.call(this._weekdaysParse, llc); 2024 if (ii !== -1) { 2025 return ii; 2026 } 2027 ii = indexOf.call(this._minWeekdaysParse, llc); 2028 return ii !== -1 ? ii : null; 2029 } else { 2030 ii = indexOf.call(this._minWeekdaysParse, llc); 2031 if (ii !== -1) { 2032 return ii; 2033 } 2034 ii = indexOf.call(this._weekdaysParse, llc); 2035 if (ii !== -1) { 2036 return ii; 2037 } 2038 ii = indexOf.call(this._shortWeekdaysParse, llc); 2039 return ii !== -1 ? ii : null; 2040 } 2041 } 2042 } 2043 2044 function localeWeekdaysParse (weekdayName, format, strict) { 2045 var i, mom, regex; 2046 2047 if (this._weekdaysParseExact) { 2048 return day_of_week__handleStrictParse.call(this, weekdayName, format, strict); 2049 } 2050 2051 if (!this._weekdaysParse) { 2052 this._weekdaysParse = []; 2053 this._minWeekdaysParse = []; 2054 this._shortWeekdaysParse = []; 2055 this._fullWeekdaysParse = []; 2056 } 2057 2058 for (i = 0; i < 7; i++) { 2059 // make the regex if we don't have it already 2060 2061 mom = create_utc__createUTC([2000, 1]).day(i); 2062 if (strict && !this._fullWeekdaysParse[i]) { 2063 this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i'); 2064 this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i'); 2065 this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i'); 2066 } 2067 if (!this._weekdaysParse[i]) { 2068 regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, ''); 2069 this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i'); 2070 } 2071 // test the regex 2072 if (strict && format === 'dddd' && this._fullWeekdaysParse[i].test(weekdayName)) { 2073 return i; 2074 } else if (strict && format === 'ddd' && this._shortWeekdaysParse[i].test(weekdayName)) { 2075 return i; 2076 } else if (strict && format === 'dd' && this._minWeekdaysParse[i].test(weekdayName)) { 2077 return i; 2078 } else if (!strict && this._weekdaysParse[i].test(weekdayName)) { 2079 return i; 2080 } 2081 } 2082 } 2083 2084 // MOMENTS 2085 2086 function getSetDayOfWeek (input) { 2087 if (!this.isValid()) { 2088 return input != null ? this : NaN; 2089 } 2090 var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay(); 2091 if (input != null) { 2092 input = parseWeekday(input, this.localeData()); 2093 return this.add(input - day, 'd'); 2094 } else { 2095 return day; 2096 } 2097 } 2098 2099 function getSetLocaleDayOfWeek (input) { 2100 if (!this.isValid()) { 2101 return input != null ? this : NaN; 2102 } 2103 var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7; 2104 return input == null ? weekday : this.add(input - weekday, 'd'); 2105 } 2106 2107 function getSetISODayOfWeek (input) { 2108 if (!this.isValid()) { 2109 return input != null ? this : NaN; 2110 } 2111 2112 // behaves the same as moment#day except 2113 // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6) 2114 // as a setter, sunday should belong to the previous week. 2115 2116 if (input != null) { 2117 var weekday = parseIsoWeekday(input, this.localeData()); 2118 return this.day(this.day() % 7 ? weekday : weekday - 7); 2119 } else { 2120 return this.day() || 7; 2121 } 2122 } 2123 2124 var defaultWeekdaysRegex = matchWord; 2125 function weekdaysRegex (isStrict) { 2126 if (this._weekdaysParseExact) { 2127 if (!hasOwnProp(this, '_weekdaysRegex')) { 2128 computeWeekdaysParse.call(this); 2129 } 2130 if (isStrict) { 2131 return this._weekdaysStrictRegex; 2132 } else { 2133 return this._weekdaysRegex; 2134 } 2135 } else { 2136 if (!hasOwnProp(this, '_weekdaysRegex')) { 2137 this._weekdaysRegex = defaultWeekdaysRegex; 2138 } 2139 return this._weekdaysStrictRegex && isStrict ? 2140 this._weekdaysStrictRegex : this._weekdaysRegex; 2141 } 2142 } 2143 2144 var defaultWeekdaysShortRegex = matchWord; 2145 function weekdaysShortRegex (isStrict) { 2146 if (this._weekdaysParseExact) { 2147 if (!hasOwnProp(this, '_weekdaysRegex')) { 2148 computeWeekdaysParse.call(this); 2149 } 2150 if (isStrict) { 2151 return this._weekdaysShortStrictRegex; 2152 } else { 2153 return this._weekdaysShortRegex; 2154 } 2155 } else { 2156 if (!hasOwnProp(this, '_weekdaysShortRegex')) { 2157 this._weekdaysShortRegex = defaultWeekdaysShortRegex; 2158 } 2159 return this._weekdaysShortStrictRegex && isStrict ? 2160 this._weekdaysShortStrictRegex : this._weekdaysShortRegex; 2161 } 2162 } 2163 2164 var defaultWeekdaysMinRegex = matchWord; 2165 function weekdaysMinRegex (isStrict) { 2166 if (this._weekdaysParseExact) { 2167 if (!hasOwnProp(this, '_weekdaysRegex')) { 2168 computeWeekdaysParse.call(this); 2169 } 2170 if (isStrict) { 2171 return this._weekdaysMinStrictRegex; 2172 } else { 2173 return this._weekdaysMinRegex; 2174 } 2175 } else { 2176 if (!hasOwnProp(this, '_weekdaysMinRegex')) { 2177 this._weekdaysMinRegex = defaultWeekdaysMinRegex; 2178 } 2179 return this._weekdaysMinStrictRegex && isStrict ? 2180 this._weekdaysMinStrictRegex : this._weekdaysMinRegex; 2181 } 2182 } 2183 2184 2185 function computeWeekdaysParse () { 2186 function cmpLenRev(a, b) { 2187 return b.length - a.length; 2188 } 2189 2190 var minPieces = [], shortPieces = [], longPieces = [], mixedPieces = [], 2191 i, mom, minp, shortp, longp; 2192 for (i = 0; i < 7; i++) { 2193 // make the regex if we don't have it already 2194 mom = create_utc__createUTC([2000, 1]).day(i); 2195 minp = this.weekdaysMin(mom, ''); 2196 shortp = this.weekdaysShort(mom, ''); 2197 longp = this.weekdays(mom, ''); 2198 minPieces.push(minp); 2199 shortPieces.push(shortp); 2200 longPieces.push(longp); 2201 mixedPieces.push(minp); 2202 mixedPieces.push(shortp); 2203 mixedPieces.push(longp); 2204 } 2205 // Sorting makes sure if one weekday (or abbr) is a prefix of another it 2206 // will match the longer piece. 2207 minPieces.sort(cmpLenRev); 2208 shortPieces.sort(cmpLenRev); 2209 longPieces.sort(cmpLenRev); 2210 mixedPieces.sort(cmpLenRev); 2211 for (i = 0; i < 7; i++) { 2212 shortPieces[i] = regexEscape(shortPieces[i]); 2213 longPieces[i] = regexEscape(longPieces[i]); 2214 mixedPieces[i] = regexEscape(mixedPieces[i]); 2215 } 2216 2217 this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i'); 2218 this._weekdaysShortRegex = this._weekdaysRegex; 2219 this._weekdaysMinRegex = this._weekdaysRegex; 2220 2221 this._weekdaysStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i'); 2222 this._weekdaysShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i'); 2223 this._weekdaysMinStrictRegex = new RegExp('^(' + minPieces.join('|') + ')', 'i'); 2224 } 2225 2226 // FORMATTING 2227 2228 function hFormat() { 2229 return this.hours() % 12 || 12; 2230 } 2231 2232 function kFormat() { 2233 return this.hours() || 24; 2234 } 2235 2236 addFormatToken('H', ['HH', 2], 0, 'hour'); 2237 addFormatToken('h', ['hh', 2], 0, hFormat); 2238 addFormatToken('k', ['kk', 2], 0, kFormat); 2239 2240 addFormatToken('hmm', 0, 0, function () { 2241 return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2); 2242 }); 2243 2244 addFormatToken('hmmss', 0, 0, function () { 2245 return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) + 2246 zeroFill(this.seconds(), 2); 2247 }); 2248 2249 addFormatToken('Hmm', 0, 0, function () { 2250 return '' + this.hours() + zeroFill(this.minutes(), 2); 2251 }); 2252 2253 addFormatToken('Hmmss', 0, 0, function () { 2254 return '' + this.hours() + zeroFill(this.minutes(), 2) + 2255 zeroFill(this.seconds(), 2); 2256 }); 2257 2258 function meridiem (token, lowercase) { 2259 addFormatToken(token, 0, 0, function () { 2260 return this.localeData().meridiem(this.hours(), this.minutes(), lowercase); 2261 }); 2262 } 2263 2264 meridiem('a', true); 2265 meridiem('A', false); 2266 2267 // ALIASES 2268 2269 addUnitAlias('hour', 'h'); 2270 2271 // PRIORITY 2272 addUnitPriority('hour', 13); 2273 2274 // PARSING 2275 2276 function matchMeridiem (isStrict, locale) { 2277 return locale._meridiemParse; 2278 } 2279 2280 addRegexToken('a', matchMeridiem); 2281 addRegexToken('A', matchMeridiem); 2282 addRegexToken('H', match1to2); 2283 addRegexToken('h', match1to2); 2284 addRegexToken('HH', match1to2, match2); 2285 addRegexToken('hh', match1to2, match2); 2286 2287 addRegexToken('hmm', match3to4); 2288 addRegexToken('hmmss', match5to6); 2289 addRegexToken('Hmm', match3to4); 2290 addRegexToken('Hmmss', match5to6); 2291 2292 addParseToken(['H', 'HH'], HOUR); 2293 addParseToken(['a', 'A'], function (input, array, config) { 2294 config._isPm = config._locale.isPM(input); 2295 config._meridiem = input; 2296 }); 2297 addParseToken(['h', 'hh'], function (input, array, config) { 2298 array[HOUR] = toInt(input); 2299 getParsingFlags(config).bigHour = true; 2300 }); 2301 addParseToken('hmm', function (input, array, config) { 2302 var pos = input.length - 2; 2303 array[HOUR] = toInt(input.substr(0, pos)); 2304 array[MINUTE] = toInt(input.substr(pos)); 2305 getParsingFlags(config).bigHour = true; 2306 }); 2307 addParseToken('hmmss', function (input, array, config) { 2308 var pos1 = input.length - 4; 2309 var pos2 = input.length - 2; 2310 array[HOUR] = toInt(input.substr(0, pos1)); 2311 array[MINUTE] = toInt(input.substr(pos1, 2)); 2312 array[SECOND] = toInt(input.substr(pos2)); 2313 getParsingFlags(config).bigHour = true; 2314 }); 2315 addParseToken('Hmm', function (input, array, config) { 2316 var pos = input.length - 2; 2317 array[HOUR] = toInt(input.substr(0, pos)); 2318 array[MINUTE] = toInt(input.substr(pos)); 2319 }); 2320 addParseToken('Hmmss', function (input, array, config) { 2321 var pos1 = input.length - 4; 2322 var pos2 = input.length - 2; 2323 array[HOUR] = toInt(input.substr(0, pos1)); 2324 array[MINUTE] = toInt(input.substr(pos1, 2)); 2325 array[SECOND] = toInt(input.substr(pos2)); 2326 }); 2327 2328 // LOCALES 2329 2330 function localeIsPM (input) { 2331 // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays 2332 // Using charAt should be more compatible. 2333 return ((input + '').toLowerCase().charAt(0) === 'p'); 2334 } 2335 2336 var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i; 2337 function localeMeridiem (hours, minutes, isLower) { 2338 if (hours > 11) { 2339 return isLower ? 'pm' : 'PM'; 2340 } else { 2341 return isLower ? 'am' : 'AM'; 2342 } 2343 } 2344 2345 2346 // MOMENTS 2347 2348 // Setting the hour should keep the time, because the user explicitly 2349 // specified which hour he wants. So trying to maintain the same hour (in 2350 // a new timezone) makes sense. Adding/subtracting hours does not follow 2351 // this rule. 2352 var getSetHour = makeGetSet('Hours', true); 2353 2354 var baseConfig = { 2355 calendar: defaultCalendar, 2356 longDateFormat: defaultLongDateFormat, 2357 invalidDate: defaultInvalidDate, 2358 ordinal: defaultOrdinal, 2359 ordinalParse: defaultOrdinalParse, 2360 relativeTime: defaultRelativeTime, 2361 2362 months: defaultLocaleMonths, 2363 monthsShort: defaultLocaleMonthsShort, 2364 2365 week: defaultLocaleWeek, 2366 2367 weekdays: defaultLocaleWeekdays, 2368 weekdaysMin: defaultLocaleWeekdaysMin, 2369 weekdaysShort: defaultLocaleWeekdaysShort, 2370 2371 meridiemParse: defaultLocaleMeridiemParse 2372 }; 2373 2374 // internal storage for locale config files 2375 var locales = {}; 2376 var globalLocale; 2377 2378 function normalizeLocale(key) { 2379 return key ? key.toLowerCase().replace('_', '-') : key; 2380 } 2381 2382 // pick the locale from the array 2383 // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each 2384 // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root 2385 function chooseLocale(names) { 2386 var i = 0, j, next, locale, split; 2387 2388 while (i < names.length) { 2389 split = normalizeLocale(names[i]).split('-'); 2390 j = split.length; 2391 next = normalizeLocale(names[i + 1]); 2392 next = next ? next.split('-') : null; 2393 while (j > 0) { 2394 locale = loadLocale(split.slice(0, j).join('-')); 2395 if (locale) { 2396 return locale; 2397 } 2398 if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) { 2399 //the next array item is better than a shallower substring of this one 2400 break; 2401 } 2402 j--; 2403 } 2404 i++; 2405 } 2406 return null; 2407 } 2408 2409 function loadLocale(name) { 2410 var oldLocale = null; 2411 // TODO: Find a better way to register and load all the locales in Node 2412 if (!locales[name] && (typeof module !== 'undefined') && 2413 module && module.exports) { 2414 try { 2415 oldLocale = globalLocale._abbr; 2416 require('./locale/' + name); 2417 // because defineLocale currently also sets the global locale, we 2418 // want to undo that for lazy loaded locales 2419 locale_locales__getSetGlobalLocale(oldLocale); 2420 } catch (e) { } 2421 } 2422 return locales[name]; 2423 } 2424 2425 // This function will load locale and then set the global locale. If 2426 // no arguments are passed in, it will simply return the current global 2427 // locale key. 2428 function locale_locales__getSetGlobalLocale (key, values) { 2429 var data; 2430 if (key) { 2431 if (isUndefined(values)) { 2432 data = locale_locales__getLocale(key); 2433 } 2434 else { 2435 data = defineLocale(key, values); 2436 } 2437 2438 if (data) { 2439 // moment.duration._locale = moment._locale = data; 2440 globalLocale = data; 2441 } 2442 } 2443 2444 return globalLocale._abbr; 2445 } 2446 2447 function defineLocale (name, config) { 2448 if (config !== null) { 2449 var parentConfig = baseConfig; 2450 config.abbr = name; 2451 if (locales[name] != null) { 2452 deprecateSimple('defineLocaleOverride', 2453 'use moment.updateLocale(localeName, config) to change ' + 2454 'an existing locale. moment.defineLocale(localeName, ' + 2455 'config) should only be used for creating a new locale ' + 2456 'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.'); 2457 parentConfig = locales[name]._config; 2458 } else if (config.parentLocale != null) { 2459 if (locales[config.parentLocale] != null) { 2460 parentConfig = locales[config.parentLocale]._config; 2461 } else { 2462 // treat as if there is no base config 2463 deprecateSimple('parentLocaleUndefined', 2464 'specified parentLocale is not defined yet. See http://momentjs.com/guides/#/warnings/parent-locale/'); 2465 } 2466 } 2467 locales[name] = new Locale(mergeConfigs(parentConfig, config)); 2468 2469 // backwards compat for now: also set the locale 2470 locale_locales__getSetGlobalLocale(name); 2471 2472 return locales[name]; 2473 } else { 2474 // useful for testing 2475 delete locales[name]; 2476 return null; 2477 } 2478 } 2479 2480 function updateLocale(name, config) { 2481 if (config != null) { 2482 var locale, parentConfig = baseConfig; 2483 // MERGE 2484 if (locales[name] != null) { 2485 parentConfig = locales[name]._config; 2486 } 2487 config = mergeConfigs(parentConfig, config); 2488 locale = new Locale(config); 2489 locale.parentLocale = locales[name]; 2490 locales[name] = locale; 2491 2492 // backwards compat for now: also set the locale 2493 locale_locales__getSetGlobalLocale(name); 2494 } else { 2495 // pass null for config to unupdate, useful for tests 2496 if (locales[name] != null) { 2497 if (locales[name].parentLocale != null) { 2498 locales[name] = locales[name].parentLocale; 2499 } else if (locales[name] != null) { 2500 delete locales[name]; 2501 } 2502 } 2503 } 2504 return locales[name]; 2505 } 2506 2507 // returns locale data 2508 function locale_locales__getLocale (key) { 2509 var locale; 2510 2511 if (key && key._locale && key._locale._abbr) { 2512 key = key._locale._abbr; 2513 } 2514 2515 if (!key) { 2516 return globalLocale; 2517 } 2518 2519 if (!isArray(key)) { 2520 //short-circuit everything else 2521 locale = loadLocale(key); 2522 if (locale) { 2523 return locale; 2524 } 2525 key = [key]; 2526 } 2527 2528 return chooseLocale(key); 2529 } 2530 2531 function locale_locales__listLocales() { 2532 return keys(locales); 2533 } 2534 2535 function checkOverflow (m) { 2536 var overflow; 2537 var a = m._a; 2538 2539 if (a && getParsingFlags(m).overflow === -2) { 2540 overflow = 2541 a[MONTH] < 0 || a[MONTH] > 11 ? MONTH : 2542 a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE : 2543 a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR : 2544 a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE : 2545 a[SECOND] < 0 || a[SECOND] > 59 ? SECOND : 2546 a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND : 2547 -1; 2548 2549 if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) { 2550 overflow = DATE; 2551 } 2552 if (getParsingFlags(m)._overflowWeeks && overflow === -1) { 2553 overflow = WEEK; 2554 } 2555 if (getParsingFlags(m)._overflowWeekday && overflow === -1) { 2556 overflow = WEEKDAY; 2557 } 2558 2559 getParsingFlags(m).overflow = overflow; 2560 } 2561 2562 return m; 2563 } 2564 2565 // iso 8601 regex 2566 // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00) 2567 var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/; 2568 var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/; 2569 2570 var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/; 2571 2572 var isoDates = [ 2573 ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/], 2574 ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/], 2575 ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/], 2576 ['GGGG-[W]WW', /\d{4}-W\d\d/, false], 2577 ['YYYY-DDD', /\d{4}-\d{3}/], 2578 ['YYYY-MM', /\d{4}-\d\d/, false], 2579 ['YYYYYYMMDD', /[+-]\d{10}/], 2580 ['YYYYMMDD', /\d{8}/], 2581 // YYYYMM is NOT allowed by the standard 2582 ['GGGG[W]WWE', /\d{4}W\d{3}/], 2583 ['GGGG[W]WW', /\d{4}W\d{2}/, false], 2584 ['YYYYDDD', /\d{7}/] 2585 ]; 2586 2587 // iso time formats and regexes 2588 var isoTimes = [ 2589 ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/], 2590 ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/], 2591 ['HH:mm:ss', /\d\d:\d\d:\d\d/], 2592 ['HH:mm', /\d\d:\d\d/], 2593 ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/], 2594 ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/], 2595 ['HHmmss', /\d\d\d\d\d\d/], 2596 ['HHmm', /\d\d\d\d/], 2597 ['HH', /\d\d/] 2598 ]; 2599 2600 var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i; 2601 2602 // date from iso format 2603 function configFromISO(config) { 2604 var i, l, 2605 string = config._i, 2606 match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string), 2607 allowTime, dateFormat, timeFormat, tzFormat; 2608 2609 if (match) { 2610 getParsingFlags(config).iso = true; 2611 2612 for (i = 0, l = isoDates.length; i < l; i++) { 2613 if (isoDates[i][1].exec(match[1])) { 2614 dateFormat = isoDates[i][0]; 2615 allowTime = isoDates[i][2] !== false; 2616 break; 2617 } 2618 } 2619 if (dateFormat == null) { 2620 config._isValid = false; 2621 return; 2622 } 2623 if (match[3]) { 2624 for (i = 0, l = isoTimes.length; i < l; i++) { 2625 if (isoTimes[i][1].exec(match[3])) { 2626 // match[2] should be 'T' or space 2627 timeFormat = (match[2] || ' ') + isoTimes[i][0]; 2628 break; 2629 } 2630 } 2631 if (timeFormat == null) { 2632 config._isValid = false; 2633 return; 2634 } 2635 } 2636 if (!allowTime && timeFormat != null) { 2637 config._isValid = false; 2638 return; 2639 } 2640 if (match[4]) { 2641 if (tzRegex.exec(match[4])) { 2642 tzFormat = 'Z'; 2643 } else { 2644 config._isValid = false; 2645 return; 2646 } 2647 } 2648 config._f = dateFormat + (timeFormat || '') + (tzFormat || ''); 2649 configFromStringAndFormat(config); 2650 } else { 2651 config._isValid = false; 2652 } 2653 } 2654 2655 // date from iso format or fallback 2656 function configFromString(config) { 2657 var matched = aspNetJsonRegex.exec(config._i); 2658 2659 if (matched !== null) { 2660 config._d = new Date(+matched[1]); 2661 return; 2662 } 2663 2664 configFromISO(config); 2665 if (config._isValid === false) { 2666 delete config._isValid; 2667 utils_hooks__hooks.createFromInputFallback(config); 2668 } 2669 } 2670 2671 utils_hooks__hooks.createFromInputFallback = deprecate( 2672 'moment construction falls back to js Date. This is ' + 2673 'discouraged and will be removed in upcoming major ' + 2674 'release. Please refer to ' + 2675 'http://momentjs.com/guides/#/warnings/js-date/ for more info.', 2676 function (config) { 2677 config._d = new Date(config._i + (config._useUTC ? ' UTC' : '')); 2678 } 2679 ); 2680 2681 // Pick the first defined of two or three arguments. 2682 function defaults(a, b, c) { 2683 if (a != null) { 2684 return a; 2685 } 2686 if (b != null) { 2687 return b; 2688 } 2689 return c; 2690 } 2691 2692 function currentDateArray(config) { 2693 // hooks is actually the exported moment object 2694 var nowValue = new Date(utils_hooks__hooks.now()); 2695 if (config._useUTC) { 2696 return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()]; 2697 } 2698 return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()]; 2699 } 2700 2701 // convert an array to a date. 2702 // the array should mirror the parameters below 2703 // note: all values past the year are optional and will default to the lowest possible value. 2704 // [year, month, day , hour, minute, second, millisecond] 2705 function configFromArray (config) { 2706 var i, date, input = [], currentDate, yearToUse; 2707 2708 if (config._d) { 2709 return; 2710 } 2711 2712 currentDate = currentDateArray(config); 2713 2714 //compute day of the year from weeks and weekdays 2715 if (config._w && config._a[DATE] == null && config._a[MONTH] == null) { 2716 dayOfYearFromWeekInfo(config); 2717 } 2718 2719 //if the day of the year is set, figure out what it is 2720 if (config._dayOfYear) { 2721 yearToUse = defaults(config._a[YEAR], currentDate[YEAR]); 2722 2723 if (config._dayOfYear > daysInYear(yearToUse)) { 2724 getParsingFlags(config)._overflowDayOfYear = true; 2725 } 2726 2727 date = createUTCDate(yearToUse, 0, config._dayOfYear); 2728 config._a[MONTH] = date.getUTCMonth(); 2729 config._a[DATE] = date.getUTCDate(); 2730 } 2731 2732 // Default to current date. 2733 // * if no year, month, day of month are given, default to today 2734 // * if day of month is given, default month and year 2735 // * if month is given, default only year 2736 // * if year is given, don't default anything 2737 for (i = 0; i < 3 && config._a[i] == null; ++i) { 2738 config._a[i] = input[i] = currentDate[i]; 2739 } 2740 2741 // Zero out whatever was not defaulted, including time 2742 for (; i < 7; i++) { 2743 config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i]; 2744 } 2745 2746 // Check for 24:00:00.000 2747 if (config._a[HOUR] === 24 && 2748 config._a[MINUTE] === 0 && 2749 config._a[SECOND] === 0 && 2750 config._a[MILLISECOND] === 0) { 2751 config._nextDay = true; 2752 config._a[HOUR] = 0; 2753 } 2754 2755 config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input); 2756 // Apply timezone offset from input. The actual utcOffset can be changed 2757 // with parseZone. 2758 if (config._tzm != null) { 2759 config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm); 2760 } 2761 2762 if (config._nextDay) { 2763 config._a[HOUR] = 24; 2764 } 2765 } 2766 2767 function dayOfYearFromWeekInfo(config) { 2768 var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow; 2769 2770 w = config._w; 2771 if (w.GG != null || w.W != null || w.E != null) { 2772 dow = 1; 2773 doy = 4; 2774 2775 // TODO: We need to take the current isoWeekYear, but that depends on 2776 // how we interpret now (local, utc, fixed offset). So create 2777 // a now version of current config (take local/utc/offset flags, and 2778 // create now). 2779 weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(local__createLocal(), 1, 4).year); 2780 week = defaults(w.W, 1); 2781 weekday = defaults(w.E, 1); 2782 if (weekday < 1 || weekday > 7) { 2783 weekdayOverflow = true; 2784 } 2785 } else { 2786 dow = config._locale._week.dow; 2787 doy = config._locale._week.doy; 2788 2789 weekYear = defaults(w.gg, config._a[YEAR], weekOfYear(local__createLocal(), dow, doy).year); 2790 week = defaults(w.w, 1); 2791 2792 if (w.d != null) { 2793 // weekday -- low day numbers are considered next week 2794 weekday = w.d; 2795 if (weekday < 0 || weekday > 6) { 2796 weekdayOverflow = true; 2797 } 2798 } else if (w.e != null) { 2799 // local weekday -- counting starts from begining of week 2800 weekday = w.e + dow; 2801 if (w.e < 0 || w.e > 6) { 2802 weekdayOverflow = true; 2803 } 2804 } else { 2805 // default to begining of week 2806 weekday = dow; 2807 } 2808 } 2809 if (week < 1 || week > weeksInYear(weekYear, dow, doy)) { 2810 getParsingFlags(config)._overflowWeeks = true; 2811 } else if (weekdayOverflow != null) { 2812 getParsingFlags(config)._overflowWeekday = true; 2813 } else { 2814 temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy); 2815 config._a[YEAR] = temp.year; 2816 config._dayOfYear = temp.dayOfYear; 2817 } 2818 } 2819 2820 // constant that refers to the ISO standard 2821 utils_hooks__hooks.ISO_8601 = function () {}; 2822 2823 // date from string and format string 2824 function configFromStringAndFormat(config) { 2825 // TODO: Move this to another part of the creation flow to prevent circular deps 2826 if (config._f === utils_hooks__hooks.ISO_8601) { 2827 configFromISO(config); 2828 return; 2829 } 2830 2831 config._a = []; 2832 getParsingFlags(config).empty = true; 2833 2834 // This array is used to make a Date, either with `new Date` or `Date.UTC` 2835 var string = '' + config._i, 2836 i, parsedInput, tokens, token, skipped, 2837 stringLength = string.length, 2838 totalParsedInputLength = 0; 2839 2840 tokens = expandFormat(config._f, config._locale).match(formattingTokens) || []; 2841 2842 for (i = 0; i < tokens.length; i++) { 2843 token = tokens[i]; 2844 parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0]; 2845 // console.log('token', token, 'parsedInput', parsedInput, 2846 // 'regex', getParseRegexForToken(token, config)); 2847 if (parsedInput) { 2848 skipped = string.substr(0, string.indexOf(parsedInput)); 2849 if (skipped.length > 0) { 2850 getParsingFlags(config).unusedInput.push(skipped); 2851 } 2852 string = string.slice(string.indexOf(parsedInput) + parsedInput.length); 2853 totalParsedInputLength += parsedInput.length; 2854 } 2855 // don't parse if it's not a known token 2856 if (formatTokenFunctions[token]) { 2857 if (parsedInput) { 2858 getParsingFlags(config).empty = false; 2859 } 2860 else { 2861 getParsingFlags(config).unusedTokens.push(token); 2862 } 2863 addTimeToArrayFromToken(token, parsedInput, config); 2864 } 2865 else if (config._strict && !parsedInput) { 2866 getParsingFlags(config).unusedTokens.push(token); 2867 } 2868 } 2869 2870 // add remaining unparsed input length to the string 2871 getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength; 2872 if (string.length > 0) { 2873 getParsingFlags(config).unusedInput.push(string); 2874 } 2875 2876 // clear _12h flag if hour is <= 12 2877 if (config._a[HOUR] <= 12 && 2878 getParsingFlags(config).bigHour === true && 2879 config._a[HOUR] > 0) { 2880 getParsingFlags(config).bigHour = undefined; 2881 } 2882 2883 getParsingFlags(config).parsedDateParts = config._a.slice(0); 2884 getParsingFlags(config).meridiem = config._meridiem; 2885 // handle meridiem 2886 config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem); 2887 2888 configFromArray(config); 2889 checkOverflow(config); 2890 } 2891 2892 2893 function meridiemFixWrap (locale, hour, meridiem) { 2894 var isPm; 2895 2896 if (meridiem == null) { 2897 // nothing to do 2898 return hour; 2899 } 2900 if (locale.meridiemHour != null) { 2901 return locale.meridiemHour(hour, meridiem); 2902 } else if (locale.isPM != null) { 2903 // Fallback 2904 isPm = locale.isPM(meridiem); 2905 if (isPm && hour < 12) { 2906 hour += 12; 2907 } 2908 if (!isPm && hour === 12) { 2909 hour = 0; 2910 } 2911 return hour; 2912 } else { 2913 // this is not supposed to happen 2914 return hour; 2915 } 2916 } 2917 2918 // date from string and array of format strings 2919 function configFromStringAndArray(config) { 2920 var tempConfig, 2921 bestMoment, 2922 2923 scoreToBeat, 2924 i, 2925 currentScore; 2926 2927 if (config._f.length === 0) { 2928 getParsingFlags(config).invalidFormat = true; 2929 config._d = new Date(NaN); 2930 return; 2931 } 2932 2933 for (i = 0; i < config._f.length; i++) { 2934 currentScore = 0; 2935 tempConfig = copyConfig({}, config); 2936 if (config._useUTC != null) { 2937 tempConfig._useUTC = config._useUTC; 2938 } 2939 tempConfig._f = config._f[i]; 2940 configFromStringAndFormat(tempConfig); 2941 2942 if (!valid__isValid(tempConfig)) { 2943 continue; 2944 } 2945 2946 // if there is any input that was not parsed add a penalty for that format 2947 currentScore += getParsingFlags(tempConfig).charsLeftOver; 2948 2949 //or tokens 2950 currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10; 2951 2952 getParsingFlags(tempConfig).score = currentScore; 2953 2954 if (scoreToBeat == null || currentScore < scoreToBeat) { 2955 scoreToBeat = currentScore; 2956 bestMoment = tempConfig; 2957 } 2958 } 2959 2960 extend(config, bestMoment || tempConfig); 2961 } 2962 2963 function configFromObject(config) { 2964 if (config._d) { 2965 return; 2966 } 2967 2968 var i = normalizeObjectUnits(config._i); 2969 config._a = map([i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond], function (obj) { 2970 return obj && parseInt(obj, 10); 2971 }); 2972 2973 configFromArray(config); 2974 } 2975 2976 function createFromConfig (config) { 2977 var res = new Moment(checkOverflow(prepareConfig(config))); 2978 if (res._nextDay) { 2979 // Adding is smart enough around DST 2980 res.add(1, 'd'); 2981 res._nextDay = undefined; 2982 } 2983 2984 return res; 2985 } 2986 2987 function prepareConfig (config) { 2988 var input = config._i, 2989 format = config._f; 2990 2991 config._locale = config._locale || locale_locales__getLocale(config._l); 2992 2993 if (input === null || (format === undefined && input === '')) { 2994 return valid__createInvalid({nullInput: true}); 2995 } 2996 2997 if (typeof input === 'string') { 2998 config._i = input = config._locale.preparse(input); 2999 } 3000 3001 if (isMoment(input)) { 3002 return new Moment(checkOverflow(input)); 3003 } else if (isArray(format)) { 3004 configFromStringAndArray(config); 3005 } else if (isDate(input)) { 3006 config._d = input; 3007 } else if (format) { 3008 configFromStringAndFormat(config); 3009 } else { 3010 configFromInput(config); 3011 } 3012 3013 if (!valid__isValid(config)) { 3014 config._d = null; 3015 } 3016 3017 return config; 3018 } 3019 3020 function configFromInput(config) { 3021 var input = config._i; 3022 if (input === undefined) { 3023 config._d = new Date(utils_hooks__hooks.now()); 3024 } else if (isDate(input)) { 3025 config._d = new Date(input.valueOf()); 3026 } else if (typeof input === 'string') { 3027 configFromString(config); 3028 } else if (isArray(input)) { 3029 config._a = map(input.slice(0), function (obj) { 3030 return parseInt(obj, 10); 3031 }); 3032 configFromArray(config); 3033 } else if (typeof(input) === 'object') { 3034 configFromObject(config); 3035 } else if (typeof(input) === 'number') { 3036 // from milliseconds 3037 config._d = new Date(input); 3038 } else { 3039 utils_hooks__hooks.createFromInputFallback(config); 3040 } 3041 } 3042 3043 function createLocalOrUTC (input, format, locale, strict, isUTC) { 3044 var c = {}; 3045 3046 if (typeof(locale) === 'boolean') { 3047 strict = locale; 3048 locale = undefined; 3049 } 3050 3051 if ((isObject(input) && isObjectEmpty(input)) || 3052 (isArray(input) && input.length === 0)) { 3053 input = undefined; 3054 } 3055 // object construction must be done this way. 3056 // https://github.com/moment/moment/issues/1423 3057 c._isAMomentObject = true; 3058 c._useUTC = c._isUTC = isUTC; 3059 c._l = locale; 3060 c._i = input; 3061 c._f = format; 3062 c._strict = strict; 3063 3064 return createFromConfig(c); 3065 } 3066 3067 function local__createLocal (input, format, locale, strict) { 3068 return createLocalOrUTC(input, format, locale, strict, false); 3069 } 3070 3071 var prototypeMin = deprecate( 3072 'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/', 3073 function () { 3074 var other = local__createLocal.apply(null, arguments); 3075 if (this.isValid() && other.isValid()) { 3076 return other < this ? this : other; 3077 } else { 3078 return valid__createInvalid(); 3079 } 3080 } 3081 ); 3082 3083 var prototypeMax = deprecate( 3084 'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/', 3085 function () { 3086 var other = local__createLocal.apply(null, arguments); 3087 if (this.isValid() && other.isValid()) { 3088 return other > this ? this : other; 3089 } else { 3090 return valid__createInvalid(); 3091 } 3092 } 3093 ); 3094 3095 // Pick a moment m from moments so that m[fn](other) is true for all 3096 // other. This relies on the function fn to be transitive. 3097 // 3098 // moments should either be an array of moment objects or an array, whose 3099 // first element is an array of moment objects. 3100 function pickBy(fn, moments) { 3101 var res, i; 3102 if (moments.length === 1 && isArray(moments[0])) { 3103 moments = moments[0]; 3104 } 3105 if (!moments.length) { 3106 return local__createLocal(); 3107 } 3108 res = moments[0]; 3109 for (i = 1; i < moments.length; ++i) { 3110 if (!moments[i].isValid() || moments[i][fn](res)) { 3111 res = moments[i]; 3112 } 3113 } 3114 return res; 3115 } 3116 3117 // TODO: Use [].sort instead? 3118 function min () { 3119 var args = [].slice.call(arguments, 0); 3120 3121 return pickBy('isBefore', args); 3122 } 3123 3124 function max () { 3125 var args = [].slice.call(arguments, 0); 3126 3127 return pickBy('isAfter', args); 3128 } 3129 3130 var now = function () { 3131 return Date.now ? Date.now() : +(new Date()); 3132 }; 3133 3134 function Duration (duration) { 3135 var normalizedInput = normalizeObjectUnits(duration), 3136 years = normalizedInput.year || 0, 3137 quarters = normalizedInput.quarter || 0, 3138 months = normalizedInput.month || 0, 3139 weeks = normalizedInput.week || 0, 3140 days = normalizedInput.day || 0, 3141 hours = normalizedInput.hour || 0, 3142 minutes = normalizedInput.minute || 0, 3143 seconds = normalizedInput.second || 0, 3144 milliseconds = normalizedInput.millisecond || 0; 3145 3146 // representation for dateAddRemove 3147 this._milliseconds = +milliseconds + 3148 seconds * 1e3 + // 1000 3149 minutes * 6e4 + // 1000 * 60 3150 hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978 3151 // Because of dateAddRemove treats 24 hours as different from a 3152 // day when working around DST, we need to store them separately 3153 this._days = +days + 3154 weeks * 7; 3155 // It is impossible translate months into days without knowing 3156 // which months you are are talking about, so we have to store 3157 // it separately. 3158 this._months = +months + 3159 quarters * 3 + 3160 years * 12; 3161 3162 this._data = {}; 3163 3164 this._locale = locale_locales__getLocale(); 3165 3166 this._bubble(); 3167 } 3168 3169 function isDuration (obj) { 3170 return obj instanceof Duration; 3171 } 3172 3173 // FORMATTING 3174 3175 function offset (token, separator) { 3176 addFormatToken(token, 0, 0, function () { 3177 var offset = this.utcOffset(); 3178 var sign = '+'; 3179 if (offset < 0) { 3180 offset = -offset; 3181 sign = '-'; 3182 } 3183 return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2); 3184 }); 3185 } 3186 3187 offset('Z', ':'); 3188 offset('ZZ', ''); 3189 3190 // PARSING 3191 3192 addRegexToken('Z', matchShortOffset); 3193 addRegexToken('ZZ', matchShortOffset); 3194 addParseToken(['Z', 'ZZ'], function (input, array, config) { 3195 config._useUTC = true; 3196 config._tzm = offsetFromString(matchShortOffset, input); 3197 }); 3198 3199 // HELPERS 3200 3201 // timezone chunker 3202 // '+10:00' > ['10', '00'] 3203 // '-1530' > ['-15', '30'] 3204 var chunkOffset = /([\+\-]|\d\d)/gi; 3205 3206 function offsetFromString(matcher, string) { 3207 var matches = ((string || '').match(matcher) || []); 3208 var chunk = matches[matches.length - 1] || []; 3209 var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0]; 3210 var minutes = +(parts[1] * 60) + toInt(parts[2]); 3211 3212 return parts[0] === '+' ? minutes : -minutes; 3213 } 3214 3215 // Return a moment from input, that is local/utc/zone equivalent to model. 3216 function cloneWithOffset(input, model) { 3217 var res, diff; 3218 if (model._isUTC) { 3219 res = model.clone(); 3220 diff = (isMoment(input) || isDate(input) ? input.valueOf() : local__createLocal(input).valueOf()) - res.valueOf(); 3221 // Use low-level api, because this fn is low-level api. 3222 res._d.setTime(res._d.valueOf() + diff); 3223 utils_hooks__hooks.updateOffset(res, false); 3224 return res; 3225 } else { 3226 return local__createLocal(input).local(); 3227 } 3228 } 3229 3230 function getDateOffset (m) { 3231 // On Firefox.24 Date#getTimezoneOffset returns a floating point. 3232 // https://github.com/moment/moment/pull/1871 3233 return -Math.round(m._d.getTimezoneOffset() / 15) * 15; 3234 } 3235 3236 // HOOKS 3237 3238 // This function will be called whenever a moment is mutated. 3239 // It is intended to keep the offset in sync with the timezone. 3240 utils_hooks__hooks.updateOffset = function () {}; 3241 3242 // MOMENTS 3243 3244 // keepLocalTime = true means only change the timezone, without 3245 // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]--> 3246 // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset 3247 // +0200, so we adjust the time as needed, to be valid. 3248 // 3249 // Keeping the time actually adds/subtracts (one hour) 3250 // from the actual represented time. That is why we call updateOffset 3251 // a second time. In case it wants us to change the offset again 3252 // _changeInProgress == true case, then we have to adjust, because 3253 // there is no such time in the given timezone. 3254 function getSetOffset (input, keepLocalTime) { 3255 var offset = this._offset || 0, 3256 localAdjust; 3257 if (!this.isValid()) { 3258 return input != null ? this : NaN; 3259 } 3260 if (input != null) { 3261 if (typeof input === 'string') { 3262 input = offsetFromString(matchShortOffset, input); 3263 } else if (Math.abs(input) < 16) { 3264 input = input * 60; 3265 } 3266 if (!this._isUTC && keepLocalTime) { 3267 localAdjust = getDateOffset(this); 3268 } 3269 this._offset = input; 3270 this._isUTC = true; 3271 if (localAdjust != null) { 3272 this.add(localAdjust, 'm'); 3273 } 3274 if (offset !== input) { 3275 if (!keepLocalTime || this._changeInProgress) { 3276 add_subtract__addSubtract(this, create__createDuration(input - offset, 'm'), 1, false); 3277 } else if (!this._changeInProgress) { 3278 this._changeInProgress = true; 3279 utils_hooks__hooks.updateOffset(this, true); 3280 this._changeInProgress = null; 3281 } 3282 } 3283 return this; 3284 } else { 3285 return this._isUTC ? offset : getDateOffset(this); 3286 } 3287 } 3288 3289 function getSetZone (input, keepLocalTime) { 3290 if (input != null) { 3291 if (typeof input !== 'string') { 3292 input = -input; 3293 } 3294 3295 this.utcOffset(input, keepLocalTime); 3296 3297 return this; 3298 } else { 3299 return -this.utcOffset(); 3300 } 3301 } 3302 3303 function setOffsetToUTC (keepLocalTime) { 3304 return this.utcOffset(0, keepLocalTime); 3305 } 3306 3307 function setOffsetToLocal (keepLocalTime) { 3308 if (this._isUTC) { 3309 this.utcOffset(0, keepLocalTime); 3310 this._isUTC = false; 3311 3312 if (keepLocalTime) { 3313 this.subtract(getDateOffset(this), 'm'); 3314 } 3315 } 3316 return this; 3317 } 3318 3319 function setOffsetToParsedOffset () { 3320 if (this._tzm) { 3321 this.utcOffset(this._tzm); 3322 } else if (typeof this._i === 'string') { 3323 this.utcOffset(offsetFromString(matchOffset, this._i)); 3324 } 3325 return this; 3326 } 3327 3328 function hasAlignedHourOffset (input) { 3329 if (!this.isValid()) { 3330 return false; 3331 } 3332 input = input ? local__createLocal(input).utcOffset() : 0; 3333 3334 return (this.utcOffset() - input) % 60 === 0; 3335 } 3336 3337 function isDaylightSavingTime () { 3338 return ( 3339 this.utcOffset() > this.clone().month(0).utcOffset() || 3340 this.utcOffset() > this.clone().month(5).utcOffset() 3341 ); 3342 } 3343 3344 function isDaylightSavingTimeShifted () { 3345 if (!isUndefined(this._isDSTShifted)) { 3346 return this._isDSTShifted; 3347 } 3348 3349 var c = {}; 3350 3351 copyConfig(c, this); 3352 c = prepareConfig(c); 3353 3354 if (c._a) { 3355 var other = c._isUTC ? create_utc__createUTC(c._a) : local__createLocal(c._a); 3356 this._isDSTShifted = this.isValid() && 3357 compareArrays(c._a, other.toArray()) > 0; 3358 } else { 3359 this._isDSTShifted = false; 3360 } 3361 3362 return this._isDSTShifted; 3363 } 3364 3365 function isLocal () { 3366 return this.isValid() ? !this._isUTC : false; 3367 } 3368 3369 function isUtcOffset () { 3370 return this.isValid() ? this._isUTC : false; 3371 } 3372 3373 function isUtc () { 3374 return this.isValid() ? this._isUTC && this._offset === 0 : false; 3375 } 3376 3377 // ASP.NET json date format regex 3378 var aspNetRegex = /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?\d*)?$/; 3379 3380 // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html 3381 // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere 3382 // and further modified to allow for strings containing both week and day 3383 var isoRegex = /^(-)?P(?:(-?[0-9,.]*)Y)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)W)?(?:(-?[0-9,.]*)D)?(?:T(?:(-?[0-9,.]*)H)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)S)?)?$/; 3384 3385 function create__createDuration (input, key) { 3386 var duration = input, 3387 // matching against regexp is expensive, do it on demand 3388 match = null, 3389 sign, 3390 ret, 3391 diffRes; 3392 3393 if (isDuration(input)) { 3394 duration = { 3395 ms : input._milliseconds, 3396 d : input._days, 3397 M : input._months 3398 }; 3399 } else if (typeof input === 'number') { 3400 duration = {}; 3401 if (key) { 3402 duration[key] = input; 3403 } else { 3404 duration.milliseconds = input; 3405 } 3406 } else if (!!(match = aspNetRegex.exec(input))) { 3407 sign = (match[1] === '-') ? -1 : 1; 3408 duration = { 3409 y : 0, 3410 d : toInt(match[DATE]) * sign, 3411 h : toInt(match[HOUR]) * sign, 3412 m : toInt(match[MINUTE]) * sign, 3413 s : toInt(match[SECOND]) * sign, 3414 ms : toInt(match[MILLISECOND]) * sign 3415 }; 3416 } else if (!!(match = isoRegex.exec(input))) { 3417 sign = (match[1] === '-') ? -1 : 1; 3418 duration = { 3419 y : parseIso(match[2], sign), 3420 M : parseIso(match[3], sign), 3421 w : parseIso(match[4], sign), 3422 d : parseIso(match[5], sign), 3423 h : parseIso(match[6], sign), 3424 m : parseIso(match[7], sign), 3425 s : parseIso(match[8], sign) 3426 }; 3427 } else if (duration == null) {// checks for null or undefined 3428 duration = {}; 3429 } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) { 3430 diffRes = momentsDifference(local__createLocal(duration.from), local__createLocal(duration.to)); 3431 3432 duration = {}; 3433 duration.ms = diffRes.milliseconds; 3434 duration.M = diffRes.months; 3435 } 3436 3437 ret = new Duration(duration); 3438 3439 if (isDuration(input) && hasOwnProp(input, '_locale')) { 3440 ret._locale = input._locale; 3441 } 3442 3443 return ret; 3444 } 3445 3446 create__createDuration.fn = Duration.prototype; 3447 3448 function parseIso (inp, sign) { 3449 // We'd normally use ~~inp for this, but unfortunately it also 3450 // converts floats to ints. 3451 // inp may be undefined, so careful calling replace on it. 3452 var res = inp && parseFloat(inp.replace(',', '.')); 3453 // apply sign while we're at it 3454 return (isNaN(res) ? 0 : res) * sign; 3455 } 3456 3457 function positiveMomentsDifference(base, other) { 3458 var res = {milliseconds: 0, months: 0}; 3459 3460 res.months = other.month() - base.month() + 3461 (other.year() - base.year()) * 12; 3462 if (base.clone().add(res.months, 'M').isAfter(other)) { 3463 --res.months; 3464 } 3465 3466 res.milliseconds = +other - +(base.clone().add(res.months, 'M')); 3467 3468 return res; 3469 } 3470 3471 function momentsDifference(base, other) { 3472 var res; 3473 if (!(base.isValid() && other.isValid())) { 3474 return {milliseconds: 0, months: 0}; 3475 } 3476 3477 other = cloneWithOffset(other, base); 3478 if (base.isBefore(other)) { 3479 res = positiveMomentsDifference(base, other); 3480 } else { 3481 res = positiveMomentsDifference(other, base); 3482 res.milliseconds = -res.milliseconds; 3483 res.months = -res.months; 3484 } 3485 3486 return res; 3487 } 3488 3489 function absRound (number) { 3490 if (number < 0) { 3491 return Math.round(-1 * number) * -1; 3492 } else { 3493 return Math.round(number); 3494 } 3495 } 3496 3497 // TODO: remove 'name' arg after deprecation is removed 3498 function createAdder(direction, name) { 3499 return function (val, period) { 3500 var dur, tmp; 3501 //invert the arguments, but complain about it 3502 if (period !== null && !isNaN(+period)) { 3503 deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period). ' + 3504 'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.'); 3505 tmp = val; val = period; period = tmp; 3506 } 3507 3508 val = typeof val === 'string' ? +val : val; 3509 dur = create__createDuration(val, period); 3510 add_subtract__addSubtract(this, dur, direction); 3511 return this; 3512 }; 3513 } 3514 3515 function add_subtract__addSubtract (mom, duration, isAdding, updateOffset) { 3516 var milliseconds = duration._milliseconds, 3517 days = absRound(duration._days), 3518 months = absRound(duration._months); 3519 3520 if (!mom.isValid()) { 3521 // No op 3522 return; 3523 } 3524 3525 updateOffset = updateOffset == null ? true : updateOffset; 3526 3527 if (milliseconds) { 3528 mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding); 3529 } 3530 if (days) { 3531 get_set__set(mom, 'Date', get_set__get(mom, 'Date') + days * isAdding); 3532 } 3533 if (months) { 3534 setMonth(mom, get_set__get(mom, 'Month') + months * isAdding); 3535 } 3536 if (updateOffset) { 3537 utils_hooks__hooks.updateOffset(mom, days || months); 3538 } 3539 } 3540 3541 var add_subtract__add = createAdder(1, 'add'); 3542 var add_subtract__subtract = createAdder(-1, 'subtract'); 3543 3544 function getCalendarFormat(myMoment, now) { 3545 var diff = myMoment.diff(now, 'days', true); 3546 return diff < -6 ? 'sameElse' : 3547 diff < -1 ? 'lastWeek' : 3548 diff < 0 ? 'lastDay' : 3549 diff < 1 ? 'sameDay' : 3550 diff < 2 ? 'nextDay' : 3551 diff < 7 ? 'nextWeek' : 'sameElse'; 3552 } 3553 3554 function moment_calendar__calendar (time, formats) { 3555 // We want to compare the start of today, vs this. 3556 // Getting start-of-today depends on whether we're local/utc/offset or not. 3557 var now = time || local__createLocal(), 3558 sod = cloneWithOffset(now, this).startOf('day'), 3559 format = utils_hooks__hooks.calendarFormat(this, sod) || 'sameElse'; 3560 3561 var output = formats && (isFunction(formats[format]) ? formats[format].call(this, now) : formats[format]); 3562
3563 return this.format(output || this.localeData().calendar(format, this, local__createLocal(now))); 3564 } 3565 3566 function clone () { 3567 return new Moment(this); 3568 } 3569 3570 function isAfter (input, units) { 3571 var localInput = isMoment(input) ? input : local__createLocal(input); 3572 if (!(this.isValid() && localInput.isValid())) { 3573 return false; 3574 } 3575 units = normalizeUnits(!isUndefined(units) ? units : 'millisecond'); 3576 if (units === 'millisecond') { 3577 return this.valueOf() > localInput.valueOf(); 3578 } else { 3579 return localInput.valueOf() < this.clone().startOf(units).valueOf(); 3580 } 3581 } 3582 3583 function isBefore (input, units) { 3584 var localInput = isMoment(input) ? input : local__createLocal(input); 3585 if (!(this.isValid() && localInput.isValid())) { 3586 return false; 3587 } 3588 units = normalizeUnits(!isUndefined(units) ? units : 'millisecond'); 3589 if (units === 'millisecond') { 3590 return this.valueOf() < localInput.valueOf(); 3591 } else { 3592 return this.clone().endOf(units).valueOf() < localInput.valueOf(); 3593 } 3594 } 3595 3596 function isBetween (from, to, units, inclusivity) { 3597 inclusivity = inclusivity || '()'; 3598 return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) && 3599 (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units)); 3600 } 3601 3602 function isSame (input, units) { 3603 var localInput = isMoment(input) ? input : local__createLocal(input), 3604 inputMs; 3605 if (!(this.isValid() && localInput.isValid())) { 3606 return false; 3607 } 3608 units = normalizeUnits(units || 'millisecond'); 3609 if (units === 'millisecond') { 3610 return this.valueOf() === localInput.valueOf(); 3611 } else { 3612 inputMs = localInput.valueOf(); 3613 return this.clone().startOf(units).valueOf() <= inputMs && inputMs <= this.clone().endOf(units).valueOf(); 3614 } 3615 } 3616 3617 function isSameOrAfter (input, units) { 3618 return this.isSame(input, units) || this.isAfter(input,units); 3619 } 3620 3621 function isSameOrBefore (input, units) { 3622 return this.isSame(input, units) || this.isBefore(input,units); 3623 } 3624 3625 function diff (input, units, asFloat) { 3626 var that, 3627 zoneDelta, 3628 delta, output; 3629 3630 if (!this.isValid()) { 3631 return NaN; 3632 } 3633 3634 that = cloneWithOffset(input, this); 3635 3636 if (!that.isValid()) { 3637 return NaN; 3638 } 3639 3640 zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4; 3641 3642 units = normalizeUnits(units); 3643 3644 if (units === 'year' || units === 'month' || units === 'quarter') { 3645 output = monthDiff(this, that); 3646 if (units === 'quarter') { 3647 output = output / 3; 3648 } else if (units === 'year') { 3649 output = output / 12; 3650 } 3651 } else { 3652 delta = this - that; 3653 output = units === 'second' ? delta / 1e3 : // 1000 3654 units === 'minute' ? delta / 6e4 : // 1000 * 60 3655 units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60 3656 units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst 3657 units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst 3658 delta; 3659 } 3660 return asFloat ? output : absFloor(output); 3661 } 3662 3663 function monthDiff (a, b) { 3664 // difference in months 3665 var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()), 3666 // b is in (anchor - 1 month, anchor + 1 month) 3667 anchor = a.clone().add(wholeMonthDiff, 'months'), 3668 anchor2, adjust; 3669 3670 if (b - anchor < 0) { 3671 anchor2 = a.clone().add(wholeMonthDiff - 1, 'months'); 3672 // linear across the month 3673 adjust = (b - anchor) / (anchor - anchor2); 3674 } else { 3675 anchor2 = a.clone().add(wholeMonthDiff + 1, 'months'); 3676 // linear across the month 3677 adjust = (b - anchor) / (anchor2 - anchor); 3678 } 3679 3680 //check for negative zero, return zero if negative zero 3681 return -(wholeMonthDiff + adjust) || 0; 3682 } 3683 3684 utils_hooks__hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ'; 3685 utils_hooks__hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]'; 3686 3687 function toString () { 3688 return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ'); 3689 } 3690 3691 function moment_format__toISOString () { 3692 var m = this.clone().utc(); 3693 if (0 < m.year() && m.year() <= 9999) { 3694 if (isFunction(Date.prototype.toISOString)) { 3695 // native implementation is ~50x faster, use it when we can 3696 return this.toDate().toISOString(); 3697 } else { 3698 return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]'); 3699 } 3700 } else { 3701 return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]'); 3702 } 3703 } 3704 3705 function format (inputString) { 3706 if (!inputString) { 3707 inputString = this.isUtc() ? utils_hooks__hooks.defaultFormatUtc : utils_hooks__hooks.defaultFormat; 3708 } 3709 var output = formatMoment(this, inputString);
3710 return this.localeData().postformat(output); 3711 } 3712 3713 function from (time, withoutSuffix) { 3714 if (this.isValid() && 3715 ((isMoment(time) && time.isValid()) || 3716 local__createLocal(time).isValid())) { 3717 return create__createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix); 3718 } else { 3719 return this.localeData().invalidDate(); 3720 } 3721 } 3722 3723 function fromNow (withoutSuffix) { 3724 return this.from(local__createLocal(), withoutSuffix); 3725 } 3726 3727 function to (time, withoutSuffix) { 3728 if (this.isValid() && 3729 ((isMoment(time) && time.isValid()) || 3730 local__createLocal(time).isValid())) { 3731 return create__createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix); 3732 } else { 3733 return this.localeData().invalidDate(); 3734 } 3735 } 3736 3737 function toNow (withoutSuffix) { 3738 return this.to(local__createLocal(), withoutSuffix); 3739 } 3740 3741 // If passed a locale key, it will set the locale for this 3742 // instance. Otherwise, it will return the locale configuration 3743 // variables for this instance. 3744 function locale (key) { 3745 var newLocaleData; 3746 3747 if (key === undefined) { 3748 return this._locale._abbr; 3749 } else { 3750 newLocaleData = locale_locales__getLocale(key); 3751 if (newLocaleData != null) { 3752 this._locale = newLocaleData; 3753 } 3754 return this; 3755 } 3756 } 3757 3758 var lang = deprecate( 3759 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.', 3760 function (key) { 3761 if (key === undefined) { 3762 return this.localeData(); 3763 } else { 3764 return this.locale(key); 3765 } 3766 } 3767 ); 3768 3769 function localeData () { 3770 return this._locale; 3771 } 3772 3773 function startOf (units) { 3774 units = normalizeUnits(units); 3775 // the following switch intentionally omits break keywords 3776 // to utilize falling through the cases. 3777 switch (units) { 3778 case 'year': 3779 this.month(0); 3780 /* falls through */ 3781 case 'quarter': 3782 case 'month': 3783 this.date(1); 3784 /* falls through */ 3785 case 'week': 3786 case 'isoWeek': 3787 case 'day': 3788 case 'date': 3789 this.hours(0); 3790 /* falls through */ 3791 case 'hour': 3792 this.minutes(0); 3793 /* falls through */ 3794 case 'minute': 3795 this.seconds(0); 3796 /* falls through */ 3797 case 'second': 3798 this.milliseconds(0); 3799 } 3800 3801 // weeks are a special case 3802 if (units === 'week') { 3803 this.weekday(0); 3804 } 3805 if (units === 'isoWeek') { 3806 this.isoWeekday(1); 3807 } 3808 3809 // quarters are also special 3810 if (units === 'quarter') { 3811 this.month(Math.floor(this.month() / 3) * 3); 3812 } 3813 3814 return this; 3815 } 3816 3817 function endOf (units) { 3818 units = normalizeUnits(units); 3819 if (units === undefined || units === 'millisecond') { 3820 return this; 3821 } 3822 3823 // 'date' is an alias for 'day', so it should be considered as such. 3824 if (units === 'date') { 3825 units = 'day'; 3826 } 3827 3828 return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms'); 3829 } 3830 3831 function to_type__valueOf () { 3832 return this._d.valueOf() - ((this._offset || 0) * 60000); 3833 } 3834 3835 function unix () { 3836 return Math.floor(this.valueOf() / 1000); 3837 } 3838 3839 function toDate () { 3840 return new Date(this.valueOf()); 3841 } 3842 3843 function toArray () { 3844 var m = this; 3845 return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()]; 3846 } 3847 3848 function toObject () { 3849 var m = this; 3850 return { 3851 years: m.year(), 3852 months: m.month(), 3853 date: m.date(), 3854 hours: m.hours(), 3855 minutes: m.minutes(), 3856 seconds: m.seconds(), 3857 milliseconds: m.milliseconds() 3858 }; 3859 } 3860 3861 function toJSON () { 3862 // new Date(NaN).toJSON() === null 3863 return this.isValid() ? this.toISOString() : null; 3864 } 3865 3866 function moment_valid__isValid () { 3867 return valid__isValid(this); 3868 } 3869 3870 function parsingFlags () { 3871 return extend({}, getParsingFlags(this)); 3872 } 3873
vendor: 26,018 bytes, lines 3874-4671
3874 function invalidAt () { 3875 return getParsingFlags(this).overflow; 3876 } 3877 3878 function creationData() { 3879 return { 3880 input: this._i, 3881 format: this._f, 3882 locale: this._locale, 3883 isUTC: this._isUTC, 3884 strict: this._strict 3885 }; 3886 } 3887 3888 // FORMATTING 3889 3890 addFormatToken(0, ['gg', 2], 0, function () { 3891 return this.weekYear() % 100; 3892 }); 3893 3894 addFormatToken(0, ['GG', 2], 0, function () { 3895 return this.isoWeekYear() % 100; 3896 }); 3897 3898 function addWeekYearFormatToken (token, getter) { 3899 addFormatToken(0, [token, token.length], 0, getter); 3900 } 3901 3902 addWeekYearFormatToken('gggg', 'weekYear'); 3903 addWeekYearFormatToken('ggggg', 'weekYear'); 3904 addWeekYearFormatToken('GGGG', 'isoWeekYear'); 3905 addWeekYearFormatToken('GGGGG', 'isoWeekYear'); 3906 3907 // ALIASES 3908 3909 addUnitAlias('weekYear', 'gg'); 3910 addUnitAlias('isoWeekYear', 'GG'); 3911 3912 // PRIORITY 3913 3914 addUnitPriority('weekYear', 1); 3915 addUnitPriority('isoWeekYear', 1); 3916 3917 3918 // PARSING 3919 3920 addRegexToken('G', matchSigned); 3921 addRegexToken('g', matchSigned); 3922 addRegexToken('GG', match1to2, match2); 3923 addRegexToken('gg', match1to2, match2); 3924 addRegexToken('GGGG', match1to4, match4); 3925 addRegexToken('gggg', match1to4, match4); 3926 addRegexToken('GGGGG', match1to6, match6); 3927 addRegexToken('ggggg', match1to6, match6); 3928 3929 addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) { 3930 week[token.substr(0, 2)] = toInt(input); 3931 }); 3932 3933 addWeekParseToken(['gg', 'GG'], function (input, week, config, token) { 3934 week[token] = utils_hooks__hooks.parseTwoDigitYear(input); 3935 }); 3936 3937 // MOMENTS 3938 3939 function getSetWeekYear (input) { 3940 return getSetWeekYearHelper.call(this, 3941 input, 3942 this.week(), 3943 this.weekday(), 3944 this.localeData()._week.dow, 3945 this.localeData()._week.doy); 3946 } 3947 3948 function getSetISOWeekYear (input) { 3949 return getSetWeekYearHelper.call(this, 3950 input, this.isoWeek(), this.isoWeekday(), 1, 4); 3951 } 3952 3953 function getISOWeeksInYear () { 3954 return weeksInYear(this.year(), 1, 4); 3955 } 3956 3957 function getWeeksInYear () { 3958 var weekInfo = this.localeData()._week; 3959 return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy); 3960 } 3961 3962 function getSetWeekYearHelper(input, week, weekday, dow, doy) { 3963 var weeksTarget; 3964 if (input == null) { 3965 return weekOfYear(this, dow, doy).year; 3966 } else { 3967 weeksTarget = weeksInYear(input, dow, doy); 3968 if (week > weeksTarget) { 3969 week = weeksTarget; 3970 } 3971 return setWeekAll.call(this, input, week, weekday, dow, doy); 3972 } 3973 } 3974 3975 function setWeekAll(weekYear, week, weekday, dow, doy) { 3976 var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy), 3977 date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear); 3978 3979 this.year(date.getUTCFullYear()); 3980 this.month(date.getUTCMonth()); 3981 this.date(date.getUTCDate()); 3982 return this; 3983 } 3984 3985 // FORMATTING 3986 3987 addFormatToken('Q', 0, 'Qo', 'quarter'); 3988 3989 // ALIASES 3990 3991 addUnitAlias('quarter', 'Q'); 3992 3993 // PRIORITY 3994 3995 addUnitPriority('quarter', 7); 3996 3997 // PARSING 3998 3999 addRegexToken('Q', match1); 4000 addParseToken('Q', function (input, array) { 4001 array[MONTH] = (toInt(input) - 1) * 3; 4002 }); 4003 4004 // MOMENTS 4005 4006 function getSetQuarter (input) { 4007 return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3); 4008 } 4009 4010 // FORMATTING 4011 4012 addFormatToken('D', ['DD', 2], 'Do', 'date'); 4013 4014 // ALIASES 4015 4016 addUnitAlias('date', 'D'); 4017 4018 // PRIOROITY 4019 addUnitPriority('date', 9); 4020 4021 // PARSING 4022 4023 addRegexToken('D', match1to2); 4024 addRegexToken('DD', match1to2, match2); 4025 addRegexToken('Do', function (isStrict, locale) { 4026 return isStrict ? locale._ordinalParse : locale._ordinalParseLenient; 4027 }); 4028 4029 addParseToken(['D', 'DD'], DATE); 4030 addParseToken('Do', function (input, array) { 4031 array[DATE] = toInt(input.match(match1to2)[0], 10); 4032 }); 4033 4034 // MOMENTS 4035 4036 var getSetDayOfMonth = makeGetSet('Date', true); 4037 4038 // FORMATTING 4039 4040 addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear'); 4041 4042 // ALIASES 4043 4044 addUnitAlias('dayOfYear', 'DDD'); 4045 4046 // PRIORITY 4047 addUnitPriority('dayOfYear', 4); 4048 4049 // PARSING 4050 4051 addRegexToken('DDD', match1to3); 4052 addRegexToken('DDDD', match3); 4053 addParseToken(['DDD', 'DDDD'], function (input, array, config) { 4054 config._dayOfYear = toInt(input); 4055 }); 4056 4057 // HELPERS 4058 4059 // MOMENTS 4060 4061 function getSetDayOfYear (input) { 4062 var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1; 4063 return input == null ? dayOfYear : this.add((input - dayOfYear), 'd'); 4064 } 4065 4066 // FORMATTING 4067 4068 addFormatToken('m', ['mm', 2], 0, 'minute'); 4069 4070 // ALIASES 4071 4072 addUnitAlias('minute', 'm'); 4073 4074 // PRIORITY 4075 4076 addUnitPriority('minute', 14); 4077 4078 // PARSING 4079 4080 addRegexToken('m', match1to2); 4081 addRegexToken('mm', match1to2, match2); 4082 addParseToken(['m', 'mm'], MINUTE); 4083 4084 // MOMENTS 4085 4086 var getSetMinute = makeGetSet('Minutes', false); 4087 4088 // FORMATTING 4089 4090 addFormatToken('s', ['ss', 2], 0, 'second'); 4091 4092 // ALIASES 4093 4094 addUnitAlias('second', 's'); 4095 4096 // PRIORITY 4097 4098 addUnitPriority('second', 15); 4099 4100 // PARSING 4101 4102 addRegexToken('s', match1to2); 4103 addRegexToken('ss', match1to2, match2); 4104 addParseToken(['s', 'ss'], SECOND); 4105 4106 // MOMENTS 4107 4108 var getSetSecond = makeGetSet('Seconds', false); 4109 4110 // FORMATTING 4111 4112 addFormatToken('S', 0, 0, function () { 4113 return ~~(this.millisecond() / 100); 4114 }); 4115 4116 addFormatToken(0, ['SS', 2], 0, function () { 4117 return ~~(this.millisecond() / 10); 4118 }); 4119 4120 addFormatToken(0, ['SSS', 3], 0, 'millisecond'); 4121 addFormatToken(0, ['SSSS', 4], 0, function () { 4122 return this.millisecond() * 10; 4123 }); 4124 addFormatToken(0, ['SSSSS', 5], 0, function () { 4125 return this.millisecond() * 100; 4126 }); 4127 addFormatToken(0, ['SSSSSS', 6], 0, function () { 4128 return this.millisecond() * 1000; 4129 }); 4130 addFormatToken(0, ['SSSSSSS', 7], 0, function () { 4131 return this.millisecond() * 10000; 4132 }); 4133 addFormatToken(0, ['SSSSSSSS', 8], 0, function () { 4134 return this.millisecond() * 100000; 4135 }); 4136 addFormatToken(0, ['SSSSSSSSS', 9], 0, function () { 4137 return this.millisecond() * 1000000; 4138 }); 4139 4140 4141 // ALIASES 4142 4143 addUnitAlias('millisecond', 'ms'); 4144 4145 // PRIORITY 4146 4147 addUnitPriority('millisecond', 16); 4148 4149 // PARSING 4150 4151 addRegexToken('S', match1to3, match1); 4152 addRegexToken('SS', match1to3, match2); 4153 addRegexToken('SSS', match1to3, match3); 4154 4155 var token; 4156 for (token = 'SSSS'; token.length <= 9; token += 'S') { 4157 addRegexToken(token, matchUnsigned); 4158 } 4159 4160 function parseMs(input, array) { 4161 array[MILLISECOND] = toInt(('0.' + input) * 1000); 4162 } 4163 4164 for (token = 'S'; token.length <= 9; token += 'S') { 4165 addParseToken(token, parseMs); 4166 } 4167 // MOMENTS 4168 4169 var getSetMillisecond = makeGetSet('Milliseconds', false); 4170 4171 // FORMATTING 4172 4173 addFormatToken('z', 0, 0, 'zoneAbbr'); 4174 addFormatToken('zz', 0, 0, 'zoneName'); 4175 4176 // MOMENTS 4177 4178 function getZoneAbbr () { 4179 return this._isUTC ? 'UTC' : ''; 4180 } 4181 4182 function getZoneName () { 4183 return this._isUTC ? 'Coordinated Universal Time' : ''; 4184 } 4185 4186 var momentPrototype__proto = Moment.prototype; 4187 4188 momentPrototype__proto.add = add_subtract__add; 4189 momentPrototype__proto.calendar = moment_calendar__calendar; 4190 momentPrototype__proto.clone = clone; 4191 momentPrototype__proto.diff = diff; 4192 momentPrototype__proto.endOf = endOf; 4193 momentPrototype__proto.format = format; 4194 momentPrototype__proto.from = from; 4195 momentPrototype__proto.fromNow = fromNow; 4196 momentPrototype__proto.to = to; 4197 momentPrototype__proto.toNow = toNow; 4198 momentPrototype__proto.get = stringGet; 4199 momentPrototype__proto.invalidAt = invalidAt; 4200 momentPrototype__proto.isAfter = isAfter; 4201 momentPrototype__proto.isBefore = isBefore; 4202 momentPrototype__proto.isBetween = isBetween; 4203 momentPrototype__proto.isSame = isSame; 4204 momentPrototype__proto.isSameOrAfter = isSameOrAfter; 4205 momentPrototype__proto.isSameOrBefore = isSameOrBefore; 4206 momentPrototype__proto.isValid = moment_valid__isValid; 4207 momentPrototype__proto.lang = lang; 4208 momentPrototype__proto.locale = locale; 4209 momentPrototype__proto.localeData = localeData; 4210 momentPrototype__proto.max = prototypeMax; 4211 momentPrototype__proto.min = prototypeMin; 4212 momentPrototype__proto.parsingFlags = parsingFlags; 4213 momentPrototype__proto.set = stringSet; 4214 momentPrototype__proto.startOf = startOf; 4215 momentPrototype__proto.subtract = add_subtract__subtract; 4216 momentPrototype__proto.toArray = toArray; 4217 momentPrototype__proto.toObject = toObject; 4218 momentPrototype__proto.toDate = toDate; 4219 momentPrototype__proto.toISOString = moment_format__toISOString; 4220 momentPrototype__proto.toJSON = toJSON; 4221 momentPrototype__proto.toString = toString; 4222 momentPrototype__proto.unix = unix; 4223 momentPrototype__proto.valueOf = to_type__valueOf; 4224 momentPrototype__proto.creationData = creationData; 4225 4226 // Year 4227 momentPrototype__proto.year = getSetYear; 4228 momentPrototype__proto.isLeapYear = getIsLeapYear; 4229 4230 // Week Year 4231 momentPrototype__proto.weekYear = getSetWeekYear; 4232 momentPrototype__proto.isoWeekYear = getSetISOWeekYear; 4233 4234 // Quarter 4235 momentPrototype__proto.quarter = momentPrototype__proto.quarters = getSetQuarter; 4236 4237 // Month 4238 momentPrototype__proto.month = getSetMonth; 4239 momentPrototype__proto.daysInMonth = getDaysInMonth; 4240 4241 // Week 4242 momentPrototype__proto.week = momentPrototype__proto.weeks = getSetWeek; 4243 momentPrototype__proto.isoWeek = momentPrototype__proto.isoWeeks = getSetISOWeek; 4244 momentPrototype__proto.weeksInYear = getWeeksInYear; 4245 momentPrototype__proto.isoWeeksInYear = getISOWeeksInYear; 4246 4247 // Day 4248 momentPrototype__proto.date = getSetDayOfMonth; 4249 momentPrototype__proto.day = momentPrototype__proto.days = getSetDayOfWeek; 4250 momentPrototype__proto.weekday = getSetLocaleDayOfWeek; 4251 momentPrototype__proto.isoWeekday = getSetISODayOfWeek; 4252 momentPrototype__proto.dayOfYear = getSetDayOfYear; 4253 4254 // Hour 4255 momentPrototype__proto.hour = momentPrototype__proto.hours = getSetHour; 4256 4257 // Minute 4258 momentPrototype__proto.minute = momentPrototype__proto.minutes = getSetMinute; 4259 4260 // Second 4261 momentPrototype__proto.second = momentPrototype__proto.seconds = getSetSecond; 4262 4263 // Millisecond 4264 momentPrototype__proto.millisecond = momentPrototype__proto.milliseconds = getSetMillisecond; 4265 4266 // Offset 4267 momentPrototype__proto.utcOffset = getSetOffset; 4268 momentPrototype__proto.utc = setOffsetToUTC; 4269 momentPrototype__proto.local = setOffsetToLocal; 4270 momentPrototype__proto.parseZone = setOffsetToParsedOffset; 4271 momentPrototype__proto.hasAlignedHourOffset = hasAlignedHourOffset; 4272 momentPrototype__proto.isDST = isDaylightSavingTime; 4273 momentPrototype__proto.isLocal = isLocal; 4274 momentPrototype__proto.isUtcOffset = isUtcOffset; 4275 momentPrototype__proto.isUtc = isUtc; 4276 momentPrototype__proto.isUTC = isUtc; 4277 4278 // Timezone 4279 momentPrototype__proto.zoneAbbr = getZoneAbbr; 4280 momentPrototype__proto.zoneName = getZoneName; 4281 4282 // Deprecations 4283 momentPrototype__proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth); 4284 momentPrototype__proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth); 4285 momentPrototype__proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear); 4286 momentPrototype__proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/', getSetZone); 4287 momentPrototype__proto.isDSTShifted = deprecate('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information', isDaylightSavingTimeShifted); 4288 4289 var momentPrototype = momentPrototype__proto; 4290 4291 function moment__createUnix (input) { 4292 return local__createLocal(input * 1000); 4293 } 4294 4295 function moment__createInZone () { 4296 return local__createLocal.apply(null, arguments).parseZone(); 4297 } 4298 4299 function preParsePostFormat (string) { 4300 return string; 4301 } 4302 4303 var prototype__proto = Locale.prototype; 4304 4305 prototype__proto.calendar = locale_calendar__calendar; 4306 prototype__proto.longDateFormat = longDateFormat; 4307 prototype__proto.invalidDate = invalidDate; 4308 prototype__proto.ordinal = ordinal; 4309 prototype__proto.preparse = preParsePostFormat; 4310 prototype__proto.postformat = preParsePostFormat; 4311 prototype__proto.relativeTime = relative__relativeTime; 4312 prototype__proto.pastFuture = pastFuture; 4313 prototype__proto.set = locale_set__set; 4314 4315 // Month 4316 prototype__proto.months = localeMonths; 4317 prototype__proto.monthsShort = localeMonthsShort; 4318 prototype__proto.monthsParse = localeMonthsParse; 4319 prototype__proto.monthsRegex = monthsRegex; 4320 prototype__proto.monthsShortRegex = monthsShortRegex; 4321 4322 // Week 4323 prototype__proto.week = localeWeek; 4324 prototype__proto.firstDayOfYear = localeFirstDayOfYear; 4325 prototype__proto.firstDayOfWeek = localeFirstDayOfWeek; 4326 4327 // Day of Week 4328 prototype__proto.weekdays = localeWeekdays; 4329 prototype__proto.weekdaysMin = localeWeekdaysMin; 4330 prototype__proto.weekdaysShort = localeWeekdaysShort; 4331 prototype__proto.weekdaysParse = localeWeekdaysParse; 4332 4333 prototype__proto.weekdaysRegex = weekdaysRegex; 4334 prototype__proto.weekdaysShortRegex = weekdaysShortRegex; 4335 prototype__proto.weekdaysMinRegex = weekdaysMinRegex; 4336 4337 // Hours 4338 prototype__proto.isPM = localeIsPM; 4339 prototype__proto.meridiem = localeMeridiem; 4340 4341 function lists__get (format, index, field, setter) { 4342 var locale = locale_locales__getLocale(); 4343 var utc = create_utc__createUTC().set(setter, index); 4344 return locale[field](utc, format); 4345 } 4346 4347 function listMonthsImpl (format, index, field) { 4348 if (typeof format === 'number') { 4349 index = format; 4350 format = undefined; 4351 } 4352 4353 format = format || ''; 4354 4355 if (index != null) { 4356 return lists__get(format, index, field, 'month'); 4357 } 4358 4359 var i; 4360 var out = []; 4361 for (i = 0; i < 12; i++) { 4362 out[i] = lists__get(format, i, field, 'month'); 4363 } 4364 return out; 4365 } 4366 4367 // () 4368 // (5) 4369 // (fmt, 5) 4370 // (fmt) 4371 // (true) 4372 // (true, 5) 4373 // (true, fmt, 5) 4374 // (true, fmt) 4375 function listWeekdaysImpl (localeSorted, format, index, field) { 4376 if (typeof localeSorted === 'boolean') { 4377 if (typeof format === 'number') { 4378 index = format; 4379 format = undefined; 4380 } 4381 4382 format = format || ''; 4383 } else { 4384 format = localeSorted; 4385 index = format; 4386 localeSorted = false; 4387 4388 if (typeof format === 'number') { 4389 index = format; 4390 format = undefined; 4391 } 4392 4393 format = format || ''; 4394 } 4395 4396 var locale = locale_locales__getLocale(), 4397 shift = localeSorted ? locale._week.dow : 0; 4398 4399 if (index != null) { 4400 return lists__get(format, (index + shift) % 7, field, 'day'); 4401 } 4402 4403 var i; 4404 var out = []; 4405 for (i = 0; i < 7; i++) { 4406 out[i] = lists__get(format, (i + shift) % 7, field, 'day'); 4407 } 4408 return out; 4409 } 4410 4411 function lists__listMonths (format, index) { 4412 return listMonthsImpl(format, index, 'months'); 4413 } 4414 4415 function lists__listMonthsShort (format, index) { 4416 return listMonthsImpl(format, index, 'monthsShort'); 4417 } 4418 4419 function lists__listWeekdays (localeSorted, format, index) { 4420 return listWeekdaysImpl(localeSorted, format, index, 'weekdays'); 4421 } 4422 4423 function lists__listWeekdaysShort (localeSorted, format, index) { 4424 return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort'); 4425 } 4426 4427 function lists__listWeekdaysMin (localeSorted, format, index) { 4428 return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin'); 4429 } 4430 4431 locale_locales__getSetGlobalLocale('en', { 4432 ordinalParse: /\d{1,2}(th|st|nd|rd)/, 4433 ordinal : function (number) { 4434 var b = number % 10, 4435 output = (toInt(number % 100 / 10) === 1) ? 'th' : 4436 (b === 1) ? 'st' : 4437 (b === 2) ? 'nd' : 4438 (b === 3) ? 'rd' : 'th'; 4439 return number + output; 4440 } 4441 }); 4442 4443 // Side effect imports 4444 utils_hooks__hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', locale_locales__getSetGlobalLocale); 4445 utils_hooks__hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', locale_locales__getLocale); 4446 4447 var mathAbs = Math.abs; 4448 4449 function duration_abs__abs () { 4450 var data = this._data; 4451 4452 this._milliseconds = mathAbs(this._milliseconds); 4453 this._days = mathAbs(this._days); 4454 this._months = mathAbs(this._months); 4455 4456 data.milliseconds = mathAbs(data.milliseconds); 4457 data.seconds = mathAbs(data.seconds); 4458 data.minutes = mathAbs(data.minutes); 4459 data.hours = mathAbs(data.hours); 4460 data.months = mathAbs(data.months); 4461 data.years = mathAbs(data.years); 4462 4463 return this; 4464 } 4465 4466 function duration_add_subtract__addSubtract (duration, input, value, direction) { 4467 var other = create__createDuration(input, value); 4468 4469 duration._milliseconds += direction * other._milliseconds; 4470 duration._days += direction * other._days; 4471 duration._months += direction * other._months; 4472 4473 return duration._bubble(); 4474 } 4475 4476 // supports only 2.0-style add(1, 's') or add(duration) 4477 function duration_add_subtract__add (input, value) { 4478 return duration_add_subtract__addSubtract(this, input, value, 1); 4479 } 4480 4481 // supports only 2.0-style subtract(1, 's') or subtract(duration) 4482 function duration_add_subtract__subtract (input, value) { 4483 return duration_add_subtract__addSubtract(this, input, value, -1); 4484 } 4485 4486 function absCeil (number) { 4487 if (number < 0) { 4488 return Math.floor(number); 4489 } else { 4490 return Math.ceil(number); 4491 } 4492 } 4493 4494 function bubble () { 4495 var milliseconds = this._milliseconds; 4496 var days = this._days; 4497 var months = this._months; 4498 var data = this._data; 4499 var seconds, minutes, hours, years, monthsFromDays; 4500 4501 // if we have a mix of positive and negative values, bubble down first 4502 // check: https://github.com/moment/moment/issues/2166 4503 if (!((milliseconds >= 0 && days >= 0 && months >= 0) || 4504 (milliseconds <= 0 && days <= 0 && months <= 0))) { 4505 milliseconds += absCeil(monthsToDays(months) + days) * 864e5; 4506 days = 0; 4507 months = 0; 4508 } 4509 4510 // The following code bubbles up values, see the tests for 4511 // examples of what that means. 4512 data.milliseconds = milliseconds % 1000; 4513 4514 seconds = absFloor(milliseconds / 1000); 4515 data.seconds = seconds % 60; 4516 4517 minutes = absFloor(seconds / 60); 4518 data.minutes = minutes % 60; 4519 4520 hours = absFloor(minutes / 60); 4521 data.hours = hours % 24; 4522 4523 days += absFloor(hours / 24); 4524 4525 // convert days to months 4526 monthsFromDays = absFloor(daysToMonths(days)); 4527 months += monthsFromDays; 4528 days -= absCeil(monthsToDays(monthsFromDays)); 4529 4530 // 12 months -> 1 year 4531 years = absFloor(months / 12); 4532 months %= 12; 4533 4534 data.days = days; 4535 data.months = months; 4536 data.years = years; 4537 4538 return this; 4539 } 4540 4541 function daysToMonths (days) { 4542 // 400 years have 146097 days (taking into account leap year rules) 4543 // 400 years have 12 months === 4800 4544 return days * 4800 / 146097; 4545 } 4546 4547 function monthsToDays (months) { 4548 // the reverse of daysToMonths 4549 return months * 146097 / 4800; 4550 } 4551 4552 function as (units) { 4553 var days; 4554 var months; 4555 var milliseconds = this._milliseconds; 4556 4557 units = normalizeUnits(units); 4558 4559 if (units === 'month' || units === 'year') { 4560 days = this._days + milliseconds / 864e5; 4561 months = this._months + daysToMonths(days); 4562 return units === 'month' ? months : months / 12; 4563 } else { 4564 // handle milliseconds separately because of floating point math errors (issue #1867) 4565 days = this._days + Math.round(monthsToDays(this._months)); 4566 switch (units) { 4567 case 'week' : return days / 7 + milliseconds / 6048e5; 4568 case 'day' : return days + milliseconds / 864e5; 4569 case 'hour' : return days * 24 + milliseconds / 36e5; 4570 case 'minute' : return days * 1440 + milliseconds / 6e4; 4571 case 'second' : return days * 86400 + milliseconds / 1000; 4572 // Math.floor prevents floating point math errors here 4573 case 'millisecond': return Math.floor(days * 864e5) + milliseconds; 4574 default: throw new Error('Unknown unit ' + units); 4575 } 4576 } 4577 } 4578 4579 // TODO: Use this.as('ms')? 4580 function duration_as__valueOf () { 4581 return ( 4582 this._milliseconds + 4583 this._days * 864e5 + 4584 (this._months % 12) * 2592e6 + 4585 toInt(this._months / 12) * 31536e6 4586 ); 4587 } 4588 4589 function makeAs (alias) { 4590 return function () { 4591 return this.as(alias); 4592 }; 4593 } 4594 4595 var asMilliseconds = makeAs('ms'); 4596 var asSeconds = makeAs('s'); 4597 var asMinutes = makeAs('m'); 4598 var asHours = makeAs('h'); 4599 var asDays = makeAs('d'); 4600 var asWeeks = makeAs('w'); 4601 var asMonths = makeAs('M'); 4602 var asYears = makeAs('y'); 4603 4604 function duration_get__get (units) { 4605 units = normalizeUnits(units); 4606 return this[units + 's'](); 4607 } 4608 4609 function makeGetter(name) { 4610 return function () { 4611 return this._data[name]; 4612 }; 4613 } 4614 4615 var milliseconds = makeGetter('milliseconds'); 4616 var seconds = makeGetter('seconds'); 4617 var minutes = makeGetter('minutes'); 4618 var hours = makeGetter('hours'); 4619 var days = makeGetter('days'); 4620 var months = makeGetter('months'); 4621 var years = makeGetter('years'); 4622 4623 function weeks () { 4624 return absFloor(this.days() / 7); 4625 } 4626 4627 var round = Math.round; 4628 var thresholds = { 4629 s: 45, // seconds to minute 4630 m: 45, // minutes to hour 4631 h: 22, // hours to day 4632 d: 26, // days to month 4633 M: 11 // months to year 4634 }; 4635 4636 // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize 4637 function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) { 4638 return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture); 4639 } 4640 4641 function duration_humanize__relativeTime (posNegDuration, withoutSuffix, locale) { 4642 var duration = create__createDuration(posNegDuration).abs(); 4643 var seconds = round(duration.as('s')); 4644 var minutes = round(duration.as('m')); 4645 var hours = round(duration.as('h')); 4646 var days = round(duration.as('d')); 4647 var months = round(duration.as('M')); 4648 var years = round(duration.as('y')); 4649 4650 var a = seconds < thresholds.s && ['s', seconds] || 4651 minutes <= 1 && ['m'] || 4652 minutes < thresholds.m && ['mm', minutes] || 4653 hours <= 1 && ['h'] || 4654 hours < thresholds.h && ['hh', hours] || 4655 days <= 1 && ['d'] || 4656 days < thresholds.d && ['dd', days] || 4657 months <= 1 && ['M'] || 4658 months < thresholds.M && ['MM', months] || 4659 years <= 1 && ['y'] || ['yy', years]; 4660 4661 a[2] = withoutSuffix; 4662 a[3] = +posNegDuration > 0; 4663 a[4] = locale; 4664 return substituteTimeAgo.apply(null, a); 4665 } 4666 4667 // This function allows you to set the rounding function for relative time strings 4668 function duration_humanize__getSetRelativeTimeRounding (roundingFunction) { 4669 if (roundingFunction === undefined) { 4670 return round; 4671 }
4672 if (typeof(roundingFunction) === 'function') { 4673 round = roundingFunction; 4674 return true; 4675 } 4676 return false; 4677 } 4678 4679 // This function allows you to set a threshold for relative time strings 4680 function duration_humanize__getSetRelativeTimeThreshold (threshold, limit) { 4681 if (thresholds[threshold] === undefined) { 4682 return false; 4683 } 4684 if (limit === undefined) { 4685 return thresholds[threshold]; 4686 } 4687 thresholds[threshold] = limit; 4688 return true; 4689 } 4690 4691 function humanize (withSuffix) { 4692 var locale = this.localeData(); 4693 var output = duration_humanize__relativeTime(this, !withSuffix, locale); 4694 4695 if (withSuffix) { 4696 output = locale.pastFuture(+this, output); 4697 } 4698 4699 return locale.postformat(output); 4700 } 4701 4702 var iso_string__abs = Math.abs; 4703 4704 function iso_string__toISOString() { 4705 // for ISO strings we do not use the normal bubbling rules: 4706 // * milliseconds bubble up until they become hours 4707 // * days do not bubble at all 4708 // * months bubble up until they become years 4709 // This is because there is no context-free conversion between hours and days 4710 // (think of clock changes) 4711 // and also not between days and months (28-31 days per month) 4712 var seconds = iso_string__abs(this._milliseconds) / 1000; 4713 var days = iso_string__abs(this._days); 4714 var months = iso_string__abs(this._months); 4715 var minutes, hours, years; 4716 4717 // 3600 seconds -> 60 minutes -> 1 hour 4718 minutes = absFloor(seconds / 60); 4719 hours = absFloor(minutes / 60); 4720 seconds %= 60; 4721 minutes %= 60; 4722 4723 // 12 months -> 1 year 4724 years = absFloor(months / 12); 4725 months %= 12; 4726 4727 4728 // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js 4729 var Y = years; 4730 var M = months; 4731 var D = days; 4732 var h = hours; 4733 var m = minutes; 4734 var s = seconds; 4735 var total = this.asSeconds(); 4736 4737 if (!total) { 4738 // this is the same as C#'s (Noda) and python (isodate)... 4739 // but not other JS (goog.date) 4740 return 'P0D'; 4741 } 4742 4743 return (total < 0 ? '-' : '') + 4744 'P' + 4745 (Y ? Y + 'Y' : '') + 4746 (M ? M + 'M' : '') + 4747 (D ? D + 'D' : '') + 4748 ((h || m || s) ? 'T' : '') + 4749 (h ? h + 'H' : '') + 4750 (m ? m + 'M' : '') + 4751 (s ? s + 'S' : ''); 4752 } 4753 4754 var duration_prototype__proto = Duration.prototype; 4755 4756 duration_prototype__proto.abs = duration_abs__abs; 4757 duration_prototype__proto.add = duration_add_subtract__add; 4758 duration_prototype__proto.subtract = duration_add_subtract__subtract; 4759 duration_prototype__proto.as = as; 4760 duration_prototype__proto.asMilliseconds = asMilliseconds; 4761 duration_prototype__proto.asSeconds = asSeconds; 4762 duration_prototype__proto.asMinutes = asMinutes; 4763 duration_prototype__proto.asHours = asHours; 4764 duration_prototype__proto.asDays = asDays; 4765 duration_prototype__proto.asWeeks = asWeeks; 4766 duration_prototype__proto.asMonths = asMonths; 4767 duration_prototype__proto.asYears = asYears; 4768 duration_prototype__proto.valueOf = duration_as__valueOf; 4769 duration_prototype__proto._bubble = bubble; 4770 duration_prototype__proto.get = duration_get__get; 4771 duration_prototype__proto.milliseconds = milliseconds; 4772 duration_prototype__proto.seconds = seconds; 4773 duration_prototype__proto.minutes = minutes; 4774 duration_prototype__proto.hours = hours; 4775 duration_prototype__proto.days = days; 4776 duration_prototype__proto.weeks = weeks; 4777 duration_prototype__proto.months = months; 4778 duration_prototype__proto.years = years; 4779 duration_prototype__proto.humanize = humanize; 4780 duration_prototype__proto.toISOString = iso_string__toISOString; 4781 duration_prototype__proto.toString = iso_string__toISOString; 4782 duration_prototype__proto.toJSON = iso_string__toISOString; 4783 duration_prototype__proto.locale = locale; 4784 duration_prototype__proto.localeData = localeData; 4785 4786 // Deprecations 4787 duration_prototype__proto.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', iso_string__toISOString); 4788 duration_prototype__proto.lang = lang; 4789 4790 // Side effect imports 4791 4792 // FORMATTING 4793 4794 addFormatToken('X', 0, 0, 'unix'); 4795 addFormatToken('x', 0, 0, 'valueOf'); 4796 4797 // PARSING 4798 4799 addRegexToken('x', matchSigned); 4800 addRegexToken('X', matchTimestamp); 4801 addParseToken('X', function (input, array, config) { 4802 config._d = new Date(parseFloat(input, 10) * 1000); 4803 }); 4804 addParseToken('x', function (input, array, config) { 4805 config._d = new Date(toInt(input)); 4806 }); 4807 4808 // Side effect imports 4809 4810 4811 utils_hooks__hooks.version = '2.14.1'; 4812 4813 setHookCallback(local__createLocal); 4814 4815 utils_hooks__hooks.fn = momentPrototype; 4816 utils_hooks__hooks.min = min; 4817 utils_hooks__hooks.max = max; 4818 utils_hooks__hooks.now = now; 4819 utils_hooks__hooks.utc = create_utc__createUTC; 4820 utils_hooks__hooks.unix = moment__createUnix; 4821 utils_hooks__hooks.months = lists__listMonths; 4822 utils_hooks__hooks.isDate = isDate; 4823 utils_hooks__hooks.locale = locale_locales__getSetGlobalLocale; 4824 utils_hooks__hooks.invalid = valid__createInvalid; 4825 utils_hooks__hooks.duration = create__createDuration; 4826 utils_hooks__hooks.isMoment = isMoment; 4827 utils_hooks__hooks.weekdays = lists__listWeekdays; 4828 utils_hooks__hooks.parseZone = moment__createInZone; 4829 utils_hooks__hooks.localeData = locale_locales__getLocale; 4830 utils_hooks__hooks.isDuration = isDuration; 4831 utils_hooks__hooks.monthsShort = lists__listMonthsShort; 4832 utils_hooks__hooks.weekdaysMin = lists__listWeekdaysMin; 4833 utils_hooks__hooks.defineLocale = defineLocale; 4834 utils_hooks__hooks.updateLocale = updateLocale; 4835 utils_hooks__hooks.locales = locale_locales__listLocales; 4836 utils_hooks__hooks.weekdaysShort = lists__listWeekdaysShort; 4837 utils_hooks__hooks.normalizeUnits = normalizeUnits; 4838 utils_hooks__hooks.relativeTimeRounding = duration_humanize__getSetRelativeTimeRounding; 4839 utils_hooks__hooks.relativeTimeThreshold = duration_humanize__getSetRelativeTimeThreshold; 4840 utils_hooks__hooks.calendarFormat = getCalendarFormat; 4841 utils_hooks__hooks.prototype = momentPrototype; 4842 4843 var _moment = utils_hooks__hooks; 4844 4845 return _moment; 4846 4847})); 4848},{}],3:[function(require,module,exports){ 4849(function(root, factory) { 4850 /* istanbul ignore next */ 4851 if (typeof define === 'function' && define.amd) { 4852 // AMD. Register as an anonymous module. 4853 define([], factory); 4854 } else if (typeof exports === 'object') { 4855 // Node. Does not work with strict CommonJS, but 4856 // only CommonJS-like environments that support module.exports, 4857 // like Node. 4858 module.exports = factory(); 4859 } else { 4860 // Browser globals (root is window) 4861 root.StringMask = factory(); 4862 } 4863}(this, function() { 4864 var tokens = { 4865 '0': {pattern: /\d/, _default: '0'}, 4866 '9': {pattern: /\d/, optional: true}, 4867 '#': {pattern: /\d/, optional: true, recursive: true}, 4868 'A': {pattern: /[a-zA-Z0-9]/}, 4869 'S': {pattern: /[a-zA-Z]/}, 4870 'U': {pattern: /[a-zA-Z]/, transform: function(c) { return c.toLocaleUpperCase(); }}, 4871 'L': {pattern: /[a-zA-Z]/, transform: function(c) { return c.toLocaleLowerCase(); }}, 4872 '$': {escape: true} 4873 }; 4874 4875 function isEscaped(pattern, pos) { 4876 var count = 0; 4877 var i = pos - 1; 4878 var token = {escape: true}; 4879 while (i >= 0 && token && token.escape) { 4880 token = tokens[pattern.charAt(i)]; 4881 count += token && token.escape ? 1 : 0; 4882 i--; 4883 } 4884 return count > 0 && count % 2 === 1; 4885 } 4886 4887 function calcOptionalNumbersToUse(pattern, value) { 4888 var numbersInP = pattern.replace(/[^0]/g,'').length; 4889 var numbersInV = value.replace(/[^\d]/g,'').length; 4890 return numbersInV - numbersInP; 4891 } 4892 4893 function concatChar(text, character, options, token) { 4894 if (token && typeof token.transform === 'function') { 4895 character = token.transform(character); 4896 } 4897 if (options.reverse) { 4898 return character + text; 4899 }
4900 return text + character; 4901 } 4902 4903 function hasMoreTokens(pattern, pos, inc) { 4904 var pc = pattern.charAt(pos); 4905 var token = tokens[pc]; 4906 if (pc === '') { 4907 return false; 4908 } 4909 return token && !token.escape ? true : hasMoreTokens(pattern, pos + inc, inc); 4910 } 4911 4912 function hasMoreRecursiveTokens(pattern, pos, inc) { 4913 var pc = pattern.charAt(pos); 4914 var token = tokens[pc]; 4915 if (pc === '') { 4916 return false; 4917 } 4918 return token && token.recursive ? true : hasMoreRecursiveTokens(pattern, pos + inc, inc); 4919 } 4920 4921 function insertChar(text, char, position) { 4922 var t = text.split(''); 4923 t.splice(position, 0, char); 4924 return t.join(''); 4925 } 4926 4927 function StringMask(pattern, opt) { 4928 this.options = opt || {}; 4929 this.options = { 4930 reverse: this.options.reverse || false, 4931 usedefaults: this.options.usedefaults || this.options.reverse 4932 }; 4933 this.pattern = pattern; 4934 } 4935 4936 StringMask.prototype.process = function proccess(value) { 4937 if (!value) { 4938 return {result: '', valid: false}; 4939 } 4940 value = value + ''; 4941 var pattern2 = this.pattern; 4942 var valid = true; 4943 var formatted = ''; 4944 var valuePos = this.options.reverse ? value.length - 1 : 0; 4945 var patternPos = 0; 4946 var optionalNumbersToUse = calcOptionalNumbersToUse(pattern2, value); 4947 var escapeNext = false; 4948 var recursive = []; 4949 var inRecursiveMode = false; 4950 4951 var steps = { 4952 start: this.options.reverse ? pattern2.length - 1 : 0, 4953 end: this.options.reverse ? -1 : pattern2.length, 4954 inc: this.options.reverse ? -1 : 1 4955 }; 4956 4957 function continueCondition(options) { 4958 if (!inRecursiveMode && !recursive.length && hasMoreTokens(pattern2, patternPos, steps.inc)) { 4959 // continue in the normal iteration 4960 return true; 4961 } else if (!inRecursiveMode && recursive.length && 4962 hasMoreRecursiveTokens(pattern2, patternPos, steps.inc)) { 4963 // continue looking for the recursive tokens 4964 // Note: all chars in the patterns after the recursive portion will be handled as static string 4965 return true; 4966 } else if (!inRecursiveMode) { 4967 // start to handle the recursive portion of the pattern 4968 inRecursiveMode = recursive.length > 0; 4969 } 4970 4971 if (inRecursiveMode) { 4972 var pc = recursive.shift(); 4973 recursive.push(pc); 4974 if (options.reverse && valuePos >= 0) { 4975 patternPos++; 4976 pattern2 = insertChar(pattern2, pc, patternPos); 4977 return true; 4978 } else if (!options.reverse && valuePos < value.length) { 4979 pattern2 = insertChar(pattern2, pc, patternPos); 4980 return true; 4981 } 4982 } 4983 return patternPos < pattern2.length && patternPos >= 0; 4984 } 4985 4986 /** 4987 * Iterate over the pattern's chars parsing/matching the input value chars 4988 * until the end of the pattern. If the pattern ends with recursive chars 4989 * the iteration will continue until the end of the input value. 4990 * 4991 * Note: The iteration must stop if an invalid char is found. 4992 */ 4993 for (patternPos = steps.start; continueCondition(this.options); patternPos = patternPos + steps.inc) { 4994 // Value char 4995 var vc = value.charAt(valuePos); 4996 // Pattern char to match with the value char 4997 var pc = pattern2.charAt(patternPos); 4998 4999 var token = tokens[pc]; 5000 if (recursive.length && token && !token.recursive) { 5001 // In the recursive portion of the pattern: tokens not recursive must be seen as static chars 5002 token = null; 5003 } 5004 5005 // 1. Handle escape tokens in pattern 5006 // go to next iteration: if the pattern char is a escape char or was escaped 5007 if (!inRecursiveMode || vc) { 5008 if (this.options.reverse && isEscaped(pattern2, patternPos)) { 5009 // pattern char is escaped, just add it and move on 5010 formatted = concatChar(formatted, pc, this.options, token); 5011 // skip escape token 5012 patternPos = patternPos + steps.inc; 5013 continue; 5014 } else if (!this.options.reverse && escapeNext) { 5015 // pattern char is escaped, just add it and move on 5016 formatted = concatChar(formatted, pc, this.options, token); 5017 escapeNext = false;
5018 continue; 5019 } else if (!this.options.reverse && token && token.escape) { 5020 // mark to escape the next pattern char 5021 escapeNext = true; 5022 continue; 5023 } 5024 } 5025 5026 // 2. Handle recursive tokens in pattern 5027 // go to next iteration: if the value str is finished or 5028 // if there is a normal token in the recursive portion of the pattern 5029 if (!inRecursiveMode && token && token.recursive) { 5030 // save it to repeat in the end of the pattern and handle the value char now 5031 recursive.push(pc); 5032 } else if (inRecursiveMode && !vc) { 5033 // in recursive mode but value is finished. Add the pattern char if it is not a recursive token 5034 formatted = concatChar(formatted, pc, this.options, token); 5035 continue; 5036 } else if (!inRecursiveMode && recursive.length > 0 && !vc) { 5037 // recursiveMode not started but already in the recursive portion of the pattern 5038 continue; 5039 } 5040 5041 // 3. Handle the value 5042 // break iterations: if value is invalid for the given pattern 5043 if (!token) { 5044 // add char of the pattern 5045 formatted = concatChar(formatted, pc, this.options, token); 5046 if (!inRecursiveMode && recursive.length) { 5047 // save it to repeat in the end of the pattern 5048 recursive.push(pc); 5049 } 5050 } else if (token.optional) { 5051 // if token is optional, only add the value char if it matchs the token pattern 5052 // if not, move on to the next pattern char 5053 if (token.pattern.test(vc) && optionalNumbersToUse) { 5054 formatted = concatChar(formatted, vc, this.options, token);
5055 valuePos = valuePos + steps.inc; 5056 optionalNumbersToUse--; 5057 } else if (recursive.length > 0 && vc) { 5058 valid = false; 5059 break; 5060 } 5061 } else if (token.pattern.test(vc)) { 5062 // if token isn't optional the value char must match the token pattern 5063 formatted = concatChar(formatted, vc, this.options, token); 5064 valuePos = valuePos + steps.inc; 5065 } else if (!vc && token._default && this.options.usedefaults) { 5066 // if the token isn't optional and has a default value, use it if the value is finished 5067 formatted = concatChar(formatted, token._default, this.options, token); 5068 } else { 5069 // the string value don't match the given pattern 5070 valid = false; 5071 break; 5072 } 5073 } 5074 5075 return {result: formatted, valid: valid}; 5076 }; 5077 5078 StringMask.prototype.apply = function(value) { 5079 return this.process(value).result; 5080 }; 5081 5082 StringMask.prototype.validate = function(value) { 5083 return this.process(value).valid; 5084 }; 5085 5086 StringMask.process = function(value, pattern, options) { 5087 return new StringMask(pattern, options).process(value); 5088 }; 5089 5090 StringMask.apply = function(value, pattern, options) { 5091 return new StringMask(pattern, options).apply(value); 5092 }; 5093 5094 StringMask.validate = function(value, pattern, options) { 5095 return new StringMask(pattern, options).validate(value); 5096 }; 5097 5098 return StringMask; 5099})); 5100 5101},{}],4:[function(require,module,exports){ 5102'use strict'; 5103 5104module.exports = angular.module('ui.utils.masks', [ 5105 require('./global/global-masks'), 5106 require('./br/br-masks'), 5107 require('./us/us-masks'), 5108 require('./ch/ch-masks') 5109]).name; 5110 5111},{"./br/br-masks":6,"./ch/ch-masks":15,"./global/global-masks":19,"./us/us-masks":27}],5:[function(require,module,exports){ 5112'use strict'; 5113 5114var StringMask = require('string-mask'); 5115var maskFactory = require('mask-factory'); 5116 5117var boletoBancarioMask = new StringMask('00000.00000 00000.000000 00000.000000 0 00000000000000'); 5118 5119module.exports = maskFactory({ 5120 clearValue: function(rawValue) { 5121 return rawValue.replace(/[^0-9]/g, '').slice(0, 47); 5122 }, 5123 format: function(cleanValue) { 5124 if (cleanValue.length === 0) { 5125 return cleanValue; 5126 } 5127 5128 return boletoBancarioMask.apply(cleanValue).replace(/[^0-9]$/, ''); 5129 }, 5130 validations: { 5131 brBoletoBancario: function(value) { 5132 return value.length === 47; 5133 } 5134 } 5135}); 5136 5137},{"mask-factory":"mask-factory","string-mask":3}],6:[function(require,module,exports){ 5138'use strict'; 5139 5140var m = angular.module('ui.utils.masks.br', [ 5141 require('../helpers'), 5142]) 5143.directive('uiBrBoletoBancarioMask', require('./boleto-bancario/boleto-bancario')) 5144.directive('uiBrCepMask', require('./cep/cep')) 5145.directive('uiBrCnpjMask', require('./cnpj/cnpj')) 5146.directive('uiBrCpfMask', require('./cpf/cpf')) 5147.directive('uiBrCpfcnpjMask', require('./cpf-cnpj/cpf-cnpj')) 5148.directive('uiBrIeMask', require('./inscricao-estadual/ie')) 5149.directive('uiNfeAccessKeyMask', require('./nfe/nfe')) 5150.directive('uiBrCarPlateMask', require('./car-plate/car-plate')) 5151.directive('uiBrPhoneNumber', require('./phone/br-phone')); 5152 5153module.exports = m.name; 5154 5155},{"../helpers":25,"./boleto-bancario/boleto-bancario":5,"./car-plate/car-plate":7,"./cep/cep":8,"./cnpj/cnpj":9,"./cpf-cnpj/cpf-cnpj":10,"./cpf/cpf":11,"./inscricao-estadual/ie":12,"./nfe/nfe":13,"./phone/br-phone":14}],7:[function(require,module,exports){ 5156'use strict'; 5157 5158var StringMask = require('string-mask'); 5159var maskFactory = require('mask-factory'); 5160 5161var carPlateMask = new StringMask('UUU-0000'); 5162 5163module.exports = maskFactory({ 5164 clearValue: function(rawValue) { 5165 return rawValue.replace(/[^a-zA-Z0-9]/g, '').slice(0, 7); 5166 }, 5167 format: function(cleanValue) { 5168 return (carPlateMask.apply(cleanValue) || '').replace(/[^a-zA-Z0-9]$/, ''); 5169 }, 5170 validations: { 5171 carPlate: function(value) { 5172 return value.length === 7; 5173 } 5174 } 5175}); 5176 5177},{"mask-factory":"mask-factory","string-mask":3}],8:[function(require,module,exports){ 5178'use strict'; 5179 5180var StringMask = require('string-mask'); 5181var maskFactory = require('mask-factory'); 5182 5183var cepMask = new StringMask('00000-000'); 5184 5185module.exports = maskFactory({ 5186 clearValue: function(rawValue) { 5187 return rawValue.toString().replace(/[^0-9]/g, '').slice(0, 8); 5188 }, 5189 format: function(cleanValue) { 5190 return (cepMask.apply(cleanValue) || '').replace(/[^0-9]$/, ''); 5191 }, 5192 validations: { 5193 cep: function(value) { 5194 return value.length === 8; 5195 } 5196 } 5197}); 5198 5199},{"mask-factory":"mask-factory","string-mask":3}],9:[function(require,module,exports){ 5200'use strict'; 5201 5202var StringMask = require('string-mask'); 5203var BrV = require('br-validations'); 5204var maskFactory = require('mask-factory'); 5205 5206var cnpjPattern = new StringMask('00.000.000\/0000-00'); 5207 5208module.exports = maskFactory({ 5209 clearValue: function(rawValue) { 5210 return rawValue.replace(/[^\d]/g, '').slice(0, 14); 5211 }, 5212 format: function(cleanValue) { 5213 return (cnpjPattern.apply(cleanValue) || '').trim().replace(/[^0-9]$/, ''); 5214 }, 5215 validations: { 5216 cnpj: function(value) { 5217 return BrV.cnpj.validate(value); 5218 } 5219 } 5220}); 5221 5222},{"br-validations":1,"mask-factory":"mask-factory","string-mask":3}],10:[function(require,module,exports){ 5223'use strict'; 5224 5225var StringMask = require('string-mask'); 5226var BrV = require('br-validations'); 5227var maskFactory = require('mask-factory'); 5228 5229var cnpjPattern = new StringMask('00.000.000\/0000-00'); 5230var cpfPattern = new StringMask('000.000.000-00'); 5231 5232module.exports = maskFactory({ 5233 clearValue: function(rawValue) { 5234 return rawValue.replace(/[^\d]/g, '').slice(0, 14); 5235 }, 5236 format: function(cleanValue) { 5237 var formatedValue; 5238 5239 if (cleanValue.length > 11) { 5240 formatedValue = cnpjPattern.apply(cleanValue); 5241 } else { 5242 formatedValue = cpfPattern.apply(cleanValue) || ''; 5243 } 5244 5245 return formatedValue.trim().replace(/[^0-9]$/, ''); 5246 }, 5247 validations: { 5248 cpf: function(value) { 5249 return value.length > 11 || BrV.cpf.validate(value); 5250 }, 5251 cnpj: function(value) { 5252 return value.length <= 11 || BrV.cnpj.validate(value); 5253 } 5254 } 5255}); 5256 5257},{"br-validations":1,"mask-factory":"mask-factory","string-mask":3}],11:[function(require,module,exports){ 5258'use strict'; 5259 5260var StringMask = require('string-mask'); 5261var BrV = require('br-validations'); 5262var maskFactory = require('mask-factory'); 5263 5264var cpfPattern = new StringMask('000.000.000-00'); 5265 5266module.exports = maskFactory({ 5267 clearValue: function(rawValue) { 5268 return rawValue.replace(/[^\d]/g, '').slice(0, 11); 5269 }, 5270 format: function(cleanValue) { 5271 return (cpfPattern.apply(cleanValue) || '').trim().replace(/[^0-9]$/, ''); 5272 }, 5273 validations: { 5274 cpf: function(value) { 5275 return BrV.cpf.validate(value); 5276 } 5277 } 5278}); 5279 5280},{"br-validations":1,"mask-factory":"mask-factory","string-mask":3}],12:[function(require,module,exports){ 5281'use strict'; 5282 5283var StringMask = require('string-mask'); 5284var BrV = require('br-validations'); 5285 5286function BrIeMaskDirective($parse) { 5287 var ieMasks = { 5288 'AC': [{mask: new StringMask('00.000.000/000-00')}], 5289 'AL': [{mask: new StringMask('000000000')}], 5290 'AM': [{mask: new StringMask('00.000.000-0')}], 5291 'AP': [{mask: new StringMask('000000000')}], 5292 'BA': [{chars: 8, mask: new StringMask('000000-00')}, 5293 {mask: new StringMask('0000000-00')}], 5294 'CE': [{mask: new StringMask('00000000-0')}], 5295 'DF': [{mask: new StringMask('00000000000-00')}], 5296 'ES': [{mask: new StringMask('00000000-0')}], 5297 'GO': [{mask: new StringMask('00.000.000-0')}], 5298 'MA': [{mask: new StringMask('000000000')}], 5299 'MG': [{mask: new StringMask('000.000.000/0000')}], 5300 'MS': [{mask: new StringMask('000000000')}], 5301 'MT': [{mask: new StringMask('0000000000-0')}], 5302 'PA': [{mask: new StringMask('00-000000-0')}], 5303 'PB': [{mask: new StringMask('00000000-0')}], 5304 'PE': [{chars: 9, mask: new StringMask('0000000-00')}, 5305 {mask: new StringMask('00.0.000.0000000-0')}], 5306 'PI': [{mask: new StringMask('000000000')}], 5307 'PR': [{mask: new StringMask('000.00000-00')}], 5308 'RJ': [{mask: new StringMask('00.000.00-0')}], 5309 'RN': [{chars: 9, mask: new StringMask('00.000.000-0')}, 5310 {mask: new StringMask('00.0.000.000-0')}], 5311 'RO': [{mask: new StringMask('0000000000000-0')}], 5312 'RR': [{mask: new StringMask('00000000-0')}], 5313 'RS': [{mask: new StringMask('000/0000000')}], 5314 'SC': [{mask: new StringMask('000.000.000')}], 5315 'SE': [{mask: new StringMask('00000000-0')}], 5316 'SP': [{mask: new StringMask('000.000.000.000')}, 5317 {mask: new StringMask('-00000000.0/000')}], 5318 'TO': [{mask: new StringMask('00000000000')}] 5319 }; 5320 5321 function clearValue(value) { 5322 if (!value) { 5323 return value; 5324 } 5325 5326 return value.replace(/[^0-9]/g, ''); 5327 } 5328 5329 function getMask(uf, value) { 5330 if (!uf || !ieMasks[uf]) { 5331 return; 5332 } 5333 5334 if (uf === 'SP' && /^P/i.test(value)) { 5335 return ieMasks.SP[1].mask; 5336 } 5337 5338 var masks = ieMasks[uf]; 5339 var i = 0; 5340 while (masks[i].chars && masks[i].chars < clearValue(value).length && i < masks.length - 1) { 5341 i++; 5342 } 5343 5344 return masks[i].mask; 5345 } 5346 5347 function applyIEMask(value, uf) { 5348 var mask = getMask(uf, value); 5349 5350 if (!mask) { 5351 return value; 5352 } 5353 5354 var processed = mask.process(clearValue(value)); 5355 var formatedValue = processed.result || ''; 5356 formatedValue = formatedValue.trim().replace(/[^0-9]$/, ''); 5357 5358 if (uf === 'SP' && /^p/i.test(value)) { 5359 return 'P' + formatedValue; 5360 } 5361 5362 return formatedValue; 5363 } 5364 5365 return { 5366 restrict: 'A', 5367 require: 'ngModel', 5368 link: function(scope, element, attrs, ctrl) { 5369 var state = ($parse(attrs.uiBrIeMask)(scope) || '').toUpperCase(); 5370 5371 function formatter(value) { 5372 if (ctrl.$isEmpty(value)) { 5373 return value; 5374 } 5375 5376 return applyIEMask(value, state); 5377 } 5378 5379 function parser(value) { 5380 if (ctrl.$isEmpty(value)) { 5381 return value; 5382 } 5383 5384 var formatedValue = applyIEMask(value, state); 5385 var actualValue = clearValue(formatedValue); 5386 5387 if (ctrl.$viewValue !== formatedValue) { 5388 ctrl.$setViewValue(formatedValue); 5389 ctrl.$render(); 5390 } 5391 5392 if (state && state.toUpperCase() === 'SP' && /^p/i.test(value)) { 5393 return 'P' + actualValue; 5394 } 5395 5396 return actualValue; 5397 } 5398 5399 ctrl.$formatters.push(formatter); 5400 ctrl.$parsers.push(parser); 5401 5402 ctrl.$validators.ie = function validator(modelValue) { 5403 return ctrl.$isEmpty(modelValue) || BrV.ie(state).validate(modelValue); 5404 }; 5405 5406 scope.$watch(attrs.uiBrIeMask, function(newState) { 5407 state = (newState || '').toUpperCase(); 5408 5409 parser(ctrl.$viewValue); 5410 ctrl.$validate(); 5411 }); 5412 } 5413 }; 5414} 5415BrIeMaskDirective.$inject = ['$parse']; 5416 5417module.exports = BrIeMaskDirective; 5418 5419},{"br-validations":1,"string-mask":3}],13:[function(require,module,exports){ 5420'use strict'; 5421 5422var StringMask = require('string-mask'); 5423var maskFactory = require('mask-factory'); 5424 5425var nfeAccessKeyMask = new StringMask('0000 0000 0000 0000 0000' + 5426 ' 0000 0000 0000 0000 0000 0000'); 5427 5428module.exports = maskFactory({ 5429 clearValue: function(rawValue) { 5430 return rawValue.replace(/[^0-9]/g, '').slice(0, 44); 5431 }, 5432 format: function(cleanValue) { 5433 return (nfeAccessKeyMask.apply(cleanValue) || '').replace(/[^0-9]$/, ''); 5434 }, 5435 validations: { 5436 nfeAccessKey: function(value) { 5437 return value.length === 44; 5438 } 5439 } 5440}); 5441 5442},{"mask-factory":"mask-factory","string-mask":3}],14:[function(require,module,exports){ 5443'use strict'; 5444 5445var StringMask = require('string-mask'); 5446var maskFactory = require('mask-factory'); 5447 5448/** 5449 * FIXME: all numbers will have 9 digits after 2016. 5450 * see http://portal.embratel.com.br/embratel/9-digito/ 5451 */ 5452var phoneMask8D = new StringMask('(00) 0000-0000'), 5453 phoneMask9D = new StringMask('(00) 00000-0000'), 5454 phoneMask0800 = new StringMask('0000-000-0000'); 5455 5456module.exports = maskFactory({ 5457 clearValue: function(rawValue) { 5458 return rawValue.toString().replace(/[^0-9]/g, '').slice(0, 11); 5459 }, 5460 format: function(cleanValue) { 5461 var formatedValue; 5462 if (cleanValue.indexOf('0800') === 0) { 5463 formatedValue = phoneMask0800.apply(cleanValue); 5464 } else if (cleanValue.length < 11) { 5465 formatedValue = phoneMask8D.apply(cleanValue) || ''; 5466 } else { 5467 formatedValue = phoneMask9D.apply(cleanValue); 5468 } 5469 5470 return formatedValue.trim().replace(/[^0-9]$/, ''); 5471 }, 5472 getModelValue: function(formattedValue, originalModelType) { 5473 var cleanValue = this.clearValue(formattedValue); 5474 5475 return originalModelType === 'number' ? parseInt(cleanValue) : cleanValue; 5476 }, 5477 validations: { 5478 brPhoneNumber: function(value) { 5479 var valueLength = value && value.toString().length; 5480 return valueLength === 10 || valueLength === 11; 5481 } 5482 } 5483}); 5484 5485},{"mask-factory":"mask-factory","string-mask":3}],15:[function(require,module,exports){ 5486'use strict'; 5487 5488var m = angular.module('ui.utils.masks.ch', [ 5489 require('../helpers'), 5490]) 5491.directive('uiChPhoneNumber', require('./phone/ch-phone')); 5492 5493module.exports = m.name; 5494 5495},{"../helpers":25,"./phone/ch-phone":16}],16:[function(require,module,exports){ 5496'use strict'; 5497 5498var StringMask = require('string-mask'); 5499var maskFactory = require('mask-factory'); 5500 5501var phoneMask = new StringMask('+00 00 000 00 00'); 5502 5503module.exports = maskFactory({ 5504 clearValue: function(rawValue) { 5505 return rawValue.toString().replace(/[^0-9]/g, '').slice(0, 11); 5506 }, 5507 format: function(cleanValue) { 5508 var formatedValue; 5509 5510 formatedValue = phoneMask.apply(cleanValue) || ''; 5511 5512 return formatedValue.trim().replace(/[^0-9]$/, ''); 5513 }, 5514 validations: { 5515 chPhoneNumber: function(value) { 5516 var valueLength = value && value.toString().length; 5517 return valueLength === 11; 5518 } 5519 } 5520}); 5521 5522},{"mask-factory":"mask-factory","string-mask":3}],17:[function(require,module,exports){ 5523'use strict'; 5524 5525var StringMask = require('string-mask'); 5526var maskFactory = require('mask-factory'); 5527 5528var ccSize = 16; 5529 5530var ccMask = new StringMask('0000 0000 0000 0000'); 5531 5532module.exports = maskFactory({ 5533 clearValue: function(rawValue) { 5534 return rawValue.toString().replace(/[^0-9]/g, '').slice(0, ccSize); 5535 }, 5536 format: function(cleanValue) { 5537 var formatedValue; 5538 5539 formatedValue = ccMask.apply(cleanValue) || ''; 5540 5541 return formatedValue.trim().replace(/[^0-9]$/, ''); 5542 }, 5543 validations: { 5544 creditCard: function(value) { 5545 var valueLength = value && value.toString().length; 5546 return valueLength === ccSize; 5547 } 5548 } 5549}); 5550 5551},{"mask-factory":"mask-factory","string-mask":3}],18:[function(require,module,exports){ 5552'use strict'; 5553 5554var moment = require('moment'); 5555var StringMask = require('string-mask'); 5556 5557function isISODateString(date) { 5558 return /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}([-+][0-9]{2}:[0-9]{2}|Z)$/ 5559 .test(date.toString()); 5560} 5561 5562function DateMaskDirective($locale) { 5563 var dateFormatMapByLocale = { 5564 'pt-br': 'DD/MM/YYYY', 5565 }; 5566 5567 var dateFormat = dateFormatMapByLocale[$locale.id] || 'YYYY-MM-DD'; 5568 5569 return { 5570 restrict: 'A', 5571 require: 'ngModel', 5572 link: function(scope, element, attrs, ctrl) { 5573 var dateMask = new StringMask(dateFormat.replace(/[YMD]/g,'0')); 5574 5575 function formatter(value) { 5576 if (ctrl.$isEmpty(value)) { 5577 return value; 5578 } 5579 5580 var cleanValue = value; 5581 if (typeof value === 'object' || isISODateString(value)) { 5582 cleanValue = moment(value).format(dateFormat); 5583 } 5584 5585 cleanValue = cleanValue.replace(/[^0-9]/g, ''); 5586 var formatedValue = dateMask.apply(cleanValue) || ''; 5587 5588 return formatedValue.trim().replace(/[^0-9]$/, ''); 5589 } 5590 5591 ctrl.$formatters.push(formatter); 5592 5593 ctrl.$parsers.push(function parser(value) { 5594 if (ctrl.$isEmpty(value)) { 5595 return value; 5596 } 5597 5598 var formatedValue = formatter(value); 5599 5600 if (ctrl.$viewValue !== formatedValue) { 5601 ctrl.$setViewValue(formatedValue); 5602 ctrl.$render(); 5603 } 5604 5605 return moment(formatedValue, dateFormat).toDate(); 5606 }); 5607 5608 ctrl.$validators.date = function validator(modelValue, viewValue) { 5609 if (ctrl.$isEmpty(modelValue)) { 5610 return true; 5611 } 5612 5613 return moment(viewValue, dateFormat).isValid() && viewValue.length === dateFormat.length; 5614 }; 5615 } 5616 }; 5617} 5618DateMaskDirective.$inject = ['$locale']; 5619 5620module.exports = DateMaskDirective; 5621 5622},{"moment":2,"string-mask":3}],19:[function(require,module,exports){ 5623'use strict'; 5624 5625var m = angular.module('ui.utils.masks.global', [ 5626 require('../helpers'), 5627]) 5628.directive('uiDateMask', require('./date/date')) 5629.directive('uiMoneyMask', require('./money/money')) 5630.directive('uiNumberMask', require('./number/number')) 5631.directive('uiPercentageMask', require('./percentage/percentage')) 5632.directive('uiScientificNotationMask', require('./scientif
5632ic-notation/scientific-notation')) 5633.directive('uiTimeMask', require('./time/time')) 5634.directive('uiCreditCard', require('./credit-card/credit-card')); 5635 5636module.exports = m.name; 5637 5638},{"../helpers":25,"./credit-card/credit-card":17,"./date/date":18,"./money/money":20,"./number/number":21,"./percentage/percentage":22,"./scientific-notation/scientific-notation":23,"./time/time":24}],20:[function(require,module,exports){ 5639'use strict'; 5640 5641var StringMask = require('string-mask'); 5642var validators = require('validators'); 5643 5644function MoneyMaskDirective($locale, $parse, PreFormatters) { 5645 return { 5646 restrict: 'A', 5647 require: 'ngModel', 5648 link: function(scope, element, attrs, ctrl) { 5649 var decimalDelimiter = $locale.NUMBER_FORMATS.DECIMAL_SEP, 5650 thousandsDelimiter = $locale.NUMBER_FORMATS.GROUP_SEP, 5651 currencySym = $locale.NUMBER_FORMATS.CURRENCY_SYM, 5652 symbolSeparation = ' ', 5653 decimals = $parse(attrs.uiMoneyMask)(scope); 5654 5655 5656 function maskFactory(decimals) { 5657 var decimalsPattern = decimals > 0 ? decimalDelimiter + new Array(decimals + 1).join('0') : ''; 5658 var maskPattern = symbolSeparation + '#' + thousandsDelimiter + '##0' + decimalsPattern; 5659 return new StringMask(maskPattern, {reverse: true}); 5660 } 5661 5662 if (angular.isDefined(attrs.uiHideGroupSep)) { 5663 thousandsDelimiter = ''; 5664 } 5665 5666 if (angular.isDefined(attrs.uiHideSpace)) { 5667 symbolSeparation = ''; 5668 } 5669 5670 if (angular.isDefined(attrs.currencySymbol)) { 5671 currencySym = attrs.currencySymbol; 5672 if (attrs.currencySymbol.length === 0) { 5673 symbolSeparation = ''; 5674 } 5675 } 5676 5677 if (isNaN(decimals)) { 5678 decimals = 2; 5679 } 5680 decimals = parseInt(decimals); 5681 var moneyMask = maskFactory(decimals); 5682 5683 function formatter(value) { 5684 if (ctrl.$isEmpty(value)) { 5685 return value; 5686 } 5687 var prefix = (angular.isDefined(attrs.uiNegativeNumber) && value < 0) ? '-' : ''; 5688 var valueToFormat = PreFormatters.prepareNumberToFormatter(value, decimals); 5689 return prefix + currencySym + moneyMask.apply(valueToFormat); 5690 } 5691 5692 function parser(value) { 5693 if (ctrl.$isEmpty(value)) { 5694 return value; 5695 } 5696 5697 var actualNumber = value.replace(/[^\d]+/g,''); 5698 actualNumber = actualNumber.replace(/^[0]+([1-9])/,'$1'); 5699 actualNumber = actualNumber || '0'; 5700 var formatedValue = currencySym + moneyMask.apply(actualNumber); 5701 5702 if (angular.isDefined(attrs.uiNegativeNumber)) { 5703 var isNegative = (value[0] === '-'), 5704 needsToInvertSign = (value.slice(-1) === '-'); 5705 5706 //only apply the minus sign if it is negative or(exclusive) 5707 //needs to be negative and the number is different from zero 5708 if (needsToInvertSign ^ isNegative && !!actualNumber) { 5709 actualNumber *= -1; 5710 formatedValue = '-' + formatedValue; 5711 } 5712 } 5713 5714 if (value !== formatedValue) { 5715 ctrl.$setViewValue(formatedValue); 5716 ctrl.$render(); 5717 } 5718 5719 return formatedValue ? parseInt(formatedValue.replace(/[^\d\-]+/g,''))/Math.pow(10,decimals) : null; 5720 } 5721 5722 ctrl.$formatters.push(formatter); 5723 ctrl.$parsers.push(parser); 5724 5725 if (attrs.uiMoneyMask) { 5726 scope.$watch(attrs.uiMoneyMask, function(_decimals) { 5727 decimals = isNaN(_decimals) ? 2 : _decimals; 5728 decimals = parseInt(decimals); 5729 moneyMask = maskFactory(decimals); 5730 5731 parser(ctrl.$viewValue); 5732 }); 5733 } 5734 5735 if (attrs.min) { 5736 var minVal; 5737 5738 ctrl.$validators.min = function(modelValue) { 5739 return validators.minNumber(ctrl, modelValue, minVal); 5740 }; 5741 5742 scope.$watch(attrs.min, function(value) { 5743 minVal = value; 5744 ctrl.$validate(); 5745 }); 5746 } 5747 5748 if (attrs.max) { 5749 var maxVal; 5750 5751 ctrl.$validators.max = function(modelValue) { 5752 return validators.maxNumber(ctrl, modelValue, maxVal); 5753 }; 5754 5755 scope.$watch(attrs.max, function(value) { 5756 maxVal = value; 5757 ctrl.$validate(); 5758 }); 5759 } 5760 } 5761 }; 5762} 5763MoneyMaskDirective.$inject = ['$locale', '$parse', 'PreFormatters']; 5764 5765module.exports = MoneyMaskDirective; 5766 5767},{"string-mask":3,"validators":"validators"}],21:[function(require,module,exports){ 5768'use strict'; 5769 5770var validators = require('validators'); 5771 5772function NumberMaskDirective($locale, $parse, PreFormatters, NumberMasks) { 5773 return { 5774 restrict: 'A', 5775 require: 'ngModel', 5776 link: function(scope, element, attrs, ctrl) { 5777 var decimalDelimiter = $locale.NUMBER_FORMATS.DECIMAL_SEP, 5778 thousandsDelimiter = $locale.NUMBER_FORMATS.GROUP_SEP, 5779 decimals = $parse(attrs.uiNumberMask)(scope); 5780
5781 if (angular.isDefined(attrs.uiHideGroupSep)) { 5782 thousandsDelimiter = ''; 5783 } 5784 5785 if (isNaN(decimals)) { 5786 decimals = 2; 5787 } 5788 5789 var viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter), 5790 modelMask = NumberMasks.modelMask(decimals); 5791 5792 function parser(value) { 5793 if (ctrl.$isEmpty(value)) { 5794 return null; 5795 } 5796 5797 var valueToFormat = PreFormatters.clearDelimitersAndLeadingZeros(value) || '0'; 5798 var formatedValue = viewMask.apply(valueToFormat); 5799 var actualNumber = parseFloat(modelMask.apply(valueToFormat)); 5800 5801 if (angular.isDefined(attrs.uiNegativeNumber)) { 5802 var isNegative = (value[0] === '-'), 5803 needsToInvertSign = (value.slice(-1) === '-'); 5804 5805 //only apply the minus sign if it is negative or(exclusive) or the first character 5806 //needs to be negative and the number is different from zero 5807 if ((needsToInvertSign ^ isNegative) || value === '-') { 5808 actualNumber *= -1; 5809 formatedValue = '-' + ((actualNumber !== 0) ? formatedValue : ''); 5810 } 5811 } 5812 5813 if (ctrl.$viewValue !== formatedValue) { 5814 ctrl.$setViewValue(formatedValue); 5815 ctrl.$render(); 5816 } 5817 5818 return actualNumber; 5819 } 5820 5821 function formatter(value) { 5822 if (ctrl.$isEmpty(value)) { 5823 return value; 5824 } 5825 5826 var prefix = (angular.isDefined(attrs.uiNegativeNumber) && value < 0) ? '-' : ''; 5827 var valueToFormat = PreFormatters.prepareNumberToFormatter(value, decimals); 5828 return prefix + viewMask.apply(valueToFormat); 5829 } 5830 5831 function clearViewValueIfMinusSign() { 5832 if (ctrl.$viewValue === '-') { 5833 ctrl.$setViewValue(''); 5834 ctrl.$render(); 5835 } 5836 } 5837 5838 element.on('blur', clearViewValueIfMinusSign); 5839 5840 ctrl.$formatters.push(formatter); 5841 ctrl.$parsers.push(parser); 5842 5843 if (attrs.uiNumberMask) { 5844 scope.$watch(attrs.uiNumberMask, function(_decimals) { 5845 decimals = isNaN(_decimals) ? 2 : _decimals; 5846 viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter); 5847 modelMask = NumberMasks.modelMask(decimals); 5848 5849 parser(ctrl.$viewValue); 5850 }); 5851 } 5852 5853 if (attrs.min) { 5854 var minVal; 5855 5856 ctrl.$validators.min = function(modelValue) { 5857 return validators.minNumber(ctrl, modelValue, minVal); 5858 }; 5859 5860 scope.$watch(attrs.min, function(value) { 5861 minVal = value; 5862 ctrl.$validate(); 5863 }); 5864 } 5865 5866 if (attrs.max) { 5867 var maxVal; 5868 5869 ctrl.$validators.max = function(modelValue) { 5870 return validators.maxNumber(ctrl, modelValue, maxVal); 5871 }; 5872 5873 scope.$watch(attrs.max, function(value) { 5874 maxVal = value; 5875 ctrl.$validate(); 5876 }); 5877 } 5878 } 5879 }; 5880} 5881NumberMaskDirective.$inject = ['$locale', '$parse', 'PreFormatters', 'NumberMasks']; 5882 5883module.exports = NumberMaskDirective; 5884 5885},{"validators":"validators"}],22:[function(require,module,exports){ 5886'use strict'; 5887 5888var validators = require('validators'); 5889 5890function PercentageMaskDirective($locale, $parse, PreFormatters, NumberMasks) { 5891 function preparePercentageToFormatter(value, decimals, modelMultiplier) { 5892 return PreFormatters.clearDelimitersAndLeadingZeros((parseFloat(value)*modelMultiplier).toFixed(decimals)); 5893 } 5894 5895 return { 5896 restrict: 'A', 5897 require: 'ngModel', 5898 link: function(scope, element, attrs, ctrl) { 5899 var decimalDelimiter = $locale.NUMBER_FORMATS.DECIMAL_SEP, 5900 thousandsDelimiter = $locale.NUMBER_FORMATS.GROUP_SEP, 5901 decimals = parseInt(attrs.uiPercentageMask), 5902 hideSpace = false, 5903 backspacePressed = false; 5904 5905 element.bind('keydown keypress', function(event) { 5906 backspacePressed = event.which === 8; 5907 }); 5908 5909 var modelValue = { 5910 multiplier : 100, 5911 decimalMask: 2 5912 }; 5913 5914 if (angular.isDefined(attrs.uiHideGroupSep)) { 5915 thousandsDelimiter = ''; 5916 } 5917 5918 if (angular.isDefined(attrs.uiHideSpace)) { 5919 hideSpace = true; 5920 } 5921 5922 if (angular.isDefined(attrs.uiPercentageValue)) { 5923 modelValue.multiplier = 1; 5924 modelValue.decimalMask = 0; 5925 } 5926 5927 if (isNaN(decimals)) { 5928 decimals = 2; 5929 } 5930 5931 var numberDecimals = decimals + modelValue.decimalMask; 5932 var viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter), 5933 modelMask = NumberMasks.modelMask(numberDecimals); 5934 5935 function formatter(value) { 5936 if (ctrl.$isEmpty(value)) { 5937 return value; 5938 } 5939 5940 var valueToFormat = preparePercentageToFormatter(value, decimals, modelValue.multiplier); 5941 return viewMask.apply(valueToFormat) + ' %'; 5942 } 5943 5944 function parse(value) { 5945 if (ctrl.$isEmpty(value)) { 5946 return null; 5947 } 5948 5949 var valueToFormat = PreFormatters.clearDelimitersAndLeadingZeros(value) || '0'; 5950 if (value.length > 1 && value.indexOf('%') === -1) { 5951 valueToFormat = valueToFormat.slice(0,valueToFormat.length-1); 5952 } 5953 if (backspacePressed && value.length === 1 && value !== '%') { 5954 valueToFormat = '0'; 5955 } 5956 var percentSign = hideSpace ? '%' : ' %'; 5957 var formatedValue = viewMask.apply(valueToFormat) + percentSign; 5958 var actualNumber = parseFloat(modelMask.apply(valueToFormat)); 5959 5960 if (ctrl.$viewValue !== formatedValue) { 5961 ctrl.$setViewValue(formatedValue); 5962 ctrl.$render(); 5963 } 5964 5965 return actualNumber; 5966 } 5967 5968 ctrl.$formatters.push(formatter); 5969 ctrl.$parsers.push(parse); 5970
5971 if (attrs.uiPercentageMask) { 5972 scope.$watch(attrs.uiPercentageMask, function(_decimals) { 5973 decimals = isNaN(_decimals) ? 2 : _decimals; 5974 5975 if (angular.isDefined(attrs.uiPercentageValue)) { 5976 modelValue.multiplier = 1; 5977 modelValue.decimalMask = 0; 5978 } 5979 5980 numberDecimals = decimals + modelValue.decimalMask; 5981 viewMask = NumberMasks.viewMask(decimals, decimalDelimiter, thousandsDelimiter); 5982 modelMask = NumberMasks.modelMask(numberDecimals); 5983 5984 parse(ctrl.$viewValue); 5985 }); 5986 } 5987 5988 if (attrs.min) { 5989 var minVal; 5990 5991 ctrl.$validators.min = function(modelValue) { 5992 return validators.minNumber(ctrl, modelValue, minVal); 5993 }; 5994 5995 scope.$watch(attrs.min, function(value) { 5996 minVal = value; 5997 ctrl.$validate(); 5998 }); 5999 } 6000 6001 if (attrs.max) { 6002 var maxVal; 6003 6004 ctrl.$validators.max = function(modelValue) { 6005 return validators.maxNumber(ctrl, modelValue, maxVal); 6006 }; 6007 6008 scope.$watch(attrs.max, function(value) { 6009 maxVal = value; 6010 ctrl.$validate(); 6011 }); 6012 } 6013 } 6014 }; 6015} 6016PercentageMaskDirective.$inject = ['$locale', '$parse', 'PreFormatters', 'NumberMasks']; 6017 6018module.exports = PercentageMaskDirective; 6019 6020},{"validators":"validators"}],23:[function(require,module,exports){ 6021'use strict'; 6022 6023var StringMask = require('string-mask'); 6024 6025function ScientificNotationMaskDirective($locale, $parse) { 6026 var decimalDelimiter = $locale.NUMBER_FORMATS.DECIMAL_SEP, 6027 defaultPrecision = 2; 6028 6029 function significandMaskBuilder(decimals) { 6030 var mask = '0'; 6031 6032 if (decimals > 0) { 6033 mask += decimalDelimiter; 6034 for (var i = 0; i < decimals; i++) { 6035 mask += '0'; 6036 } 6037 } 6038 6039 return new StringMask(mask, { 6040 reverse: true 6041 }); 6042 } 6043 6044 return { 6045 restrict: 'A', 6046 require: 'ngModel', 6047 link: function(scope, element, attrs, ctrl) { 6048 var decimals = $parse(attrs.uiScientificNotationMask)(scope); 6049 6050 if (isNaN(decimals)) { 6051 decimals = defaultPrecision; 6052 } 6053 6054 var significandMask = significandMaskBuilder(decimals); 6055 6056 function splitNumber(value) { 6057 var stringValue = value.toString(), 6058 splittedNumber = stringValue.match(/(-?[0-9]*)[\.]?([0-9]*)?[Ee]?([\+-]?[0-9]*)?/); 6059 6060 return { 6061 integerPartOfSignificand: splittedNumber[1], 6062 decimalPartOfSignificand: splittedNumber[2], 6063 exponent: splittedNumber[3] | 0 6064 }; 6065 } 6066 6067 function formatter(value) { 6068 if (ctrl.$isEmpty(value)) { 6069 return value; 6070 } 6071 6072 if (typeof value === 'string') { 6073 value = value.replace(decimalDelimiter, '.'); 6074 } else if (typeof value === 'number') { 6075 value = value.toExponential(decimals); 6076 } 6077 6078 var formattedValue, exponent; 6079 var splittedNumber = splitNumber(value); 6080 6081 var integerPartOfSignificand = splittedNumber.integerPartOfSignificand || 0; 6082 var numberToFormat = integerPartOfSignificand.toString(); 6083 if (angular.isDefined(splittedNumber.decimalPartOfSignificand)) { 6084 numberToFormat += splittedNumber.decimalPartOfSignificand; 6085 } 6086 6087 var needsNormalization = 6088 (integerPartOfSignificand >= 1 || integerPartOfSignificand <= -1) && 6089 ( 6090 (angular.isDefined(splittedNumber.decimalPartOfSignificand) && 6091 splittedNumber.decimalPartOfSignificand.length > decimals) || 6092 (decimals === 0 && numberToFormat.length >= 2) 6093 ); 6094 6095 if (needsNormalization) { 6096 exponent = numberToFormat.slice(decimals + 1, numberToFormat.length); 6097 numberToFormat = numberToFormat.slice(0, decimals + 1); 6098 } 6099 6100 formattedValue = significandMask.apply(numberToFormat); 6101 6102 if (splittedNumber.exponent !== 0) { 6103 exponent = splittedNumber.exponent; 6104 } 6105 6106 if (angular.isDefined(exponent)) { 6107 formattedValue += 'e' + exponent; 6108 } 6109 6110 return formattedValue; 6111 } 6112 6113 function parser(value) { 6114 if (ctrl.$isEmpty(value)) { 6115 return value; 6116 } 6117 6118 var viewValue = formatter(value), 6119 modelValue = parseFloat(viewValue.replace(decimalDelimiter, '.')); 6120 6121 if (ctrl.$viewValue !== viewValue) { 6122 ctrl.$setViewValue(viewValue); 6123 ctrl.$render(); 6124 } 6125 6126 return modelValue; 6127 } 6128 6129 ctrl.$formatters.push(formatter); 6130 ctrl.$parsers.push(parser); 6131 6132 ctrl.$validators.max = function validator(value) { 6133 return ctrl.$isEmpty(value) || value < Number.MAX_VALUE; 6134 }; 6135 } 6136 }; 6137} 6138ScientificNotationMaskDirective.$inject = ['$locale', '$parse']; 6139 6140module.exports = ScientificNotationMaskDirective; 6141 6142},{"string-mask":3}],24:[function(require,module,exports){ 6143'use strict'; 6144 6145var StringMask = require('string-mask'); 6146 6147module.exports = function TimeMaskDirective() { 6148 return { 6149 restrict: 'A', 6150 require: 'ngModel', 6151 link: function(scope, element, attrs, ctrl) { 6152 var timeFormat = '00:00:00'; 6153
6154 if (angular.isDefined(attrs.uiTimeMask) && attrs.uiTimeMask === 'short') { 6155 timeFormat = '00:00'; 6156 } 6157 6158 var formattedValueLength = timeFormat.length; 6159 var unformattedValueLength = timeFormat.replace(':', '').length; 6160 var timeMask = new StringMask(timeFormat); 6161 6162 function formatter(value) { 6163 if (ctrl.$isEmpty(value)) { 6164 return value; 6165 } 6166 6167 var cleanValue = value.replace(/[^0-9]/g, '').slice(0, unformattedValueLength) || ''; 6168 return (timeMask.apply(cleanValue) || '').replace(/[^0-9]$/, ''); 6169 } 6170 6171 ctrl.$formatters.push(formatter); 6172 6173 ctrl.$parsers.push(function parser(value) { 6174 if (ctrl.$isEmpty(value)) { 6175 return value; 6176 } 6177 6178 var viewValue = formatter(value); 6179 var modelValue = viewValue; 6180 6181 if (ctrl.$viewValue !== viewValue) { 6182 ctrl.$setViewValue(viewValue); 6183 ctrl.$render(); 6184 } 6185 6186 return modelValue; 6187 }); 6188 6189 ctrl.$validators.time = function(modelValue) { 6190 if (ctrl.$isEmpty(modelValue)) { 6191 return true; 6192 } 6193 6194 var splittedValue = modelValue.toString().split(/:/).filter(function(v) { 6195 return !!v; 6196 }); 6197 6198 var hours = parseInt(splittedValue[0]), 6199 minutes = parseInt(splittedValue[1]), 6200 seconds = parseInt(splittedValue[2] || 0); 6201 6202 return modelValue.toString().length === formattedValueLength && 6203 hours < 24 && minutes < 60 && seconds < 60; 6204 }; 6205 } 6206 }; 6207}; 6208 6209},{"string-mask":3}],25:[function(require,module,exports){ 6210'use strict'; 6211 6212var StringMask = require('string-mask'); 6213 6214var m = angular.module('ui.utils.masks.helpers', []); 6215 6216module.exports = m.name; 6217 6218m.factory('PreFormatters', [function() { 6219 function clearDelimitersAndLeadingZeros(value) { 6220 if (value === '0') { 6221 return '0'; 6222 } 6223 6224 var cleanValue = value.replace(/^-/,'').replace(/^0*/, ''); 6225 return cleanValue.replace(/[^0-9]/g, ''); 6226 } 6227 6228 function prepareNumberToFormatter(value, decimals) { 6229 return clearDelimitersAndLeadingZeros((parseFloat(value)).toFixed(decimals)); 6230 } 6231 6232 return { 6233 clearDelimitersAndLeadingZeros: clearDelimitersAndLeadingZeros, 6234 prepareNumberToFormatter: prepareNumberToFormatter 6235 }; 6236}]) 6237.factory('NumberMasks', [function() { 6238 return { 6239 viewMask: function(decimals, decimalDelimiter, thousandsDelimiter) { 6240 var mask = '#' + thousandsDelimiter + '##0'; 6241 6242 if (decimals > 0) { 6243 mask += decimalDelimiter; 6244 for (var i = 0; i < decimals; i++) { 6245 mask += '0'; 6246 } 6247 } 6248 6249 return new StringMask(mask, { 6250 reverse: true 6251 }); 6252 }, 6253 modelMask: function(decimals) { 6254 var mask = '###0'; 6255 6256 if (decimals > 0) { 6257 mask += '.'; 6258 for (var i = 0; i < decimals; i++) { 6259 mask += '0'; 6260 } 6261 } 6262 6263 return new StringMask(mask, { 6264 reverse: true 6265 }); 6266 } 6267 }; 6268}]); 6269 6270},{"string-mask":3}],26:[function(require,module,exports){ 6271'use strict'; 6272 6273var StringMask = require('string-mask'); 6274var maskFactory = require('mask-factory'); 6275 6276var phoneMaskUS = new StringMask('(000) 000-0000'), 6277 phoneMaskINTL = new StringMask('+00-00-000-000000'); 6278 6279module.exports = maskFactory({ 6280 clearValue: function(rawValue) { 6281 return rawValue.toString().replace(/[^0-9]/g, ''); 6282 }, 6283 format: function(cleanValue) { 6284 var formattedValue; 6285 6286 if (cleanValue.length < 11) { 6287 formattedValue = phoneMaskUS.apply(cleanValue) || ''; 6288 } else { 6289 formattedValue = phoneMaskINTL.apply(cleanValue); 6290 } 6291 6292 return formattedValue.trim().replace(/[^0-9]$/, ''); 6293 }, 6294 validations: { 6295 usPhoneNumber: function(value) { 6296 return value && value.toString().length > 9; 6297 } 6298 } 6299}); 6300 6301},{"mask-factory":"mask-factory","string-mask":3}],27:[function(require,module,exports){ 6302'use strict'; 6303 6304var m = angular.module('ui.utils.masks.us', [ 6305 require('../helpers') 6306]) 6307.directive('uiUsPhoneNumber', require('./phone/us-phone')); 6308 6309module.exports = m.name; 6310 6311},{"../helpers":25,"./phone/us-phone":26}],"mask-factory":[function(require,module,exports){ 6312'use strict'; 6313 6314module.exports = function maskFactory(maskDefinition) { 6315 return function MaskDirective() { 6316 return { 6317 restrict: 'A', 6318 require: 'ngModel', 6319 link: function(scope, element, attrs, ctrl) { 6320 ctrl.$formatters.push(function formatter(value) { 6321 if (ctrl.$isEmpty(value)) { 6322 return value; 6323 } 6324 6325 var cleanValue = maskDefinition.clearValue(value); 6326 return maskDefinition.format(cleanValue); 6327 }); 6328 6329 ctrl.$parsers.push(function parser(value) { 6330 if (ctrl.$isEmpty(value)) { 6331 return value; 6332 } 6333 6334 var cleanValue = maskDefinition.clearValue(value); 6335 var formattedValue = maskDefinition.format(cleanValue); 6336 6337 if (ctrl.$viewValue !== formattedValue) { 6338 ctrl.$setViewValue(formattedValue); 6339 ctrl.$render(); 6340 } 6341 6342 if (angular.isUndefined(maskDefinition.getModelValue)) { 6343 return cleanValue; 6344 } 6345 6346 var actualModelType = typeof ctrl.$modelValue; 6347 return maskDefinition.getModelValue(formattedValue, actualModelType); 6348 }); 6349
6350 angular.forEach(maskDefinition.validations, function(validatorFn, validationErrorKey) { 6351 ctrl.$validators[validationErrorKey] = function validator(modelValue, viewValue) { 6352 return ctrl.$isEmpty(modelValue) || validatorFn(modelValue, viewValue); 6353 }; 6354 }); 6355 } 6356 }; 6357 }; 6358}; 6359 6360},{}],"validators":[function(require,module,exports){ 6361'use strict'; 6362 6363module.exports = { 6364 maxNumber: function(ctrl, value, limit) { 6365 var max = parseFloat(limit, 10); 6366 return ctrl.$isEmpty(value) || isNaN(max) || value <= max; 6367 }, 6368 minNumber: function(ctrl, value, limit) { 6369 var min = parseFloat(limit, 10); 6370 return ctrl.$isEmpty(value) || isNaN(min) || value >= min; 6371 } 6372}; 6373 6374},{}]},{},[4]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.