ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From onechipore...@apache.org
Subject [1/3] ambari git commit: AMBARI-13293. Ambari Web: Set/change the timezone (onechiporenko)
Date Fri, 02 Oct 2015 09:42:59 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 69988db50 -> f0949259f


http://git-wip-us.apache.org/repos/asf/ambari/blob/f0949259/ambari-web/vendor/scripts/moment.js
----------------------------------------------------------------------
diff --git a/ambari-web/vendor/scripts/moment.js b/ambari-web/vendor/scripts/moment.js
index b40374b..fe0e19c 100644
--- a/ambari-web/vendor/scripts/moment.js
+++ b/ambari-web/vendor/scripts/moment.js
@@ -1,466 +1,213 @@
 //! moment.js
-//! version : 2.5.1
+//! version : 2.10.6
 //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
 //! license : MIT
 //! momentjs.com
 
-(function (undefined) {
-
-  /************************************
-   Constants
-   ************************************/
-
-  var moment,
-    VERSION = "2.5.1",
-    global = this,
-    round = Math.round,
-    i,
-
-    YEAR = 0,
-    MONTH = 1,
-    DATE = 2,
-    HOUR = 3,
-    MINUTE = 4,
-    SECOND = 5,
-    MILLISECOND = 6,
-
-  // internal storage for language config files
-    languages = {},
-
-  // moment internal properties
-    momentProperties = {
-      _isAMomentObject: null,
-      _i : null,
-      _f : null,
-      _l : null,
-      _strict : null,
-      _isUTC : null,
-      _offset : null,  // optional. Combine with _isUTC
-      _pf : null,
-      _lang : null  // optional
-    },
-
-  // check for nodeJS
-    hasModule = (typeof module !== 'undefined' && module.exports && typeof require !== 'undefined'),
-
-  // ASP.NET json date format regex
-    aspNetJsonRegex = /^\/?Date\((\-?\d+)/i,
-    aspNetTimeSpanJsonRegex = /(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,
+(function (global, factory) {
+  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
+    typeof define === 'function' && define.amd ? define(factory) :
+      global.moment = factory()
+}(this, function () { 'use strict';
 
-  // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
-  // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
-    isoDurationRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/,
-
-  // format tokens
-    formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,4}|X|zz?|ZZ?|.)/g,
-    localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,
-
-  // parsing token regexes
-    parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99
-    parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999
-    parseTokenOneToFourDigits = /\d{1,4}/, // 0 - 9999
-    parseTokenOneToSixDigits = /[+\-]?\d{1,6}/, // -999,999 - 999,999
-    parseTokenDigits = /\d+/, // nonzero number of digits
-    parseTokenWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i, // any word (or two) characters or numbers including two/three word month in arabic.
-    parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
-    parseTokenT = /T/i, // T (ISO separator)
-    parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
-
-  //strict parsing regexes
-    parseTokenOneDigit = /\d/, // 0 - 9
-    parseTokenTwoDigits = /\d\d/, // 00 - 99
-    parseTokenThreeDigits = /\d{3}/, // 000 - 999
-    parseTokenFourDigits = /\d{4}/, // 0000 - 9999
-    parseTokenSixDigits = /[+-]?\d{6}/, // -999,999 - 999,999
-    parseTokenSignedNumber = /[+-]?\d+/, // -inf - inf
-
-  // iso 8601 regex
-  // 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)
-    isoRegex = /^\s*(?:[+-]\d{6}|\d{4})-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
-
-    isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',
-
-    isoDates = [
-      ['YYYYYY-MM-DD', /[+-]\d{6}-\d{2}-\d{2}/],
-      ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/],
-      ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/],
-      ['GGGG-[W]WW', /\d{4}-W\d{2}/],
-      ['YYYY-DDD', /\d{4}-\d{3}/]
-    ],
-
-  // iso time formats and regexes
-    isoTimes = [
-      ['HH:mm:ss.SSSS', /(T| )\d\d:\d\d:\d\d\.\d{1,3}/],
-      ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/],
-      ['HH:mm', /(T| )\d\d:\d\d/],
-      ['HH', /(T| )\d\d/]
-    ],
-
-  // timezone chunker "+10:00" > ["10", "00"] or "-1530" > ["-15", "30"]
-    parseTimezoneChunker = /([\+\-]|\d\d)/gi,
-
-  // getter and setter names
-    proxyGettersAndSetters = 'Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),
-    unitMillisecondFactors = {
-      'Milliseconds' : 1,
-      'Seconds' : 1e3,
-      'Minutes' : 6e4,
-      'Hours' : 36e5,
-      'Days' : 864e5,
-      'Months' : 2592e6,
-      'Years' : 31536e6
-    },
-
-    unitAliases = {
-      ms : 'millisecond',
-      s : 'second',
-      m : 'minute',
-      h : 'hour',
-      d : 'day',
-      D : 'date',
-      w : 'week',
-      W : 'isoWeek',
-      M : 'month',
-      y : 'year',
-      DDD : 'dayOfYear',
-      e : 'weekday',
-      E : 'isoWeekday',
-      gg: 'weekYear',
-      GG: 'isoWeekYear'
-    },
-
-    camelFunctions = {
-      dayofyear : 'dayOfYear',
-      isoweekday : 'isoWeekday',
-      isoweek : 'isoWeek',
-      weekyear : 'weekYear',
-      isoweekyear : 'isoWeekYear'
-    },
-
-  // format function strings
-    formatFunctions = {},
-
-  // tokens to ordinalize and pad
-    ordinalizeTokens = 'DDD w W M D d'.split(' '),
-    paddedTokens = 'M D H h m s w W'.split(' '),
-
-    formatTokenFunctions = {
-      M    : function () {
-        return this.month() + 1;
-      },
-      MMM  : function (format) {
-        return this.lang().monthsShort(this, format);
-      },
-      MMMM : function (format) {
-        return this.lang().months(this, format);
-      },
-      D    : function () {
-        return this.date();
-      },
-      DDD  : function () {
-        return this.dayOfYear();
-      },
-      d    : function () {
-        return this.day();
-      },
-      dd   : function (format) {
-        return this.lang().weekdaysMin(this, format);
-      },
-      ddd  : function (format) {
-        return this.lang().weekdaysShort(this, format);
-      },
-      dddd : function (format) {
-        return this.lang().weekdays(this, format);
-      },
-      w    : function () {
-        return this.week();
-      },
-      W    : function () {
-        return this.isoWeek();
-      },
-      YY   : function () {
-        return leftZeroFill(this.year() % 100, 2);
-      },
-      YYYY : function () {
-        return leftZeroFill(this.year(), 4);
-      },
-      YYYYY : function () {
-        return leftZeroFill(this.year(), 5);
-      },
-      YYYYYY : function () {
-        var y = this.year(), sign = y >= 0 ? '+' : '-';
-        return sign + leftZeroFill(Math.abs(y), 6);
-      },
-      gg   : function () {
-        return leftZeroFill(this.weekYear() % 100, 2);
-      },
-      gggg : function () {
-        return leftZeroFill(this.weekYear(), 4);
-      },
-      ggggg : function () {
-        return leftZeroFill(this.weekYear(), 5);
-      },
-      GG   : function () {
-        return leftZeroFill(this.isoWeekYear() % 100, 2);
-      },
-      GGGG : function () {
-        return leftZeroFill(this.isoWeekYear(), 4);
-      },
-      GGGGG : function () {
-        return leftZeroFill(this.isoWeekYear(), 5);
-      },
-      e : function () {
-        return this.weekday();
-      },
-      E : function () {
-        return this.isoWeekday();
-      },
-      a    : function () {
-        return this.lang().meridiem(this.hours(), this.minutes(), true);
-      },
-      A    : function () {
-        return this.lang().meridiem(this.hours(), this.minutes(), false);
-      },
-      H    : function () {
-        return this.hours();
-      },
-      h    : function () {
-        return this.hours() % 12 || 12;
-      },
-      m    : function () {
-        return this.minutes();
-      },
-      s    : function () {
-        return this.seconds();
-      },
-      S    : function () {
-        return toInt(this.milliseconds() / 100);
-      },
-      SS   : function () {
-        return leftZeroFill(toInt(this.milliseconds() / 10), 2);
-      },
-      SSS  : function () {
-        return leftZeroFill(this.milliseconds(), 3);
-      },
-      SSSS : function () {
-        return leftZeroFill(this.milliseconds(), 3);
-      },
-      Z    : function () {
-        var a = -this.zone(),
-          b = "+";
-        if (a < 0) {
-          a = -a;
-          b = "-";
-        }
-        return b + leftZeroFill(toInt(a / 60), 2) + ":" + leftZeroFill(toInt(a) % 60, 2);
-      },
-      ZZ   : function () {
-        var a = -this.zone(),
-          b = "+";
-        if (a < 0) {
-          a = -a;
-          b = "-";
-        }
-        return b + leftZeroFill(toInt(a / 60), 2) + leftZeroFill(toInt(a) % 60, 2);
-      },
-      z : function () {
-        return this.zoneAbbr();
-      },
-      zz : function () {
-        return this.zoneName();
-      },
-      X    : function () {
-        return this.unix();
-      },
-      Q : function () {
-        return this.quarter();
-      }
-    },
-
-    lists = ['months', 'monthsShort', 'weekdays', 'weekdaysShort', 'weekdaysMin'];
+  var hookCallback;
 
-  function defaultParsingFlags() {
-    // We need to deep clone this object, and es5 standard is not very
-    // helpful.
-    return {
-      empty : false,
-      unusedTokens : [],
-      unusedInput : [],
-      overflow : -2,
-      charsLeftOver : 0,
-      nullInput : false,
-      invalidMonth : null,
-      invalidFormat : false,
-      userInvalidated : false,
-      iso: false
-    };
+  function utils_hooks__hooks () {
+    return hookCallback.apply(null, arguments);
   }
 
-  function padToken(func, count) {
-    return function (a) {
-      return leftZeroFill(func.call(this, a), count);
-    };
-  }
-  function ordinalizeToken(func, period) {
-    return function (a) {
-      return this.lang().ordinal(func.call(this, a), period);
-    };
+  // This is done to register the method called with moment()
+  // without creating circular dependencies.
+  function setHookCallback (callback) {
+    hookCallback = callback;
   }
 
-  while (ordinalizeTokens.length) {
-    i = ordinalizeTokens.pop();
-    formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i], i);
-  }
-  while (paddedTokens.length) {
-    i = paddedTokens.pop();
-    formatTokenFunctions[i + i] = padToken(formatTokenFunctions[i], 2);
+  function isArray(input) {
+    return Object.prototype.toString.call(input) === '[object Array]';
   }
-  formatTokenFunctions.DDDD = padToken(formatTokenFunctions.DDD, 3);
-
-
-  /************************************
-   Constructors
-   ************************************/
-
-  function Language() {
 
+  function isDate(input) {
+    return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
   }
 
-  // Moment prototype object
-  function Moment(config) {
-    checkOverflow(config);
-    extend(this, config);
+  function map(arr, fn) {
+    var res = [], i;
+    for (i = 0; i < arr.length; ++i) {
+      res.push(fn(arr[i], i));
+    }
+    return res;
   }
 
-  // Duration Constructor
-  function Duration(duration) {
-    var normalizedInput = normalizeObjectUnits(duration),
-      years = normalizedInput.year || 0,
-      months = normalizedInput.month || 0,
-      weeks = normalizedInput.week || 0,
-      days = normalizedInput.day || 0,
-      hours = normalizedInput.hour || 0,
-      minutes = normalizedInput.minute || 0,
-      seconds = normalizedInput.second || 0,
-      milliseconds = normalizedInput.millisecond || 0;
-
-    // representation for dateAddRemove
-    this._milliseconds = +milliseconds +
-      seconds * 1e3 + // 1000
-      minutes * 6e4 + // 1000 * 60
-      hours * 36e5; // 1000 * 60 * 60
-    // Because of dateAddRemove treats 24 hours as different from a
-    // day when working around DST, we need to store them separately
-    this._days = +days +
-      weeks * 7;
-    // It is impossible translate months into days without knowing
-    // which months you are are talking about, so we have to store
-    // it separately.
-    this._months = +months +
-      years * 12;
-
-    this._data = {};
-
-    this._bubble();
+  function hasOwnProp(a, b) {
+    return Object.prototype.hasOwnProperty.call(a, b);
   }
 
-  /************************************
-   Helpers
-   ************************************/
-
-
   function extend(a, b) {
     for (var i in b) {
-      if (b.hasOwnProperty(i)) {
+      if (hasOwnProp(b, i)) {
         a[i] = b[i];
       }
     }
 
-    if (b.hasOwnProperty("toString")) {
+    if (hasOwnProp(b, 'toString')) {
       a.toString = b.toString;
     }
 
-    if (b.hasOwnProperty("valueOf")) {
+    if (hasOwnProp(b, 'valueOf')) {
       a.valueOf = b.valueOf;
     }
 
     return a;
   }
 
-  function cloneMoment(m) {
-    var result = {}, i;
-    for (i in m) {
-      if (m.hasOwnProperty(i) && momentProperties.hasOwnProperty(i)) {
-        result[i] = m[i];
-      }
-    }
+  function create_utc__createUTC (input, format, locale, strict) {
+    return createLocalOrUTC(input, format, locale, strict, true).utc();
+  }
 
-    return result;
+  function defaultParsingFlags() {
+    // We need to deep clone this object.
+    return {
+      empty           : false,
+      unusedTokens    : [],
+      unusedInput     : [],
+      overflow        : -2,
+      charsLeftOver   : 0,
+      nullInput       : false,
+      invalidMonth    : null,
+      invalidFormat   : false,
+      userInvalidated : false,
+      iso             : false
+    };
   }
 
-  function absRound(number) {
-    if (number < 0) {
-      return Math.ceil(number);
-    } else {
-      return Math.floor(number);
+  function getParsingFlags(m) {
+    if (m._pf == null) {
+      m._pf = defaultParsingFlags();
     }
+    return m._pf;
   }
 
-  // left zero fill a number
-  // see http://jsperf.com/left-zero-filling for performance comparison
-  function leftZeroFill(number, targetLength, forceSign) {
-    var output = '' + Math.abs(number),
-      sign = number >= 0;
+  function valid__isValid(m) {
+    if (m._isValid == null) {
+      var flags = getParsingFlags(m);
+      m._isValid = !isNaN(m._d.getTime()) &&
+        flags.overflow < 0 &&
+        !flags.empty &&
+        !flags.invalidMonth &&
+        !flags.invalidWeekday &&
+        !flags.nullInput &&
+        !flags.invalidFormat &&
+        !flags.userInvalidated;
 
-    while (output.length < targetLength) {
-      output = '0' + output;
+      if (m._strict) {
+        m._isValid = m._isValid &&
+          flags.charsLeftOver === 0 &&
+          flags.unusedTokens.length === 0 &&
+          flags.bigHour === undefined;
+      }
     }
-    return (sign ? (forceSign ? '+' : '') : '-') + output;
+    return m._isValid;
   }
 
-  // helper function for _.addTime and _.subtractTime
-  function addOrSubtractDurationFromMoment(mom, duration, isAdding, ignoreUpdateOffset) {
-    var milliseconds = duration._milliseconds,
-      days = duration._days,
-      months = duration._months,
-      minutes,
-      hours;
+  function valid__createInvalid (flags) {
+    var m = create_utc__createUTC(NaN);
+    if (flags != null) {
+      extend(getParsingFlags(m), flags);
+    }
+    else {
+      getParsingFlags(m).userInvalidated = true;
+    }
 
-    if (milliseconds) {
-      mom._d.setTime(+mom._d + milliseconds * isAdding);
+    return m;
+  }
+
+  var momentProperties = utils_hooks__hooks.momentProperties = [];
+
+  function copyConfig(to, from) {
+    var i, prop, val;
+
+    if (typeof from._isAMomentObject !== 'undefined') {
+      to._isAMomentObject = from._isAMomentObject;
     }
-    // store the minutes and hours so we can restore them
-    if (days || months) {
-      minutes = mom.minute();
-      hours = mom.hour();
+    if (typeof from._i !== 'undefined') {
+      to._i = from._i;
     }
-    if (days) {
-      mom.date(mom.date() + days * isAdding);
+    if (typeof from._f !== 'undefined') {
+      to._f = from._f;
     }
-    if (months) {
-      mom.month(mom.month() + months * isAdding);
+    if (typeof from._l !== 'undefined') {
+      to._l = from._l;
+    }
+    if (typeof from._strict !== 'undefined') {
+      to._strict = from._strict;
+    }
+    if (typeof from._tzm !== 'undefined') {
+      to._tzm = from._tzm;
+    }
+    if (typeof from._isUTC !== 'undefined') {
+      to._isUTC = from._isUTC;
     }
-    if (milliseconds && !ignoreUpdateOffset) {
-      moment.updateOffset(mom);
+    if (typeof from._offset !== 'undefined') {
+      to._offset = from._offset;
+    }
+    if (typeof from._pf !== 'undefined') {
+      to._pf = getParsingFlags(from);
+    }
+    if (typeof from._locale !== 'undefined') {
+      to._locale = from._locale;
+    }
+
+    if (momentProperties.length > 0) {
+      for (i in momentProperties) {
+        prop = momentProperties[i];
+        val = from[prop];
+        if (typeof val !== 'undefined') {
+          to[prop] = val;
+        }
+      }
     }
-    // restore the minutes and hours after possibly changing dst
-    if (days || months) {
-      mom.minute(minutes);
-      mom.hour(hours);
+
+    return to;
+  }
+
+  var updateInProgress = false;
+
+  // Moment prototype object
+  function Moment(config) {
+    copyConfig(this, config);
+    this._d = new Date(config._d != null ? config._d.getTime() : NaN);
+    // Prevent infinite loop in case updateOffset creates new moment
+    // objects.
+    if (updateInProgress === false) {
+      updateInProgress = true;
+      utils_hooks__hooks.updateOffset(this);
+      updateInProgress = false;
     }
   }
 
-  // check if is an array
-  function isArray(input) {
-    return Object.prototype.toString.call(input) === '[object Array]';
+  function isMoment (obj) {
+    return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
   }
 
-  function isDate(input) {
-    return  Object.prototype.toString.call(input) === '[object Date]' ||
-      input instanceof Date;
+  function absFloor (number) {
+    if (number < 0) {
+      return Math.ceil(number);
+    } else {
+      return Math.floor(number);
+    }
+  }
+
+  function toInt(argumentForCoercion) {
+    var coercedNumber = +argumentForCoercion,
+      value = 0;
+
+    if (coercedNumber !== 0 && isFinite(coercedNumber)) {
+      value = absFloor(coercedNumber);
+    }
+
+    return value;
   }
 
-  // compare two arrays, return the number of differences
   function compareArrays(array1, array2, dontConvert) {
     var len = Math.min(array1.length, array2.length),
       lengthDiff = Math.abs(array1.length - array2.length),
@@ -475,417 +222,234 @@
     return diffs + lengthDiff;
   }
 
-  function normalizeUnits(units) {
-    if (units) {
-      var lowered = units.toLowerCase().replace(/(.)s$/, '$1');
-      units = unitAliases[units] || camelFunctions[lowered] || lowered;
-    }
-    return units;
+  function Locale() {
   }
 
-  function normalizeObjectUnits(inputObject) {
-    var normalizedInput = {},
-      normalizedProp,
-      prop;
-
-    for (prop in inputObject) {
-      if (inputObject.hasOwnProperty(prop)) {
-        normalizedProp = normalizeUnits(prop);
-        if (normalizedProp) {
-          normalizedInput[normalizedProp] = inputObject[prop];
-        }
-      }
-    }
+  var locales = {};
+  var globalLocale;
 
-    return normalizedInput;
+  function normalizeLocale(key) {
+    return key ? key.toLowerCase().replace('_', '-') : key;
   }
 
-  function makeList(field) {
-    var count, setter;
-
-    if (field.indexOf('week') === 0) {
-      count = 7;
-      setter = 'day';
-    }
-    else if (field.indexOf('month') === 0) {
-      count = 12;
-      setter = 'month';
-    }
-    else {
-      return;
-    }
-
-    moment[field] = function (format, index) {
-      var i, getter,
-        method = moment.fn._lang[field],
-        results = [];
+  // pick the locale from the array
+  // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
+  // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
+  function chooseLocale(names) {
+    var i = 0, j, next, locale, split;
 
-      if (typeof format === 'number') {
-        index = format;
-        format = undefined;
+    while (i < names.length) {
+      split = normalizeLocale(names[i]).split('-');
+      j = split.length;
+      next = normalizeLocale(names[i + 1]);
+      next = next ? next.split('-') : null;
+      while (j > 0) {
+        locale = loadLocale(split.slice(0, j).join('-'));
+        if (locale) {
+          return locale;
+        }
+        if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
+          //the next array item is better than a shallower substring of this one
+          break;
+        }
+        j--;
       }
+      i++;
+    }
+    return null;
+  }
 
-      getter = function (i) {
-        var m = moment().utc().set(setter, i);
-        return method.call(moment.fn._lang, m, format || '');
-      };
+  function loadLocale(name) {
+    var oldLocale = null;
+    // TODO: Find a better way to register and load all the locales in Node
+    if (!locales[name] && typeof module !== 'undefined' &&
+      module && module.exports) {
+      try {
+        oldLocale = globalLocale._abbr;
+        require('./locale/' + name);
+        // because defineLocale currently also sets the global locale, we
+        // want to undo that for lazy loaded locales
+        locale_locales__getSetGlobalLocale(oldLocale);
+      } catch (e) { }
+    }
+    return locales[name];
+  }
 
-      if (index != null) {
-        return getter(index);
+  // This function will load locale and then set the global locale.  If
+  // no arguments are passed in, it will simply return the current global
+  // locale key.
+  function locale_locales__getSetGlobalLocale (key, values) {
+    var data;
+    if (key) {
+      if (typeof values === 'undefined') {
+        data = locale_locales__getLocale(key);
       }
       else {
-        for (i = 0; i < count; i++) {
-          results.push(getter(i));
-        }
-        return results;
+        data = defineLocale(key, values);
       }
-    };
-  }
-
-  function toInt(argumentForCoercion) {
-    var coercedNumber = +argumentForCoercion,
-      value = 0;
 
-    if (coercedNumber !== 0 && isFinite(coercedNumber)) {
-      if (coercedNumber >= 0) {
-        value = Math.floor(coercedNumber);
-      } else {
-        value = Math.ceil(coercedNumber);
+      if (data) {
+        // moment.duration._locale = moment._locale = data;
+        globalLocale = data;
       }
     }
 
-    return value;
+    return globalLocale._abbr;
   }
 
-  function daysInMonth(year, month) {
-    return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
-  }
+  function defineLocale (name, values) {
+    if (values !== null) {
+      values.abbr = name;
+      locales[name] = locales[name] || new Locale();
+      locales[name].set(values);
 
-  function daysInYear(year) {
-    return isLeapYear(year) ? 366 : 365;
-  }
+      // backwards compat for now: also set the locale
+      locale_locales__getSetGlobalLocale(name);
 
-  function isLeapYear(year) {
-    return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
+      return locales[name];
+    } else {
+      // useful for testing
+      delete locales[name];
+      return null;
+    }
   }
 
-  function checkOverflow(m) {
-    var overflow;
-    if (m._a && m._pf.overflow === -2) {
-      overflow =
-        m._a[MONTH] < 0 || m._a[MONTH] > 11 ? MONTH :
-          m._a[DATE] < 1 || m._a[DATE] > daysInMonth(m._a[YEAR], m._a[MONTH]) ? DATE :
-            m._a[HOUR] < 0 || m._a[HOUR] > 23 ? HOUR :
-              m._a[MINUTE] < 0 || m._a[MINUTE] > 59 ? MINUTE :
-                m._a[SECOND] < 0 || m._a[SECOND] > 59 ? SECOND :
-                  m._a[MILLISECOND] < 0 || m._a[MILLISECOND] > 999 ? MILLISECOND :
-                    -1;
-
-      if (m._pf._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
-        overflow = DATE;
-      }
+  // returns locale data
+  function locale_locales__getLocale (key) {
+    var locale;
 
-      m._pf.overflow = overflow;
+    if (key && key._locale && key._locale._abbr) {
+      key = key._locale._abbr;
     }
-  }
 
-  function isValid(m) {
-    if (m._isValid == null) {
-      m._isValid = !isNaN(m._d.getTime()) &&
-        m._pf.overflow < 0 &&
-        !m._pf.empty &&
-        !m._pf.invalidMonth &&
-        !m._pf.nullInput &&
-        !m._pf.invalidFormat &&
-        !m._pf.userInvalidated;
+    if (!key) {
+      return globalLocale;
+    }
 
-      if (m._strict) {
-        m._isValid = m._isValid &&
-          m._pf.charsLeftOver === 0 &&
-          m._pf.unusedTokens.length === 0;
+    if (!isArray(key)) {
+      //short-circuit everything else
+      locale = loadLocale(key);
+      if (locale) {
+        return locale;
       }
+      key = [key];
     }
-    return m._isValid;
-  }
 
-  function normalizeLanguage(key) {
-    return key ? key.toLowerCase().replace('_', '-') : key;
+    return chooseLocale(key);
   }
 
-  // Return a moment from input, that is local/utc/zone equivalent to model.
-  function makeAs(input, model) {
-    return model._isUTC ? moment(input).zone(model._offset || 0) :
-      moment(input).local();
-  }
+  var aliases = {};
 
-  /************************************
-   Languages
-   ************************************/
+  function addUnitAlias (unit, shorthand) {
+    var lowerCase = unit.toLowerCase();
+    aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
+  }
 
+  function normalizeUnits(units) {
+    return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
+  }
 
-  extend(Language.prototype, {
+  function normalizeObjectUnits(inputObject) {
+    var normalizedInput = {},
+      normalizedProp,
+      prop;
 
-    set : function (config) {
-      var prop, i;
-      for (i in config) {
-        prop = config[i];
-        if (typeof prop === 'function') {
-          this[i] = prop;
-        } else {
-          this['_' + i] = prop;
+    for (prop in inputObject) {
+      if (hasOwnProp(inputObject, prop)) {
+        normalizedProp = normalizeUnits(prop);
+        if (normalizedProp) {
+          normalizedInput[normalizedProp] = inputObject[prop];
         }
       }
-    },
-
-    _months : "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
-    months : function (m) {
-      return this._months[m.month()];
-    },
-
-    _monthsShort : "Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),
-    monthsShort : function (m) {
-      return this._monthsShort[m.month()];
-    },
-
-    monthsParse : function (monthName) {
-      var i, mom, regex;
+    }
 
-      if (!this._monthsParse) {
-        this._monthsParse = [];
-      }
+    return normalizedInput;
+  }
 
-      for (i = 0; i < 12; i++) {
-        // make the regex if we don't have it already
-        if (!this._monthsParse[i]) {
-          mom = moment.utc([2000, i]);
-          regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
-          this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
-        }
-        // test the regex
-        if (this._monthsParse[i].test(monthName)) {
-          return i;
-        }
+  function makeGetSet (unit, keepTime) {
+    return function (value) {
+      if (value != null) {
+        get_set__set(this, unit, value);
+        utils_hooks__hooks.updateOffset(this, keepTime);
+        return this;
+      } else {
+        return get_set__get(this, unit);
       }
-    },
-
-    _weekdays : "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
-    weekdays : function (m) {
-      return this._weekdays[m.day()];
-    },
-
-    _weekdaysShort : "Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),
-    weekdaysShort : function (m) {
-      return this._weekdaysShort[m.day()];
-    },
+    };
+  }
 
-    _weekdaysMin : "Su_Mo_Tu_We_Th_Fr_Sa".split("_"),
-    weekdaysMin : function (m) {
-      return this._weekdaysMin[m.day()];
-    },
+  function get_set__get (mom, unit) {
+    return mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]();
+  }
 
-    weekdaysParse : function (weekdayName) {
-      var i, mom, regex;
+  function get_set__set (mom, unit, value) {
+    return mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
+  }
 
-      if (!this._weekdaysParse) {
-        this._weekdaysParse = [];
-      }
+  // MOMENTS
 
-      for (i = 0; i < 7; i++) {
-        // make the regex if we don't have it already
-        if (!this._weekdaysParse[i]) {
-          mom = moment([2000, 1]).day(i);
-          regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
-          this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
-        }
-        // test the regex
-        if (this._weekdaysParse[i].test(weekdayName)) {
-          return i;
-        }
+  function getSet (units, value) {
+    var unit;
+    if (typeof units === 'object') {
+      for (unit in units) {
+        this.set(unit, units[unit]);
       }
-    },
-
-    _longDateFormat : {
-      LT : "h:mm A",
-      L : "MM/DD/YYYY",
-      LL : "MMMM D YYYY",
-      LLL : "MMMM D YYYY LT",
-      LLLL : "dddd, MMMM D YYYY LT"
-    },
-    longDateFormat : function (key) {
-      var output = this._longDateFormat[key];
-      if (!output && this._longDateFormat[key.toUpperCase()]) {
-        output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) {
-          return val.slice(1);
-        });
-        this._longDateFormat[key] = output;
-      }
-      return output;
-    },
-
-    isPM : function (input) {
-      // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
-      // Using charAt should be more compatible.
-      return ((input + '').toLowerCase().charAt(0) === 'p');
-    },
-
-    _meridiemParse : /[ap]\.?m?\.?/i,
-    meridiem : function (hours, minutes, isLower) {
-      if (hours > 11) {
-        return isLower ? 'pm' : 'PM';
-      } else {
-        return isLower ? 'am' : 'AM';
+    } else {
+      units = normalizeUnits(units);
+      if (typeof this[units] === 'function') {
+        return this[units](value);
       }
-    },
-
-    _calendar : {
-      sameDay : '[Today at] LT',
-      nextDay : '[Tomorrow at] LT',
-      nextWeek : 'dddd [at] LT',
-      lastDay : '[Yesterday at] LT',
-      lastWeek : '[Last] dddd [at] LT',
-      sameElse : 'L'
-    },
-    calendar : function (key, mom) {
-      var output = this._calendar[key];
-      return typeof output === 'function' ? output.apply(mom) : output;
-    },
-
-    _relativeTime : {
-      future : "in %s",
-      past : "%s ago",
-      s : "a few seconds",
-      m : "a minute",
-      mm : "%d minutes",
-      h : "an hour",
-      hh : "%d hours",
-      d : "a day",
-      dd : "%d days",
-      M : "a month",
-      MM : "%d months",
-      y : "a year",
-      yy : "%d years"
-    },
-    relativeTime : function (number, withoutSuffix, string, isFuture) {
-      var output = this._relativeTime[string];
-      return (typeof output === 'function') ?
-        output(number, withoutSuffix, string, isFuture) :
-        output.replace(/%d/i, number);
-    },
-    pastFuture : function (diff, output) {
-      var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
-      return typeof format === 'function' ? format(output) : format.replace(/%s/i, output);
-    },
+    }
+    return this;
+  }
 
-    ordinal : function (number) {
-      return this._ordinal.replace("%d", number);
-    },
-    _ordinal : "%d",
+  function zeroFill(number, targetLength, forceSign) {
+    var absNumber = '' + Math.abs(number),
+      zerosToFill = targetLength - absNumber.length,
+      sign = number >= 0;
+    return (sign ? (forceSign ? '+' : '') : '-') +
+      Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
+  }
 
-    preparse : function (string) {
-      return string;
-    },
+  var formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Q|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
 
-    postformat : function (string) {
-      return string;
-    },
+  var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
 
-    week : function (mom) {
-      return weekOfYear(mom, this._week.dow, this._week.doy).week;
-    },
+  var formatFunctions = {};
 
-    _week : {
-      dow : 0, // Sunday is the first day of the week.
-      doy : 6  // The week that contains Jan 1st is the first week of the year.
-    },
+  var formatTokenFunctions = {};
 
-    _invalidDate: 'Invalid date',
-    invalidDate: function () {
-      return this._invalidDate;
+  // token:    'M'
+  // padded:   ['MM', 2]
+  // ordinal:  'Mo'
+  // callback: function () { this.month() + 1 }
+  function addFormatToken (token, padded, ordinal, callback) {
+    var func = callback;
+    if (typeof callback === 'string') {
+      func = function () {
+        return this[callback]();
+      };
     }
-  });
-
-  // Loads a language definition into the `languages` cache.  The function
-  // takes a key and optionally values.  If not in the browser and no values
-  // are provided, it will load the language file module.  As a convenience,
-  // this function also returns the language values.
-  function loadLang(key, values) {
-    values.abbr = key;
-    if (!languages[key]) {
-      languages[key] = new Language();
+    if (token) {
+      formatTokenFunctions[token] = func;
+    }
+    if (padded) {
+      formatTokenFunctions[padded[0]] = function () {
+        return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
+      };
+    }
+    if (ordinal) {
+      formatTokenFunctions[ordinal] = function () {
+        return this.localeData().ordinal(func.apply(this, arguments), token);
+      };
     }
-    languages[key].set(values);
-    return languages[key];
   }
 
-  // Remove a language from the `languages` cache. Mostly useful in tests.
-  function unloadLang(key) {
-    delete languages[key];
-  }
-
-  // Determines which language definition to use and returns it.
-  //
-  // With no parameters, it will return the global language.  If you
-  // pass in a language key, such as 'en', it will return the
-  // definition for 'en', so long as 'en' has already been loaded using
-  // moment.lang.
-  function getLangDefinition(key) {
-    var i = 0, j, lang, next, split,
-      get = function (k) {
-        if (!languages[k] && hasModule) {
-          try {
-            require('./lang/' + k);
-          } catch (e) { }
-        }
-        return languages[k];
-      };
-
-    if (!key) {
-      return moment.fn._lang;
-    }
-
-    if (!isArray(key)) {
-      //short-circuit everything else
-      lang = get(key);
-      if (lang) {
-        return lang;
-      }
-      key = [key];
-    }
-
-    //pick the language from the array
-    //try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
-    //substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
-    while (i < key.length) {
-      split = normalizeLanguage(key[i]).split('-');
-      j = split.length;
-      next = normalizeLanguage(key[i + 1]);
-      next = next ? next.split('-') : null;
-      while (j > 0) {
-        lang = get(split.slice(0, j).join('-'));
-        if (lang) {
-          return lang;
-        }
-        if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
-          //the next array item is better than a shallower substring of this one
-          break;
-        }
-        j--;
-      }
-      i++;
-    }
-    return moment.fn._lang;
-  }
-
-  /************************************
-   Formatting
-   ************************************/
-
-
-  function removeFormattingTokens(input) {
-    if (input.match(/\[[\s\S]/)) {
-      return input.replace(/^\[|\]$/g, "");
-    }
-    return input.replace(/\\/g, "");
+  function removeFormattingTokens(input) {
+    if (input.match(/\[[\s\S]/)) {
+      return input.replace(/^\[|\]$/g, '');
+    }
+    return input.replace(/\\/g, '');
   }
 
   function makeFormatFunction(format) {
@@ -900,7 +464,7 @@
     }
 
     return function (mom) {
-      var output = "";
+      var output = '';
       for (i = 0; i < length; i++) {
         output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
       }
@@ -910,25 +474,21 @@
 
   // format date using native date object
   function formatMoment(m, format) {
-
     if (!m.isValid()) {
-      return m.lang().invalidDate();
+      return m.localeData().invalidDate();
     }
 
-    format = expandFormat(format, m.lang());
-
-    if (!formatFunctions[format]) {
-      formatFunctions[format] = makeFormatFunction(format);
-    }
+    format = expandFormat(format, m.localeData());
+    formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format);
 
     return formatFunctions[format](m);
   }
 
-  function expandFormat(format, lang) {
+  function expandFormat(format, locale) {
     var i = 5;
 
     function replaceLongDateFormatTokens(input) {
-      return lang.longDateFormat(input) || input;
+      return locale.longDateFormat(input) || input;
     }
 
     localFormattingTokens.lastIndex = 0;
@@ -941,493 +501,343 @@
     return format;
   }
 
+  var match1         = /\d/;            //       0 - 9
+  var match2         = /\d\d/;          //      00 - 99
+  var match3         = /\d{3}/;         //     000 - 999
+  var match4         = /\d{4}/;         //    0000 - 9999
+  var match6         = /[+-]?\d{6}/;    // -999999 - 999999
+  var match1to2      = /\d\d?/;         //       0 - 99
+  var match1to3      = /\d{1,3}/;       //       0 - 999
+  var match1to4      = /\d{1,4}/;       //       0 - 9999
+  var match1to6      = /[+-]?\d{1,6}/;  // -999999 - 999999
 
-  /************************************
-   Parsing
-   ************************************/
-
-
-    // get the regex to find the next token
-  function getParseRegexForToken(token, config) {
-    var a, strict = config._strict;
-    switch (token) {
-      case 'DDDD':
-        return parseTokenThreeDigits;
-      case 'YYYY':
-      case 'GGGG':
-      case 'gggg':
-        return strict ? parseTokenFourDigits : parseTokenOneToFourDigits;
-      case 'Y':
-      case 'G':
-      case 'g':
-        return parseTokenSignedNumber;
-      case 'YYYYYY':
-      case 'YYYYY':
-      case 'GGGGG':
-      case 'ggggg':
-        return strict ? parseTokenSixDigits : parseTokenOneToSixDigits;
-      case 'S':
-        if (strict) { return parseTokenOneDigit; }
-      /* falls through */
-      case 'SS':
-        if (strict) { return parseTokenTwoDigits; }
-      /* falls through */
-      case 'SSS':
-        if (strict) { return parseTokenThreeDigits; }
-      /* falls through */
-      case 'DDD':
-        return parseTokenOneToThreeDigits;
-      case 'MMM':
-      case 'MMMM':
-      case 'dd':
-      case 'ddd':
-      case 'dddd':
-        return parseTokenWord;
-      case 'a':
-      case 'A':
-        return getLangDefinition(config._l)._meridiemParse;
-      case 'X':
-        return parseTokenTimestampMs;
-      case 'Z':
-      case 'ZZ':
-        return parseTokenTimezone;
-      case 'T':
-        return parseTokenT;
-      case 'SSSS':
-        return parseTokenDigits;
-      case 'MM':
-      case 'DD':
-      case 'YY':
-      case 'GG':
-      case 'gg':
-      case 'HH':
-      case 'hh':
-      case 'mm':
-      case 'ss':
-      case 'ww':
-      case 'WW':
-        return strict ? parseTokenTwoDigits : parseTokenOneOrTwoDigits;
-      case 'M':
-      case 'D':
-      case 'd':
-      case 'H':
-      case 'h':
-      case 'm':
-      case 's':
-      case 'w':
-      case 'W':
-      case 'e':
-      case 'E':
-        return parseTokenOneOrTwoDigits;
-      default :
-        a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\', '')), "i"));
-        return a;
-    }
-  }
-
-  function timezoneMinutesFromString(string) {
-    string = string || "";
-    var possibleTzMatches = (string.match(parseTokenTimezone) || []),
-      tzChunk = possibleTzMatches[possibleTzMatches.length - 1] || [],
-      parts = (tzChunk + '').match(parseTimezoneChunker) || ['-', 0, 0],
-      minutes = +(parts[1] * 60) + toInt(parts[2]);
-
-    return parts[0] === '+' ? -minutes : minutes;
-  }
-
-  // function to convert string input to date
-  function addTimeToArrayFromToken(token, input, config) {
-    var a, datePartArray = config._a;
-
-    switch (token) {
-      // MONTH
-      case 'M' : // fall through to MM
-      case 'MM' :
-        if (input != null) {
-          datePartArray[MONTH] = toInt(input) - 1;
-        }
-        break;
-      case 'MMM' : // fall through to MMMM
-      case 'MMMM' :
-        a = getLangDefinition(config._l).monthsParse(input);
-        // if we didn't find a month name, mark the date as invalid.
-        if (a != null) {
-          datePartArray[MONTH] = a;
-        } else {
-          config._pf.invalidMonth = input;
-        }
-        break;
-      // DAY OF MONTH
-      case 'D' : // fall through to DD
-      case 'DD' :
-        if (input != null) {
-          datePartArray[DATE] = toInt(input);
-        }
-        break;
-      // DAY OF YEAR
-      case 'DDD' : // fall through to DDDD
-      case 'DDDD' :
-        if (input != null) {
-          config._dayOfYear = toInt(input);
-        }
-
-        break;
-      // YEAR
-      case 'YY' :
-        datePartArray[YEAR] = toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
-        break;
-      case 'YYYY' :
-      case 'YYYYY' :
-      case 'YYYYYY' :
-        datePartArray[YEAR] = toInt(input);
-        break;
-      // AM / PM
-      case 'a' : // fall through to A
-      case 'A' :
-        config._isPm = getLangDefinition(config._l).isPM(input);
-        break;
-      // 24 HOUR
-      case 'H' : // fall through to hh
-      case 'HH' : // fall through to hh
-      case 'h' : // fall through to hh
-      case 'hh' :
-        datePartArray[HOUR] = toInt(input);
-        break;
-      // MINUTE
-      case 'm' : // fall through to mm
-      case 'mm' :
-        datePartArray[MINUTE] = toInt(input);
-        break;
-      // SECOND
-      case 's' : // fall through to ss
-      case 'ss' :
-        datePartArray[SECOND] = toInt(input);
-        break;
-      // MILLISECOND
-      case 'S' :
-      case 'SS' :
-      case 'SSS' :
-      case 'SSSS' :
-        datePartArray[MILLISECOND] = toInt(('0.' + input) * 1000);
-        break;
-      // UNIX TIMESTAMP WITH MS
-      case 'X':
-        config._d = new Date(parseFloat(input) * 1000);
-        break;
-      // TIMEZONE
-      case 'Z' : // fall through to ZZ
-      case 'ZZ' :
-        config._useUTC = true;
-        config._tzm = timezoneMinutesFromString(input);
-        break;
-      case 'w':
-      case 'ww':
-      case 'W':
-      case 'WW':
-      case 'd':
-      case 'dd':
-      case 'ddd':
-      case 'dddd':
-      case 'e':
-      case 'E':
-        token = token.substr(0, 1);
-      /* falls through */
-      case 'gg':
-      case 'gggg':
-      case 'GG':
-      case 'GGGG':
-      case 'GGGGG':
-        token = token.substr(0, 2);
-        if (input) {
-          config._w = config._w || {};
-          config._w[token] = input;
-        }
-        break;
-    }
-  }
-
-  // convert an array to a date.
-  // the array should mirror the parameters below
-  // note: all values past the year are optional and will default to the lowest possible value.
-  // [year, month, day , hour, minute, second, millisecond]
-  function dateFromConfig(config) {
-    var i, date, input = [], currentDate,
-      yearToUse, fixYear, w, temp, lang, weekday, week;
+  var matchUnsigned  = /\d+/;           //       0 - inf
+  var matchSigned    = /[+-]?\d+/;      //    -inf - inf
 
-    if (config._d) {
-      return;
-    }
+  var matchOffset    = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
 
-    currentDate = currentDateArray(config);
+  var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
 
-    //compute day of the year from weeks and weekdays
-    if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
-      fixYear = function (val) {
-        var int_val = parseInt(val, 10);
-        return val ?
-          (val.length < 3 ? (int_val > 68 ? 1900 + int_val : 2000 + int_val) : int_val) :
-          (config._a[YEAR] == null ? moment().weekYear() : config._a[YEAR]);
-      };
+  // any word (or two) characters or numbers including two/three word month in arabic.
+  var matchWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
 
-      w = config._w;
-      if (w.GG != null || w.W != null || w.E != null) {
-        temp = dayOfYearFromWeeks(fixYear(w.GG), w.W || 1, w.E, 4, 1);
-      }
-      else {
-        lang = getLangDefinition(config._l);
-        weekday = w.d != null ?  parseWeekday(w.d, lang) :
-          (w.e != null ?  parseInt(w.e, 10) + lang._week.dow : 0);
+  var regexes = {};
 
-        week = parseInt(w.w, 10) || 1;
+  function isFunction (sth) {
+    // https://github.com/moment/moment/issues/2325
+    return typeof sth === 'function' &&
+      Object.prototype.toString.call(sth) === '[object Function]';
+  }
 
-        //if we're parsing 'd', then the low day numbers may be next week
-        if (w.d != null && weekday < lang._week.dow) {
-          week++;
-        }
 
-        temp = dayOfYearFromWeeks(fixYear(w.gg), week, weekday, lang._week.doy, lang._week.dow);
-      }
+  function addRegexToken (token, regex, strictRegex) {
+    regexes[token] = isFunction(regex) ? regex : function (isStrict) {
+      return (isStrict && strictRegex) ? strictRegex : regex;
+    };
+  }
 
-      config._a[YEAR] = temp.year;
-      config._dayOfYear = temp.dayOfYear;
+  function getParseRegexForToken (token, config) {
+    if (!hasOwnProp(regexes, token)) {
+      return new RegExp(unescapeFormat(token));
     }
 
-    //if the day of the year is set, figure out what it is
-    if (config._dayOfYear) {
-      yearToUse = config._a[YEAR] == null ? currentDate[YEAR] : config._a[YEAR];
+    return regexes[token](config._strict, config._locale);
+  }
 
-      if (config._dayOfYear > daysInYear(yearToUse)) {
-        config._pf._overflowDayOfYear = true;
-      }
+  // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
+  function unescapeFormat(s) {
+    return s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
+      return p1 || p2 || p3 || p4;
+    }).replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
+  }
 
-      date = makeUTCDate(yearToUse, 0, config._dayOfYear);
-      config._a[MONTH] = date.getUTCMonth();
-      config._a[DATE] = date.getUTCDate();
-    }
+  var tokens = {};
 
-    // Default to current date.
-    // * if no year, month, day of month are given, default to today
-    // * if day of month is given, default month and year
-    // * if month is given, default only year
-    // * if year is given, don't default anything
-    for (i = 0; i < 3 && config._a[i] == null; ++i) {
-      config._a[i] = input[i] = currentDate[i];
+  function addParseToken (token, callback) {
+    var i, func = callback;
+    if (typeof token === 'string') {
+      token = [token];
+    }
+    if (typeof callback === 'number') {
+      func = function (input, array) {
+        array[callback] = toInt(input);
+      };
+    }
+    for (i = 0; i < token.length; i++) {
+      tokens[token[i]] = func;
     }
+  }
 
-    // Zero out whatever was not defaulted, including time
-    for (; i < 7; i++) {
-      config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
+  function addWeekParseToken (token, callback) {
+    addParseToken(token, function (input, array, config, token) {
+      config._w = config._w || {};
+      callback(input, config._w, config, token);
+    });
+  }
+
+  function addTimeToArrayFromToken(token, input, config) {
+    if (input != null && hasOwnProp(tokens, token)) {
+      tokens[token](input, config._a, config, token);
     }
+  }
 
-    // add the offsets to the time to be parsed so that we can have a clean array for checking isValid
-    input[HOUR] += toInt((config._tzm || 0) / 60);
-    input[MINUTE] += toInt((config._tzm || 0) % 60);
+  var YEAR = 0;
+  var MONTH = 1;
+  var DATE = 2;
+  var HOUR = 3;
+  var MINUTE = 4;
+  var SECOND = 5;
+  var MILLISECOND = 6;
 
-    config._d = (config._useUTC ? makeUTCDate : makeDate).apply(null, input);
+  function daysInMonth(year, month) {
+    return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
   }
 
-  function dateFromObject(config) {
-    var normalizedInput;
+  // FORMATTING
 
-    if (config._d) {
-      return;
-    }
+  addFormatToken('M', ['MM', 2], 'Mo', function () {
+    return this.month() + 1;
+  });
+
+  addFormatToken('MMM', 0, 0, function (format) {
+    return this.localeData().monthsShort(this, format);
+  });
 
-    normalizedInput = normalizeObjectUnits(config._i);
-    config._a = [
-      normalizedInput.year,
-      normalizedInput.month,
-      normalizedInput.day,
-      normalizedInput.hour,
-      normalizedInput.minute,
-      normalizedInput.second,
-      normalizedInput.millisecond
-    ];
+  addFormatToken('MMMM', 0, 0, function (format) {
+    return this.localeData().months(this, format);
+  });
 
-    dateFromConfig(config);
-  }
+  // ALIASES
 
-  function currentDateArray(config) {
-    var now = new Date();
-    if (config._useUTC) {
-      return [
-        now.getUTCFullYear(),
-        now.getUTCMonth(),
-        now.getUTCDate()
-      ];
+  addUnitAlias('month', 'M');
+
+  // PARSING
+
+  addRegexToken('M',    match1to2);
+  addRegexToken('MM',   match1to2, match2);
+  addRegexToken('MMM',  matchWord);
+  addRegexToken('MMMM', matchWord);
+
+  addParseToken(['M', 'MM'], function (input, array) {
+    array[MONTH] = toInt(input) - 1;
+  });
+
+  addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
+    var month = config._locale.monthsParse(input, token, config._strict);
+    // if we didn't find a month name, mark the date as invalid.
+    if (month != null) {
+      array[MONTH] = month;
     } else {
-      return [now.getFullYear(), now.getMonth(), now.getDate()];
+      getParsingFlags(config).invalidMonth = input;
     }
-  }
+  });
 
-  // date from string and format string
-  function makeDateFromStringAndFormat(config) {
+  // LOCALES
 
-    config._a = [];
-    config._pf.empty = true;
+  var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
+  function localeMonths (m) {
+    return this._months[m.month()];
+  }
 
-    // This array is used to make a Date, either with `new Date` or `Date.UTC`
-    var lang = getLangDefinition(config._l),
-      string = '' + config._i,
-      i, parsedInput, tokens, token, skipped,
-      stringLength = string.length,
-      totalParsedInputLength = 0;
+  var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
+  function localeMonthsShort (m) {
+    return this._monthsShort[m.month()];
+  }
 
-    tokens = expandFormat(config._f, lang).match(formattingTokens) || [];
+  function localeMonthsParse (monthName, format, strict) {
+    var i, mom, regex;
 
-    for (i = 0; i < tokens.length; i++) {
-      token = tokens[i];
-      parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
-      if (parsedInput) {
-        skipped = string.substr(0, string.indexOf(parsedInput));
-        if (skipped.length > 0) {
-          config._pf.unusedInput.push(skipped);
-        }
-        string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
-        totalParsedInputLength += parsedInput.length;
+    if (!this._monthsParse) {
+      this._monthsParse = [];
+      this._longMonthsParse = [];
+      this._shortMonthsParse = [];
+    }
+
+    for (i = 0; i < 12; i++) {
+      // make the regex if we don't have it already
+      mom = create_utc__createUTC([2000, i]);
+      if (strict && !this._longMonthsParse[i]) {
+        this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
+        this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
       }
-      // don't parse if it's not a known token
-      if (formatTokenFunctions[token]) {
-        if (parsedInput) {
-          config._pf.empty = false;
-        }
-        else {
-          config._pf.unusedTokens.push(token);
-        }
-        addTimeToArrayFromToken(token, parsedInput, config);
+      if (!strict && !this._monthsParse[i]) {
+        regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
+        this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
       }
-      else if (config._strict && !parsedInput) {
-        config._pf.unusedTokens.push(token);
+      // test the regex
+      if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
+        return i;
+      } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
+        return i;
+      } else if (!strict && this._monthsParse[i].test(monthName)) {
+        return i;
       }
     }
+  }
 
-    // add remaining unparsed input length to the string
-    config._pf.charsLeftOver = stringLength - totalParsedInputLength;
-    if (string.length > 0) {
-      config._pf.unusedInput.push(string);
-    }
+  // MOMENTS
 
-    // handle am pm
-    if (config._isPm && config._a[HOUR] < 12) {
-      config._a[HOUR] += 12;
-    }
-    // if is 12 am, change hours to 0
-    if (config._isPm === false && config._a[HOUR] === 12) {
-      config._a[HOUR] = 0;
+  function setMonth (mom, value) {
+    var dayOfMonth;
+
+    // TODO: Move this out of here!
+    if (typeof value === 'string') {
+      value = mom.localeData().monthsParse(value);
+      // TODO: Another silent failure?
+      if (typeof value !== 'number') {
+        return mom;
+      }
     }
 
-    dateFromConfig(config);
-    checkOverflow(config);
+    dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
+    mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
+    return mom;
   }
 
-  function unescapeFormat(s) {
-    return s.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
-      return p1 || p2 || p3 || p4;
-    });
+  function getSetMonth (value) {
+    if (value != null) {
+      setMonth(this, value);
+      utils_hooks__hooks.updateOffset(this, true);
+      return this;
+    } else {
+      return get_set__get(this, 'Month');
+    }
   }
 
-  // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
-  function regexpEscape(s) {
-    return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
+  function getDaysInMonth () {
+    return daysInMonth(this.year(), this.month());
   }
 
-  // date from string and array of format strings
-  function makeDateFromStringAndArray(config) {
-    var tempConfig,
-      bestMoment,
+  function checkOverflow (m) {
+    var overflow;
+    var a = m._a;
 
-      scoreToBeat,
-      i,
-      currentScore;
+    if (a && getParsingFlags(m).overflow === -2) {
+      overflow =
+        a[MONTH]       < 0 || a[MONTH]       > 11  ? MONTH :
+          a[DATE]        < 1 || a[DATE]        > daysInMonth(a[YEAR], a[MONTH]) ? DATE :
+            a[HOUR]        < 0 || a[HOUR]        > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :
+              a[MINUTE]      < 0 || a[MINUTE]      > 59  ? MINUTE :
+                a[SECOND]      < 0 || a[SECOND]      > 59  ? SECOND :
+                  a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :
+                    -1;
 
-    if (config._f.length === 0) {
-      config._pf.invalidFormat = true;
-      config._d = new Date(NaN);
-      return;
+      if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
+        overflow = DATE;
+      }
+
+      getParsingFlags(m).overflow = overflow;
     }
 
-    for (i = 0; i < config._f.length; i++) {
-      currentScore = 0;
-      tempConfig = extend({}, config);
-      tempConfig._pf = defaultParsingFlags();
-      tempConfig._f = config._f[i];
-      makeDateFromStringAndFormat(tempConfig);
+    return m;
+  }
 
-      if (!isValid(tempConfig)) {
-        continue;
-      }
+  function warn(msg) {
+    if (utils_hooks__hooks.suppressDeprecationWarnings === false && typeof console !== 'undefined' && console.warn) {
+      console.warn('Deprecation warning: ' + msg);
+    }
+  }
 
-      // if there is any input that was not parsed add a penalty for that format
-      currentScore += tempConfig._pf.charsLeftOver;
+  function deprecate(msg, fn) {
+    var firstTime = true;
 
-      //or tokens
-      currentScore += tempConfig._pf.unusedTokens.length * 10;
+    return extend(function () {
+      if (firstTime) {
+        warn(msg + '\n' + (new Error()).stack);
+        firstTime = false;
+      }
+      return fn.apply(this, arguments);
+    }, fn);
+  }
 
-      tempConfig._pf.score = currentScore;
+  var deprecations = {};
 
-      if (scoreToBeat == null || currentScore < scoreToBeat) {
-        scoreToBeat = currentScore;
-        bestMoment = tempConfig;
-      }
+  function deprecateSimple(name, msg) {
+    if (!deprecations[name]) {
+      warn(msg);
+      deprecations[name] = true;
     }
-
-    extend(config, bestMoment || tempConfig);
   }
 
+  utils_hooks__hooks.suppressDeprecationWarnings = false;
+
+  var from_string__isoRegex = /^\s*(?:[+-]\d{6}|\d{4})-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/;
+
+  var isoDates = [
+    ['YYYYYY-MM-DD', /[+-]\d{6}-\d{2}-\d{2}/],
+    ['YYYY-MM-DD', /\d{4}-\d{2}-\d{2}/],
+    ['GGGG-[W]WW-E', /\d{4}-W\d{2}-\d/],
+    ['GGGG-[W]WW', /\d{4}-W\d{2}/],
+    ['YYYY-DDD', /\d{4}-\d{3}/]
+  ];
+
+  // iso time formats and regexes
+  var isoTimes = [
+    ['HH:mm:ss.SSSS', /(T| )\d\d:\d\d:\d\d\.\d+/],
+    ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/],
+    ['HH:mm', /(T| )\d\d:\d\d/],
+    ['HH', /(T| )\d\d/]
+  ];
+
+  var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
+
   // date from iso format
-  function makeDateFromString(config) {
+  function configFromISO(config) {
     var i, l,
       string = config._i,
-      match = isoRegex.exec(string);
+      match = from_string__isoRegex.exec(string);
 
     if (match) {
-      config._pf.iso = true;
+      getParsingFlags(config).iso = true;
       for (i = 0, l = isoDates.length; i < l; i++) {
         if (isoDates[i][1].exec(string)) {
-          // match[5] should be "T" or undefined
-          config._f = isoDates[i][0] + (match[6] || " ");
+          config._f = isoDates[i][0];
           break;
         }
       }
       for (i = 0, l = isoTimes.length; i < l; i++) {
         if (isoTimes[i][1].exec(string)) {
-          config._f += isoTimes[i][0];
+          // match[6] should be 'T' or space
+          config._f += (match[6] || ' ') + isoTimes[i][0];
           break;
         }
       }
-      if (string.match(parseTokenTimezone)) {
-        config._f += "Z";
+      if (string.match(matchOffset)) {
+        config._f += 'Z';
       }
-      makeDateFromStringAndFormat(config);
-    }
-    else {
-      config._d = new Date(string);
+      configFromStringAndFormat(config);
+    } else {
+      config._isValid = false;
     }
   }
 
-  function makeDateFromInput(config) {
-    var input = config._i,
-      matched = aspNetJsonRegex.exec(input);
+  // date from iso format or fallback
+  function configFromString(config) {
+    var matched = aspNetJsonRegex.exec(config._i);
 
-    if (input === undefined) {
-      config._d = new Date();
-    } else if (matched) {
+    if (matched !== null) {
       config._d = new Date(+matched[1]);
-    } else if (typeof input === 'string') {
-      makeDateFromString(config);
-    } else if (isArray(input)) {
-      config._a = input.slice(0);
-      dateFromConfig(config);
-    } else if (isDate(input)) {
-      config._d = new Date(+input);
-    } else if (typeof(input) === 'object') {
-      dateFromObject(config);
-    } else {
-      config._d = new Date(input);
+      return;
+    }
+
+    configFromISO(config);
+    if (config._isValid === false) {
+      delete config._isValid;
+      utils_hooks__hooks.createFromInputFallback(config);
     }
   }
 
-  function makeDate(y, m, d, h, M, s, ms) {
+  utils_hooks__hooks.createFromInputFallback = deprecate(
+    'moment construction falls back to js Date. This is ' +
+    'discouraged and will be removed in upcoming major ' +
+    'release. Please refer to ' +
+    'https://github.com/moment/moment/issues/1407 for more info.',
+    function (config) {
+      config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
+    }
+  );
+
+  function createDate (y, m, d, h, M, s, ms) {
     //can't just apply() to create a date:
     //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
     var date = new Date(y, m, d, h, M, s, ms);
@@ -1439,7 +849,7 @@
     return date;
   }
 
-  function makeUTCDate(y) {
+  function createUTCDate (y) {
     var date = new Date(Date.UTC.apply(null, arguments));
     if (y < 1970) {
       date.setUTCFullYear(y);
@@ -1447,66 +857,86 @@
     return date;
   }
 
-  function parseWeekday(input, language) {
-    if (typeof input === 'string') {
-      if (!isNaN(input)) {
-        input = parseInt(input, 10);
-      }
-      else {
-        input = language.weekdaysParse(input);
-        if (typeof input !== 'number') {
-          return null;
-        }
-      }
-    }
-    return input;
-  }
+  addFormatToken(0, ['YY', 2], 0, function () {
+    return this.year() % 100;
+  });
+
+  addFormatToken(0, ['YYYY',   4],       0, 'year');
+  addFormatToken(0, ['YYYYY',  5],       0, 'year');
+  addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
+
+  // ALIASES
+
+  addUnitAlias('year', 'y');
+
+  // PARSING
+
+  addRegexToken('Y',      matchSigned);
+  addRegexToken('YY',     match1to2, match2);
+  addRegexToken('YYYY',   match1to4, match4);
+  addRegexToken('YYYYY',  match1to6, match6);
+  addRegexToken('YYYYYY', match1to6, match6);
+
+  addParseToken(['YYYYY', 'YYYYYY'], YEAR);
+  addParseToken('YYYY', function (input, array) {
+    array[YEAR] = input.length === 2 ? utils_hooks__hooks.parseTwoDigitYear(input) : toInt(input);
+  });
+  addParseToken('YY', function (input, array) {
+    array[YEAR] = utils_hooks__hooks.parseTwoDigitYear(input);
+  });
 
-  /************************************
-   Relative Time
-   ************************************/
+  // HELPERS
 
+  function daysInYear(year) {
+    return isLeapYear(year) ? 366 : 365;
+  }
 
-    // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
-  function substituteTimeAgo(string, number, withoutSuffix, isFuture, lang) {
-    return lang.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
+  function isLeapYear(year) {
+    return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
   }
 
-  function relativeTime(milliseconds, withoutSuffix, lang) {
-    var seconds = round(Math.abs(milliseconds) / 1000),
-      minutes = round(seconds / 60),
-      hours = round(minutes / 60),
-      days = round(hours / 24),
-      years = round(days / 365),
-      args = seconds < 45 && ['s', seconds] ||
-        minutes === 1 && ['m'] ||
-        minutes < 45 && ['mm', minutes] ||
-        hours === 1 && ['h'] ||
-        hours < 22 && ['hh', hours] ||
-        days === 1 && ['d'] ||
-        days <= 25 && ['dd', days] ||
-        days <= 45 && ['M'] ||
-        days < 345 && ['MM', round(days / 30)] ||
-        years === 1 && ['y'] || ['yy', years];
-    args[2] = withoutSuffix;
-    args[3] = milliseconds > 0;
-    args[4] = lang;
-    return substituteTimeAgo.apply({}, args);
+  // HOOKS
+
+  utils_hooks__hooks.parseTwoDigitYear = function (input) {
+    return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
+  };
+
+  // MOMENTS
+
+  var getSetYear = makeGetSet('FullYear', false);
+
+  function getIsLeapYear () {
+    return isLeapYear(this.year());
   }
 
+  addFormatToken('w', ['ww', 2], 'wo', 'week');
+  addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
+
+  // ALIASES
 
-  /************************************
-   Week of Year
-   ************************************/
+  addUnitAlias('week', 'w');
+  addUnitAlias('isoWeek', 'W');
+
+  // PARSING
+
+  addRegexToken('w',  match1to2);
+  addRegexToken('ww', match1to2, match2);
+  addRegexToken('W',  match1to2);
+  addRegexToken('WW', match1to2, match2);
+
+  addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
+    week[token.substr(0, 1)] = toInt(input);
+  });
 
+  // HELPERS
 
-    // firstDayOfWeek       0 = sun, 6 = sat
-    //                      the day of the week that starts the week
-    //                      (usually sunday or monday)
-    // firstDayOfWeekOfYear 0 = sun, 6 = sat
-    //                      the first week is the week that contains the first
-    //                      of this day of the week
-    //                      (eg. ISO weeks use thursday (4))
+  // firstDayOfWeek       0 = sun, 6 = sat
+  //                      the day of the week that starts the week
+  //                      (usually sunday or monday)
+  // firstDayOfWeekOfYear 0 = sun, 6 = sat
+  //                      the first week is the week that contains the first
+  //                      of this day of the week
+  //                      (eg. ISO weeks use thursday (4))
   function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {
     var end = firstDayOfWeekOfYear - firstDayOfWeek,
       daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(),
@@ -1521,6248 +951,2245 @@
       daysToDayOfWeek += 7;
     }
 
-    adjustedMoment = moment(mom).add('d', daysToDayOfWeek);
+    adjustedMoment = local__createLocal(mom).add(daysToDayOfWeek, 'd');
     return {
       week: Math.ceil(adjustedMoment.dayOfYear() / 7),
       year: adjustedMoment.year()
     };
   }
 
-  //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
-  function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
-    var d = makeUTCDate(year, 0, 1).getUTCDay(), daysToAdd, dayOfYear;
+  // LOCALES
 
-    weekday = weekday != null ? weekday : firstDayOfWeek;
-    daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0) - (d < firstDayOfWeek ? 7 : 0);
-    dayOfYear = 7 * (week - 1) + (weekday - firstDayOfWeek) + daysToAdd + 1;
-
-    return {
-      year: dayOfYear > 0 ? year : year - 1,
-      dayOfYear: dayOfYear > 0 ?  dayOfYear : daysInYear(year - 1) + dayOfYear
-    };
+  function localeWeek (mom) {
+    return weekOfYear(mom, this._week.dow, this._week.doy).week;
   }
 
-  /************************************
-   Top Level Functions
-   ************************************/
+  var defaultLocaleWeek = {
+    dow : 0, // Sunday is the first day of the week.
+    doy : 6  // The week that contains Jan 1st is the first week of the year.
+  };
 
-  function makeMoment(config) {
-    var input = config._i,
-      format = config._f;
-
-    if (input === null) {
-      return moment.invalid({nullInput: true});
-    }
-
-    if (typeof input === 'string') {
-      config._i = input = getLangDefinition().preparse(input);
-    }
-
-    if (moment.isMoment(input)) {
-      config = cloneMoment(input);
-
-      config._d = new Date(+input._d);
-    } else if (format) {
-      if (isArray(format)) {
-        makeDateFromStringAndArray(config);
-      } else {
-        makeDateFromStringAndFormat(config);
-      }
-    } else {
-      makeDateFromInput(config);
-    }
-
-    return new Moment(config);
+  function localeFirstDayOfWeek () {
+    return this._week.dow;
   }
 
-  moment = function (input, format, lang, strict) {
-    var c;
+  function localeFirstDayOfYear () {
+    return this._week.doy;
+  }
 
-    if (typeof(lang) === "boolean") {
-      strict = lang;
-      lang = undefined;
-    }
-    // object construction must be done this way.
-    // https://github.com/moment/moment/issues/1423
-    c = {};
-    c._isAMomentObject = true;
-    c._i = input;
-    c._f = format;
-    c._l = lang;
-    c._strict = strict;
-    c._isUTC = false;
-    c._pf = defaultParsingFlags();
+  // MOMENTS
 
-    return makeMoment(c);
-  };
+  function getSetWeek (input) {
+    var week = this.localeData().week(this);
+    return input == null ? week : this.add((input - week) * 7, 'd');
+  }
 
-  // creating with utc
-  moment.utc = function (input, format, lang, strict) {
-    var c;
+  function getSetISOWeek (input) {
+    var week = weekOfYear(this, 1, 4).week;
+    return input == null ? week : this.add((input - week) * 7, 'd');
+  }
 
-    if (typeof(lang) === "boolean") {
-      strict = lang;
-      lang = undefined;
-    }
-    // object construction must be done this way.
-    // https://github.com/moment/moment/issues/1423
-    c = {};
-    c._isAMomentObject = true;
-    c._useUTC = true;
-    c._isUTC = true;
-    c._l = lang;
-    c._i = input;
-    c._f = format;
-    c._strict = strict;
-    c._pf = defaultParsingFlags();
+  addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
 
-    return makeMoment(c).utc();
-  };
+  // ALIASES
 
-  // creating with unix timestamp (in seconds)
-  moment.unix = function (input) {
-    return moment(input * 1000);
-  };
+  addUnitAlias('dayOfYear', 'DDD');
 
-  // duration
-  moment.duration = function (input, key) {
-    var duration = input,
-    // matching against regexp is expensive, do it on demand
-      match = null,
-      sign,
-      ret,
-      parseIso;
+  // PARSING
 
-    if (moment.isDuration(input)) {
-      duration = {
-        ms: input._milliseconds,
-        d: input._days,
-        M: input._months
-      };
-    } else if (typeof input === 'number') {
-      duration = {};
-      if (key) {
-        duration[key] = input;
-      } else {
-        duration.milliseconds = input;
-      }
-    } else if (!!(match = aspNetTimeSpanJsonRegex.exec(input))) {
-      sign = (match[1] === "-") ? -1 : 1;
-      duration = {
-        y: 0,
-        d: toInt(match[DATE]) * sign,
-        h: toInt(match[HOUR]) * sign,
-        m: toInt(match[MINUTE]) * sign,
-        s: toInt(match[SECOND]) * sign,
-        ms: toInt(match[MILLISECOND]) * sign
-      };
-    } else if (!!(match = isoDurationRegex.exec(input))) {
-      sign = (match[1] === "-") ? -1 : 1;
-      parseIso = function (inp) {
-        // We'd normally use ~~inp for this, but unfortunately it also
-        // converts floats to ints.
-        // inp may be undefined, so careful calling replace on it.
-        var res = inp && parseFloat(inp.replace(',', '.'));
-        // apply sign while we're at it
-        return (isNaN(res) ? 0 : res) * sign;
-      };
-      duration = {
-        y: parseIso(match[2]),
-        M: parseIso(match[3]),
-        d: parseIso(match[4]),
-        h: parseIso(match[5]),
-        m: parseIso(match[6]),
-        s: parseIso(match[7]),
-        w: parseIso(match[8])
-      };
-    }
+  addRegexToken('DDD',  match1to3);
+  addRegexToken('DDDD', match3);
+  addParseToken(['DDD', 'DDDD'], function (input, array, config) {
+    config._dayOfYear = toInt(input);
+  });
 
-    ret = new Duration(duration);
+  // HELPERS
 
-    if (moment.isDuration(input) && input.hasOwnProperty('_lang')) {
-      ret._lang = input._lang;
+  //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
+  function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {
+    var week1Jan = 6 + firstDayOfWeek - firstDayOfWeekOfYear, janX = createUTCDate(year, 0, 1 + week1Jan), d = janX.getUTCDay(), dayOfYear;
+    if (d < firstDayOfWeek) {
+      d += 7;
     }
 
-    return ret;
-  };
+    weekday = weekday != null ? 1 * weekday : firstDayOfWeek;
 
-  // version number
-  moment.version = VERSION;
+    dayOfYear = 1 + week1Jan + 7 * (week - 1) - d + weekday;
 
-  // default format
-  moment.defaultFormat = isoFormat;
+    return {
+      year: dayOfYear > 0 ? year : year - 1,
+      dayOfYear: dayOfYear > 0 ?  dayOfYear : daysInYear(year - 1) + dayOfYear
+    };
+  }
 
-  // This function will be called whenever a moment is mutated.
-  // It is intended to keep the offset in sync with the timezone.
-  moment.updateOffset = function () {};
+  // MOMENTS
 
-  // This function will load languages and then set the global language.  If
-  // no arguments are passed in, it will simply return the current global
-  // language key.
-  moment.lang = function (key, values) {
-    var r;
-    if (!key) {
-      return moment.fn._lang._abbr;
-    }
-    if (values) {
-      loadLang(normalizeLanguage(key), values);
-    } else if (values === null) {
-      unloadLang(key);
-      key = 'en';
-    } else if (!languages[key]) {
-      getLangDefinition(key);
-    }
-    r = moment.duration.fn._lang = moment.fn._lang = getLangDefinition(key);
-    return r._abbr;
-  };
+  function getSetDayOfYear (input) {
+    var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
+    return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
+  }
 
-  // returns language data
-  moment.langData = function (key) {
-    if (key && key._lang && key._lang._abbr) {
-      key = key._lang._abbr;
+  // Pick the first defined of two or three arguments.
+  function defaults(a, b, c) {
+    if (a != null) {
+      return a;
     }
-    return getLangDefinition(key);
-  };
-
-  // compare moment object
-  moment.isMoment = function (obj) {
-    return obj instanceof Moment ||
-      (obj != null &&  obj.hasOwnProperty('_isAMomentObject'));
-  };
-
-  // for typechecking Duration objects
-  moment.isDuration = function (obj) {
-    return obj instanceof Duration;
-  };
+    if (b != null) {
+      return b;
+    }
+    return c;
+  }
 
-  for (i = lists.length - 1; i >= 0; --i) {
-    makeList(lists[i]);
+  function currentDateArray(config) {
+    var now = new Date();
+    if (config._useUTC) {
+      return [now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()];
+    }
+    return [now.getFullYear(), now.getMonth(), now.getDate()];
   }
 
-  moment.normalizeUnits = function (units) {
-    return normalizeUnits(units);
-  };
+  // convert an array to a date.
+  // the array should mirror the parameters below
+  // note: all values past the year are optional and will default to the lowest possible value.
+  // [year, month, day , hour, minute, second, millisecond]
+  function configFromArray (config) {
+    var i, date, input = [], currentDate, yearToUse;
 
-  moment.invalid = function (flags) {
-    var m = moment.utc(NaN);
-    if (flags != null) {
-      extend(m._pf, flags);
+    if (config._d) {
+      return;
     }
-    else {
-      m._pf.userInvalidated = true;
+
+    currentDate = currentDateArray(config);
+
+    //compute day of the year from weeks and weekdays
+    if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
+      dayOfYearFromWeekInfo(config);
     }
 
-    return m;
-  };
+    //if the day of the year is set, figure out what it is
+    if (config._dayOfYear) {
+      yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
 
-  moment.parseZone = function (input) {
-    return moment(input).parseZone();
-  };
+      if (config._dayOfYear > daysInYear(yearToUse)) {
+        getParsingFlags(config)._overflowDayOfYear = true;
+      }
 
-  /************************************
-   Moment Prototype
-   ************************************/
+      date = createUTCDate(yearToUse, 0, config._dayOfYear);
+      config._a[MONTH] = date.getUTCMonth();
+      config._a[DATE] = date.getUTCDate();
+    }
 
+    // Default to current date.
+    // * if no year, month, day of month are given, default to today
+    // * if day of month is given, default month and year
+    // * if month is given, default only year
+    // * if year is given, don't default anything
+    for (i = 0; i < 3 && config._a[i] == null; ++i) {
+      config._a[i] = input[i] = currentDate[i];
+    }
 
-  extend(moment.fn = Moment.prototype, {
+    // Zero out whatever was not defaulted, including time
+    for (; i < 7; i++) {
+      config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
+    }
 
-    clone : function () {
-      return moment(this);
-    },
+    // Check for 24:00:00.000
+    if (config._a[HOUR] === 24 &&
+      config._a[MINUTE] === 0 &&
+      config._a[SECOND] === 0 &&
+      config._a[MILLISECOND] === 0) {
+      config._nextDay = true;
+      config._a[HOUR] = 0;
+    }
 
-    valueOf : function () {
-      return +this._d + ((this._offset || 0) * 60000);
-    },
+    config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
+    // Apply timezone offset from input. The actual utcOffset can be changed
+    // with parseZone.
+    if (config._tzm != null) {
+      config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
+    }
 
-    unix : function () {
-      return Math.floor(+this / 1000);
-    },
+    if (config._nextDay) {
+      config._a[HOUR] = 24;
+    }
+  }
 
-    toString : function () {
-      return this.clone().lang('en').format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ");
-    },
+  function dayOfYearFromWeekInfo(config) {
+    var w, weekYear, week, weekday, dow, doy, temp;
+
+    w = config._w;
+    if (w.GG != null || w.W != null || w.E != null) {
+      dow = 1;
+      doy = 4;
+
+      // TODO: We need to take the current isoWeekYear, but that depends on
+      // how we interpret now (local, utc, fixed offset). So create
+      // a now version of current config (take local/utc/offset flags, and
+      // create now).
+      weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(local__createLocal(), 1, 4).year);
+      week = defaults(w.W, 1);
+      weekday = defaults(w.E, 1);
+    } else {
+      dow = config._locale._week.dow;
+      doy = config._locale._week.doy;
 
-    toDate : function () {
-      return this._offset ? new Date(+this) : this._d;
-    },
+      weekYear = defaults(w.gg, config._a[YEAR], weekOfYear(local__createLocal(), dow, doy).year);
+      week = defaults(w.w, 1);
 
-    toISOString : function () {
-      var m = moment(this).utc();
-      if (0 < m.year() && m.year() <= 9999) {
-        return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
+      if (w.d != null) {
+        // weekday -- low day numbers are considered next week
+        weekday = w.d;
+        if (weekday < dow) {
+          ++week;
+        }
+      } else if (w.e != null) {
+        // local weekday -- counting starts from begining of week
+        weekday = w.e + dow;
       } else {
-        return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
-      }
-    },
-
-    toArray : function () {
-      var m = this;
-      return [
-        m.year(),
-        m.month(),
-        m.date(),
-        m.hours(),
-        m.minutes(),
-        m.seconds(),
-        m.milliseconds()
-      ];
-    },
-
-    isValid : function () {
-      return isValid(this);
-    },
-
-    isDSTShifted : function () {
-
-      if (this._a) {
-        return this.isValid() && compareArrays(this._a, (this._isUTC ? moment.utc(this._a) : moment(this._a)).toArray()) > 0;
+        // default to begining of week
+        weekday = dow;
       }
+    }
+    temp = dayOfYearFromWeeks(weekYear, week, weekday, doy, dow);
 
-      return false;
-    },
+    config._a[YEAR] = temp.year;
+    config._dayOfYear = temp.dayOfYear;
+  }
 
-    parsingFlags : function () {
-      return extend({}, this._pf);
-    },
+  utils_hooks__hooks.ISO_8601 = function () {};
 
-    invalidAt: function () {
-      return this._pf.overflow;
-    },
+  // date from string and format string
+  function configFromStringAndFormat(config) {
+    // TODO: Move this to another part of the creation flow to prevent circular deps
+    if (config._f === utils_hooks__hooks.ISO_8601) {
+      configFromISO(config);
+      return;
+    }
 
-    utc : function () {
-      return this.zone(0);
-    },
+    config._a = [];
+    getParsingFlags(config).empty = true;
 
-    local : function () {
-      this.zone(0);
-      this._isUTC = false;
-      return this;
-    },
+    // This array is used to make a Date, either with `new Date` or `Date.UTC`
+    var string = '' + config._i,
+      i, parsedInput, tokens, token, skipped,
+      stringLength = string.length,
+      totalParsedInputLength = 0;
 
-    format : function (inputString) {
-      var output = formatMoment(this, inputString || moment.defaultFormat);
-      return this.lang().postformat(output);
-    },
+    tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
 
-    add : function (input, val) {
-      var dur;
-      // switch args to support add('s', 1) and add(1, 's')
-      if (typeof input === 'string') {
-        dur = moment.duration(+val, input);
-      } else {
-        dur = moment.duration(input, val);
+    for (i = 0; i < tokens.length; i++) {
+      token = tokens[i];
+      parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
+      if (parsedInput) {
+        skipped = string.substr(0, string.indexOf(parsedInput));
+        if (skipped.length > 0) {
+          getParsingFlags(config).unusedInput.push(skipped);
+        }
+        string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
+        totalParsedInputLength += parsedInput.length;
       }
-      addOrSubtractDurationFromMoment(this, dur, 1);
-      return this;
-    },
-
-    subtract : function (input, val) {
-      var dur;
-      // switch args to support subtract('s', 1) and subtract(1, 's')
-      if (typeof input === 'string') {
-        dur = moment.duration(+val, input);
-      } else {
-        dur = moment.duration(input, val);
+      // don't parse if it's not a known token
+      if (formatTokenFunctions[token]) {
+        if (parsedInput) {
+          getParsingFlags(config).empty = false;
+        }
+        else {
+          getParsingFlags(config).unusedTokens.push(token);
+        }
+        addTimeToArrayFromToken(token, parsedInput, config);
       }
-      addOrSubtractDurationFromMoment(this, dur, -1);
-      return this;
-    },
+      else if (config._strict && !parsedInput) {
+        getParsingFlags(config).unusedTokens.push(token);
+      }
+    }
 
-    diff : function (input, units, asFloat) {
-      var that = makeAs(input, this),
-        zoneDiff = (this.zone() - that.zone()) * 6e4,
-        diff, output;
+    // add remaining unparsed input length to the string
+    getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;
+    if (string.length > 0) {
+      getParsingFlags(config).unusedInput.push(string);
+    }
 
-      units = normalizeUnits(units);
+    // clear _12h flag if hour is <= 12
+    if (getParsingFlags(config).bigHour === true &&
+      config._a[HOUR] <= 12 &&
+      config._a[HOUR] > 0) {
+      getParsingFlags(config).bigHour = undefined;
+    }
+    // handle meridiem
+    config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);
 
-      if (units === 'year' || units === 'month') {
-        // average number of days in the months in the given dates
-        diff = (this.daysInMonth() + that.daysInMonth()) * 432e5; // 24 * 60 * 60 * 1000 / 2
-        // difference in months
-        output = ((this.year() - that.year()) * 12) + (this.month() - that.month());
-        // adjust by taking difference in days, average number of days
-        // and dst in the given months.
-        output += ((this - moment(this).startOf('month')) -
-          (that - moment(that).startOf('month'))) / diff;
-        // same as above but with zones, to negate all dst
-        output -= ((this.zone() - moment(this).startOf('month').zone()) -
-          (that.zone() - moment(that).startOf('month').zone())) * 6e4 / diff;
-        if (units === 'year') {
-          output = output / 12;
-        }
-      } else {
-        diff = (this - that);
-        output = units === 'second' ? diff / 1e3 : // 1000
-          units === 'minute' ? diff / 6e4 : // 1000 * 60
-            units === 'hour' ? diff / 36e5 : // 1000 * 60 * 60
-              units === 'day' ? (diff - zoneDiff) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
-                units === 'week' ? (diff - zoneDiff) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
-                  diff;
-      }
-      return asFloat ? output : absRound(output);
-    },
-
-    from : function (time, withoutSuffix) {
-      return moment.duration(this.diff(time)).lang(this.lang()._abbr).humanize(!withoutSuffix);
-    },
-
-    fromNow : function (withoutSuffix) {
-      return this.from(moment(), withoutSuffix);
-    },
-
-    calendar : function () {
-      // We want to compare the start of today, vs this.
-      // Getting start-of-today depends on whether we're zone'd or not.
-      var sod = makeAs(moment(), this).startOf('day'),
-        diff = this.diff(sod, 'days', true),
-        format = diff < -6 ? 'sameElse' :
-          diff < -1 ? 'lastWeek' :
-            diff < 0 ? 'lastDay' :
-              diff < 1 ? 'sameDay' :
-                diff < 2 ? 'nextDay' :
-                  diff < 7 ? 'nextWeek' : 'sameElse';
-      return this.format(this.lang().calendar(format, this));
-    },
-
-    isLeapYear : function () {
-      return isLeapYear(this.year());
-    },
-
-    isDST : function () {
-      return (this.zone() < this.clone().month(0).zone() ||
-        this.zone() < this.clone().month(5).zone());
-    },
-
-    day : function (input) {
-      var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
-      if (input != null) {
-        input = parseWeekday(input, this.lang());
-        return this.add({ d : input - day });
-      } else {
-        return day;
-      }
-    },
-
-    month : function (input) {
-      var utc = this._isUTC ? 'UTC' : '',
-        dayOfMonth;
-
-      if (input != null) {
-        if (typeof input === 'string') {
-          input = this.lang().monthsParse(input);
-          if (typeof input !== 'number') {
-            return this;
-          }
-        }
+    configFromArray(config);
+    checkOverflow(config);
+  }
 
-        dayOfMonth = this.date();
-        this.date(1);
-        this._d['set' + utc + 'Month'](input);
-        this.date(Math.min(dayOfMonth, this.daysInMonth()));
 
-        moment.updateOffset(this);
-        return this;
-      } else {
-        return this._d['get' + utc + 'Month']();
-      }
-    },
+  function meridiemFixWrap (locale, hour, meridiem) {
+    var isPm;
 
-    startOf: function (units) {
-      units = normalizeUnits(units);
-      // the following switch intentionally omits break keywords
-      // to utilize falling through the cases.
-      switch (units) {
-        case 'year':
-          this.month(0);
-        /* falls through */
-        case 'month':
-          this.date(1);
-        /* falls through */
-        case 'week':
-        case 'isoWeek':
-        case 'day':
-          this.hours(0);
-        /* falls through */
-        case 'hour':
-          this.minutes(0);
-        /* falls through */
-        case 'minute':
-          this.seconds(0);
-        /* falls through */
-        case 'second':
-          this.milliseconds(0);
-        /* falls through */
+    if (meridiem == null) {
+      // nothing to do
+      return hour;
+    }
+    if (locale.meridiemHour != null) {
+      return locale.meridiemHour(hour, meridiem);
+    } else if (locale.isPM != null) {
+      // Fallback
+      isPm = locale.isPM(meridiem);
+      if (isPm && hour < 12) {
+        hour += 12;
       }
-
-      // weeks are a special case
-      if (units === 'week') {
-        this.weekday(0);
-      } else if (units === 'isoWeek') {
-        this.isoWeekday(1);
+      if (!isPm && hour === 12) {
+        hour = 0;
       }
+      return hour;
+    } else {
+      // this is not supposed to happen
+      return hour;
+    }
+  }
 
-      return this;
-    },
+  function configFromStringAndArray(config) {
+    var tempConfig,
+      bestMoment,
 
-    endOf: function (units) {
-      units = normalizeUnits(units);
-   

<TRUNCATED>

Mime
View raw message