diff --git a/.prettierignore b/.prettierignore index 512364cf..92128c34 100644 --- a/.prettierignore +++ b/.prettierignore @@ -7,5 +7,4 @@ _locales contrib package.json test/diff_match_patch.js -utils/sugar-custom.js utils/varNameValidator.js diff --git a/utils/sugar-custom.js b/utils/sugar-custom.js index dd8d745d..7307957d 100644 --- a/utils/sugar-custom.js +++ b/utils/sugar-custom.js @@ -6,8 +6,8 @@ * https://sugarjs.com/ * * ---------------------------- */ -(function() { - 'use strict'; +(function () { + "use strict"; /*** * @module Core @@ -20,27 +20,30 @@ var Sugar; // The name of Sugar in the global namespace. - var SUGAR_GLOBAL = 'Sugar'; + var SUGAR_GLOBAL = "Sugar"; // Natives available on initialization. Letting Object go first to ensure its // global is set by the time the rest are checking for chainable Object methods. - var NATIVE_NAMES = 'Object Number String Array Date RegExp Function'; + var NATIVE_NAMES = "Object Number String Array Date RegExp Function"; // Static method flag - var STATIC = 0x1; + var STATIC = 0x1; // Instance method flag var INSTANCE = 0x2; // IE8 has a broken defineProperty but no defineProperties so this saves a try/catch. - var PROPERTY_DESCRIPTOR_SUPPORT = !!(Object.defineProperty && Object.defineProperties); + var PROPERTY_DESCRIPTOR_SUPPORT = !!( + Object.defineProperty && Object.defineProperties + ); // The global context. Rhino uses a different "global" keyword so // do an extra check to be sure that it's actually the global context. - var globalContext = typeof global !== 'undefined' && global.Object === Object ? global : this; + var globalContext = + typeof global !== "undefined" && global.Object === Object ? global : this; // Is the environment node? - var hasExports = typeof module !== 'undefined' && module.exports; + var hasExports = typeof module !== "undefined" && module.exports; // Whether object instance methods can be mapped to the prototype. var allowObjectPrototype = false; @@ -52,11 +55,12 @@ var namespacesByClassString = {}; // Defining properties. - var defineProperty = PROPERTY_DESCRIPTOR_SUPPORT ? Object.defineProperty : definePropertyShim; + var defineProperty = PROPERTY_DESCRIPTOR_SUPPORT + ? Object.defineProperty + : definePropertyShim; // A default chainable class for unknown types. - var DefaultChainable = getNewChainableClass('Chainable'); - + var DefaultChainable = getNewChainableClass("Chainable"); // Global methods @@ -67,8 +71,8 @@ // Reuse already defined Sugar global object. return; } - Sugar = function(arg) { - forEachProperty(Sugar, function(sugarNamespace, name) { + Sugar = function (arg) { + forEachProperty(Sugar, function (sugarNamespace, name) { // Although only the only enumerable properties on the global // object are Sugar namespaces, environments that can't set // non-enumerable properties will step through the utility methods @@ -89,7 +93,7 @@ // Contexts such as QML have a read-only global context. } } - forEachProperty(NATIVE_NAMES.split(' '), function(name) { + forEachProperty(NATIVE_NAMES.split(" "), function (name) { createNamespace(name); }); setGlobalProperties(); @@ -115,9 +119,8 @@ * ***/ function createNamespace(name) { - // Is the current namespace Object? - var isObject = name === 'Object'; + var isObject = name === "Object"; // A Sugar namespace is also a chainable class: Sugar.Array, etc. var sugarNamespace = getNewChainableClass(name, true); @@ -180,19 +183,24 @@ * ***/ var extend = function (opts) { - - var nativeClass = globalContext[name], nativeProto = nativeClass.prototype; - var staticMethods = {}, instanceMethods = {}, methodsByName; + var nativeClass = globalContext[name], + nativeProto = nativeClass.prototype; + var staticMethods = {}, + instanceMethods = {}, + methodsByName; function objectRestricted(name, target) { - return isObject && target === nativeProto && - (!allowObjectPrototype || name === 'get' || name === 'set'); + return ( + isObject && + target === nativeProto && + (!allowObjectPrototype || name === "get" || name === "set") + ); } function arrayOptionExists(field, val) { var arr = opts[field]; if (arr) { - for (var i = 0, el; el = arr[i]; i++) { + for (var i = 0, el; (el = arr[i]); i++) { if (el === val) { return true; } @@ -221,18 +229,22 @@ } function namespaceIsExcepted() { - return arrayOptionExists('except', nativeClass) || - arrayOptionExcludes('namespaces', nativeClass); + return ( + arrayOptionExists("except", nativeClass) || + arrayOptionExcludes("namespaces", nativeClass) + ); } function methodIsExcepted(methodName) { - return arrayOptionExists('except', methodName); + return arrayOptionExists("except", methodName); } function canExtend(methodName, method, target) { - return !objectRestricted(methodName, target) && - !disallowedByFlags(methodName, target, method.flags) && - !methodIsExcepted(methodName); + return ( + !objectRestricted(methodName, target) && + !disallowedByFlags(methodName, target, method.flags) && + !methodIsExcepted(methodName) + ); } opts = opts || {}; @@ -240,26 +252,35 @@ if (namespaceIsExcepted()) { return; - } else if (isObject && typeof opts.objectPrototype === 'boolean') { + } else if (isObject && typeof opts.objectPrototype === "boolean") { // Store "objectPrototype" flag for future reference. allowObjectPrototype = opts.objectPrototype; } - forEachProperty(methodsByName || sugarNamespace, function(method, methodName) { - if (methodsByName) { - // If we have method names passed in an array, - // then we need to flip the key and value here - // and find the method in the Sugar namespace. - methodName = method; - method = sugarNamespace[methodName]; - } - if (hasOwn(method, 'instance') && canExtend(methodName, method, nativeProto)) { - instanceMethods[methodName] = method.instance; - } - if(hasOwn(method, 'static') && canExtend(methodName, method, nativeClass)) { - staticMethods[methodName] = method; - } - }); + forEachProperty( + methodsByName || sugarNamespace, + function (method, methodName) { + if (methodsByName) { + // If we have method names passed in an array, + // then we need to flip the key and value here + // and find the method in the Sugar namespace. + methodName = method; + method = sugarNamespace[methodName]; + } + if ( + hasOwn(method, "instance") && + canExtend(methodName, method, nativeProto) + ) { + instanceMethods[methodName] = method.instance; + } + if ( + hasOwn(method, "static") && + canExtend(methodName, method, nativeClass) + ) { + staticMethods[methodName] = method; + } + }, + ); // Accessing the extend target each time instead of holding a reference as // it may have been overwritten (for example Date by Sinon). Also need to @@ -272,13 +293,13 @@ // all methods in the namespace will be extended // to the native. This includes all future defined // methods, so add a flag here to check later. - setProperty(sugarNamespace, 'active', true); + setProperty(sugarNamespace, "active", true); } return sugarNamespace; }; function defineWithOptionCollect(methodName, instance, args) { - setProperty(sugarNamespace, methodName, function(arg1, arg2, arg3) { + setProperty(sugarNamespace, methodName, function (arg1, arg2, arg3) { var opts = collectDefineOptions(arg1, arg2, arg3); defineMethods(sugarNamespace, opts.methods, instance, args, opts.last); return sugarNamespace; @@ -309,7 +330,7 @@ * @param {string} methodName - Name of a single method to be defined. * @param {Function} methodFn - Function body of a single method to be defined. ***/ - defineWithOptionCollect('defineStatic', STATIC); + defineWithOptionCollect("defineStatic", STATIC); /*** * @method defineInstance(methods) @@ -343,7 +364,7 @@ * @param {string} methodName - Name of a single method to be defined. * @param {Function} methodFn - Function body of a single method to be defined. ***/ - defineWithOptionCollect('defineInstance', INSTANCE); + defineWithOptionCollect("defineInstance", INSTANCE); /*** * @method defineInstanceAndStatic(methods) @@ -367,8 +388,7 @@ * @param {string} methodName - Name of a single method to be defined. * @param {Function} methodFn - Function body of a single method to be defined. ***/ - defineWithOptionCollect('defineInstanceAndStatic', INSTANCE | STATIC); - + defineWithOptionCollect("defineInstanceAndStatic", INSTANCE | STATIC); /*** * @method defineStaticWithArguments(methods) @@ -397,7 +417,7 @@ * @param {string} methodName - Name of a single method to be defined. * @param {Function} methodFn - Function body of a single method to be defined. ***/ - defineWithOptionCollect('defineStaticWithArguments', STATIC, true); + defineWithOptionCollect("defineStaticWithArguments", STATIC, true); /*** * @method defineInstanceWithArguments(methods) @@ -426,7 +446,7 @@ * @param {string} methodName - Name of a single method to be defined. * @param {Function} methodFn - Function body of a single method to be defined. ***/ - defineWithOptionCollect('defineInstanceWithArguments', INSTANCE, true); + defineWithOptionCollect("defineInstanceWithArguments", INSTANCE, true); /*** * @method defineStaticPolyfill(methods) @@ -453,11 +473,15 @@ * @param {string} methodName - Name of a single method to be defined. * @param {Function} methodFn - Function body of a single method to be defined. ***/ - setProperty(sugarNamespace, 'defineStaticPolyfill', function(arg1, arg2, arg3) { - var opts = collectDefineOptions(arg1, arg2, arg3); - extendNative(globalContext[name], opts.methods, true, opts.last); - return sugarNamespace; - }); + setProperty( + sugarNamespace, + "defineStaticPolyfill", + function (arg1, arg2, arg3) { + var opts = collectDefineOptions(arg1, arg2, arg3); + extendNative(globalContext[name], opts.methods, true, opts.last); + return sugarNamespace; + }, + ); /*** * @method defineInstancePolyfill(methods) @@ -486,15 +510,24 @@ * @param {string} methodName - Name of a single method to be defined. * @param {Function} methodFn - Function body of a single method to be defined. ***/ - setProperty(sugarNamespace, 'defineInstancePolyfill', function(arg1, arg2, arg3) { - var opts = collectDefineOptions(arg1, arg2, arg3); - extendNative(globalContext[name].prototype, opts.methods, true, opts.last); - // Map instance polyfills to chainable as well. - forEachProperty(opts.methods, function(fn, methodName) { - defineChainableMethod(sugarNamespace, methodName, fn); - }); - return sugarNamespace; - }); + setProperty( + sugarNamespace, + "defineInstancePolyfill", + function (arg1, arg2, arg3) { + var opts = collectDefineOptions(arg1, arg2, arg3); + extendNative( + globalContext[name].prototype, + opts.methods, + true, + opts.last, + ); + // Map instance polyfills to chainable as well. + forEachProperty(opts.methods, function (fn, methodName) { + defineChainableMethod(sugarNamespace, methodName, fn); + }); + return sugarNamespace; + }, + ); /*** * @method alias(toName, from) @@ -510,40 +543,40 @@ * @param {string} toName - Name for new method. * @param {string|Function} from - Method to alias, or string shortcut. ***/ - setProperty(sugarNamespace, 'alias', function(name, source) { - var method = typeof source === 'string' ? sugarNamespace[source] : source; + setProperty(sugarNamespace, "alias", function (name, source) { + var method = + typeof source === "string" ? sugarNamespace[source] : source; setMethod(sugarNamespace, name, method); return sugarNamespace; }); // Each namespace can extend only itself through its .extend method. - setProperty(sugarNamespace, 'extend', extend); + setProperty(sugarNamespace, "extend", extend); // Cache the class to namespace relationship for later use. namespacesByName[name] = sugarNamespace; - namespacesByClassString['[object ' + name + ']'] = sugarNamespace; + namespacesByClassString["[object " + name + "]"] = sugarNamespace; mapNativeToChainable(name); mapObjectChainablesToNamespace(sugarNamespace); - // Export - return Sugar[name] = sugarNamespace; + return (Sugar[name] = sugarNamespace); } function setGlobalProperties() { - setProperty(Sugar, 'extend', Sugar); - setProperty(Sugar, 'toString', toString); - setProperty(Sugar, 'createNamespace', createNamespace); + setProperty(Sugar, "extend", Sugar); + setProperty(Sugar, "toString", toString); + setProperty(Sugar, "createNamespace", createNamespace); - setProperty(Sugar, 'util', { - 'hasOwn': hasOwn, - 'getOwn': getOwn, - 'setProperty': setProperty, - 'classToString': classToString, - 'defineProperty': defineProperty, - 'forEachProperty': forEachProperty, - 'mapNativeToChainable': mapNativeToChainable + setProperty(Sugar, "util", { + hasOwn: hasOwn, + getOwn: getOwn, + setProperty: setProperty, + classToString: classToString, + defineProperty: defineProperty, + forEachProperty: forEachProperty, + mapNativeToChainable: mapNativeToChainable, }); } @@ -551,12 +584,12 @@ return SUGAR_GLOBAL; } - // Defining Methods function defineMethods(sugarNamespace, methods, type, args, flags) { - forEachProperty(methods, function(method, methodName) { - var instanceMethod, staticMethod = method; + forEachProperty(methods, function (method, methodName) { + var instanceMethod, + staticMethod = method; if (args) { staticMethod = wrapMethodWithArguments(method); } @@ -568,11 +601,11 @@ // make sure that's not the case before creating one. if (type & INSTANCE && !method.instance) { instanceMethod = wrapInstanceMethod(method, args); - setProperty(staticMethod, 'instance', instanceMethod); + setProperty(staticMethod, "instance", instanceMethod); } if (type & STATIC) { - setProperty(staticMethod, 'static', true); + setProperty(staticMethod, "static", true); } setMethod(sugarNamespace, methodName, staticMethod); @@ -587,7 +620,7 @@ function collectDefineOptions(arg1, arg2, arg3) { var methods, last; - if (typeof arg1 === 'string') { + if (typeof arg1 === "string") { methods = {}; methods[arg1] = arg2; last = arg3; @@ -597,12 +630,14 @@ } return { last: last, - methods: methods + methods: methods, }; } function wrapInstanceMethod(fn, args) { - return args ? wrapMethodWithArguments(fn, true) : wrapInstanceMethodFixed(fn); + return args + ? wrapMethodWithArguments(fn, true) + : wrapInstanceMethodFixed(fn); } function wrapMethodWithArguments(fn, instance) { @@ -612,8 +647,10 @@ // a prototype, then "this" will be pushed into the arguments array so start // collecting 1 argument earlier. var startCollect = fn.length - 1 - (instance ? 1 : 0); - return function() { - var args = [], collectedArgs = [], len; + return function () { + var args = [], + collectedArgs = [], + len; if (instance) { args.push(this); } @@ -632,29 +669,29 @@ } function wrapInstanceMethodFixed(fn) { - switch(fn.length) { + switch (fn.length) { // Wrapped instance methods will always be passed the instance // as the first argument, but requiring the argument to be defined // may cause confusion here, so return the same wrapped function regardless. case 0: case 1: - return function() { + return function () { return fn(this); }; case 2: - return function(a) { + return function (a) { return fn(this, a); }; case 3: - return function(a, b) { + return function (a, b) { return fn(this, a, b); }; case 4: - return function(a, b, c) { + return function (a, b, c) { return fn(this, a, b, c); }; case 5: - return function(a, b, c, d) { + return function (a, b, c, d) { return fn(this, a, b, c, d); }; } @@ -663,7 +700,7 @@ // Method helpers function extendNative(target, source, polyfill, override) { - forEachProperty(source, function(method, name) { + forEachProperty(source, function (method, name) { if (polyfill && !override && target[name]) { // Method exists, so bail. return; @@ -679,7 +716,6 @@ } } - // Chainables function getNewChainableClass(name) { @@ -693,17 +729,20 @@ } this.raw = obj; }; - setProperty(fn, 'toString', function() { + setProperty(fn, "toString", function () { return SUGAR_GLOBAL + name; }); - setProperty(fn.prototype, 'valueOf', function() { + setProperty(fn.prototype, "valueOf", function () { return this.raw; }); return fn; } function defineChainableMethod(sugarNamespace, methodName, fn) { - var wrapped = wrapWithChainableResult(fn), existing, collision, dcp; + var wrapped = wrapWithChainableResult(fn), + existing, + collision, + dcp; dcp = DefaultChainable.prototype; existing = dcp[methodName]; @@ -735,15 +774,18 @@ } function mapObjectChainablesToNamespace(sugarNamespace) { - forEachProperty(Sugar.Object && Sugar.Object.prototype, function(val, methodName) { - if (typeof val === 'function') { - setObjectChainableOnNamespace(sugarNamespace, methodName, val); - } - }); + forEachProperty( + Sugar.Object && Sugar.Object.prototype, + function (val, methodName) { + if (typeof val === "function") { + setObjectChainableOnNamespace(sugarNamespace, methodName, val); + } + }, + ); } function mapObjectChainableToAllNamespaces(methodName, fn) { - forEachProperty(namespacesByName, function(sugarNamespace) { + forEachProperty(namespacesByName, function (sugarNamespace) { setObjectChainableOnNamespace(sugarNamespace, methodName, fn); }); } @@ -756,14 +798,15 @@ } function wrapWithChainableResult(fn) { - return function() { + return function () { return new DefaultChainable(fn.apply(this.raw, arguments)); }; } function disambiguateMethod(methodName) { - var fn = function() { - var raw = this.raw, sugarNamespace; + var fn = function () { + var raw = this.raw, + sugarNamespace; if (raw != null) { // Find the Sugar namespace for this unknown. sugarNamespace = namespacesByClassString[classToString(raw)]; @@ -784,13 +827,13 @@ function mapNativeToChainable(name, methodNames) { var sugarNamespace = namespacesByName[name], - nativeProto = globalContext[name].prototype; + nativeProto = globalContext[name].prototype; if (!methodNames && ownPropertyNames) { methodNames = ownPropertyNames(nativeProto); } - forEachProperty(methodNames, function(methodName) { + forEachProperty(methodNames, function (methodName) { if (nativeMethodProhibited(methodName)) { // Sugar chainables have their own constructors as well as "valueOf" // methods, so exclude them here. The __proto__ argument should be trapped @@ -800,7 +843,7 @@ } try { var fn = nativeProto[methodName]; - if (typeof fn !== 'function') { + if (typeof fn !== "function") { // Bail on anything not a function. return; } @@ -814,23 +857,24 @@ } function nativeMethodProhibited(methodName) { - return methodName === 'constructor' || - methodName === 'valueOf' || - methodName === '__proto__'; + return ( + methodName === "constructor" || + methodName === "valueOf" || + methodName === "__proto__" + ); } - // Util // Internal references var ownPropertyNames = Object.getOwnPropertyNames, - internalToString = Object.prototype.toString, - internalHasOwnProperty = Object.prototype.hasOwnProperty; + internalToString = Object.prototype.toString, + internalHasOwnProperty = Object.prototype.hasOwnProperty; // Defining this as a variable here as the ES5 module // overwrites it to patch DONTENUM. var forEachProperty = function (obj, fn) { - for(var key in obj) { + for (var key in obj) { if (!hasOwn(obj, key)) continue; if (fn.call(obj, obj[key], key, obj) === false) break; } @@ -846,7 +890,7 @@ value: value, enumerable: !!enumerable, configurable: true, - writable: true + writable: true, }); } @@ -875,62 +919,67 @@ * @description Internal utility and common methods. ***/ - // For type checking, etc. Excludes object as this is more nuanced. - var NATIVE_TYPES = 'Boolean Number String Date RegExp Function Array Error Set Map'; + var NATIVE_TYPES = + "Boolean Number String Date RegExp Function Array Error Set Map"; // Prefix for private properties - var PRIVATE_PROP_PREFIX = '_sugar_'; + var PRIVATE_PROP_PREFIX = "_sugar_"; // Regex for matching a formatted string var STRING_FORMAT_REG = /([{}])\1|\{([^}]*)\}|(%)%|(%(\w*))/g; // Common chars var HALF_WIDTH_ZERO = 0x30, - FULL_WIDTH_ZERO = 0xff10, - HALF_WIDTH_PERIOD = '.', - FULL_WIDTH_PERIOD = '.', - HALF_WIDTH_COMMA = ',', - OPEN_BRACE = '{', - CLOSE_BRACE = '}'; + FULL_WIDTH_ZERO = 0xff10, + HALF_WIDTH_PERIOD = ".", + FULL_WIDTH_PERIOD = ".", + HALF_WIDTH_COMMA = ",", + OPEN_BRACE = "{", + CLOSE_BRACE = "}"; // Namespace aliases - var sugarObject = Sugar.Object, - sugarArray = Sugar.Array, - sugarDate = Sugar.Date, - sugarString = Sugar.String, - sugarNumber = Sugar.Number, - sugarFunction = Sugar.Function, - sugarRegExp = Sugar.RegExp; + var sugarObject = Sugar.Object, + sugarArray = Sugar.Array, + sugarDate = Sugar.Date, + sugarString = Sugar.String, + sugarNumber = Sugar.Number, + sugarFunction = Sugar.Function, + sugarRegExp = Sugar.RegExp; // Core utility aliases - var hasOwn = Sugar.util.hasOwn, - getOwn = Sugar.util.getOwn, - setProperty = Sugar.util.setProperty, - classToString = Sugar.util.classToString, - defineProperty = Sugar.util.defineProperty, - forEachProperty = Sugar.util.forEachProperty, - mapNativeToChainable = Sugar.util.mapNativeToChainable; + var hasOwn = Sugar.util.hasOwn, + getOwn = Sugar.util.getOwn, + setProperty = Sugar.util.setProperty, + classToString = Sugar.util.classToString, + defineProperty = Sugar.util.defineProperty, + forEachProperty = Sugar.util.forEachProperty, + mapNativeToChainable = Sugar.util.mapNativeToChainable; // Class checks var isSerializable, - isBoolean, isNumber, isString, - isDate, isRegExp, isFunction, - isArray, isSet, isMap, isError; + isBoolean, + isNumber, + isString, + isDate, + isRegExp, + isFunction, + isArray, + isSet, + isMap, + isError; function buildClassChecks() { - var knownTypes = {}; function addCoreTypes() { - var names = spaceSplit(NATIVE_TYPES); isBoolean = buildPrimitiveClassCheck(names[0]); - isNumber = buildPrimitiveClassCheck(names[1]); - isString = buildPrimitiveClassCheck(names[2]); + isNumber = buildPrimitiveClassCheck(names[1]); + isString = buildPrimitiveClassCheck(names[2]); - isDate = buildClassCheck(names[3]); + isDate = buildClassCheck(names[3]); isRegExp = buildClassCheck(names[4]); // Wanted to enhance performance here by using simply "typeof" @@ -944,34 +993,33 @@ // https://bugzilla.mozilla.org/show_bug.cgi?id=268945 (won't fix) isFunction = buildClassCheck(names[5]); - isArray = Array.isArray || buildClassCheck(names[6]); isError = buildClassCheck(names[7]); - isSet = buildClassCheck(names[8], typeof Set !== 'undefined' && Set); - isMap = buildClassCheck(names[9], typeof Map !== 'undefined' && Map); + isSet = buildClassCheck(names[8], typeof Set !== "undefined" && Set); + isMap = buildClassCheck(names[9], typeof Map !== "undefined" && Map); // Add core types as known so that they can be checked by value below, // notably excluding Functions and adding Arguments and Error. - addKnownType('Arguments'); + addKnownType("Arguments"); addKnownType(names[0]); addKnownType(names[1]); addKnownType(names[2]); addKnownType(names[3]); addKnownType(names[4]); addKnownType(names[6]); - } function addArrayTypes() { - var types = 'Int8 Uint8 Uint8Clamped Int16 Uint16 Int32 Uint32 Float32 Float64'; - forEach(spaceSplit(types), function(str) { - addKnownType(str + 'Array'); + var types = + "Int8 Uint8 Uint8Clamped Int16 Uint16 Int32 Uint32 Float32 Float64"; + forEach(spaceSplit(types), function (str) { + addKnownType(str + "Array"); }); } function addKnownType(className) { - var str = '[object '+ className +']'; + var str = "[object " + className + "]"; knownTypes[str] = true; } @@ -981,7 +1029,7 @@ function buildClassCheck(className, globalObject) { // istanbul ignore if - if (globalObject && isClass(new globalObject, 'Object')) { + if (globalObject && isClass(new globalObject(), "Object")) { return getConstructorClassCheck(globalObject); } else { return getToStringClassCheck(className); @@ -994,13 +1042,13 @@ // istanbul ignore next function getConstructorClassCheck(obj) { var ctorStr = String(obj); - return function(obj) { + return function (obj) { return String(obj.constructor) === ctorStr; }; } function getToStringClassCheck(className) { - return function(obj, str) { + return function (obj, str) { // perf: Returning up front on instanceof appears to be slower. return isClass(obj, className, str); }; @@ -1008,16 +1056,16 @@ function buildPrimitiveClassCheck(className) { var type = className.toLowerCase(); - return function(obj) { + return function (obj) { var t = typeof obj; - return t === type || t === 'object' && isClass(obj, className); + return t === type || (t === "object" && isClass(obj, className)); }; } addCoreTypes(); addArrayTypes(); - isSerializable = function(obj, className) { + isSerializable = function (obj, className) { // Only known objects can be serialized. This notably excludes functions, // host objects, Symbols (which are matched by reference), and instances // of classes. The latter can arguably be matched by value, but @@ -1026,32 +1074,31 @@ className = className || classToString(obj); return isKnownType(className) || isPlainObject(obj, className); }; - } function isClass(obj, className, str) { if (!str) { str = classToString(obj); } - return str === '[object '+ className +']'; + return str === "[object " + className + "]"; } // Wrapping the core's "define" methods to // save a few bytes in the minified script. function wrapNamespace(method) { - return function(sugarNamespace, arg1, arg2) { + return function (sugarNamespace, arg1, arg2) { sugarNamespace[method](arg1, arg2); }; } // Method define aliases - var alias = wrapNamespace('alias'), - defineStatic = wrapNamespace('defineStatic'), - defineInstance = wrapNamespace('defineInstance'), - defineStaticPolyfill = wrapNamespace('defineStaticPolyfill'), - defineInstancePolyfill = wrapNamespace('defineInstancePolyfill'), - defineInstanceAndStatic = wrapNamespace('defineInstanceAndStatic'), - defineInstanceWithArguments = wrapNamespace('defineInstanceWithArguments'); + var alias = wrapNamespace("alias"), + defineStatic = wrapNamespace("defineStatic"), + defineInstance = wrapNamespace("defineInstance"), + defineStaticPolyfill = wrapNamespace("defineStaticPolyfill"), + defineInstancePolyfill = wrapNamespace("defineInstancePolyfill"), + defineInstanceAndStatic = wrapNamespace("defineInstanceAndStatic"), + defineInstanceWithArguments = wrapNamespace("defineInstanceWithArguments"); function defineInstanceSimilar(sugarNamespace, set, fn, flags) { defineInstance(sugarNamespace, collectSimilarMethods(set, fn), flags); @@ -1062,7 +1109,7 @@ if (isString(set)) { set = spaceSplit(set); } - forEach(set, function(el, i) { + forEach(set, function (el, i) { fn(methods, el, i); }); return methods; @@ -1087,7 +1134,7 @@ options = {}; options[arg1] = arg2; } - forEachProperty(options, function(val, name) { + forEachProperty(options, function (val, name) { if (val === null) { val = defaults[name]; } @@ -1095,8 +1142,8 @@ }); } - defineAccessor(namespace, 'getOption', getOption); - defineAccessor(namespace, 'setOption', setOption); + defineAccessor(namespace, "getOption", getOption); + defineAccessor(namespace, "setOption", setOption); return getOption; } @@ -1110,7 +1157,7 @@ function privatePropertyAccessor(key) { var privateKey = PRIVATE_PROP_PREFIX + key; - return function(obj, val) { + return function (obj, val) { if (arguments.length > 1) { setProperty(obj, privateKey, val); return obj; @@ -1120,7 +1167,7 @@ } function setChainableConstructor(sugarNamespace, createFn) { - sugarNamespace.prototype.constructor = function() { + sugarNamespace.prototype.constructor = function () { return createFn.apply(this, arguments); }; } @@ -1136,19 +1183,21 @@ } function isObjectType(obj, type) { - return !!obj && (type || typeof obj) === 'object'; + return !!obj && (type || typeof obj) === "object"; } function isPlainObject(obj, className) { - return isObjectType(obj) && - isClass(obj, 'Object', className) && - hasValidPlainObjectPrototype(obj) && - hasOwnEnumeratedProperties(obj); + return ( + isObjectType(obj) && + isClass(obj, "Object", className) && + hasValidPlainObjectPrototype(obj) && + hasOwnEnumeratedProperties(obj) + ); } function hasValidPlainObjectPrototype(obj) { - var hasToString = 'toString' in obj; - var hasConstructor = 'constructor' in obj; + var hasToString = "toString" in obj; + var hasConstructor = "constructor" in obj; // An object created with Object.create(null) has no methods in the // prototype chain, so check if any are missing. The additional hasToString // check is for false positives on some host objects in old IE which have @@ -1157,9 +1206,12 @@ // robust way of ensuring this if the global has been hijacked). Note that // accessing the constructor directly (without "in" or "hasOwnProperty") // will throw a permissions error in IE8 on cross-domain windows. - return (!hasConstructor && !hasToString) || - (hasConstructor && !hasOwn(obj, 'constructor') && - hasOwn(obj.constructor.prototype, 'isPrototypeOf')); + return ( + (!hasConstructor && !hasToString) || + (hasConstructor && + !hasOwn(obj, "constructor") && + hasOwn(obj.constructor.prototype, "isPrototypeOf")) + ); } function hasOwnEnumeratedProperties(obj) { @@ -1182,18 +1234,19 @@ } function simpleMerge(target, source) { - forEachProperty(source, function(val, key) { + forEachProperty(source, function (val, key) { target[key] = val; }); return target; } function isArrayIndex(n) { - return n >>> 0 == n && n != 0xFFFFFFFF; + return n >>> 0 == n && n != 0xffffffff; } function iterateOverSparseArray(arr, fn, fromIndex, loop) { - var indexes = getSparseArrayIndexes(arr, fromIndex, loop), index; + var indexes = getSparseArrayIndexes(arr, fromIndex, loop), + index; for (var i = 0, len = indexes.length; i < len; i++) { index = indexes[i]; fn.call(arr, arr[index], index, arr); @@ -1205,13 +1258,17 @@ // If they are not, however, the wrapping function will be deoptimized, so // isolate here (also to share between es5 and array modules). function getSparseArrayIndexes(arr, fromIndex, loop, fromRight) { - var indexes = [], i; + var indexes = [], + i; for (i in arr) { - if (isArrayIndex(i) && (loop || (fromRight ? i <= fromIndex : i >= fromIndex))) { + if ( + isArrayIndex(i) && + (loop || (fromRight ? i <= fromIndex : i >= fromIndex)) + ) { indexes.push(+i); } } - indexes.sort(function(a, b) { + indexes.sort(function (a, b) { var aLoop = a > fromIndex; var bLoop = b > fromIndex; // This block cannot be reached unless ES5 methods are being shimmed. @@ -1225,7 +1282,7 @@ } function spaceSplit(str) { - return str.split(' '); + return str.split(" "); } function commaSplit(str) { @@ -1264,10 +1321,12 @@ } // istanbul ignore next - var trunc = Math.trunc || function(n) { - if (n === 0 || !isFinite(n)) return n; - return n < 0 ? ceil(n) : floor(n); - }; + var trunc = + Math.trunc || + function (n) { + if (n === 0 || !isFinite(n)) return n; + return n < 0 ? ceil(n) : floor(n); + }; function withPrecision(val, precision, fn) { var multiplier = pow(10, abs(precision || 0)); @@ -1278,22 +1337,30 @@ function padNumber(num, place, sign, base, replacement) { var str = abs(num).toString(base || 10); - str = repeatString(replacement || '0', place - str.replace(/\.\d+/, '').length) + str; + str = + repeatString( + replacement || "0", + place - str.replace(/\.\d+/, "").length, + ) + str; if (sign || num < 0) { - str = (num < 0 ? '-' : '+') + str; + str = (num < 0 ? "-" : "+") + str; } return str; } function getOrdinalSuffix(num) { if (num >= 11 && num <= 13) { - return 'th'; + return "th"; } else { - switch(num % 10) { - case 1: return 'st'; - case 2: return 'nd'; - case 3: return 'rd'; - default: return 'th'; + switch (num % 10) { + case 1: + return "st"; + case 2: + return "nd"; + case 3: + return "rd"; + default: + return "th"; } } } @@ -1302,14 +1369,17 @@ var fullWidthNumberReg, fullWidthNumberMap, fullWidthNumbers; function buildFullWidthNumber() { - var fwp = FULL_WIDTH_PERIOD, hwp = HALF_WIDTH_PERIOD, hwc = HALF_WIDTH_COMMA, fwn = ''; + var fwp = FULL_WIDTH_PERIOD, + hwp = HALF_WIDTH_PERIOD, + hwc = HALF_WIDTH_COMMA, + fwn = ""; fullWidthNumberMap = {}; for (var i = 0, digit; i <= 9; i++) { digit = chr(i + FULL_WIDTH_ZERO); fwn += digit; fullWidthNumberMap[digit] = chr(i + HALF_WIDTH_ZERO); } - fullWidthNumberMap[hwc] = ''; + fullWidthNumberMap[hwc] = ""; fullWidthNumberMap[fwp] = hwp; // Mapping this to itself to capture it easily // in stringToNumber to detect decimals later. @@ -1319,13 +1389,13 @@ } // Math aliases - var abs = Math.abs, - pow = Math.pow, - min = Math.min, - max = Math.max, - ceil = Math.ceil, - floor = Math.floor, - round = Math.round; + var abs = Math.abs, + pow = Math.pow, + min = Math.min, + max = Math.max, + ceil = Math.ceil, + floor = Math.floor, + round = Math.round; var chr = String.fromCharCode; @@ -1334,13 +1404,13 @@ } function repeatString(str, num) { - var result = ''; + var result = ""; str = str.toString(); while (num > 0) { if (num & 1) { result += str; } - if (num >>= 1) { + if ((num >>= 1)) { str += str; } } @@ -1352,7 +1422,6 @@ } function createFormatMatcher(bracketMatcher, percentMatcher, precheck) { - var reg = STRING_FORMAT_REG; var compileMemoized = memoizeFunction(compile); @@ -1374,7 +1443,7 @@ } if (get) { assertPassesPrecheck(precheck, bKey, pKey); - fn = function(obj, opt) { + fn = function (obj, opt) { return get(obj, token, opt); }; } @@ -1386,34 +1455,38 @@ var sub = str.slice(start, end); assertNoUnmatched(sub, OPEN_BRACE); assertNoUnmatched(sub, CLOSE_BRACE); - format.push(function() { + format.push(function () { return sub; }); } } function getLiteral(str) { - return function() { + return function () { return str; }; } function assertPassesPrecheck(precheck, bt, pt) { if (precheck && !precheck(bt, pt)) { - throw new TypeError('Invalid token '+ (bt || pt) +' in format string'); + throw new TypeError( + "Invalid token " + (bt || pt) + " in format string", + ); } } function assertNoUnmatched(str, chr) { if (str.indexOf(chr) !== -1) { - throw new TypeError('Unmatched '+ chr +' in format string'); + throw new TypeError("Unmatched " + chr + " in format string"); } } function compile(str) { - var format = [], lastIndex = 0, match; + var format = [], + lastIndex = 0, + match; reg.lastIndex = 0; - while(match = reg.exec(str)) { + while ((match = reg.exec(str))) { getSubstring(format, str, lastIndex, match.index); getToken(format, match); lastIndex = reg.lastIndex; @@ -1422,8 +1495,9 @@ return format; } - return function(str, obj, opt) { - var format = compileMemoized(str), result = ''; + return function (str, obj, opt) { + var format = compileMemoized(str), + result = ""; for (var i = 0; i < format.length; i++) { result += format[i](obj, opt); } @@ -1432,18 +1506,18 @@ } function allCharsReg(src) { - return RegExp('[' + src + ']', 'g'); + return RegExp("[" + src + "]", "g"); } function escapeRegExp(str) { if (!isString(str)) str = String(str); - return str.replace(/([\\\/\'*+?|()\[\]{}.^$-])/g,'\\$1'); + return str.replace(/([\\\/\'*+?|()\[\]{}.^$-])/g, "\\$1"); } - var _utc = privatePropertyAccessor('utc'); + var _utc = privatePropertyAccessor("utc"); function callDateGet(d, method) { - return d['get' + (_utc(d) ? 'UTC' : '') + method](); + return d["get" + (_utc(d) ? "UTC" : "") + method](); } function callDateSet(d, method, value, safe) { @@ -1457,7 +1531,7 @@ if (safe && value === callDateGet(d, method, value)) { return; } - d['set' + (_utc(d) ? 'UTC' : '') + method](value); + d["set" + (_utc(d) ? "UTC" : "") + method](value); } var INTERNAL_MEMOIZE_LIMIT = 1000; @@ -1466,9 +1540,10 @@ // ended up clunky as that is also serializing arguments. Separating // these implementations turned out to be simpler. function memoizeFunction(fn) { - var memo = {}, counter = 0; + var memo = {}, + counter = 0; - return function(key) { + return function (key) { if (hasOwn(memo, key)) { return memo[key]; } @@ -1478,7 +1553,7 @@ counter = 0; } counter++; - return memo[key] = fn(key); + return (memo[key] = fn(key)); }; } @@ -1493,15 +1568,25 @@ * ***/ - var DATE_OPTIONS = { - 'newDateInternal': defaultNewDate + newDateInternal: defaultNewDate, }; var LOCALE_ARRAY_FIELDS = [ - 'months', 'weekdays', 'units', 'numerals', 'placeholders', - 'articles', 'tokens', 'timeMarkers', 'ampm', 'timeSuffixes', - 'parse', 'timeParse', 'timeFrontParse', 'modifiers' + "months", + "weekdays", + "units", + "numerals", + "placeholders", + "articles", + "tokens", + "timeMarkers", + "ampm", + "timeSuffixes", + "parse", + "timeParse", + "timeFrontParse", + "modifiers", ]; // Regex for stripping Timezone Abbreviations @@ -1511,510 +1596,514 @@ var MINUTES = 60 * 1000; // Date unit indexes - var HOURS_INDEX = 3, - DAY_INDEX = 4, - WEEK_INDEX = 5, - MONTH_INDEX = 6, - YEAR_INDEX = 7; + var HOURS_INDEX = 3, + DAY_INDEX = 4, + WEEK_INDEX = 5, + MONTH_INDEX = 6, + YEAR_INDEX = 7; // ISO Defaults var ISO_FIRST_DAY_OF_WEEK = 1, - ISO_FIRST_DAY_OF_WEEK_YEAR = 4; + ISO_FIRST_DAY_OF_WEEK_YEAR = 4; var ParsingTokens = { - 'yyyy': { - param: 'year', - src: '\\d{4}' + yyyy: { + param: "year", + src: "\\d{4}", }, - 'MM': { - param: 'month', - src: '[01]?\\d' + MM: { + param: "month", + src: "[01]?\\d", }, - 'dd': { - param: 'date', - src: '[0123]?\\d' + dd: { + param: "date", + src: "[0123]?\\d", }, - 'hh': { - param: 'hour', - src: '[0-2]?\\d' + hh: { + param: "hour", + src: "[0-2]?\\d", }, - 'mm': { - param: 'minute', - src: '[0-5]\\d' + mm: { + param: "minute", + src: "[0-5]\\d", }, - 'ss': { - param: 'second', - src: '[0-5]\\d(?:[,.]\\d+)?' + ss: { + param: "second", + src: "[0-5]\\d(?:[,.]\\d+)?", }, - 'yy': { - param: 'year', - src: '\\d{2}' + yy: { + param: "year", + src: "\\d{2}", }, - 'y': { - param: 'year', - src: '\\d' + y: { + param: "year", + src: "\\d", }, - 'yearSign': { - src: '[+-]', - sign: true + yearSign: { + src: "[+-]", + sign: true, }, - 'tzHour': { - src: '[0-1]\\d' + tzHour: { + src: "[0-1]\\d", }, - 'tzMinute': { - src: '[0-5]\\d' + tzMinute: { + src: "[0-5]\\d", }, - 'tzSign': { - src: '[+−-]', - sign: true + tzSign: { + src: "[+−-]", + sign: true, }, - 'ihh': { - param: 'hour', - src: '[0-2]?\\d(?:[,.]\\d+)?' + ihh: { + param: "hour", + src: "[0-2]?\\d(?:[,.]\\d+)?", }, - 'imm': { - param: 'minute', - src: '[0-5]\\d(?:[,.]\\d+)?' + imm: { + param: "minute", + src: "[0-5]\\d(?:[,.]\\d+)?", }, - 'GMT': { - param: 'utc', - src: 'GMT', - val: 1 + GMT: { + param: "utc", + src: "GMT", + val: 1, }, - 'Z': { - param: 'utc', - src: 'Z', - val: 1 + Z: { + param: "utc", + src: "Z", + val: 1, + }, + timestamp: { + src: "\\d+", }, - 'timestamp': { - src: '\\d+' - } }; var LocalizedParsingTokens = { - 'year': { - base: 'yyyy', - requiresSuffix: true + year: { + base: "yyyy", + requiresSuffix: true, }, - 'month': { - base: 'MM', - requiresSuffix: true + month: { + base: "MM", + requiresSuffix: true, }, - 'date': { - base: 'dd', - requiresSuffix: true + date: { + base: "dd", + requiresSuffix: true, }, - 'hour': { - base: 'hh', - requiresSuffixOr: ':' + hour: { + base: "hh", + requiresSuffixOr: ":", }, - 'minute': { - base: 'mm' + minute: { + base: "mm", }, - 'second': { - base: 'ss' + second: { + base: "ss", + }, + num: { + src: "\\d+", + requiresNumerals: true, }, - 'num': { - src: '\\d+', - requiresNumerals: true - } }; var CoreParsingFormats = [ { // 12-1978 // 08-1978 (MDY) - src: '{MM}[-.\\/]{yyyy}' + src: "{MM}[-.\\/]{yyyy}", }, { // 12/08/1978 // 08/12/1978 (MDY) time: true, - src: '{dd}[-.\\/]{MM}(?:[-.\\/]{yyyy|yy|y})?', - mdy: '{MM}[-.\\/]{dd}(?:[-.\\/]{yyyy|yy|y})?' + src: "{dd}[-.\\/]{MM}(?:[-.\\/]{yyyy|yy|y})?", + mdy: "{MM}[-.\\/]{dd}(?:[-.\\/]{yyyy|yy|y})?", }, { // 1975-08-25 time: true, - src: '{yyyy}[-.\\/]{MM}(?:[-.\\/]{dd})?' + src: "{yyyy}[-.\\/]{MM}(?:[-.\\/]{dd})?", }, { // .NET JSON - src: '\\\\/Date\\({timestamp}(?:[+-]\\d{4,4})?\\)\\\\/' + src: "\\\\/Date\\({timestamp}(?:[+-]\\d{4,4})?\\)\\\\/", }, { // ISO-8601 - src: '{yearSign?}{yyyy}(?:-?{MM}(?:-?{dd}(?:T{ihh}(?::?{imm}(?::?{ss})?)?)?)?)?{tzOffset?}' - } + src: "{yearSign?}{yyyy}(?:-?{MM}(?:-?{dd}(?:T{ihh}(?::?{imm}(?::?{ss})?)?)?)?)?{tzOffset?}", + }, ]; var CoreOutputFormats = { - 'ISO8601': '{yyyy}-{MM}-{dd}T{HH}:{mm}:{ss}.{SSS}{Z}', - 'RFC1123': '{Dow}, {dd} {Mon} {yyyy} {HH}:{mm}:{ss} {ZZ}', - 'RFC1036': '{Weekday}, {dd}-{Mon}-{yy} {HH}:{mm}:{ss} {ZZ}' + ISO8601: "{yyyy}-{MM}-{dd}T{HH}:{mm}:{ss}.{SSS}{Z}", + RFC1123: "{Dow}, {dd} {Mon} {yyyy} {HH}:{mm}:{ss} {ZZ}", + RFC1036: "{Weekday}, {dd}-{Mon}-{yy} {HH}:{mm}:{ss} {ZZ}", }; var FormatTokensBase = [ { - ldml: 'Dow', - strf: 'a', - lowerToken: 'dow', - get: function(d, localeCode) { + ldml: "Dow", + strf: "a", + lowerToken: "dow", + get: function (d, localeCode) { return localeManager.get(localeCode).getWeekdayName(getWeekday(d), 2); - } + }, }, { - ldml: 'Weekday', - strf: 'A', - lowerToken: 'weekday', + ldml: "Weekday", + strf: "A", + lowerToken: "weekday", allowAlternates: true, - get: function(d, localeCode, alternate) { - return localeManager.get(localeCode).getWeekdayName(getWeekday(d), alternate); - } + get: function (d, localeCode, alternate) { + return localeManager + .get(localeCode) + .getWeekdayName(getWeekday(d), alternate); + }, }, { - ldml: 'Mon', - strf: 'b h', - lowerToken: 'mon', - get: function(d, localeCode) { + ldml: "Mon", + strf: "b h", + lowerToken: "mon", + get: function (d, localeCode) { return localeManager.get(localeCode).getMonthName(getMonth(d), 2); - } + }, }, { - ldml: 'Month', - strf: 'B', - lowerToken: 'month', + ldml: "Month", + strf: "B", + lowerToken: "month", allowAlternates: true, - get: function(d, localeCode, alternate) { - return localeManager.get(localeCode).getMonthName(getMonth(d), alternate); - } + get: function (d, localeCode, alternate) { + return localeManager + .get(localeCode) + .getMonthName(getMonth(d), alternate); + }, }, { - strf: 'C', - get: function(d) { + strf: "C", + get: function (d) { return getYear(d).toString().slice(0, 2); - } + }, }, { - ldml: 'd date day', - strf: 'd', + ldml: "d date day", + strf: "d", strfPadding: 2, - ldmlPaddedToken: 'dd', - ordinalToken: 'do', - get: function(d) { + ldmlPaddedToken: "dd", + ordinalToken: "do", + get: function (d) { return getDate(d); - } + }, }, { - strf: 'e', - get: function(d) { - return padNumber(getDate(d), 2, false, 10, ' '); - } + strf: "e", + get: function (d) { + return padNumber(getDate(d), 2, false, 10, " "); + }, }, { - ldml: 'H 24hr', - strf: 'H', + ldml: "H 24hr", + strf: "H", strfPadding: 2, - ldmlPaddedToken: 'HH', - get: function(d) { + ldmlPaddedToken: "HH", + get: function (d) { return getHours(d); - } + }, }, { - ldml: 'h hours 12hr', - strf: 'I', + ldml: "h hours 12hr", + strf: "I", strfPadding: 2, - ldmlPaddedToken: 'hh', - get: function(d) { + ldmlPaddedToken: "hh", + get: function (d) { return getHours(d) % 12 || 12; - } + }, }, { - ldml: 'D', - strf: 'j', + ldml: "D", + strf: "j", strfPadding: 3, - ldmlPaddedToken: 'DDD', - get: function(d) { + ldmlPaddedToken: "DDD", + get: function (d) { var s = setUnitAndLowerToEdge(cloneDate(d), MONTH_INDEX); return getDaysSince(d, s) + 1; - } + }, }, { - ldml: 'M', - strf: 'm', + ldml: "M", + strf: "m", strfPadding: 2, - ordinalToken: 'Mo', - ldmlPaddedToken: 'MM', - get: function(d) { + ordinalToken: "Mo", + ldmlPaddedToken: "MM", + get: function (d) { return getMonth(d) + 1; - } + }, }, { - ldml: 'm minutes', - strf: 'M', + ldml: "m minutes", + strf: "M", strfPadding: 2, - ldmlPaddedToken: 'mm', - get: function(d) { - return callDateGet(d, 'Minutes'); - } + ldmlPaddedToken: "mm", + get: function (d) { + return callDateGet(d, "Minutes"); + }, }, { - ldml: 'Q', - get: function(d) { + ldml: "Q", + get: function (d) { return ceil((getMonth(d) + 1) / 3); - } + }, }, { - ldml: 'TT', - strf: 'p', - get: function(d, localeCode) { + ldml: "TT", + strf: "p", + get: function (d, localeCode) { return getMeridiemToken(d, localeCode); - } + }, }, { - ldml: 'tt', - strf: 'P', - get: function(d, localeCode) { + ldml: "tt", + strf: "P", + get: function (d, localeCode) { return getMeridiemToken(d, localeCode).toLowerCase(); - } + }, }, { - ldml: 'T', - lowerToken: 't', - get: function(d, localeCode) { + ldml: "T", + lowerToken: "t", + get: function (d, localeCode) { return getMeridiemToken(d, localeCode).charAt(0); - } + }, }, { - ldml: 's seconds', - strf: 'S', + ldml: "s seconds", + strf: "S", strfPadding: 2, - ldmlPaddedToken: 'ss', - get: function(d) { - return callDateGet(d, 'Seconds'); - } + ldmlPaddedToken: "ss", + get: function (d) { + return callDateGet(d, "Seconds"); + }, }, { - ldml: 'S ms', + ldml: "S ms", strfPadding: 3, - ldmlPaddedToken: 'SSS', - get: function(d) { - return callDateGet(d, 'Milliseconds'); - } + ldmlPaddedToken: "SSS", + get: function (d) { + return callDateGet(d, "Milliseconds"); + }, }, { - ldml: 'e', - strf: 'u', - ordinalToken: 'eo', - get: function(d) { + ldml: "e", + strf: "u", + ordinalToken: "eo", + get: function (d) { return getWeekday(d) || 7; - } + }, }, { - strf: 'U', + strf: "U", strfPadding: 2, - get: function(d) { + get: function (d) { // Sunday first, 0-53 return getWeekNumber(d, false, 0); - } + }, }, { - ldml: 'W', - strf: 'V', + ldml: "W", + strf: "V", strfPadding: 2, - ordinalToken: 'Wo', - ldmlPaddedToken: 'WW', - get: function(d) { + ordinalToken: "Wo", + ldmlPaddedToken: "WW", + get: function (d) { // Monday first, 1-53 (ISO8601) return getWeekNumber(d, true); - } + }, }, { - strf: 'w', - get: function(d) { + strf: "w", + get: function (d) { return getWeekday(d); - } + }, }, { - ldml: 'w', - ordinalToken: 'wo', - ldmlPaddedToken: 'ww', - get: function(d, localeCode) { + ldml: "w", + ordinalToken: "wo", + ldmlPaddedToken: "ww", + get: function (d, localeCode) { // Locale dependent, 1-53 var loc = localeManager.get(localeCode), - dow = loc.getFirstDayOfWeek(localeCode), - doy = loc.getFirstDayOfWeekYear(localeCode); + dow = loc.getFirstDayOfWeek(localeCode), + doy = loc.getFirstDayOfWeekYear(localeCode); return getWeekNumber(d, true, dow, doy); - } + }, }, { - strf: 'W', + strf: "W", strfPadding: 2, - get: function(d) { + get: function (d) { // Monday first, 0-53 return getWeekNumber(d, false); - } + }, }, { - ldmlPaddedToken: 'gggg', - ldmlTwoDigitToken: 'gg', - get: function(d, localeCode) { + ldmlPaddedToken: "gggg", + ldmlTwoDigitToken: "gg", + get: function (d, localeCode) { return getWeekYear(d, localeCode); - } + }, }, { - strf: 'G', + strf: "G", strfPadding: 4, - strfTwoDigitToken: 'g', - ldmlPaddedToken: 'GGGG', - ldmlTwoDigitToken: 'GG', - get: function(d, localeCode) { + strfTwoDigitToken: "g", + ldmlPaddedToken: "GGGG", + ldmlTwoDigitToken: "GG", + get: function (d, localeCode) { return getWeekYear(d, localeCode, true); - } + }, }, { - ldml: 'year', - ldmlPaddedToken: 'yyyy', - ldmlTwoDigitToken: 'yy', - strf: 'Y', + ldml: "year", + ldmlPaddedToken: "yyyy", + ldmlTwoDigitToken: "yy", + strf: "Y", strfPadding: 4, - strfTwoDigitToken: 'y', - get: function(d) { + strfTwoDigitToken: "y", + get: function (d) { return getYear(d); - } + }, }, { - ldml: 'ZZ', - strf: 'z', - get: function(d) { + ldml: "ZZ", + strf: "z", + get: function (d) { return getUTCOffset(d); - } + }, }, { - ldml: 'X', - get: function(d) { + ldml: "X", + get: function (d) { return trunc(d.getTime() / 1000); - } + }, }, { - ldml: 'x', - get: function(d) { + ldml: "x", + get: function (d) { return d.getTime(); - } + }, }, { - ldml: 'Z', - get: function(d) { + ldml: "Z", + get: function (d) { return getUTCOffset(d, true); - } + }, }, { - ldml: 'z', - strf: 'Z', - get: function(d) { + ldml: "z", + strf: "Z", + get: function (d) { // Note that this is not accurate in all browsing environments! // https://github.com/moment/moment/issues/162 // It will continue to be supported for Node and usage with the // understanding that it may be blank. var match = d.toString().match(TIMEZONE_ABBREVIATION_REG); - return match ? match[1]: ''; - } + return match ? match[1] : ""; + }, }, { - strf: 'D', - alias: '%m/%d/%y' + strf: "D", + alias: "%m/%d/%y", }, { - strf: 'F', - alias: '%Y-%m-%d' + strf: "F", + alias: "%Y-%m-%d", }, { - strf: 'r', - alias: '%I:%M:%S %p' + strf: "r", + alias: "%I:%M:%S %p", }, { - strf: 'R', - alias: '%H:%M' + strf: "R", + alias: "%H:%M", }, { - strf: 'T', - alias: '%H:%M:%S' + strf: "T", + alias: "%H:%M:%S", }, { - strf: 'x', - alias: '{short}' + strf: "x", + alias: "{short}", }, { - strf: 'X', - alias: '{time}' + strf: "X", + alias: "{time}", }, { - strf: 'c', - alias: '{stamp}' - } + strf: "c", + alias: "{stamp}", + }, ]; var DateUnits = [ { - name: 'millisecond', - method: 'Milliseconds', + name: "millisecond", + method: "Milliseconds", multiplier: 1, start: 0, - end: 999 + end: 999, }, { - name: 'second', - method: 'Seconds', + name: "second", + method: "Seconds", multiplier: 1000, start: 0, - end: 59 + end: 59, }, { - name: 'minute', - method: 'Minutes', + name: "minute", + method: "Minutes", multiplier: 60 * 1000, start: 0, - end: 59 + end: 59, }, { - name: 'hour', - method: 'Hours', + name: "hour", + method: "Hours", multiplier: 60 * 60 * 1000, start: 0, - end: 23 + end: 23, }, { - name: 'day', - alias: 'date', - method: 'Date', + name: "day", + alias: "date", + method: "Date", ambiguous: true, multiplier: 24 * 60 * 60 * 1000, start: 1, - end: function(d) { + end: function (d) { return getDaysInMonth(d); - } + }, }, { - name: 'week', - method: 'ISOWeek', + name: "week", + method: "ISOWeek", ambiguous: true, - multiplier: 7 * 24 * 60 * 60 * 1000 + multiplier: 7 * 24 * 60 * 60 * 1000, }, { - name: 'month', - method: 'Month', + name: "month", + method: "Month", ambiguous: true, multiplier: 30.4375 * 24 * 60 * 60 * 1000, start: 0, - end: 11 + end: 11, }, { - name: 'year', - method: 'FullYear', + name: "year", + method: "FullYear", ambiguous: true, multiplier: 365.25 * 24 * 60 * 60 * 1000, - start: 0 - } + start: 0, + }, ]; /*** @@ -2066,11 +2155,11 @@ } function getNewDate() { - return _dateOptions('newDateInternal')(); + return _dateOptions("newDateInternal")(); } function defaultNewDate() { - return new Date; + return new Date(); } function cloneDate(d) { @@ -2087,44 +2176,44 @@ function assertDateIsValid(d) { if (!dateIsValid(d)) { - throw new TypeError('Date is not valid'); + throw new TypeError("Date is not valid"); } } function getHours(d) { - return callDateGet(d, 'Hours'); + return callDateGet(d, "Hours"); } function getWeekday(d) { - return callDateGet(d, 'Day'); + return callDateGet(d, "Day"); } function getDate(d) { - return callDateGet(d, 'Date'); + return callDateGet(d, "Date"); } function getMonth(d) { - return callDateGet(d, 'Month'); + return callDateGet(d, "Month"); } function getYear(d) { - return callDateGet(d, 'FullYear'); + return callDateGet(d, "FullYear"); } function setDate(d, val) { - callDateSet(d, 'Date', val); + callDateSet(d, "Date", val); } function setMonth(d, val) { - callDateSet(d, 'Month', val); + callDateSet(d, "Month", val); } function setYear(d, val) { - callDateSet(d, 'FullYear', val); + callDateSet(d, "FullYear", val); } function getDaysInMonth(d) { - return 32 - callDateGet(new Date(getYear(d), getMonth(d), 32), 'Date'); + return 32 - callDateGet(new Date(getYear(d), getMonth(d), 32), "Date"); } function setWeekday(d, dow, dir) { @@ -2134,7 +2223,7 @@ // Allow a "direction" parameter to determine whether a weekday can // be set beyond the current weekday in either direction. var ndir = dir > 0 ? 1 : -1; - var offset = dow % 7 - currentWeekday; + var offset = (dow % 7) - currentWeekday; if (offset && offset / abs(offset) !== ndir) { dow += 7 * ndir; } @@ -2146,7 +2235,7 @@ // Normal callDateSet method with ability // to handle ISOWeek setting as well. function callDateSetWithWeek(d, method, value, safe) { - if (method === 'ISOWeek') { + if (method === "ISOWeek") { setISOWeekNumber(d, value); } else { callDateSet(d, method, value, safe); @@ -2158,12 +2247,15 @@ } function getUTCOffset(d, iso) { - var offset = _utc(d) ? 0 : tzOffset(d), hours, mins, colon; - colon = iso === true ? ':' : ''; - if (!offset && iso) return 'Z'; + var offset = _utc(d) ? 0 : tzOffset(d), + hours, + mins, + colon; + colon = iso === true ? ":" : ""; + if (!offset && iso) return "Z"; hours = padNumber(trunc(-offset / 60), 2, true); mins = padNumber(abs(offset % 60), 2); - return hours + colon + mins; + return hours + colon + mins; } function tzOffset(d) { @@ -2171,7 +2263,8 @@ } function collectDateArguments(args, allowDuration) { - var arg1 = args[0], arg2 = args[1]; + var arg1 = args[0], + arg2 = args[1]; if (allowDuration && isString(arg1)) { arg1 = getDateParamsFromString(arg1); } else if (isNumber(arg1) && isNumber(arg2)) { @@ -2186,8 +2279,9 @@ } function collectDateParamsFromArguments(args) { - var params = {}, index = 0; - walkUnitDown(YEAR_INDEX, function(unit) { + var params = {}, + index = 0; + walkUnitDown(YEAR_INDEX, function (unit) { var arg = args[index++]; if (isDefined(arg)) { params[unit.name] = arg; @@ -2197,7 +2291,9 @@ } function getDateParamsFromString(str) { - var match, num, params = {}; + var match, + num, + params = {}; match = str.match(/^(-?\d*[\d.]\d*)?\s?(\w+?)s?$/i); if (match) { if (isUndefined(num)) { @@ -2251,7 +2347,6 @@ // Years -> Milliseconds checking all date params including "weekday" function iterateOverDateParams(params, fn, startIndex, endIndex) { - function run(name, unit, i) { var val = getDateParam(params, name); if (isDefined(val)) { @@ -2259,17 +2354,20 @@ } } - iterateOverDateUnits(function (unit, i) { - var result = run(unit.name, unit, i); - if (result !== false && i === DAY_INDEX) { - // Check for "weekday", which has a distinct meaning - // in the context of setting a date, but has the same - // meaning as "day" as a unit of time. - result = run('weekday', unit, i); - } - return result; - }, startIndex, endIndex); - + iterateOverDateUnits( + function (unit, i) { + var result = run(unit.name, unit, i); + if (result !== false && i === DAY_INDEX) { + // Check for "weekday", which has a distinct meaning + // in the context of setting a date, but has the same + // meaning as "day" as a unit of time. + result = run("weekday", unit, i); + } + return result; + }, + startIndex, + endIndex, + ); } // Years -> Days @@ -2297,7 +2395,10 @@ } function moveToBeginningOfWeek(d, firstDayOfWeek) { - setWeekday(d, floor((getWeekday(d) - firstDayOfWeek) / 7) * 7 + firstDayOfWeek); + setWeekday( + d, + floor((getWeekday(d) - firstDayOfWeek) / 7) * 7 + firstDayOfWeek, + ); return d; } @@ -2309,7 +2410,10 @@ function moveToBeginningOfUnit(d, unitIndex, localeCode) { if (unitIndex === WEEK_INDEX) { - moveToBeginningOfWeek(d, localeManager.get(localeCode).getFirstDayOfWeek()); + moveToBeginningOfWeek( + d, + localeManager.get(localeCode).getFirstDayOfWeek(), + ); } return setUnitAndLowerToEdge(d, getLowerUnitIndex(unitIndex)); } @@ -2318,11 +2422,16 @@ if (unitIndex === WEEK_INDEX) { moveToEndOfWeek(d, localeManager.get(localeCode).getFirstDayOfWeek()); } - return setUnitAndLowerToEdge(d, getLowerUnitIndex(unitIndex), stopIndex, true); + return setUnitAndLowerToEdge( + d, + getLowerUnitIndex(unitIndex), + stopIndex, + true, + ); } function setUnitAndLowerToEdge(d, startIndex, stopIndex, end) { - walkUnitDown(startIndex, function(unit, i) { + walkUnitDown(startIndex, function (unit, i) { var val = end ? unit.end : unit.start; if (isFunction(val)) { val = val(d); @@ -2334,9 +2443,11 @@ } function getDateParamKey(params, key) { - return getOwnKey(params, key) || - getOwnKey(params, key + 's') || - (key === 'day' && getOwnKey(params, 'date')); + return ( + getOwnKey(params, key) || + getOwnKey(params, key + "s") || + (key === "day" && getOwnKey(params, "date")) + ); } function getDateParam(params, key) { @@ -2348,9 +2459,10 @@ } function getUnitIndexForParamName(name) { - var params = {}, unitIndex; + var params = {}, + unitIndex; params[name] = 1; - iterateOverDateParams(params, function(name, val, unit, i) { + iterateOverDateParams(params, function (name, val, unit, i) { unitIndex = i; return false; }); @@ -2362,11 +2474,13 @@ } function getTimeDistanceForUnit(d1, d2, unit) { - var fwd = d2 > d1, num, tmp; + var fwd = d2 > d1, + num, + tmp; if (!fwd) { tmp = d2; - d2 = d1; - d1 = tmp; + d2 = d1; + d1 = tmp; } num = d2 - d1; if (unit.multiplier > 1) { @@ -2395,13 +2509,13 @@ if (token.val) { val = token.val; } else if (token.sign) { - val = str === '+' ? 1 : -1; + val = str === "+" ? 1 : -1; } else if (token.bool) { val = !!val; } else { - val = +str.replace(/,/, '.'); + val = +str.replace(/,/, "."); } - if (token.param === 'month') { + if (token.param === "month") { val -= 1; } return val; @@ -2411,7 +2525,8 @@ // Following IETF here, adding 1900 or 2000 depending on the last two digits. // Note that this makes no accordance for what should happen after 2050, but // intentionally ignoring this for now. https://www.ietf.org/rfc/rfc2822.txt - var val = +str, delta; + var val = +str, + delta; val += val < 50 ? 2000 : 1900; if (prefer) { delta = val - getYear(d); @@ -2425,8 +2540,13 @@ function setISOWeekNumber(d, num) { if (isNumber(num)) { // Intentionally avoiding updateDate here to prevent circular dependencies. - var isoWeek = cloneDate(d), dow = getWeekday(d); - moveToFirstDayOfWeekYear(isoWeek, ISO_FIRST_DAY_OF_WEEK, ISO_FIRST_DAY_OF_WEEK_YEAR); + var isoWeek = cloneDate(d), + dow = getWeekday(d); + moveToFirstDayOfWeekYear( + isoWeek, + ISO_FIRST_DAY_OF_WEEK, + ISO_FIRST_DAY_OF_WEEK_YEAR, + ); setDate(isoWeek, getDate(isoWeek) + 7 * (num - 1)); setYear(d, getYear(isoWeek)); setMonth(d, getMonth(isoWeek)); @@ -2436,8 +2556,14 @@ return d.getTime(); } - function getWeekNumber(d, allowPrevious, firstDayOfWeek, firstDayOfWeekYear) { - var isoWeek, n = 0; + function getWeekNumber( + d, + allowPrevious, + firstDayOfWeek, + firstDayOfWeekYear, + ) { + var isoWeek, + n = 0; if (isUndefined(firstDayOfWeek)) { firstDayOfWeek = ISO_FIRST_DAY_OF_WEEK; } @@ -2512,11 +2638,11 @@ adu[0] = 1; } if (dRelative) { - type = 'duration'; + type = "duration"; } else if (adu[2] > 0) { - type = 'future'; + type = "future"; } else { - type = 'past'; + type = "past"; } return localeManager.get(localeCode).getRelativeFormat(adu, type); } @@ -2525,8 +2651,9 @@ // the largest possible meaningful unit. In other words, if passed // 3600000, this will return an array which represents "1 hour". function getAdjustedUnit(ms, fn) { - var unitIndex = 0, value = 0; - iterateOverDateUnits(function(unit, i) { + var unitIndex = 0, + value = 0; + iterateOverDateUnits(function (unit, i) { value = abs(fn(unit)); if (value >= 1) { unitIndex = i; @@ -2539,7 +2666,7 @@ // Gets the adjusted unit based on simple division by // date unit multiplier. function getAdjustedUnitForNumber(ms) { - return getAdjustedUnit(ms, function(unit) { + return getAdjustedUnit(ms, function (unit) { return trunc(withPrecision(ms / unit.multiplier, 1)); }); } @@ -2564,7 +2691,7 @@ } } ms = d - dRelative; - return getAdjustedUnit(ms, function(u) { + return getAdjustedUnit(ms, function (u) { return abs(getTimeDistanceForUnit(d, dRelative, u)); }); } @@ -2574,52 +2701,51 @@ function dateFormat(d, format, localeCode) { assertDateIsValid(d); - format = CoreOutputFormats[format] || format || '{long}'; + format = CoreOutputFormats[format] || format || "{long}"; return dateFormatMatcher(format, d, localeCode); } function getMeridiemToken(d, localeCode) { var hours = getHours(d); - return localeManager.get(localeCode).ampm[trunc(hours / 12)] || ''; + return localeManager.get(localeCode).ampm[trunc(hours / 12)] || ""; } function buildDateFormatTokens() { - function addFormats(target, tokens, fn) { if (tokens) { - forEach(spaceSplit(tokens), function(token) { + forEach(spaceSplit(tokens), function (token) { target[token] = fn; }); } } function buildLowercase(get) { - return function(d, localeCode) { + return function (d, localeCode) { return get(d, localeCode).toLowerCase(); }; } function buildOrdinal(get) { - return function(d, localeCode) { + return function (d, localeCode) { var n = get(d, localeCode); return n + localeManager.get(localeCode).getOrdinal(n); }; } function buildPadded(get, padding) { - return function(d, localeCode) { + return function (d, localeCode) { return padNumber(get(d, localeCode), padding); }; } function buildTwoDigits(get) { - return function(d, localeCode) { + return function (d, localeCode) { return get(d, localeCode) % 100; }; } function buildAlias(alias) { - return function(d, localeCode) { + return function (d, localeCode) { return dateFormatMatcher(alias, d, localeCode); }; } @@ -2631,7 +2757,7 @@ } function buildAlternate(f, n) { - var alternate = function(d, localeCode) { + var alternate = function (d, localeCode) { return f.get(d, localeCode, n); }; addFormats(ldmlTokens, f.ldml + n, alternate); @@ -2641,7 +2767,7 @@ } function getIdentityFormat(name) { - return function(d, localeCode) { + return function (d, localeCode) { var loc = localeManager.get(localeCode); return dateFormatMatcher(loc[name], d, localeCode); }; @@ -2650,8 +2776,9 @@ ldmlTokens = {}; strfTokens = {}; - forEach(FormatTokensBase, function(f) { - var get = f.get, getPadded; + forEach(FormatTokensBase, function (f) { + var get = f.get, + getPadded; if (f.lowerToken) { ldmlTokens[f.lowerToken] = buildLowercase(get); } @@ -2659,7 +2786,10 @@ ldmlTokens[f.ordinalToken] = buildOrdinal(get, f); } if (f.ldmlPaddedToken) { - ldmlTokens[f.ldmlPaddedToken] = buildPadded(get, f.ldmlPaddedToken.length); + ldmlTokens[f.ldmlPaddedToken] = buildPadded( + get, + f.ldmlPaddedToken.length, + ); } if (f.ldmlTwoDigitToken) { ldmlTokens[f.ldmlTwoDigitToken] = buildPadded(buildTwoDigits(get), 2); @@ -2680,24 +2810,27 @@ addFormats(strfTokens, f.strf, getPadded || get); }); - forEachProperty(CoreOutputFormats, function(src, name) { + forEachProperty(CoreOutputFormats, function (src, name) { addFormats(ldmlTokens, name, buildAlias(src)); }); - defineInstanceSimilar(sugarDate, 'short medium long full', function(methods, name) { - var fn = getIdentityFormat(name); - addFormats(ldmlTokens, name, fn); - methods[name] = fn; - }); + defineInstanceSimilar( + sugarDate, + "short medium long full", + function (methods, name) { + var fn = getIdentityFormat(name); + addFormats(ldmlTokens, name, fn); + methods[name] = fn; + }, + ); - addFormats(ldmlTokens, 'time', getIdentityFormat('time')); - addFormats(ldmlTokens, 'stamp', getIdentityFormat('stamp')); + addFormats(ldmlTokens, "time", getIdentityFormat("time")); + addFormats(ldmlTokens, "stamp", getIdentityFormat("stamp")); } var dateFormatMatcher; function buildDateFormatMatcher() { - function getLdml(d, token, localeCode) { return getOwn(ldmlTokens, token)(d, localeCode); } @@ -2719,18 +2852,25 @@ if (!dateIsValid(date)) return; if (isString(d)) { d = trim(d).toLowerCase(); - switch(true) { - case d === 'future': return date.getTime() > getNewDate().getTime(); - case d === 'past': return date.getTime() < getNewDate().getTime(); - case d === 'today': return compareDay(date); - case d === 'tomorrow': return compareDay(date, 1); - case d === 'yesterday': return compareDay(date, -1); - case d === 'weekday': return getWeekday(date) > 0 && getWeekday(date) < 6; - case d === 'weekend': return getWeekday(date) === 0 || getWeekday(date) === 6; + switch (true) { + case d === "future": + return date.getTime() > getNewDate().getTime(); + case d === "past": + return date.getTime() < getNewDate().getTime(); + case d === "today": + return compareDay(date); + case d === "tomorrow": + return compareDay(date, 1); + case d === "yesterday": + return compareDay(date, -1); + case d === "weekday": + return getWeekday(date) > 0 && getWeekday(date) < 6; + case d === "weekend": + return getWeekday(date) === 0 || getWeekday(date) === 6; - case (isDefined(tmp = English.weekdayMap[d])): + case isDefined((tmp = English.weekdayMap[d])): return getWeekday(date) === tmp; - case (isDefined(tmp = English.monthMap[d])): + case isDefined((tmp = English.monthMap[d])): return getMonth(date) === tmp; } } @@ -2738,7 +2878,15 @@ } function compareDate(date, d, margin, localeCode, options) { - var loMargin = 0, hiMargin = 0, timezoneShift, compareEdges, override, min, max, p, t; + var loMargin = 0, + hiMargin = 0, + timezoneShift, + compareEdges, + override, + min, + max, + p, + t; function getTimezoneShift() { // If there is any specificity in the date then we're implicitly not @@ -2773,7 +2921,11 @@ moveToBeginningOfUnit(p.date, p.set.specificity, localeCode); } if (compareEdges || p.set.specificity === MONTH_INDEX) { - max = moveToEndOfUnit(cloneDate(p.date), p.set.specificity, localeCode).getTime(); + max = moveToEndOfUnit( + cloneDate(p.date), + p.set.specificity, + localeCode, + ).getTime(); } else { max = addSpecificUnit(); } @@ -2785,7 +2937,7 @@ hiMargin = -50; } } - t = date.getTime(); + t = date.getTime(); min = p.date.getTime(); max = max || min; timezoneShift = getTimezoneShift(); @@ -2793,7 +2945,7 @@ min -= timezoneShift; max -= timezoneShift; } - return t >= (min - loMargin) && t <= (max + hiMargin); + return t >= min - loMargin && t <= max + hiMargin; } function compareDay(d, shift) { @@ -2801,9 +2953,11 @@ if (shift) { setDate(comp, getDate(comp) + shift); } - return getYear(d) === getYear(comp) && - getMonth(d) === getMonth(comp) && - getDate(d) === getDate(comp); + return ( + getYear(d) === getYear(comp) && + getMonth(d) === getMonth(comp) && + getDate(d) === getDate(comp) + ); } function createDate(d, options, forceClone) { @@ -2815,7 +2969,6 @@ } function getExtendedDate(contextDate, d, opt, forceClone) { - var date, set, loc, options, afterCallbacks, relative, weekdayDir; afterCallbacks = []; @@ -2823,19 +2976,22 @@ function getDateOptions(opt) { var options = isString(opt) ? { locale: opt } : opt || {}; - options.prefer = +!!getOwn(options, 'future') - +!!getOwn(options, 'past'); + options.prefer = + +!!getOwn(options, "future") - +!!getOwn(options, "past"); return options; } function getFormatParams(match, dif) { - var set = getOwn(options, 'params') || {}; - forEach(dif.to, function(field, i) { - var str = match[i + 1], token, val; + var set = getOwn(options, "params") || {}; + forEach(dif.to, function (field, i) { + var str = match[i + 1], + token, + val; if (!str) return; - if (field === 'yy' || field === 'y') { - field = 'year'; - val = getYearFromAbbreviation(str, date, getOwn(options, 'prefer')); - } else if (token = getOwn(ParsingTokens, field)) { + if (field === "yy" || field === "y") { + field = "year"; + val = getYearFromAbbreviation(str, date, getOwn(options, "prefer")); + } else if ((token = getOwn(ParsingTokens, field))) { field = token.param || field; val = getParsingTokenValue(token, str); } else { @@ -2849,10 +3005,10 @@ // Clone date will set the utc flag, but it will // be overriden later, so set option flags instead. function cloneDateByFlag(d, clone) { - if (_utc(d) && !isDefined(getOwn(options, 'fromUTC'))) { + if (_utc(d) && !isDefined(getOwn(options, "fromUTC"))) { options.fromUTC = true; } - if (_utc(d) && !isDefined(getOwn(options, 'setUTC'))) { + if (_utc(d) && !isDefined(getOwn(options, "setUTC"))) { options.setUTC = true; } if (clone) { @@ -2866,23 +3022,21 @@ } function fireCallbacks() { - forEach(afterCallbacks, function(fn) { + forEach(afterCallbacks, function (fn) { fn.call(); }); } function parseStringDate(str) { - str = str.toLowerCase(); // The act of getting the locale will initialize // if it is missing and add the required formats. - loc = localeManager.get(getOwn(options, 'locale')); + loc = localeManager.get(getOwn(options, "locale")); - for (var i = 0, dif, match; dif = loc.compiledFormats[i]; i++) { + for (var i = 0, dif, match; (dif = loc.compiledFormats[i]); i++) { match = str.match(dif.reg); if (match) { - // Note that caching the format will modify the compiledFormats array // which is not a good idea to do inside its for loop, however we // know at this point that we have a matched format and that we will @@ -2946,10 +3100,10 @@ if (!set) { // Fall back to native parsing date = new Date(str); - if (getOwn(options, 'fromUTC')) { + if (getOwn(options, "fromUTC")) { // Falling back to system date here which cannot be parsed as UTC, // so if we're forcing UTC then simply add the offset. - date.setTime(date.getTime() + (tzOffset(date) * MINUTES)); + date.setTime(date.getTime() + tzOffset(date) * MINUTES); } } else if (relative) { updateDate(date, set, false, 1); @@ -2959,7 +3113,7 @@ // so preemtively reset the time here to prevent this. resetTime(date); } - updateDate(date, set, true, 0, getOwn(options, 'prefer'), weekdayDir); + updateDate(date, set, true, 0, getOwn(options, "prefer"), weekdayDir); } fireCallbacks(); return date; @@ -3010,8 +3164,8 @@ // If the date has hours past 24, we need to prevent it from traversing // into a new day as that would make it being part of a new week in // ambiguous dates such as "Monday". - afterDateSet(function() { - advanceDate(date, 'date', trunc(hour / 24)); + afterDateSet(function () { + advanceDate(date, "date", trunc(hour / 24)); }); } } @@ -3020,7 +3174,7 @@ resetTime(date); if (isUndefined(set.unit)) { set.unit = DAY_INDEX; - set.num = set.day; + set.num = set.day; delete set.day; } } @@ -3040,8 +3194,8 @@ // if not set up front. The last case will set up the params necessary to // shift the weekday and allow separateAbsoluteUnits below to handle setting // it after the date has been shifted. - if(isDefined(set.weekday)) { - if(unitIndex === MONTH_INDEX) { + if (isDefined(set.weekday)) { + if (unitIndex === MONTH_INDEX) { setOrdinalWeekday(num); num = 1; } else { @@ -3084,11 +3238,12 @@ } function handleEdge(edge, params) { - var edgeIndex = params.unit, weekdayOfMonth; + var edgeIndex = params.unit, + weekdayOfMonth; if (!edgeIndex) { // If we have "the end of January", then we need to find the unit index. - iterateOverHigherDateParams(params, function(unitName, val, unit, i) { - if (unitName === 'weekday' && isDefined(params.month)) { + iterateOverHigherDateParams(params, function (unitName, val, unit, i) { + if (unitName === "weekday" && isDefined(params.month)) { // If both a month and weekday exist, then we have a format like // "the last tuesday in November, 2012", where the "last" is still // relative to the end of the month, so prevent the unit "weekday" @@ -3104,19 +3259,24 @@ weekdayOfMonth = params.weekday; delete params.weekday; } - afterDateSet(function() { + afterDateSet(function () { var stopIndex; // "edge" values that are at the very edge are "2" so the beginning of the // year is -2 and the end of the year is 2. Conversely, the "last day" is // actually 00:00am so it is 1. -1 is reserved but unused for now. if (edge < 0) { - moveToBeginningOfUnit(date, edgeIndex, getOwn(options, 'locale')); + moveToBeginningOfUnit(date, edgeIndex, getOwn(options, "locale")); } else if (edge > 0) { if (edge === 1) { stopIndex = DAY_INDEX; moveToBeginningOfUnit(date, DAY_INDEX); } - moveToEndOfUnit(date, edgeIndex, getOwn(options, 'locale'), stopIndex); + moveToEndOfUnit( + date, + edgeIndex, + getOwn(options, "locale"), + stopIndex, + ); } if (isDefined(weekdayOfMonth)) { setWeekday(date, weekdayOfMonth, -edge); @@ -3144,7 +3304,7 @@ function separateAbsoluteUnits(unitIndex) { var params; - iterateOverDateParams(set, function(name, val, unit, i) { + iterateOverDateParams(set, function (name, val, unit, i) { // If there is a time unit set that is more specific than // the matched unit we have a string like "5:30am in 2 minutes", // which is meaningless, so invalidate the date... @@ -3160,8 +3320,15 @@ } }); if (params) { - afterDateSet(function() { - updateDate(date, params, true, false, getOwn(options, 'prefer'), weekdayDir); + afterDateSet(function () { + updateDate( + date, + params, + true, + false, + getOwn(options, "prefer"), + weekdayDir, + ); }); if (set.edge) { // "the end of March of next year" @@ -3179,12 +3346,12 @@ date = getNewDate(); } - _utc(date, getOwn(options, 'fromUTC')); + _utc(date, getOwn(options, "fromUTC")); if (isString(d)) { date = parseStringDate(d); } else if (isDate(d)) { - date = cloneDateByFlag(d, hasOwn(options, 'clone') || forceClone); + date = cloneDateByFlag(d, hasOwn(options, "clone") || forceClone); } else if (isObjectType(d)) { set = simpleClone(d); updateDate(date, set, true); @@ -3197,10 +3364,10 @@ // "2012-11-15T12:00:00Z", in the majority of cases you are using it to create // a date that will, after creation, be manipulated as local, so reset the utc // flag here unless "setUTC" is also set. - _utc(date, !!getOwn(options, 'setUTC')); + _utc(date, !!getOwn(options, "setUTC")); return { set: set, - date: date + date: date, }; } @@ -3209,7 +3376,7 @@ function setUpperUnit(unitName, unitIndex) { if (prefer && !upperUnitIndex) { - if (unitName === 'weekday') { + if (unitName === "weekday") { upperUnitIndex = WEEK_INDEX; } else { upperUnitIndex = getHigherUnitIndex(unitIndex); @@ -3230,9 +3397,11 @@ if (!upperUnitIndex || upperUnitIndex > YEAR_INDEX) { return; } - switch(prefer) { - case -1: return d > getNewDate(); - case 1: return d < getNewDate(); + switch (prefer) { + case -1: + return d > getNewDate(); + case 1: + return d < getNewDate(); } } @@ -3245,20 +3414,22 @@ function handleFraction(unit, unitIndex, fraction) { if (unitIndex) { var lowerUnit = DateUnits[getLowerUnitIndex(unitIndex)]; - var val = round(unit.multiplier / lowerUnit.multiplier * fraction); + var val = round((unit.multiplier / lowerUnit.multiplier) * fraction); params[lowerUnit.name] = val; } } function monthHasShifted(d, targetMonth) { if (targetMonth < 0) { - targetMonth = targetMonth % 12 + 12; + targetMonth = (targetMonth % 12) + 12; } return targetMonth % 12 !== getMonth(d); } function setUnit(unitName, value, unit, unitIndex) { - var method = unit.method, checkMonth, fraction; + var method = unit.method, + checkMonth, + fraction; setUpperUnit(unitName, unitIndex); setSpecificity(unitIndex); @@ -3269,7 +3440,7 @@ value = trunc(value); } - if (unitName === 'weekday') { + if (unitName === "weekday") { if (!advance) { // Weekdays are always considered absolute units so simply set them // here even if it is an "advance" operation. This is to help avoid @@ -3304,14 +3475,14 @@ // so avoiding this situation in callDateSet by checking up front that // the value is not the same before setting. if (advance && !unit.ambiguous) { - d.setTime(d.getTime() + (value * advance * unit.multiplier)); + d.setTime(d.getTime() + value * advance * unit.multiplier); return; } else if (advance) { if (unitIndex === WEEK_INDEX) { value *= 7; method = DateUnits[DAY_INDEX].method; } - value = (value * advance) + callDateGet(d, method); + value = value * advance + callDateGet(d, method); } callDateSetWithWeek(d, method, value, advance); if (checkMonth && monthHasShifted(d, value)) { @@ -3357,23 +3528,23 @@ } function arrayToRegAlternates(arr) { - var joined = arr.join(''); + var joined = arr.join(""); if (!arr || !arr.length) { - return ''; + return ""; } if (joined.length === arr.length) { - return '[' + joined + ']'; + return "[" + joined + "]"; } // map handles sparse arrays so no need to compact the array here. - return map(arr, escapeRegExp).join('|'); + return map(arr, escapeRegExp).join("|"); } function getRegNonCapturing(src, opt) { if (src.length > 1) { - src = '(?:' + src + ')'; + src = "(?:" + src + ")"; } if (opt) { - src += '?'; + src += "?"; } return src; } @@ -3383,7 +3554,7 @@ if (token.requiresSuffix) { src = getRegNonCapturing(src + getRegNonCapturing(suffix)); } else if (token.requiresSuffixOr) { - src += getRegNonCapturing(token.requiresSuffixOr + '|' + suffix); + src += getRegNonCapturing(token.requiresSuffixOr + "|" + suffix); } else { src += getRegNonCapturing(suffix, true); } @@ -3399,15 +3570,13 @@ } function buildLocales() { - function LocaleManager(loc) { this.locales = {}; this.add(loc); } LocaleManager.prototype = { - - get: function(code, fallback) { + get: function (code, fallback) { var loc = this.locales[code]; if (!loc && LazyLoadedLocales[code]) { loc = this.add(code, LazyLoadedLocales[code]); @@ -3417,19 +3586,19 @@ return loc || fallback === false ? loc : this.current; }, - getAll: function() { + getAll: function () { return this.locales; }, - set: function(code) { + set: function (code) { var loc = this.get(code, false); if (!loc) { - throw new TypeError('Invalid Locale: ' + code); + throw new TypeError("Invalid Locale: " + code); } - return this.current = loc; + return (this.current = loc); }, - add: function(code, def) { + add: function (code, def) { if (!def) { def = code; code = def.code; @@ -3444,13 +3613,12 @@ return loc; }, - remove: function(code) { + remove: function (code) { if (this.current.code === code) { - this.current = this.get('en'); + this.current = this.get("en"); } return delete this.locales[code]; - } - + }, }; // Sorry about this guys... @@ -3459,32 +3627,31 @@ } function getNewLocale(def) { - function Locale(def) { this.init(def); } Locale.prototype = { - - getMonthName: function(n, alternate) { + getMonthName: function (n, alternate) { if (this.monthSuffix) { - return (n + 1) + this.monthSuffix; + return n + 1 + this.monthSuffix; } return getArrayWithOffset(this.months, n, alternate, 12); }, - getWeekdayName: function(n, alternate) { + getWeekdayName: function (n, alternate) { return getArrayWithOffset(this.weekdays, n, alternate, 7); }, - getTokenValue: function(field, str) { - var map = this[field + 'Map'], val; + getTokenValue: function (field, str) { + var map = this[field + "Map"], + val; if (map) { val = map[str]; } if (isUndefined(val)) { val = this.getNumber(str); - if (field === 'month') { + if (field === "month") { // Months are the only numeric date field // whose value is not the same as its number. val -= 1; @@ -3493,7 +3660,7 @@ return val; }, - getNumber: function(str) { + getNumber: function (str) { var num = this.numeralMap[str]; if (isDefined(num)) { return num; @@ -3501,7 +3668,7 @@ // The unary plus operator here show better performance and handles // every format that parseFloat does with the exception of trailing // characters, which are guaranteed not to be in our string at this point. - num = +str.replace(/,/, '.'); + num = +str.replace(/,/, "."); if (!isNaN(num)) { return num; } @@ -3513,15 +3680,21 @@ return num; }, - getNumeralValue: function(str) { - var place = 1, num = 0, lastWasPlace, isPlace, numeral, digit, arr; + getNumeralValue: function (str) { + var place = 1, + num = 0, + lastWasPlace, + isPlace, + numeral, + digit, + arr; // Note that "numerals" that need to be converted through this method are // all considered to be single characters in order to handle CJK. This // method is by no means unique to CJK, but the complexity of handling // inflections in non-CJK languages adds too much overhead for not enough // value, so avoiding for now. - arr = str.split(''); - for (var i = arr.length - 1; numeral = arr[i]; i--) { + arr = str.split(""); + for (var i = arr.length - 1; (numeral = arr[i]); i--) { digit = getOwn(this.numeralMap, numeral); if (isUndefined(digit)) { digit = getOwn(fullWidthNumberMap, numeral) || 0; @@ -3545,66 +3718,76 @@ return num; }, - getOrdinal: function(n) { + getOrdinal: function (n) { var suffix = this.ordinalSuffix; return suffix || getOrdinalSuffix(n); }, - getRelativeFormat: function(adu, type) { + getRelativeFormat: function (adu, type) { return this.convertAdjustedToFormat(adu, type); }, - getDuration: function(ms) { - return this.convertAdjustedToFormat(getAdjustedUnitForNumber(max(0, ms)), 'duration'); + getDuration: function (ms) { + return this.convertAdjustedToFormat( + getAdjustedUnitForNumber(max(0, ms)), + "duration", + ); }, - getFirstDayOfWeek: function() { + getFirstDayOfWeek: function () { var val = this.firstDayOfWeek; return isDefined(val) ? val : ISO_FIRST_DAY_OF_WEEK; }, - getFirstDayOfWeekYear: function() { + getFirstDayOfWeekYear: function () { return this.firstDayOfWeekYear || ISO_FIRST_DAY_OF_WEEK_YEAR; }, - convertAdjustedToFormat: function(adu, type) { - var sign, unit, mult, - num = adu[0], - u = adu[1], - ms = adu[2], - format = this[type] || this.relative; + convertAdjustedToFormat: function (adu, type) { + var sign, + unit, + mult, + num = adu[0], + u = adu[1], + ms = adu[2], + format = this[type] || this.relative; if (isFunction(format)) { return format.call(this, num, u, ms, type); } mult = !this.plural || num === 1 ? 0 : 1; unit = this.units[mult * 8 + u] || this.units[u]; - sign = this[ms > 0 ? 'fromNow' : 'ago']; - return format.replace(/\{(.*?)\}/g, function(full, match) { - switch(match) { - case 'num': return num; - case 'unit': return unit; - case 'sign': return sign; + sign = this[ms > 0 ? "fromNow" : "ago"]; + return format.replace(/\{(.*?)\}/g, function (full, match) { + switch (match) { + case "num": + return num; + case "unit": + return unit; + case "sign": + return sign; } }); }, - cacheFormat: function(dif, i) { + cacheFormat: function (dif, i) { this.compiledFormats.splice(i, 1); this.compiledFormats.unshift(dif); }, - addFormat: function(src, to) { + addFormat: function (src, to) { var loc = this; function getTokenSrc(str) { - var suffix, src, val, - opt = str.match(/\?$/), - nc = str.match(/^(\d+)\??$/), - slice = str.match(/(\d)(?:-(\d))?/), - key = str.replace(/[^a-z]+$/i, ''); + var suffix, + src, + val, + opt = str.match(/\?$/), + nc = str.match(/^(\d+)\??$/), + slice = str.match(/(\d)(?:-(\d))?/), + key = str.replace(/[^a-z]+$/i, ""); // Allowing alias tokens such as {time} - if (val = getOwn(loc.parsingAliases, key)) { + if ((val = getOwn(loc.parsingAliases, key))) { src = replaceParsingTokens(val); if (opt) { src = getRegNonCapturing(src, true); @@ -3614,7 +3797,7 @@ if (nc) { src = loc.tokens[nc[1]]; - } else if (val = getOwn(ParsingTokens, key)) { + } else if ((val = getOwn(ParsingTokens, key))) { src = val.src; } else { val = getOwn(loc.parsingTokens, key) || getOwn(loc, key); @@ -3623,18 +3806,18 @@ // by either {month} or {months}, falling back as necessary, however // regardless of whether or not a fallback occurs, the final field to // be passed to addRawFormat must be normalized as singular. - key = key.replace(/s$/, ''); + key = key.replace(/s$/, ""); if (!val) { - val = getOwn(loc.parsingTokens, key) || getOwn(loc, key + 's'); + val = getOwn(loc.parsingTokens, key) || getOwn(loc, key + "s"); } if (isString(val)) { src = val; - suffix = loc[key + 'Suffix']; + suffix = loc[key + "Suffix"]; } else { if (slice) { - val = filter(val, function(m, i) { + val = filter(val, function (m, i) { var mod = i % (loc.units ? 8 : val.length); return mod >= slice[1] && mod <= (slice[2] || slice[1]); }); @@ -3643,7 +3826,7 @@ } } if (!src) { - return ''; + return ""; } if (nc) { // Non-capturing tokens like {0} @@ -3651,27 +3834,27 @@ } else { // Capturing group and add to parsed tokens to.push(key); - src = '(' + src + ')'; + src = "(" + src + ")"; } if (suffix) { // Date/time suffixes such as those in CJK src = getParsingTokenWithSuffix(key, src, suffix); } if (opt) { - src += '?'; + src += "?"; } return src; } function replaceParsingTokens(str) { - // Make spaces optional - str = str.replace(/ /g, '\\s*'); + str = str.replace(/ /g, "\\s*"); - return str.replace(/\{([^,]+?)\}/g, function(match, token) { - var tokens = token.split('|'), src; + return str.replace(/\{([^,]+?)\}/g, function (match, token) { + var tokens = token.split("|"), + src; if (tokens.length > 1) { - src = getRegNonCapturing(map(tokens, getTokenSrc).join('|')); + src = getRegNonCapturing(map(tokens, getTokenSrc).join("|")); } else { src = getTokenSrc(token); } @@ -3687,14 +3870,14 @@ loc.addRawFormat(src, to); }, - addRawFormat: function(format, to) { + addRawFormat: function (format, to) { this.compiledFormats.unshift({ - reg: RegExp('^ *' + format + ' *$', 'i'), - to: to + reg: RegExp("^ *" + format + " *$", "i"), + to: to, }); }, - init: function(def) { + init: function (def) { var loc = this; // -- Initialization helpers @@ -3710,7 +3893,7 @@ } function initArrayFields() { - forEach(LOCALE_ARRAY_FIELDS, function(name) { + forEach(LOCALE_ARRAY_FIELDS, function (name) { var val = loc[name]; if (isString(val)) { loc[name] = commaSplit(val); @@ -3723,16 +3906,19 @@ // -- Value array build helpers function buildValueArray(name, mod, map, fn) { - var field = name, all = [], setMap; + var field = name, + all = [], + setMap; if (!loc[field]) { - field += 's'; + field += "s"; } if (!map) { map = {}; setMap = true; } - forAllAlternates(field, function(alt, j, i) { - var idx = j * mod + i, val; + forAllAlternates(field, function (alt, j, i) { + var idx = j * mod + i, + val; val = fn ? fn(i) : i; map[alt] = val; map[alt.toLowerCase()] = val; @@ -3740,44 +3926,47 @@ }); loc[field] = all; if (setMap) { - loc[name + 'Map'] = map; + loc[name + "Map"] = map; } } function forAllAlternates(field, fn) { - forEach(loc[field], function(str, i) { - forEachAlternate(str, function(alt, j) { + forEach(loc[field], function (str, i) { + forEachAlternate(str, function (alt, j) { fn(alt, j, i); }); }); } function forEachAlternate(str, fn) { - var arr = map(str.split('+'), function(split) { - return split.replace(/(.+):(.+)$/, function(full, base, suffixes) { - return map(suffixes.split('|'), function(suffix) { - return base + suffix; - }).join('|'); - }); - }).join('|'); - forEach(arr.split('|'), fn); + var arr = map(str.split("+"), function (split) { + return split.replace( + /(.+):(.+)$/, + function (full, base, suffixes) { + return map(suffixes.split("|"), function (suffix) { + return base + suffix; + }).join("|"); + }, + ); + }).join("|"); + forEach(arr.split("|"), fn); } function buildNumerals() { var map = {}; - buildValueArray('numeral', 10, map); - buildValueArray('article', 1, map, function() { + buildValueArray("numeral", 10, map); + buildValueArray("article", 1, map, function () { return 1; }); - buildValueArray('placeholder', 4, map, function(n) { + buildValueArray("placeholder", 4, map, function (n) { return pow(10, n + 1); }); loc.numeralMap = map; } function buildTimeFormats() { - loc.parsingAliases['time'] = getTimeFormat(); - loc.parsingAliases['tzOffset'] = getTZOffsetFormat(); + loc.parsingAliases["time"] = getTimeFormat(); + loc.parsingAliases["tzOffset"] = getTZOffsetFormat(); } function getTimeFormat() { @@ -3785,68 +3974,72 @@ if (loc.ampmFront) { // "ampmFront" exists mostly for CJK locales, which also presume that // time suffixes exist, allowing this to be a simpler regex. - src = '{ampm?} {hour} (?:{minute} (?::?{second})?)?'; - } else if(loc.ampm.length) { - src = '{hour}(?:[.:]{minute}(?:[.:]{second})? {ampm?}| {ampm})'; + src = "{ampm?} {hour} (?:{minute} (?::?{second})?)?"; + } else if (loc.ampm.length) { + src = "{hour}(?:[.:]{minute}(?:[.:]{second})? {ampm?}| {ampm})"; } else { - src = '{hour}(?:[.:]{minute}(?:[.:]{second})?)'; + src = "{hour}(?:[.:]{minute}(?:[.:]{second})?)"; } return src; } function getTZOffsetFormat() { - return '(?:{Z}|{GMT?}(?:{tzSign}{tzHour}(?::?{tzMinute}(?: \\([\\w\\s]+\\))?)?)?)?'; + return "(?:{Z}|{GMT?}(?:{tzSign}{tzHour}(?::?{tzMinute}(?: \\([\\w\\s]+\\))?)?)?)?"; } function buildParsingTokens() { - forEachProperty(LocalizedParsingTokens, function(token, name) { + forEachProperty(LocalizedParsingTokens, function (token, name) { var src, arr; src = token.base ? ParsingTokens[token.base].src : token.src; if (token.requiresNumerals || loc.numeralUnits) { src += getNumeralSrc(); } - arr = loc[name + 's']; + arr = loc[name + "s"]; if (arr && arr.length) { - src += '|' + arrayToRegAlternates(arr); + src += "|" + arrayToRegAlternates(arr); } loc.parsingTokens[name] = src; }); } function getNumeralSrc() { - var all, src = ''; + var all, + src = ""; all = loc.numerals.concat(loc.placeholders).concat(loc.articles); if (loc.allowsFullWidth) { - all = all.concat(fullWidthNumbers.split('')); + all = all.concat(fullWidthNumbers.split("")); } if (all.length) { - src = '|(?:' + arrayToRegAlternates(all) + ')+'; + src = "|(?:" + arrayToRegAlternates(all) + ")+"; } return src; } function buildTimeSuffixes() { - iterateOverDateUnits(function(unit, i) { + iterateOverDateUnits(function (unit, i) { var token = loc.timeSuffixes[i]; if (token) { - loc[(unit.alias || unit.name) + 'Suffix'] = token; + loc[(unit.alias || unit.name) + "Suffix"] = token; } }); } function buildModifiers() { - forEach(loc.modifiers, function(modifier) { - var name = modifier.name, mapKey = name + 'Map', map; + forEach(loc.modifiers, function (modifier) { + var name = modifier.name, + mapKey = name + "Map", + map; map = loc[mapKey] || {}; - forEachAlternate(modifier.src, function(alt, j) { - var token = getOwn(loc.parsingTokens, name), val = modifier.value; + forEachAlternate(modifier.src, function (alt, j) { + var token = getOwn(loc.parsingTokens, name), + val = modifier.value; map[alt] = val; - loc.parsingTokens[name] = token ? token + '|' + alt : alt; - if (modifier.name === 'sign' && j === 0) { + loc.parsingTokens[name] = token ? token + "|" + alt : alt; + if (modifier.name === "sign" && j === 0) { // Hooking in here to set the first "fromNow" or "ago" modifier // directly on the locale, so that it can be reused in the // relative format. - loc[val === 1 ? 'fromNow' : 'ago'] = alt; + loc[val === 1 ? "fromNow" : "ago"] = alt; } }); loc[mapKey] = map; @@ -3856,7 +4049,7 @@ // -- Format adding helpers function addCoreFormats() { - forEach(CoreParsingFormats, function(df) { + forEach(CoreParsingFormats, function (df) { var src = df.src; if (df.mdy && loc.mdy) { // Use the mm/dd/yyyy variant if it @@ -3872,17 +4065,17 @@ loc.addFormat(src); } }); - loc.addFormat('{time}'); + loc.addFormat("{time}"); } function addLocaleFormats() { - addFormatSet('parse'); - addFormatSet('timeParse', true); - addFormatSet('timeFrontParse', true, true); + addFormatSet("parse"); + addFormatSet("timeParse", true); + addFormatSet("timeFrontParse", true, true); } function addFormatSet(field, allowTime, timeFront) { - forEach(loc[field], function(format) { + forEach(loc[field], function (format) { if (allowTime) { format = getFormatWithTime(format, timeFront); } @@ -3898,27 +4091,28 @@ } function getTimeBefore() { - return getRegNonCapturing('{time}[,\\s\\u3000]', true); + return getRegNonCapturing("{time}[,\\s\\u3000]", true); } function getTimeAfter() { - var markers = ',?[\\s\\u3000]', localized; + var markers = ",?[\\s\\u3000]", + localized; localized = arrayToRegAlternates(loc.timeMarkers); if (localized) { - markers += '| (?:' + localized + ') '; + markers += "| (?:" + localized + ") "; } markers = getRegNonCapturing(markers, loc.timeMarkerOptional); - return getRegNonCapturing(markers + '{time}', true); + return getRegNonCapturing(markers + "{time}", true); } initFormats(); initDefinition(); initArrayFields(); - buildValueArray('month', 12); - buildValueArray('weekday', 7); - buildValueArray('unit', 8); - buildValueArray('ampm', 2); + buildValueArray("month", 12); + buildValueArray("weekday", 7); + buildValueArray("unit", 8); + buildValueArray("ampm", 2); buildNumerals(); buildTimeFormats(); @@ -3931,9 +4125,7 @@ // that more specific formats should come later. addCoreFormats(); addLocaleFormats(); - - } - + }, }; return new Locale(def); @@ -4185,42 +4377,54 @@ * ***/ function buildDateUnitMethods() { + defineInstanceSimilar( + sugarDate, + DateUnits, + function (methods, unit, index) { + var name = unit.name, + caps = simpleCapitalize(name); - defineInstanceSimilar(sugarDate, DateUnits, function(methods, unit, index) { - var name = unit.name, caps = simpleCapitalize(name); - - if (index > DAY_INDEX) { - forEach(['Last','This','Next'], function(shift) { - methods['is' + shift + caps] = function(d, localeCode) { - return compareDate(d, shift + ' ' + name, 0, localeCode, { locale: 'en' }); + if (index > DAY_INDEX) { + forEach(["Last", "This", "Next"], function (shift) { + methods["is" + shift + caps] = function (d, localeCode) { + return compareDate(d, shift + " " + name, 0, localeCode, { + locale: "en", + }); + }; + }); + } + if (index > HOURS_INDEX) { + methods["beginningOf" + caps] = function (d, localeCode) { + return moveToBeginningOfUnit(d, index, localeCode); }; - }); - } - if (index > HOURS_INDEX) { - methods['beginningOf' + caps] = function(d, localeCode) { - return moveToBeginningOfUnit(d, index, localeCode); + methods["endOf" + caps] = function (d, localeCode) { + return moveToEndOfUnit(d, index, localeCode); + }; + } + + methods["add" + caps + "s"] = function (d, num, reset) { + return advanceDate(d, name, num, reset); }; - methods['endOf' + caps] = function(d, localeCode) { - return moveToEndOfUnit(d, index, localeCode); + + var since = function (date, d, options) { + return getTimeDistanceForUnit( + date, + createDateWithContext(date, d, options, true), + unit, + ); + }; + var until = function (date, d, options) { + return getTimeDistanceForUnit( + createDateWithContext(date, d, options, true), + date, + unit, + ); }; - } - - methods['add' + caps + 's'] = function(d, num, reset) { - return advanceDate(d, name, num, reset); - }; - - var since = function(date, d, options) { - return getTimeDistanceForUnit(date, createDateWithContext(date, d, options, true), unit); - }; - var until = function(date, d, options) { - return getTimeDistanceForUnit(createDateWithContext(date, d, options, true), date, unit); - }; - - methods[name + 'sAgo'] = methods[name + 'sUntil'] = until; - methods[name + 'sSince'] = methods[name + 'sFromNow'] = since; - - }); + methods[name + "sAgo"] = methods[name + "sUntil"] = until; + methods[name + "sSince"] = methods[name + "sFromNow"] = since; + }, + ); } /*** @@ -4271,19 +4475,20 @@ * ***/ function buildRelativeAliases() { - var special = spaceSplit('Today Yesterday Tomorrow Weekday Weekend Future Past'); + var special = spaceSplit( + "Today Yesterday Tomorrow Weekday Weekend Future Past", + ); var weekdays = English.weekdays.slice(0, 7); - var months = English.months.slice(0, 12); + var months = English.months.slice(0, 12); var together = special.concat(weekdays).concat(months); - defineInstanceSimilar(sugarDate, together, function(methods, name) { - methods['is'+ name] = function(d) { + defineInstanceSimilar(sugarDate, together, function (methods, name) { + methods["is" + name] = function (d) { return fullCompareDate(d, name); }; }); } defineStatic(sugarDate, { - /*** * @method create(d, [options]) * @returns Date @@ -4355,7 +4560,7 @@ * @option {Object} [params] * ***/ - 'create': function(d, options) { + create: function (d, options) { return createDate(d, options); }, @@ -4377,7 +4582,7 @@ * @param {string} [localeCode] * ***/ - 'getLocale': function(code) { + getLocale: function (code) { return localeManager.get(code, !code); }, @@ -4392,7 +4597,7 @@ * Date.getAllLocales() * ***/ - 'getAllLocales': function() { + getAllLocales: function () { return localeManager.getAll(); }, @@ -4407,7 +4612,7 @@ * Date.getAllLocaleCodes() * ***/ - 'getAllLocaleCodes': function() { + getAllLocaleCodes: function () { return getKeys(localeManager.getAll()); }, @@ -4425,7 +4630,7 @@ * @param {string} localeCode * ***/ - 'setLocale': function(code) { + setLocale: function (code) { return localeManager.set(code); }, @@ -4444,7 +4649,7 @@ * @param {Object} def * ***/ - 'addLocale': function(code, set) { + addLocale: function (code, set) { return localeManager.add(code, set); }, @@ -4461,14 +4666,12 @@ * @param {string} localeCode * ***/ - 'removeLocale': function(code) { + removeLocale: function (code) { return localeManager.remove(code); - } - + }, }); defineInstanceWithArguments(sugarDate, { - /*** * @method set(set, [reset] = false) * @returns Date @@ -4497,7 +4700,7 @@ * @param {number} [milliseconds] * ***/ - 'set': function(d, args) { + set: function (d, args) { args = collectDateArguments(args); return updateDate(d, args[0], args[1]); }, @@ -4532,7 +4735,7 @@ * @param {number} [milliseconds] * ***/ - 'advance': function(d, args) { + advance: function (d, args) { return advanceDateWithArgs(d, args, 1); }, @@ -4566,14 +4769,12 @@ * @param {number} [milliseconds] * ***/ - 'rewind': function(d, args) { + rewind: function (d, args) { return advanceDateWithArgs(d, args, -1); - } - + }, }); defineInstance(sugarDate, { - /*** * @method get(d, [options]) * @returns Date @@ -4592,7 +4793,7 @@ * @param {DateCreateOptions} options * ***/ - 'get': function(date, d, options) { + get: function (date, d, options) { return createDateWithContext(date, d, options); }, @@ -4609,7 +4810,7 @@ * @param {number} dow * ***/ - 'setWeekday': function(date, dow) { + setWeekday: function (date, dow) { return setWeekday(date, dow); }, @@ -4626,7 +4827,7 @@ * @param {number} num * ***/ - 'setISOWeek': function(date, num) { + setISOWeek: function (date, num) { return setISOWeekNumber(date, num); }, @@ -4642,7 +4843,7 @@ * new Date().getISOWeek() -> today's week of the year * ***/ - 'getISOWeek': function(date) { + getISOWeek: function (date) { return getWeekNumber(date, true); }, @@ -4658,7 +4859,7 @@ * new Date().beginningOfISOWeek() -> Monday * ***/ - 'beginningOfISOWeek': function(date) { + beginningOfISOWeek: function (date) { var day = getWeekday(date); if (day === 0) { day = -6; @@ -4681,7 +4882,7 @@ * new Date().endOfISOWeek() -> Sunday * ***/ - 'endOfISOWeek': function(date) { + endOfISOWeek: function (date) { if (getWeekday(date) !== 0) { setWeekday(date, 7); } @@ -4702,7 +4903,7 @@ * @param {boolean} iso * ***/ - 'getUTCOffset': function(date, iso) { + getUTCOffset: function (date, iso) { return getUTCOffset(date, iso); }, @@ -4724,7 +4925,7 @@ * @param {boolean} on * ***/ - 'setUTC': function(date, on) { + setUTC: function (date, on) { return _utc(date, on); }, @@ -4743,7 +4944,7 @@ * new Date().setUTC(true).isUTC() -> true * ***/ - 'isUTC': function(date) { + isUTC: function (date) { return isUTC(date); }, @@ -4758,7 +4959,7 @@ * new Date('flexor').isValid() -> false * ***/ - 'isValid': function(date) { + isValid: function (date) { return dateIsValid(date); }, @@ -4779,7 +4980,7 @@ * @param {number} [margin] * ***/ - 'isAfter': function(date, d, margin) { + isAfter: function (date, d, margin) { return date.getTime() > createDate(d).getTime() - (margin || 0); }, @@ -4800,7 +5001,7 @@ * @param {number} [margin] * ***/ - 'isBefore': function(date, d, margin) { + isBefore: function (date, d, margin) { return date.getTime() < createDate(d).getTime() + (margin || 0); }, @@ -4823,14 +5024,14 @@ * @param {number} [margin] * ***/ - 'isBetween': function(date, d1, d2, margin) { - var t = date.getTime(); + isBetween: function (date, d1, d2, margin) { + var t = date.getTime(); var t1 = createDate(d1).getTime(); var t2 = createDate(d2).getTime(); var lo = min(t1, t2); var hi = max(t1, t2); margin = margin || 0; - return (lo - margin <= t) && (hi + margin >= t); + return lo - margin <= t && hi + margin >= t; }, /*** @@ -4843,9 +5044,9 @@ * millenium.isLeapYear() -> true * ***/ - 'isLeapYear': function(date) { + isLeapYear: function (date) { var year = getYear(date); - return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0); + return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; }, /*** @@ -4859,7 +5060,7 @@ * feb.daysInMonth() -> 28 or 29 * ***/ - 'daysInMonth': function(date) { + daysInMonth: function (date) { return getDaysInMonth(date); }, @@ -4939,7 +5140,7 @@ * @param {string} [localeCode] * ***/ - 'format': function(date, f, localeCode) { + format: function (date, f, localeCode) { return dateFormat(date, f, localeCode); }, @@ -4984,7 +5185,7 @@ * @callbackReturns {string} relativeFn * ***/ - 'relative': function(date, localeCode, relativeFn) { + relative: function (date, localeCode, relativeFn) { return dateRelative(date, null, localeCode, relativeFn); }, @@ -5006,7 +5207,7 @@ * * ***/ - 'relativeTo': function(date, d, localeCode) { + relativeTo: function (date, d, localeCode) { return dateRelative(date, createDate(d), localeCode); }, @@ -5034,7 +5235,7 @@ * @param {number} [margin] * ***/ - 'is': function(date, d, margin) { + is: function (date, d, margin) { return fullCompareDate(date, d, margin); }, @@ -5056,7 +5257,7 @@ * @param {string} [localeCode] * ***/ - 'reset': function(date, unit, localeCode) { + reset: function (date, unit, localeCode) { var unitIndex = unit ? getUnitIndexForParamName(unit) : DAY_INDEX; moveToBeginningOfUnit(date, unitIndex, localeCode); return date; @@ -5074,7 +5275,7 @@ * new Date().clone() -> Copy of now * ***/ - 'clone': function(date) { + clone: function (date) { return cloneDate(date); }, @@ -5083,7 +5284,7 @@ * @alias toISOString * ***/ - 'iso': function(date) { + iso: function (date) { return date.toISOString(); }, @@ -5097,7 +5298,7 @@ * new Date().getWeekday(); -> (ex.) 3 * ***/ - 'getWeekday': function(date) { + getWeekday: function (date) { return getWeekday(date); }, @@ -5111,108 +5312,111 @@ * new Date().getUTCWeekday(); -> (ex.) 3 * ***/ - 'getUTCWeekday': function(date) { + getUTCWeekday: function (date) { return date.getUTCDay(); - } - + }, }); var EnglishLocaleBaseDefinition = { - 'code': 'en', - 'plural': true, - 'timeMarkers': 'at', - 'ampm': 'AM|A.M.|a,PM|P.M.|p', - 'units': 'millisecond:|s,second:|s,minute:|s,hour:|s,day:|s,week:|s,month:|s,year:|s', - 'months': 'Jan:uary|,Feb:ruary|,Mar:ch|,Apr:il|,May,Jun:e|,Jul:y|,Aug:ust|,Sep:tember|t|,Oct:ober|,Nov:ember|,Dec:ember|', - 'weekdays': 'Sun:day|,Mon:day|,Tue:sday|,Wed:nesday|,Thu:rsday|,Fri:day|,Sat:urday|+weekend', - 'numerals': 'zero,one|first,two|second,three|third,four:|th,five|fifth,six:|th,seven:|th,eight:|h,nin:e|th,ten:|th', - 'articles': 'a,an,the', - 'tokens': 'the,st|nd|rd|th,of|in,a|an,on', - 'time': '{H}:{mm}', - 'past': '{num} {unit} {sign}', - 'future': '{num} {unit} {sign}', - 'duration': '{num} {unit}', - 'modifiers': [ - { 'name': 'half', 'src': 'half', 'value': .5 }, - { 'name': 'midday', 'src': 'noon', 'value': 12 }, - { 'name': 'midday', 'src': 'midnight', 'value': 24 }, - { 'name': 'day', 'src': 'yesterday', 'value': -1 }, - { 'name': 'day', 'src': 'today|tonight', 'value': 0 }, - { 'name': 'day', 'src': 'tomorrow', 'value': 1 }, - { 'name': 'sign', 'src': 'ago|before', 'value': -1 }, - { 'name': 'sign', 'src': 'from now|after|from|in|later', 'value': 1 }, - { 'name': 'edge', 'src': 'first day|first|beginning', 'value': -2 }, - { 'name': 'edge', 'src': 'last day', 'value': 1 }, - { 'name': 'edge', 'src': 'end|last', 'value': 2 }, - { 'name': 'shift', 'src': 'last', 'value': -1 }, - { 'name': 'shift', 'src': 'the|this', 'value': 0 }, - { 'name': 'shift', 'src': 'next', 'value': 1 } + code: "en", + plural: true, + timeMarkers: "at", + ampm: "AM|A.M.|a,PM|P.M.|p", + units: + "millisecond:|s,second:|s,minute:|s,hour:|s,day:|s,week:|s,month:|s,year:|s", + months: + "Jan:uary|,Feb:ruary|,Mar:ch|,Apr:il|,May,Jun:e|,Jul:y|,Aug:ust|,Sep:tember|t|,Oct:ober|,Nov:ember|,Dec:ember|", + weekdays: + "Sun:day|,Mon:day|,Tue:sday|,Wed:nesday|,Thu:rsday|,Fri:day|,Sat:urday|+weekend", + numerals: + "zero,one|first,two|second,three|third,four:|th,five|fifth,six:|th,seven:|th,eight:|h,nin:e|th,ten:|th", + articles: "a,an,the", + tokens: "the,st|nd|rd|th,of|in,a|an,on", + time: "{H}:{mm}", + past: "{num} {unit} {sign}", + future: "{num} {unit} {sign}", + duration: "{num} {unit}", + modifiers: [ + { name: "half", src: "half", value: 0.5 }, + { name: "midday", src: "noon", value: 12 }, + { name: "midday", src: "midnight", value: 24 }, + { name: "day", src: "yesterday", value: -1 }, + { name: "day", src: "today|tonight", value: 0 }, + { name: "day", src: "tomorrow", value: 1 }, + { name: "sign", src: "ago|before", value: -1 }, + { name: "sign", src: "from now|after|from|in|later", value: 1 }, + { name: "edge", src: "first day|first|beginning", value: -2 }, + { name: "edge", src: "last day", value: 1 }, + { name: "edge", src: "end|last", value: 2 }, + { name: "shift", src: "last", value: -1 }, + { name: "shift", src: "the|this", value: 0 }, + { name: "shift", src: "next", value: 1 }, ], - 'parse': [ - '(?:just)? now', - '{shift} {unit:5-7}', + parse: [ + "(?:just)? now", + "{shift} {unit:5-7}", "{months?} (?:{year}|'{yy})", - '{midday} {4?} {day|weekday}', - '{months},?(?:[-.\\/\\s]{year})?', - '{edge} of (?:day)? {day|weekday}', - '{0} {num}{1?} {weekday} {2} {months},? {year?}', - '{shift?} {day?} {weekday?} {timeMarker?} {midday}', - '{sign?} {3?} {half} {3?} {unit:3-4|unit:7} {sign?}', - '{0?} {edge} {weekday?} {2} {shift?} {unit:4-7?} {months?},? {year?}' + "{midday} {4?} {day|weekday}", + "{months},?(?:[-.\\/\\s]{year})?", + "{edge} of (?:day)? {day|weekday}", + "{0} {num}{1?} {weekday} {2} {months},? {year?}", + "{shift?} {day?} {weekday?} {timeMarker?} {midday}", + "{sign?} {3?} {half} {3?} {unit:3-4|unit:7} {sign?}", + "{0?} {edge} {weekday?} {2} {shift?} {unit:4-7?} {months?},? {year?}", ], - 'timeParse': [ - '{day|weekday}', - '{shift} {unit:5?} {weekday}', - '{0?} {date}{1?} {2?} {months?}', - '{weekday} {2?} {shift} {unit:5}', - '{0?} {num} {2?} {months}\\.?,? {year?}', - '{num?} {unit:4-5} {sign} {day|weekday}', - '{year}[-.\\/\\s]{months}[-.\\/\\s]{date}', - '{0|months} {date?}{1?} of {shift} {unit:6-7}', - '{0?} {num}{1?} {weekday} of {shift} {unit:6}', + timeParse: [ + "{day|weekday}", + "{shift} {unit:5?} {weekday}", + "{0?} {date}{1?} {2?} {months?}", + "{weekday} {2?} {shift} {unit:5}", + "{0?} {num} {2?} {months}\\.?,? {year?}", + "{num?} {unit:4-5} {sign} {day|weekday}", + "{year}[-.\\/\\s]{months}[-.\\/\\s]{date}", + "{0|months} {date?}{1?} of {shift} {unit:6-7}", + "{0?} {num}{1?} {weekday} of {shift} {unit:6}", "{date}[-.\\/\\s]{months}[-.\\/\\s](?:{year}|'?{yy})", - "{weekday?}\\.?,? {months}\\.?,? {date}{1?},? (?:{year}|'{yy})?" + "{weekday?}\\.?,? {months}\\.?,? {date}{1?},? (?:{year}|'{yy})?", + ], + timeFrontParse: [ + "{sign} {num} {unit}", + "{num} {unit} {sign}", + "{4?} {day|weekday}", ], - 'timeFrontParse': [ - '{sign} {num} {unit}', - '{num} {unit} {sign}', - '{4?} {day|weekday}' - ] }; var AmericanEnglishDefinition = getEnglishVariant({ - 'mdy': true, - 'firstDayOfWeek': 0, - 'firstDayOfWeekYear': 1, - 'short': '{MM}/{dd}/{yyyy}', - 'medium': '{Month} {d}, {yyyy}', - 'long': '{Month} {d}, {yyyy} {time}', - 'full': '{Weekday}, {Month} {d}, {yyyy} {time}', - 'stamp': '{Dow} {Mon} {d} {yyyy} {time}', - 'time': '{h}:{mm} {TT}' + mdy: true, + firstDayOfWeek: 0, + firstDayOfWeekYear: 1, + short: "{MM}/{dd}/{yyyy}", + medium: "{Month} {d}, {yyyy}", + long: "{Month} {d}, {yyyy} {time}", + full: "{Weekday}, {Month} {d}, {yyyy} {time}", + stamp: "{Dow} {Mon} {d} {yyyy} {time}", + time: "{h}:{mm} {TT}", }); var BritishEnglishDefinition = getEnglishVariant({ - 'short': '{dd}/{MM}/{yyyy}', - 'medium': '{d} {Month} {yyyy}', - 'long': '{d} {Month} {yyyy} {H}:{mm}', - 'full': '{Weekday}, {d} {Month}, {yyyy} {time}', - 'stamp': '{Dow} {d} {Mon} {yyyy} {time}' + short: "{dd}/{MM}/{yyyy}", + medium: "{d} {Month} {yyyy}", + long: "{d} {Month} {yyyy} {H}:{mm}", + full: "{Weekday}, {d} {Month}, {yyyy} {time}", + stamp: "{Dow} {d} {Mon} {yyyy} {time}", }); var CanadianEnglishDefinition = getEnglishVariant({ - 'short': '{yyyy}-{MM}-{dd}', - 'medium': '{d} {Month}, {yyyy}', - 'long': '{d} {Month}, {yyyy} {H}:{mm}', - 'full': '{Weekday}, {d} {Month}, {yyyy} {time}', - 'stamp': '{Dow} {d} {Mon} {yyyy} {time}' + short: "{yyyy}-{MM}-{dd}", + medium: "{d} {Month}, {yyyy}", + long: "{d} {Month}, {yyyy} {H}:{mm}", + full: "{Weekday}, {d} {Month}, {yyyy} {time}", + stamp: "{Dow} {d} {Mon} {yyyy} {time}", }); var LazyLoadedLocales = { - 'en-US': AmericanEnglishDefinition, - 'en-GB': BritishEnglishDefinition, - 'en-AU': BritishEnglishDefinition, - 'en-CA': CanadianEnglishDefinition + "en-US": AmericanEnglishDefinition, + "en-GB": BritishEnglishDefinition, + "en-AU": BritishEnglishDefinition, + "en-CA": CanadianEnglishDefinition, }; buildLocales(); @@ -5234,21 +5438,20 @@ * ***/ + var DURATION_UNITS = "year|month|week|day|hour|minute|second|millisecond"; - var DURATION_UNITS = 'year|month|week|day|hour|minute|second|millisecond'; - - var DURATION_REG = RegExp('(\\d+)?\\s*('+ DURATION_UNITS +')s?', 'i'); + var DURATION_REG = RegExp("(\\d+)?\\s*(" + DURATION_UNITS + ")s?", "i"); var MULTIPLIERS = { - 'Hours': 60 * 60 * 1000, - 'Minutes': 60 * 1000, - 'Seconds': 1000, - 'Milliseconds': 1 + Hours: 60 * 60 * 1000, + Minutes: 60 * 1000, + Seconds: 1000, + Milliseconds: 1, }; function Range(start, end) { this.start = cloneRangeMember(start); - this.end = cloneRangeMember(end); + this.end = cloneRangeMember(end); } function getRangeMemberPrimitiveValue(m) { @@ -5267,28 +5470,29 @@ function getDateIncrementObject(amt) { var match, val, unit; if (isNumber(amt)) { - return [amt, 'Milliseconds']; + return [amt, "Milliseconds"]; } match = amt.match(DURATION_REG); val = +match[1] || 1; unit = simpleCapitalize(match[2].toLowerCase()); if (unit.match(/hour|minute|second/i)) { - unit += 's'; - } else if (unit === 'Year') { - unit = 'FullYear'; - } else if (unit === 'Week') { - unit = 'Date'; + unit += "s"; + } else if (unit === "Year") { + unit = "FullYear"; + } else if (unit === "Week") { + unit = "Date"; val *= 7; - } else if (unit === 'Day') { - unit = 'Date'; + } else if (unit === "Day") { + unit = "Date"; } return [val, unit]; } function incrementDate(src, amount, unit) { - var mult = MULTIPLIERS[unit], d; + var mult = MULTIPLIERS[unit], + d; if (mult) { - d = new Date(src.getTime() + (amount * mult)); + d = new Date(src.getTime() + amount * mult); } else { d = new Date(src); callDateSet(d, unit, callDateGet(src, unit) + amount); @@ -5296,14 +5500,22 @@ return d; } - var FULL_CAPTURED_DURATION = '((?:\\d+)?\\s*(?:' + DURATION_UNITS + '))s?'; + var FULL_CAPTURED_DURATION = "((?:\\d+)?\\s*(?:" + DURATION_UNITS + "))s?"; // Duration text formats - var RANGE_REG_FROM_TO = /(?:from)?\s*(.+)\s+(?:to|until)\s+(.+)$/i, - RANGE_REG_REAR_DURATION = RegExp('(.+)\\s*for\\s*' + FULL_CAPTURED_DURATION, 'i'), - RANGE_REG_FRONT_DURATION = RegExp('(?:for)?\\s*'+ FULL_CAPTURED_DURATION +'\\s*(?:starting)?\\s(?:at\\s)?(.+)', 'i'); + var RANGE_REG_FROM_TO = /(?:from)?\s*(.+)\s+(?:to|until)\s+(.+)$/i, + RANGE_REG_REAR_DURATION = RegExp( + "(.+)\\s*for\\s*" + FULL_CAPTURED_DURATION, + "i", + ), + RANGE_REG_FRONT_DURATION = RegExp( + "(?:for)?\\s*" + + FULL_CAPTURED_DURATION + + "\\s*(?:starting)?\\s(?:at\\s)?(.+)", + "i", + ); - var DateRangeConstructor = function(start, end) { + var DateRangeConstructor = function (start, end) { if (arguments.length === 1 && isString(start)) { return createDateRangeFromString(start); } @@ -5313,15 +5525,15 @@ function createDateRangeFromString(str) { var match, datetime, duration, dio, start, end; if (sugarDate.get && (match = str.match(RANGE_REG_FROM_TO))) { - start = getDateForRange(match[1].replace('from', 'at')); + start = getDateForRange(match[1].replace("from", "at")); end = sugarDate.get(start, match[2]); return new Range(start, end); } - if (match = str.match(RANGE_REG_FRONT_DURATION)) { + if ((match = str.match(RANGE_REG_FRONT_DURATION))) { duration = match[1]; datetime = match[2]; } - if (match = str.match(RANGE_REG_REAR_DURATION)) { + if ((match = str.match(RANGE_REG_REAR_DURATION))) { datetime = match[1]; duration = match[2]; } @@ -5347,7 +5559,6 @@ } defineStatic(sugarDate, { - /*** * @method range([start], [end]) * @returns Range @@ -5375,8 +5586,7 @@ * @param {string|Date} [end] * ***/ - 'range': DateRangeConstructor - + range: DateRangeConstructor, }); /*** @@ -5393,48 +5603,50 @@ * Sugar.Date.setLocale('ca') * */ - Sugar.Date.addLocale('ca', { - 'plural': true, - 'units': 'milisegon:|s,segon:|s,minut:|s,hor:a|es,di:a|es,setman:a|es,mes:|os,any:|s', - 'months': 'gen:er|,febr:er|,mar:ç|,abr:il|,mai:g|,jun:y|,jul:iol|,ag:ost|,set:embre|,oct:ubre|,nov:embre|,des:embre|', - 'weekdays': 'diumenge|dg,dilluns|dl,dimarts|dt,dimecres|dc,dijous|dj,divendres|dv,dissabte|ds', - 'numerals': 'zero,un,dos,tres,quatre,cinc,sis,set,vuit,nou,deu', - 'tokens': 'el,la,de', - 'short': '{dd}/{MM}/{yyyy}', - 'medium': '{d} {month} {yyyy}', - 'long': '{d} {month} {yyyy} {time}', - 'full': '{weekday} {d} {month} {yyyy} {time}', - 'stamp': '{dow} {d} {mon} {yyyy} {time}', - 'time': '{H}:{mm}', - 'past': '{sign} {num} {unit}', - 'future': '{sign} {num} {unit}', - 'duration': '{num} {unit}', - 'timeMarkers': 'a las', - 'ampm': 'am,pm', - 'modifiers': [ - { 'name': 'day', 'src': "abans d'ahir", 'value': -2 }, - { 'name': 'day', 'src': 'ahir', 'value': -1 }, - { 'name': 'day', 'src': 'avui', 'value': 0 }, - { 'name': 'day', 'src': 'demà|dema', 'value': 1 }, - { 'name': 'sign', 'src': 'fa', 'value': -1 }, - { 'name': 'sign', 'src': 'en', 'value': 1 }, - { 'name': 'shift', 'src': 'passat', 'value': -1 }, - { 'name': 'shift', 'src': 'el proper|la propera', 'value': 1 } + Sugar.Date.addLocale("ca", { + plural: true, + units: + "milisegon:|s,segon:|s,minut:|s,hor:a|es,di:a|es,setman:a|es,mes:|os,any:|s", + months: + "gen:er|,febr:er|,mar:ç|,abr:il|,mai:g|,jun:y|,jul:iol|,ag:ost|,set:embre|,oct:ubre|,nov:embre|,des:embre|", + weekdays: + "diumenge|dg,dilluns|dl,dimarts|dt,dimecres|dc,dijous|dj,divendres|dv,dissabte|ds", + numerals: "zero,un,dos,tres,quatre,cinc,sis,set,vuit,nou,deu", + tokens: "el,la,de", + short: "{dd}/{MM}/{yyyy}", + medium: "{d} {month} {yyyy}", + long: "{d} {month} {yyyy} {time}", + full: "{weekday} {d} {month} {yyyy} {time}", + stamp: "{dow} {d} {mon} {yyyy} {time}", + time: "{H}:{mm}", + past: "{sign} {num} {unit}", + future: "{sign} {num} {unit}", + duration: "{num} {unit}", + timeMarkers: "a las", + ampm: "am,pm", + modifiers: [ + { name: "day", src: "abans d'ahir", value: -2 }, + { name: "day", src: "ahir", value: -1 }, + { name: "day", src: "avui", value: 0 }, + { name: "day", src: "demà|dema", value: 1 }, + { name: "sign", src: "fa", value: -1 }, + { name: "sign", src: "en", value: 1 }, + { name: "shift", src: "passat", value: -1 }, + { name: "shift", src: "el proper|la propera", value: 1 }, ], - 'parse': [ - '{sign} {num} {unit}', - '{num} {unit} {sign}', - '{0?}{1?} {unit:5-7} {shift}', - '{0?}{1?} {shift} {unit:5-7}' + parse: [ + "{sign} {num} {unit}", + "{num} {unit} {sign}", + "{0?}{1?} {unit:5-7} {shift}", + "{0?}{1?} {shift} {unit:5-7}", + ], + timeParse: [ + "{shift} {weekday}", + "{weekday} {shift}", + "{date?} {2?} {months}\\.? {2?} {year?}", ], - 'timeParse': [ - '{shift} {weekday}', - '{weekday} {shift}', - '{date?} {2?} {months}\\.? {2?} {year?}' - ] }); - /* * Danish locale definition. * See the readme for customization and more information. @@ -5443,54 +5655,57 @@ * Sugar.Date.setLocale('da') * */ - Sugar.Date.addLocale('da', { - 'plural': true, - 'units': 'millisekund:|er,sekund:|er,minut:|ter,tim:e|er,dag:|e,ug:e|er|en,måned:|er|en+maaned:|er|en,år:||et+aar:||et', - 'months': 'jan:uar|,feb:ruar|,mar:ts|,apr:il|,maj,jun:i|,jul:i|,aug:ust|,sep:tember|,okt:ober|,nov:ember|,dec:ember|', - 'weekdays': 'søn:dag|+son:dag|,man:dag|,tir:sdag|,ons:dag|,tor:sdag|,fre:dag|,lør:dag|+lor:dag|', - 'numerals': 'nul,en|et,to,tre,fire,fem,seks,syv,otte,ni,ti', - 'tokens': 'den,for', - 'articles': 'den', - 'short': '{dd}-{MM}-{yyyy}', - 'medium': '{d}. {month} {yyyy}', - 'long': '{d}. {month} {yyyy} {time}', - 'full': '{weekday} d. {d}. {month} {yyyy} {time}', - 'stamp': '{dow} {d} {mon} {yyyy} {time}', - 'time': '{H}:{mm}', - 'past': '{num} {unit} {sign}', - 'future': '{sign} {num} {unit}', - 'duration': '{num} {unit}', - 'ampm': 'am,pm', - 'modifiers': [ - { 'name': 'day', 'src': 'forgårs|i forgårs|forgaars|i forgaars', 'value': -2 }, - { 'name': 'day', 'src': 'i går|igår|i gaar|igaar', 'value': -1 }, - { 'name': 'day', 'src': 'i dag|idag', 'value': 0 }, - { 'name': 'day', 'src': 'i morgen|imorgen', 'value': 1 }, - { 'name': 'day', 'src': 'over morgon|overmorgen|i over morgen|i overmorgen|iovermorgen', 'value': 2 }, - { 'name': 'sign', 'src': 'siden', 'value': -1 }, - { 'name': 'sign', 'src': 'om', 'value': 1 }, - { 'name': 'shift', 'src': 'i sidste|sidste', 'value': -1 }, - { 'name': 'shift', 'src': 'denne', 'value': 0 }, - { 'name': 'shift', 'src': 'næste|naeste', 'value': 1 } + Sugar.Date.addLocale("da", { + plural: true, + units: + "millisekund:|er,sekund:|er,minut:|ter,tim:e|er,dag:|e,ug:e|er|en,måned:|er|en+maaned:|er|en,år:||et+aar:||et", + months: + "jan:uar|,feb:ruar|,mar:ts|,apr:il|,maj,jun:i|,jul:i|,aug:ust|,sep:tember|,okt:ober|,nov:ember|,dec:ember|", + weekdays: + "søn:dag|+son:dag|,man:dag|,tir:sdag|,ons:dag|,tor:sdag|,fre:dag|,lør:dag|+lor:dag|", + numerals: "nul,en|et,to,tre,fire,fem,seks,syv,otte,ni,ti", + tokens: "den,for", + articles: "den", + short: "{dd}-{MM}-{yyyy}", + medium: "{d}. {month} {yyyy}", + long: "{d}. {month} {yyyy} {time}", + full: "{weekday} d. {d}. {month} {yyyy} {time}", + stamp: "{dow} {d} {mon} {yyyy} {time}", + time: "{H}:{mm}", + past: "{num} {unit} {sign}", + future: "{sign} {num} {unit}", + duration: "{num} {unit}", + ampm: "am,pm", + modifiers: [ + { name: "day", src: "forgårs|i forgårs|forgaars|i forgaars", value: -2 }, + { name: "day", src: "i går|igår|i gaar|igaar", value: -1 }, + { name: "day", src: "i dag|idag", value: 0 }, + { name: "day", src: "i morgen|imorgen", value: 1 }, + { + name: "day", + src: "over morgon|overmorgen|i over morgen|i overmorgen|iovermorgen", + value: 2, + }, + { name: "sign", src: "siden", value: -1 }, + { name: "sign", src: "om", value: 1 }, + { name: "shift", src: "i sidste|sidste", value: -1 }, + { name: "shift", src: "denne", value: 0 }, + { name: "shift", src: "næste|naeste", value: 1 }, ], - 'parse': [ - '{months} {year?}', - '{num} {unit} {sign}', - '{sign} {num} {unit}', - '{1?} {num} {unit} {sign}', - '{shift} {unit:5-7}' + parse: [ + "{months} {year?}", + "{num} {unit} {sign}", + "{sign} {num} {unit}", + "{1?} {num} {unit} {sign}", + "{shift} {unit:5-7}", ], - 'timeParse': [ - '{day|weekday}', - '{date} {months?}\\.? {year?}' + timeParse: ["{day|weekday}", "{date} {months?}\\.? {year?}"], + timeFrontParse: [ + "{shift} {weekday}", + "{0?} {weekday?},? {date}\\.? {months?}\\.? {year?}", ], - 'timeFrontParse': [ - '{shift} {weekday}', - '{0?} {weekday?},? {date}\\.? {months?}\\.? {year?}' - ] }); - /* * German locale definition. * See the readme for customization and more information. @@ -5499,52 +5714,59 @@ * Sugar.Date.setLocale('de') * */ - Sugar.Date.addLocale('de', { - 'plural': true, - 'units': 'Millisekunde:|n,Sekunde:|n,Minute:|n,Stunde:|n,Tag:|en,Woche:|n,Monat:|en,Jahr:|en|e', - 'months': 'Jan:uar|,Feb:ruar|,M:är|ärz|ar|arz,Apr:il|,Mai,Juni,Juli,Aug:ust|,Sept:ember|,Okt:ober|,Nov:ember|,Dez:ember|', - 'weekdays': 'So:nntag|,Mo:ntag|,Di:enstag|,Mi:ttwoch|,Do:nnerstag|,Fr:eitag|,Sa:mstag|', - 'numerals': 'null,ein:|e|er|en|em,zwei,drei,vier,fuenf,sechs,sieben,acht,neun,zehn', - 'tokens': 'der', - 'short': '{dd}.{MM}.{yyyy}', - 'medium': '{d}. {Month} {yyyy}', - 'long': '{d}. {Month} {yyyy} {time}', - 'full': '{Weekday}, {d}. {Month} {yyyy} {time}', - 'stamp': '{Dow} {d} {Mon} {yyyy} {time}', - 'time': '{H}:{mm}', - 'past': '{sign} {num} {unit}', - 'future': '{sign} {num} {unit}', - 'duration': '{num} {unit}', - 'timeMarkers': 'um', - 'ampm': 'am,pm', - 'modifiers': [ - { 'name': 'day', 'src': 'vorgestern', 'value': -2 }, - { 'name': 'day', 'src': 'gestern', 'value': -1 }, - { 'name': 'day', 'src': 'heute', 'value': 0 }, - { 'name': 'day', 'src': 'morgen', 'value': 1 }, - { 'name': 'day', 'src': 'übermorgen|ubermorgen|uebermorgen', 'value': 2 }, - { 'name': 'sign', 'src': 'vor:|her', 'value': -1 }, - { 'name': 'sign', 'src': 'in', 'value': 1 }, - { 'name': 'shift', 'src': 'letzte:|r|n|s', 'value': -1 }, - { 'name': 'shift', 'src': 'nächste:|r|n|s+nachste:|r|n|s+naechste:|r|n|s+kommende:n|r', 'value': 1 } + Sugar.Date.addLocale("de", { + plural: true, + units: + "Millisekunde:|n,Sekunde:|n,Minute:|n,Stunde:|n,Tag:|en,Woche:|n,Monat:|en,Jahr:|en|e", + months: + "Jan:uar|,Feb:ruar|,M:är|ärz|ar|arz,Apr:il|,Mai,Juni,Juli,Aug:ust|,Sept:ember|,Okt:ober|,Nov:ember|,Dez:ember|", + weekdays: + "So:nntag|,Mo:ntag|,Di:enstag|,Mi:ttwoch|,Do:nnerstag|,Fr:eitag|,Sa:mstag|", + numerals: + "null,ein:|e|er|en|em,zwei,drei,vier,fuenf,sechs,sieben,acht,neun,zehn", + tokens: "der", + short: "{dd}.{MM}.{yyyy}", + medium: "{d}. {Month} {yyyy}", + long: "{d}. {Month} {yyyy} {time}", + full: "{Weekday}, {d}. {Month} {yyyy} {time}", + stamp: "{Dow} {d} {Mon} {yyyy} {time}", + time: "{H}:{mm}", + past: "{sign} {num} {unit}", + future: "{sign} {num} {unit}", + duration: "{num} {unit}", + timeMarkers: "um", + ampm: "am,pm", + modifiers: [ + { name: "day", src: "vorgestern", value: -2 }, + { name: "day", src: "gestern", value: -1 }, + { name: "day", src: "heute", value: 0 }, + { name: "day", src: "morgen", value: 1 }, + { name: "day", src: "übermorgen|ubermorgen|uebermorgen", value: 2 }, + { name: "sign", src: "vor:|her", value: -1 }, + { name: "sign", src: "in", value: 1 }, + { name: "shift", src: "letzte:|r|n|s", value: -1 }, + { + name: "shift", + src: "nächste:|r|n|s+nachste:|r|n|s+naechste:|r|n|s+kommende:n|r", + value: 1, + }, ], - 'parse': [ - '{months} {year?}', - '{sign} {num} {unit}', - '{num} {unit} {sign}', - '{shift} {unit:5-7}' + parse: [ + "{months} {year?}", + "{sign} {num} {unit}", + "{num} {unit} {sign}", + "{shift} {unit:5-7}", ], - 'timeParse': [ - '{shift?} {day|weekday}', - '{weekday?},? {date}\\.? {months?}\\.? {year?}' + timeParse: [ + "{shift?} {day|weekday}", + "{weekday?},? {date}\\.? {months?}\\.? {year?}", + ], + timeFrontParse: [ + "{shift} {weekday}", + "{weekday?},? {date}\\.? {months?}\\.? {year?}", ], - 'timeFrontParse': [ - '{shift} {weekday}', - '{weekday?},? {date}\\.? {months?}\\.? {year?}' - ] }); - /* * Spanish locale definition. * See the readme for customization and more information. @@ -5553,52 +5775,54 @@ * Sugar.Date.setLocale('es') * */ - Sugar.Date.addLocale('es', { - 'plural': true, - 'units': 'milisegundo:|s,segundo:|s,minuto:|s,hora:|s,día|días|dia|dias,semana:|s,mes:|es,año|años|ano|anos', - 'months': 'ene:ro|,feb:rero|,mar:zo|,abr:il|,may:o|,jun:io|,jul:io|,ago:sto|,sep:tiembre|,oct:ubre|,nov:iembre|,dic:iembre|', - 'weekdays': 'dom:ingo|,lun:es|,mar:tes|,mié:rcoles|+mie:rcoles|,jue:ves|,vie:rnes|,sáb:ado|+sab:ado|', - 'numerals': 'cero,uno,dos,tres,cuatro,cinco,seis,siete,ocho,nueve,diez', - 'tokens': 'el,la,de', - 'short': '{dd}/{MM}/{yyyy}', - 'medium': '{d} de {Month} de {yyyy}', - 'long': '{d} de {Month} de {yyyy} {time}', - 'full': '{weekday}, {d} de {month} de {yyyy} {time}', - 'stamp': '{dow} {d} {mon} {yyyy} {time}', - 'time': '{H}:{mm}', - 'past': '{sign} {num} {unit}', - 'future': '{sign} {num} {unit}', - 'duration': '{num} {unit}', - 'timeMarkers': 'a las', - 'ampm': 'am,pm', - 'modifiers': [ - { 'name': 'day', 'src': 'anteayer', 'value': -2 }, - { 'name': 'day', 'src': 'ayer', 'value': -1 }, - { 'name': 'day', 'src': 'hoy', 'value': 0 }, - { 'name': 'day', 'src': 'mañana|manana', 'value': 1 }, - { 'name': 'sign', 'src': 'hace', 'value': -1 }, - { 'name': 'sign', 'src': 'dentro de', 'value': 1 }, - { 'name': 'shift', 'src': 'pasad:o|a', 'value': -1 }, - { 'name': 'shift', 'src': 'próximo|próxima|proximo|proxima', 'value': 1 } + Sugar.Date.addLocale("es", { + plural: true, + units: + "milisegundo:|s,segundo:|s,minuto:|s,hora:|s,día|días|dia|dias,semana:|s,mes:|es,año|años|ano|anos", + months: + "ene:ro|,feb:rero|,mar:zo|,abr:il|,may:o|,jun:io|,jul:io|,ago:sto|,sep:tiembre|,oct:ubre|,nov:iembre|,dic:iembre|", + weekdays: + "dom:ingo|,lun:es|,mar:tes|,mié:rcoles|+mie:rcoles|,jue:ves|,vie:rnes|,sáb:ado|+sab:ado|", + numerals: "cero,uno,dos,tres,cuatro,cinco,seis,siete,ocho,nueve,diez", + tokens: "el,la,de", + short: "{dd}/{MM}/{yyyy}", + medium: "{d} de {Month} de {yyyy}", + long: "{d} de {Month} de {yyyy} {time}", + full: "{weekday}, {d} de {month} de {yyyy} {time}", + stamp: "{dow} {d} {mon} {yyyy} {time}", + time: "{H}:{mm}", + past: "{sign} {num} {unit}", + future: "{sign} {num} {unit}", + duration: "{num} {unit}", + timeMarkers: "a las", + ampm: "am,pm", + modifiers: [ + { name: "day", src: "anteayer", value: -2 }, + { name: "day", src: "ayer", value: -1 }, + { name: "day", src: "hoy", value: 0 }, + { name: "day", src: "mañana|manana", value: 1 }, + { name: "sign", src: "hace", value: -1 }, + { name: "sign", src: "dentro de", value: 1 }, + { name: "shift", src: "pasad:o|a", value: -1 }, + { name: "shift", src: "próximo|próxima|proximo|proxima", value: 1 }, ], - 'parse': [ - '{months} {2?} {year?}', - '{sign} {num} {unit}', - '{num} {unit} {sign}', - '{0?}{1?} {unit:5-7} {shift}', - '{0?}{1?} {shift} {unit:5-7}' + parse: [ + "{months} {2?} {year?}", + "{sign} {num} {unit}", + "{num} {unit} {sign}", + "{0?}{1?} {unit:5-7} {shift}", + "{0?}{1?} {shift} {unit:5-7}", ], - 'timeParse': [ - '{shift?} {day|weekday} {shift?}', - '{date} {2?} {months?}\\.? {2?} {year?}' + timeParse: [ + "{shift?} {day|weekday} {shift?}", + "{date} {2?} {months?}\\.? {2?} {year?}", + ], + timeFrontParse: [ + "{shift?} {weekday} {shift?}", + "{date} {2?} {months?}\\.? {2?} {year?}", ], - 'timeFrontParse': [ - '{shift?} {weekday} {shift?}', - '{date} {2?} {months?}\\.? {2?} {year?}' - ] }); - /* * Finnish locale definition. * See the readme for customization and more information. @@ -5607,65 +5831,72 @@ * Sugar.Date.setLocale('fi') * */ - Sugar.Date.addLocale('fi', { - 'plural': true, - 'units': 'millisekun:ti|tia|nin|teja|tina,sekun:ti|tia|nin|teja|tina,minuut:ti|tia|in|teja|tina,tun:ti|tia|nin|teja|tina,päiv:ä|ää|än|iä|änä,viik:ko|koa|on|olla|koja|kona,kuukau:si|tta|den+kuussa,vuo:si|tta|den|sia|tena|nna', - 'months': 'tammi:kuuta||kuu,helmi:kuuta||kuu,maalis:kuuta||kuu,huhti:kuuta||kuu,touko:kuuta||kuu,kesä:kuuta||kuu,heinä:kuuta||kuu,elo:kuuta||kuu,syys:kuuta||kuu,loka:kuuta||kuu,marras:kuuta||kuu,joulu:kuuta||kuu', - 'weekdays': 'su:nnuntai||nnuntaina,ma:anantai||anantaina,ti:istai||istaina,ke:skiviikko||skiviikkona,to:rstai||rstaina,pe:rjantai||rjantaina,la:uantai||uantaina', - 'numerals': 'nolla,yksi|ensimmäinen,kaksi|toinen,kolm:e|as,neljä:|s,vii:si|des,kuu:si|des,seitsemä:n|s,kahdeksa:n|s,yhdeksä:n|s,kymmene:n|s', - 'short': '{d}.{M}.{yyyy}', - 'medium': '{d}. {month} {yyyy}', - 'long': '{d}. {month} {yyyy} klo {time}', - 'full': '{weekday} {d}. {month} {yyyy} klo {time}', - 'stamp': '{dow} {d} {mon} {yyyy} {time}', - 'time': '{H}.{mm}', - 'timeMarkers': 'klo,kello', - 'ordinalSuffix': '.', - 'relative': function(num, unit, ms, format) { - var units = this['units']; + Sugar.Date.addLocale("fi", { + plural: true, + units: + "millisekun:ti|tia|nin|teja|tina,sekun:ti|tia|nin|teja|tina,minuut:ti|tia|in|teja|tina,tun:ti|tia|nin|teja|tina,päiv:ä|ää|än|iä|änä,viik:ko|koa|on|olla|koja|kona,kuukau:si|tta|den+kuussa,vuo:si|tta|den|sia|tena|nna", + months: + "tammi:kuuta||kuu,helmi:kuuta||kuu,maalis:kuuta||kuu,huhti:kuuta||kuu,touko:kuuta||kuu,kesä:kuuta||kuu,heinä:kuuta||kuu,elo:kuuta||kuu,syys:kuuta||kuu,loka:kuuta||kuu,marras:kuuta||kuu,joulu:kuuta||kuu", + weekdays: + "su:nnuntai||nnuntaina,ma:anantai||anantaina,ti:istai||istaina,ke:skiviikko||skiviikkona,to:rstai||rstaina,pe:rjantai||rjantaina,la:uantai||uantaina", + numerals: + "nolla,yksi|ensimmäinen,kaksi|toinen,kolm:e|as,neljä:|s,vii:si|des,kuu:si|des,seitsemä:n|s,kahdeksa:n|s,yhdeksä:n|s,kymmene:n|s", + short: "{d}.{M}.{yyyy}", + medium: "{d}. {month} {yyyy}", + long: "{d}. {month} {yyyy} klo {time}", + full: "{weekday} {d}. {month} {yyyy} klo {time}", + stamp: "{dow} {d} {mon} {yyyy} {time}", + time: "{H}.{mm}", + timeMarkers: "klo,kello", + ordinalSuffix: ".", + relative: function (num, unit, ms, format) { + var units = this["units"]; function numberWithUnit(mult) { - return num + ' ' + units[(8 * mult) + unit]; + return num + " " + units[8 * mult + unit]; } function baseUnit() { return numberWithUnit(num === 1 ? 0 : 1); } - switch(format) { - case 'duration': return baseUnit(); - case 'past': return baseUnit() + ' sitten'; - case 'future': return numberWithUnit(2) + ' kuluttua'; + switch (format) { + case "duration": + return baseUnit(); + case "past": + return baseUnit() + " sitten"; + case "future": + return numberWithUnit(2) + " kuluttua"; } }, - 'modifiers': [ - { 'name': 'day', 'src': 'toissa päivänä', 'value': -2 }, - { 'name': 'day', 'src': 'eilen|eilistä', 'value': -1 }, - { 'name': 'day', 'src': 'tänään', 'value': 0 }, - { 'name': 'day', 'src': 'huomenna|huomista', 'value': 1 }, - { 'name': 'day', 'src': 'ylihuomenna|ylihuomista', 'value': 2 }, - { 'name': 'sign', 'src': 'sitten|aiemmin', 'value': -1 }, - { 'name': 'sign', 'src': 'päästä|kuluttua|myöhemmin', 'value': 1 }, - { 'name': 'edge', 'src': 'lopussa', 'value': 2 }, - { 'name': 'edge', 'src': 'ensimmäinen|ensimmäisenä', 'value': -2 }, - { 'name': 'shift', 'src': 'edel:linen|lisenä', 'value': -1 }, - { 'name': 'shift', 'src': 'viime', 'value': -1 }, - { 'name': 'shift', 'src': 'tä:llä|ssä|nä|mä', 'value': 0 }, - { 'name': 'shift', 'src': 'seuraava|seuraavana|tuleva|tulevana|ensi', 'value': 1 } + modifiers: [ + { name: "day", src: "toissa päivänä", value: -2 }, + { name: "day", src: "eilen|eilistä", value: -1 }, + { name: "day", src: "tänään", value: 0 }, + { name: "day", src: "huomenna|huomista", value: 1 }, + { name: "day", src: "ylihuomenna|ylihuomista", value: 2 }, + { name: "sign", src: "sitten|aiemmin", value: -1 }, + { name: "sign", src: "päästä|kuluttua|myöhemmin", value: 1 }, + { name: "edge", src: "lopussa", value: 2 }, + { name: "edge", src: "ensimmäinen|ensimmäisenä", value: -2 }, + { name: "shift", src: "edel:linen|lisenä", value: -1 }, + { name: "shift", src: "viime", value: -1 }, + { name: "shift", src: "tä:llä|ssä|nä|mä", value: 0 }, + { + name: "shift", + src: "seuraava|seuraavana|tuleva|tulevana|ensi", + value: 1, + }, ], - 'parse': [ - '{months} {year?}', - '{shift} {unit:5-7}' + parse: ["{months} {year?}", "{shift} {unit:5-7}"], + timeParse: [ + "{shift?} {day|weekday}", + "{weekday?},? {date}\\.? {months?}\\.? {year?}", ], - 'timeParse': [ - '{shift?} {day|weekday}', - '{weekday?},? {date}\\.? {months?}\\.? {year?}' + timeFrontParse: [ + "{shift?} {day|weekday}", + "{num?} {unit} {sign}", + "{weekday?},? {date}\\.? {months?}\\.? {year?}", ], - 'timeFrontParse': [ - '{shift?} {day|weekday}', - '{num?} {unit} {sign}', - '{weekday?},? {date}\\.? {months?}\\.? {year?}' - ] }); - /* * French locale definition. * See the readme for customization and more information. @@ -5674,49 +5905,51 @@ * Sugar.Date.setLocale('fr') * */ - Sugar.Date.addLocale('fr', { - 'plural': true, - 'units': 'milliseconde:|s,seconde:|s,minute:|s,heure:|s,jour:|s,semaine:|s,mois,an:|s|née|nee', - 'months': 'janv:ier|,févr:ier|+fevr:ier|,mars,avr:il|,mai,juin,juil:let|,août,sept:embre|,oct:obre|,nov:embre|,déc:embre|+dec:embre|', - 'weekdays': 'dim:anche|,lun:di|,mar:di|,mer:credi|,jeu:di|,ven:dredi|,sam:edi|', - 'numerals': 'zéro,un:|e,deux,trois,quatre,cinq,six,sept,huit,neuf,dix', - 'tokens': "l'|la|le,er", - 'short': '{dd}/{MM}/{yyyy}', - 'medium': '{d} {month} {yyyy}', - 'long': '{d} {month} {yyyy} {time}', - 'full': '{weekday} {d} {month} {yyyy} {time}', - 'stamp': '{dow} {d} {mon} {yyyy} {time}', - 'time': '{H}:{mm}', - 'past': '{sign} {num} {unit}', - 'future': '{sign} {num} {unit}', - 'duration': '{num} {unit}', - 'timeMarkers': 'à', - 'ampm': 'am,pm', - 'modifiers': [ - { 'name': 'day', 'src': 'hier', 'value': -1 }, - { 'name': 'day', 'src': "aujourd'hui", 'value': 0 }, - { 'name': 'day', 'src': 'demain', 'value': 1 }, - { 'name': 'sign', 'src': 'il y a', 'value': -1 }, - { 'name': 'sign', 'src': "dans|d'ici", 'value': 1 }, - { 'name': 'shift', 'src': 'derni:èr|er|ère|ere', 'value': -1 }, - { 'name': 'shift', 'src': 'prochain:|e', 'value': 1 } + Sugar.Date.addLocale("fr", { + plural: true, + units: + "milliseconde:|s,seconde:|s,minute:|s,heure:|s,jour:|s,semaine:|s,mois,an:|s|née|nee", + months: + "janv:ier|,févr:ier|+fevr:ier|,mars,avr:il|,mai,juin,juil:let|,août,sept:embre|,oct:obre|,nov:embre|,déc:embre|+dec:embre|", + weekdays: + "dim:anche|,lun:di|,mar:di|,mer:credi|,jeu:di|,ven:dredi|,sam:edi|", + numerals: "zéro,un:|e,deux,trois,quatre,cinq,six,sept,huit,neuf,dix", + tokens: "l'|la|le,er", + short: "{dd}/{MM}/{yyyy}", + medium: "{d} {month} {yyyy}", + long: "{d} {month} {yyyy} {time}", + full: "{weekday} {d} {month} {yyyy} {time}", + stamp: "{dow} {d} {mon} {yyyy} {time}", + time: "{H}:{mm}", + past: "{sign} {num} {unit}", + future: "{sign} {num} {unit}", + duration: "{num} {unit}", + timeMarkers: "à", + ampm: "am,pm", + modifiers: [ + { name: "day", src: "hier", value: -1 }, + { name: "day", src: "aujourd'hui", value: 0 }, + { name: "day", src: "demain", value: 1 }, + { name: "sign", src: "il y a", value: -1 }, + { name: "sign", src: "dans|d'ici", value: 1 }, + { name: "shift", src: "derni:èr|er|ère|ere", value: -1 }, + { name: "shift", src: "prochain:|e", value: 1 }, ], - 'parse': [ - '{months} {year?}', - '{sign} {num} {unit}', - '{0?} {unit:5-7} {shift}' + parse: [ + "{months} {year?}", + "{sign} {num} {unit}", + "{0?} {unit:5-7} {shift}", ], - 'timeParse': [ - '{day|weekday} {shift?}', - '{weekday?},? {0?} {date}{1?} {months}\\.? {year?}' + timeParse: [ + "{day|weekday} {shift?}", + "{weekday?},? {0?} {date}{1?} {months}\\.? {year?}", + ], + timeFrontParse: [ + "{0?} {weekday} {shift}", + "{weekday?},? {0?} {date}{1?} {months}\\.? {year?}", ], - 'timeFrontParse': [ - '{0?} {weekday} {shift}', - '{weekday?},? {0?} {date}{1?} {months}\\.? {year?}' - ] }); - /* * Italian locale definition. * See the readme for customization and more information. @@ -5725,51 +5958,54 @@ * Sugar.Date.setLocale('it') * */ - Sugar.Date.addLocale('it', { - 'plural': true, - 'units': 'millisecond:o|i,second:o|i,minut:o|i,or:a|e,giorn:o|i,settiman:a|e,mes:e|i,ann:o|i', - 'months': 'gen:naio|,feb:braio|,mar:zo|,apr:ile|,mag:gio|,giu:gno|,lug:lio|,ago:sto|,set:tembre|,ott:obre|,nov:embre|,dic:embre|', - 'weekdays': 'dom:enica|,lun:edì||edi,mar:tedì||tedi,mer:coledì||coledi,gio:vedì||vedi,ven:erdì||erdi,sab:ato|', - 'numerals': "zero,un:|a|o|',due,tre,quattro,cinque,sei,sette,otto,nove,dieci", - 'tokens': "l'|la|il", - 'short': '{dd}/{MM}/{yyyy}', - 'medium': '{d} {month} {yyyy}', - 'long': '{d} {month} {yyyy} {time}', - 'full': '{weekday}, {d} {month} {yyyy} {time}', - 'stamp': '{dow} {d} {mon} {yyyy} {time}', - 'time': '{H}:{mm}', - 'past': '{num} {unit} {sign}', - 'future': '{num} {unit} {sign}', - 'duration': '{num} {unit}', - 'timeMarkers': 'alle', - 'ampm': 'am,pm', - 'modifiers': [ - { 'name': 'day', 'src': 'ieri', 'value': -1 }, - { 'name': 'day', 'src': 'oggi', 'value': 0 }, - { 'name': 'day', 'src': 'domani', 'value': 1 }, - { 'name': 'day', 'src': 'dopodomani', 'value': 2 }, - { 'name': 'sign', 'src': 'fa', 'value': -1 }, - { 'name': 'sign', 'src': 'da adesso', 'value': 1 }, - { 'name': 'shift', 'src': 'scors:o|a', 'value': -1 }, - { 'name': 'shift', 'src': 'prossim:o|a', 'value': 1 } + Sugar.Date.addLocale("it", { + plural: true, + units: + "millisecond:o|i,second:o|i,minut:o|i,or:a|e,giorn:o|i,settiman:a|e,mes:e|i,ann:o|i", + months: + "gen:naio|,feb:braio|,mar:zo|,apr:ile|,mag:gio|,giu:gno|,lug:lio|,ago:sto|,set:tembre|,ott:obre|,nov:embre|,dic:embre|", + weekdays: + "dom:enica|,lun:edì||edi,mar:tedì||tedi,mer:coledì||coledi,gio:vedì||vedi,ven:erdì||erdi,sab:ato|", + numerals: + "zero,un:|a|o|',due,tre,quattro,cinque,sei,sette,otto,nove,dieci", + tokens: "l'|la|il", + short: "{dd}/{MM}/{yyyy}", + medium: "{d} {month} {yyyy}", + long: "{d} {month} {yyyy} {time}", + full: "{weekday}, {d} {month} {yyyy} {time}", + stamp: "{dow} {d} {mon} {yyyy} {time}", + time: "{H}:{mm}", + past: "{num} {unit} {sign}", + future: "{num} {unit} {sign}", + duration: "{num} {unit}", + timeMarkers: "alle", + ampm: "am,pm", + modifiers: [ + { name: "day", src: "ieri", value: -1 }, + { name: "day", src: "oggi", value: 0 }, + { name: "day", src: "domani", value: 1 }, + { name: "day", src: "dopodomani", value: 2 }, + { name: "sign", src: "fa", value: -1 }, + { name: "sign", src: "da adesso", value: 1 }, + { name: "shift", src: "scors:o|a", value: -1 }, + { name: "shift", src: "prossim:o|a", value: 1 }, ], - 'parse': [ - '{months} {year?}', - '{num} {unit} {sign}', - '{0?} {unit:5-7} {shift}', - '{0?} {shift} {unit:5-7}' + parse: [ + "{months} {year?}", + "{num} {unit} {sign}", + "{0?} {unit:5-7} {shift}", + "{0?} {shift} {unit:5-7}", ], - 'timeParse': [ - '{shift?} {day|weekday}', - '{weekday?},? {date} {months?}\\.? {year?}' + timeParse: [ + "{shift?} {day|weekday}", + "{weekday?},? {date} {months?}\\.? {year?}", + ], + timeFrontParse: [ + "{shift?} {day|weekday}", + "{weekday?},? {date} {months?}\\.? {year?}", ], - 'timeFrontParse': [ - '{shift?} {day|weekday}', - '{weekday?},? {date} {months?}\\.? {year?}' - ] }); - /* * Japanese locale definition. * See the readme for customization and more information. @@ -5778,66 +6014,61 @@ * Sugar.Date.setLocale('ja') * */ - Sugar.Date.addLocale('ja', { - 'ampmFront': true, - 'numeralUnits': true, - 'allowsFullWidth': true, - 'timeMarkerOptional': true, - 'firstDayOfWeek': 0, - 'firstDayOfWeekYear': 1, - 'units': 'ミリ秒,秒,分,時間,日,週間|週,ヶ月|ヵ月|月,年|年度', - 'weekdays': '日:曜日||曜,月:曜日||曜,火:曜日||曜,水:曜日||曜,木:曜日||曜,金:曜日||曜,土:曜日||曜', - 'numerals': '〇,一,二,三,四,五,六,七,八,九', - 'placeholders': '十,百,千,万', - 'timeSuffixes': ',秒,分,時,日,,月,年度?', - 'short': '{yyyy}/{MM}/{dd}', - 'medium': '{yyyy}年{M}月{d}日', - 'long': '{yyyy}年{M}月{d}日{time}', - 'full': '{yyyy}年{M}月{d}日{time} {weekday}', - 'stamp': '{yyyy}年{M}月{d}日 {H}:{mm} {dow}', - 'time': '{tt}{h}時{mm}分', - 'past': '{num}{unit}{sign}', - 'future': '{num}{unit}{sign}', - 'duration': '{num}{unit}', - 'ampm': '午前,午後', - 'modifiers': [ - { 'name': 'day', 'src': '一昨々日|前々々日', 'value': -3 }, - { 'name': 'day', 'src': '一昨日|おととい|前々日', 'value': -2 }, - { 'name': 'day', 'src': '昨日|前日', 'value': -1 }, - { 'name': 'day', 'src': '今日|当日|本日', 'value': 0 }, - { 'name': 'day', 'src': '明日|翌日|次日', 'value': 1 }, - { 'name': 'day', 'src': '明後日|翌々日', 'value': 2 }, - { 'name': 'day', 'src': '明々後日|翌々々日', 'value': 3 }, - { 'name': 'sign', 'src': '前', 'value': -1 }, - { 'name': 'sign', 'src': '後', 'value': 1 }, - { 'name': 'edge', 'src': '始|初日|頭', 'value': -2 }, - { 'name': 'edge', 'src': '末|尻', 'value': 2 }, - { 'name': 'edge', 'src': '末日', 'value': 1 }, - { 'name': 'shift', 'src': '一昨々|前々々', 'value': -3 }, - { 'name': 'shift', 'src': '一昨|前々|先々', 'value': -2 }, - { 'name': 'shift', 'src': '先|昨|去|前', 'value': -1 }, - { 'name': 'shift', 'src': '今|本|当', 'value': 0 }, - { 'name': 'shift', 'src': '来|明|翌|次', 'value': 1 }, - { 'name': 'shift', 'src': '明後|翌々|次々|再来|さ来', 'value': 2 }, - { 'name': 'shift', 'src': '明々後|翌々々', 'value': 3 } + Sugar.Date.addLocale("ja", { + ampmFront: true, + numeralUnits: true, + allowsFullWidth: true, + timeMarkerOptional: true, + firstDayOfWeek: 0, + firstDayOfWeekYear: 1, + units: "ミリ秒,秒,分,時間,日,週間|週,ヶ月|ヵ月|月,年|年度", + weekdays: + "日:曜日||曜,月:曜日||曜,火:曜日||曜,水:曜日||曜,木:曜日||曜,金:曜日||曜,土:曜日||曜", + numerals: "〇,一,二,三,四,五,六,七,八,九", + placeholders: "十,百,千,万", + timeSuffixes: ",秒,分,時,日,,月,年度?", + short: "{yyyy}/{MM}/{dd}", + medium: "{yyyy}年{M}月{d}日", + long: "{yyyy}年{M}月{d}日{time}", + full: "{yyyy}年{M}月{d}日{time} {weekday}", + stamp: "{yyyy}年{M}月{d}日 {H}:{mm} {dow}", + time: "{tt}{h}時{mm}分", + past: "{num}{unit}{sign}", + future: "{num}{unit}{sign}", + duration: "{num}{unit}", + ampm: "午前,午後", + modifiers: [ + { name: "day", src: "一昨々日|前々々日", value: -3 }, + { name: "day", src: "一昨日|おととい|前々日", value: -2 }, + { name: "day", src: "昨日|前日", value: -1 }, + { name: "day", src: "今日|当日|本日", value: 0 }, + { name: "day", src: "明日|翌日|次日", value: 1 }, + { name: "day", src: "明後日|翌々日", value: 2 }, + { name: "day", src: "明々後日|翌々々日", value: 3 }, + { name: "sign", src: "前", value: -1 }, + { name: "sign", src: "後", value: 1 }, + { name: "edge", src: "始|初日|頭", value: -2 }, + { name: "edge", src: "末|尻", value: 2 }, + { name: "edge", src: "末日", value: 1 }, + { name: "shift", src: "一昨々|前々々", value: -3 }, + { name: "shift", src: "一昨|前々|先々", value: -2 }, + { name: "shift", src: "先|昨|去|前", value: -1 }, + { name: "shift", src: "今|本|当", value: 0 }, + { name: "shift", src: "来|明|翌|次", value: 1 }, + { name: "shift", src: "明後|翌々|次々|再来|さ来", value: 2 }, + { name: "shift", src: "明々後|翌々々", value: 3 }, ], - 'parse': [ - '{month}{edge}', - '{num}{unit}{sign}', - '{year?}{month}', - '{year}' + parse: ["{month}{edge}", "{num}{unit}{sign}", "{year?}{month}", "{year}"], + timeParse: [ + "{day|weekday}", + "{shift}{unit:5}{weekday?}", + "{shift}{unit:7}{month}{edge}", + "{shift}{unit:7}{month?}{date?}", + "{shift}{unit:6}{edge?}{date?}", + "{year?}{month?}{date}", ], - 'timeParse': [ - '{day|weekday}', - '{shift}{unit:5}{weekday?}', - '{shift}{unit:7}{month}{edge}', - '{shift}{unit:7}{month?}{date?}', - '{shift}{unit:6}{edge?}{date?}', - '{year?}{month?}{date}' - ] }); - /* * Korean locale definition. * See the readme for customization and more information. @@ -5846,49 +6077,48 @@ * Sugar.Date.setLocale('ko') * */ - Sugar.Date.addLocale('ko', { - 'ampmFront': true, - 'numeralUnits': true, - 'units': '밀리초,초,분,시간,일,주,개월|달,년|해', - 'weekdays': '일:요일|,월:요일|,화:요일|,수:요일|,목:요일|,금:요일|,토:요일|', - 'numerals': '영|제로,일|한,이,삼,사,오,육,칠,팔,구,십', - 'short': '{yyyy}.{MM}.{dd}', - 'medium': '{yyyy}년 {M}월 {d}일', - 'long': '{yyyy}년 {M}월 {d}일 {time}', - 'full': '{yyyy}년 {M}월 {d}일 {weekday} {time}', - 'stamp': '{yyyy}년 {M}월 {d}일 {H}:{mm} {dow}', - 'time': '{tt} {h}시 {mm}분', - 'past': '{num}{unit} {sign}', - 'future': '{num}{unit} {sign}', - 'duration': '{num}{unit}', - 'timeSuffixes': ',초,분,시,일,,월,년', - 'ampm': '오전,오후', - 'modifiers': [ - { 'name': 'day', 'src': '그저께', 'value': -2 }, - { 'name': 'day', 'src': '어제', 'value': -1 }, - { 'name': 'day', 'src': '오늘', 'value': 0 }, - { 'name': 'day', 'src': '내일', 'value': 1 }, - { 'name': 'day', 'src': '모레', 'value': 2 }, - { 'name': 'sign', 'src': '전', 'value': -1 }, - { 'name': 'sign', 'src': '후', 'value': 1 }, - { 'name': 'shift', 'src': '지난|작', 'value': -1 }, - { 'name': 'shift', 'src': '이번|올', 'value': 0 }, - { 'name': 'shift', 'src': '다음|내', 'value': 1 } + Sugar.Date.addLocale("ko", { + ampmFront: true, + numeralUnits: true, + units: "밀리초,초,분,시간,일,주,개월|달,년|해", + weekdays: "일:요일|,월:요일|,화:요일|,수:요일|,목:요일|,금:요일|,토:요일|", + numerals: "영|제로,일|한,이,삼,사,오,육,칠,팔,구,십", + short: "{yyyy}.{MM}.{dd}", + medium: "{yyyy}년 {M}월 {d}일", + long: "{yyyy}년 {M}월 {d}일 {time}", + full: "{yyyy}년 {M}월 {d}일 {weekday} {time}", + stamp: "{yyyy}년 {M}월 {d}일 {H}:{mm} {dow}", + time: "{tt} {h}시 {mm}분", + past: "{num}{unit} {sign}", + future: "{num}{unit} {sign}", + duration: "{num}{unit}", + timeSuffixes: ",초,분,시,일,,월,년", + ampm: "오전,오후", + modifiers: [ + { name: "day", src: "그저께", value: -2 }, + { name: "day", src: "어제", value: -1 }, + { name: "day", src: "오늘", value: 0 }, + { name: "day", src: "내일", value: 1 }, + { name: "day", src: "모레", value: 2 }, + { name: "sign", src: "전", value: -1 }, + { name: "sign", src: "후", value: 1 }, + { name: "shift", src: "지난|작", value: -1 }, + { name: "shift", src: "이번|올", value: 0 }, + { name: "shift", src: "다음|내", value: 1 }, ], - 'parse': [ - '{num}{unit} {sign}', - '{shift?} {unit:5-7}', - '{year?} {month}', - '{year}' + parse: [ + "{num}{unit} {sign}", + "{shift?} {unit:5-7}", + "{year?} {month}", + "{year}", + ], + timeParse: [ + "{day|weekday}", + "{shift} {unit:5?} {weekday}", + "{year?} {month?} {date} {weekday?}", ], - 'timeParse': [ - '{day|weekday}', - '{shift} {unit:5?} {weekday}', - '{year?} {month?} {date} {weekday?}' - ] }); - /* * Dutch locale definition. * See the readme for customization and more information. @@ -5897,49 +6127,51 @@ * Sugar.Date.setLocale('nl') * */ - Sugar.Date.addLocale('nl', { - 'plural': true, - 'units': 'milliseconde:|n,seconde:|n,minu:ut|ten,uur,dag:|en,we:ek|ken,maand:|en,jaar', - 'months': 'jan:uari|,feb:ruari|,maart|mrt,apr:il|,mei,jun:i|,jul:i|,aug:ustus|,sep:tember|,okt:ober|,nov:ember|,dec:ember|', - 'weekdays': 'zondag|zo,maandag|ma,dinsdag|di,woensdag|wo|woe,donderdag|do,vrijdag|vr|vrij,zaterdag|za', - 'numerals': 'nul,een,twee,drie,vier,vijf,zes,zeven,acht,negen,tien', - 'short': '{dd}-{MM}-{yyyy}', - 'medium': '{d} {month} {yyyy}', - 'long': '{d} {Month} {yyyy} {time}', - 'full': '{weekday} {d} {Month} {yyyy} {time}', - 'stamp': '{dow} {d} {Mon} {yyyy} {time}', - 'time': '{H}:{mm}', - 'past': '{num} {unit} {sign}', - 'future': '{num} {unit} {sign}', - 'duration': '{num} {unit}', - 'timeMarkers': "'s,om", - 'modifiers': [ - { 'name': 'day', 'src': 'gisteren', 'value': -1 }, - { 'name': 'day', 'src': 'vandaag', 'value': 0 }, - { 'name': 'day', 'src': 'morgen', 'value': 1 }, - { 'name': 'day', 'src': 'overmorgen', 'value': 2 }, - { 'name': 'sign', 'src': 'geleden', 'value': -1 }, - { 'name': 'sign', 'src': 'vanaf nu', 'value': 1 }, - { 'name': 'shift', 'src': 'laatste|vorige|afgelopen', 'value': -1 }, - { 'name': 'shift', 'src': 'volgend:|e', 'value': 1 } + Sugar.Date.addLocale("nl", { + plural: true, + units: + "milliseconde:|n,seconde:|n,minu:ut|ten,uur,dag:|en,we:ek|ken,maand:|en,jaar", + months: + "jan:uari|,feb:ruari|,maart|mrt,apr:il|,mei,jun:i|,jul:i|,aug:ustus|,sep:tember|,okt:ober|,nov:ember|,dec:ember|", + weekdays: + "zondag|zo,maandag|ma,dinsdag|di,woensdag|wo|woe,donderdag|do,vrijdag|vr|vrij,zaterdag|za", + numerals: "nul,een,twee,drie,vier,vijf,zes,zeven,acht,negen,tien", + short: "{dd}-{MM}-{yyyy}", + medium: "{d} {month} {yyyy}", + long: "{d} {Month} {yyyy} {time}", + full: "{weekday} {d} {Month} {yyyy} {time}", + stamp: "{dow} {d} {Mon} {yyyy} {time}", + time: "{H}:{mm}", + past: "{num} {unit} {sign}", + future: "{num} {unit} {sign}", + duration: "{num} {unit}", + timeMarkers: "'s,om", + modifiers: [ + { name: "day", src: "gisteren", value: -1 }, + { name: "day", src: "vandaag", value: 0 }, + { name: "day", src: "morgen", value: 1 }, + { name: "day", src: "overmorgen", value: 2 }, + { name: "sign", src: "geleden", value: -1 }, + { name: "sign", src: "vanaf nu", value: 1 }, + { name: "shift", src: "laatste|vorige|afgelopen", value: -1 }, + { name: "shift", src: "volgend:|e", value: 1 }, ], - 'parse': [ - '{months} {year?}', - '{num} {unit} {sign}', - '{0?} {unit:5-7} {shift}', - '{0?} {shift} {unit:5-7}' + parse: [ + "{months} {year?}", + "{num} {unit} {sign}", + "{0?} {unit:5-7} {shift}", + "{0?} {shift} {unit:5-7}", ], - 'timeParse': [ - '{shift?} {day|weekday}', - '{weekday?},? {date} {months?}\\.? {year?}' + timeParse: [ + "{shift?} {day|weekday}", + "{weekday?},? {date} {months?}\\.? {year?}", + ], + timeFrontParse: [ + "{shift?} {day|weekday}", + "{weekday?},? {date} {months?}\\.? {year?}", ], - 'timeFrontParse': [ - '{shift?} {day|weekday}', - '{weekday?},? {date} {months?}\\.? {year?}' - ] }); - /* * Norwegian locale definition. * See the readme for customization and more information. @@ -5948,47 +6180,49 @@ * Sugar.Date.setLocale('no') * */ - Sugar.Date.addLocale('no', { - 'plural': true, - 'units': 'millisekund:|er,sekund:|er,minutt:|er,tim:e|er,dag:|er,uk:e|er|en,måned:|er|en+maaned:|er|en,år:||et+aar:||et', - 'months': 'januar,februar,mars,april,mai,juni,juli,august,september,oktober,november,desember', - 'weekdays': 'søndag|sondag,mandag,tirsdag,onsdag,torsdag,fredag,lørdag|lordag', - 'numerals': 'en|et,to,tre,fire,fem,seks,sju|syv,åtte,ni,ti', - 'tokens': 'den,for', - 'articles': 'den', - 'short':'d. {d}. {month} {yyyy}', - 'long': 'den {d}. {month} {yyyy} {H}:{mm}', - 'full': '{Weekday} den {d}. {month} {yyyy} {H}:{mm}:{ss}', - 'past': '{num} {unit} {sign}', - 'future': '{sign} {num} {unit}', - 'duration': '{num} {unit}', - 'ampm': 'am,pm', - 'modifiers': [ - { 'name': 'day', 'src': 'forgårs|i forgårs|forgaars|i forgaars', 'value': -2 }, - { 'name': 'day', 'src': 'i går|igår|i gaar|igaar', 'value': -1 }, - { 'name': 'day', 'src': 'i dag|idag', 'value': 0 }, - { 'name': 'day', 'src': 'i morgen|imorgen', 'value': 1 }, - { 'name': 'day', 'src': 'overimorgen|overmorgen|over i morgen', 'value': 2 }, - { 'name': 'sign', 'src': 'siden', 'value': -1 }, - { 'name': 'sign', 'src': 'om', 'value': 1 }, - { 'name': 'shift', 'src': 'i siste|siste', 'value': -1 }, - { 'name': 'shift', 'src': 'denne', 'value': 0 }, - { 'name': 'shift', 'src': 'neste', 'value': 1 } + Sugar.Date.addLocale("no", { + plural: true, + units: + "millisekund:|er,sekund:|er,minutt:|er,tim:e|er,dag:|er,uk:e|er|en,måned:|er|en+maaned:|er|en,år:||et+aar:||et", + months: + "januar,februar,mars,april,mai,juni,juli,august,september,oktober,november,desember", + weekdays: + "søndag|sondag,mandag,tirsdag,onsdag,torsdag,fredag,lørdag|lordag", + numerals: "en|et,to,tre,fire,fem,seks,sju|syv,åtte,ni,ti", + tokens: "den,for", + articles: "den", + short: "d. {d}. {month} {yyyy}", + long: "den {d}. {month} {yyyy} {H}:{mm}", + full: "{Weekday} den {d}. {month} {yyyy} {H}:{mm}:{ss}", + past: "{num} {unit} {sign}", + future: "{sign} {num} {unit}", + duration: "{num} {unit}", + ampm: "am,pm", + modifiers: [ + { name: "day", src: "forgårs|i forgårs|forgaars|i forgaars", value: -2 }, + { name: "day", src: "i går|igår|i gaar|igaar", value: -1 }, + { name: "day", src: "i dag|idag", value: 0 }, + { name: "day", src: "i morgen|imorgen", value: 1 }, + { name: "day", src: "overimorgen|overmorgen|over i morgen", value: 2 }, + { name: "sign", src: "siden", value: -1 }, + { name: "sign", src: "om", value: 1 }, + { name: "shift", src: "i siste|siste", value: -1 }, + { name: "shift", src: "denne", value: 0 }, + { name: "shift", src: "neste", value: 1 }, ], - 'parse': [ - '{num} {unit} {sign}', - '{sign} {num} {unit}', - '{1?} {num} {unit} {sign}', - '{shift} {unit:5-7}' + parse: [ + "{num} {unit} {sign}", + "{sign} {num} {unit}", + "{1?} {num} {unit} {sign}", + "{shift} {unit:5-7}", + ], + timeParse: [ + "{date} {month}", + "{shift} {weekday}", + "{0?} {weekday?},? {date?} {month}\\.? {year}", ], - 'timeParse': [ - '{date} {month}', - '{shift} {weekday}', - '{0?} {weekday?},? {date?} {month}\\.? {year}' - ] }); - /* * Polish locale definition. * See the readme for customization and more information. @@ -5997,82 +6231,99 @@ * Sugar.Date.setLocale('pl') * */ - Sugar.Date.addLocale('pl', { - 'plural': true, - 'units': 'milisekund:a|y|,sekund:a|y|,minut:a|y|,godzin:a|y|,dzień|dni|dni,tydzień|tygodnie|tygodni,miesiąc|miesiące|miesięcy,rok|lata|lat', - 'months': 'sty:cznia||czeń,lut:ego||y,mar:ca||zec,kwi:etnia||ecień,maj:a|,cze:rwca||rwiec,lip:ca||iec,sie:rpnia||rpień,wrz:eśnia||esień,paź:dziernika||dziernik,lis:topada||topad,gru:dnia||dzień', - 'weekdays': 'nie:dziela||dzielę,pon:iedziałek|,wt:orek|,śr:oda||odę,czw:artek|,piątek|pt,sobota|sb|sobotę', - 'numerals': 'zero,jeden|jedną,dwa|dwie,trzy,cztery,pięć,sześć,siedem,osiem,dziewięć,dziesięć', - 'tokens': 'w|we,roku', - 'short': '{dd}.{MM}.{yyyy}', - 'medium': '{d} {month} {yyyy}', - 'long': '{d} {month} {yyyy} {time}', - 'full' : '{weekday}, {d} {month} {yyyy} {time}', - 'stamp': '{dow} {d} {mon} {yyyy} {time}', - 'time': '{H}:{mm}', - 'timeMarkers': 'o', - 'ampm': 'am,pm', - 'modifiers': [ - { 'name': 'day', 'src': 'przedwczoraj', 'value': -2 }, - { 'name': 'day', 'src': 'wczoraj', 'value': -1 }, - { 'name': 'day', 'src': 'dzisiaj|dziś', 'value': 0 }, - { 'name': 'day', 'src': 'jutro', 'value': 1 }, - { 'name': 'day', 'src': 'pojutrze', 'value': 2 }, - { 'name': 'sign', 'src': 'temu|przed', 'value': -1 }, - { 'name': 'sign', 'src': 'za', 'value': 1 }, - { 'name': 'shift', 'src': 'zeszły|zeszła|ostatni|ostatnia', 'value': -1 }, - { 'name': 'shift', 'src': 'następny|następna|następnego|przyszły|przyszła|przyszłego', 'value': 1 } + Sugar.Date.addLocale("pl", { + plural: true, + units: + "milisekund:a|y|,sekund:a|y|,minut:a|y|,godzin:a|y|,dzień|dni|dni,tydzień|tygodnie|tygodni,miesiąc|miesiące|miesięcy,rok|lata|lat", + months: + "sty:cznia||czeń,lut:ego||y,mar:ca||zec,kwi:etnia||ecień,maj:a|,cze:rwca||rwiec,lip:ca||iec,sie:rpnia||rpień,wrz:eśnia||esień,paź:dziernika||dziernik,lis:topada||topad,gru:dnia||dzień", + weekdays: + "nie:dziela||dzielę,pon:iedziałek|,wt:orek|,śr:oda||odę,czw:artek|,piątek|pt,sobota|sb|sobotę", + numerals: + "zero,jeden|jedną,dwa|dwie,trzy,cztery,pięć,sześć,siedem,osiem,dziewięć,dziesięć", + tokens: "w|we,roku", + short: "{dd}.{MM}.{yyyy}", + medium: "{d} {month} {yyyy}", + long: "{d} {month} {yyyy} {time}", + full: "{weekday}, {d} {month} {yyyy} {time}", + stamp: "{dow} {d} {mon} {yyyy} {time}", + time: "{H}:{mm}", + timeMarkers: "o", + ampm: "am,pm", + modifiers: [ + { name: "day", src: "przedwczoraj", value: -2 }, + { name: "day", src: "wczoraj", value: -1 }, + { name: "day", src: "dzisiaj|dziś", value: 0 }, + { name: "day", src: "jutro", value: 1 }, + { name: "day", src: "pojutrze", value: 2 }, + { name: "sign", src: "temu|przed", value: -1 }, + { name: "sign", src: "za", value: 1 }, + { name: "shift", src: "zeszły|zeszła|ostatni|ostatnia", value: -1 }, + { + name: "shift", + src: "następny|następna|następnego|przyszły|przyszła|przyszłego", + value: 1, + }, ], - 'relative': function (num, unit, ms, format) { + relative: function (num, unit, ms, format) { // special cases for relative days var DAY = 4; if (unit === DAY) { - if (num === 1 && format === 'past') return 'wczoraj'; - if (num === 1 && format === 'future') return 'jutro'; - if (num === 2 && format === 'past') return 'przedwczoraj'; - if (num === 2 && format === 'future') return 'pojutrze'; + if (num === 1 && format === "past") return "wczoraj"; + if (num === 1 && format === "future") return "jutro"; + if (num === 2 && format === "past") return "przedwczoraj"; + if (num === 2 && format === "future") return "pojutrze"; } var mult; - var last = +num.toFixed(0).slice(-1); + var last = +num.toFixed(0).slice(-1); var last2 = +num.toFixed(0).slice(-2); switch (true) { - case num === 1: mult = 0; break; - case last2 >= 12 && last2 <= 14: mult = 2; break; - case last >= 2 && last <= 4: mult = 1; break; - default: mult = 2; + case num === 1: + mult = 0; + break; + case last2 >= 12 && last2 <= 14: + mult = 2; + break; + case last >= 2 && last <= 4: + mult = 1; + break; + default: + mult = 2; } - var text = this['units'][(mult * 8) + unit]; - var prefix = num + ' '; + var text = this["units"][mult * 8 + unit]; + var prefix = num + " "; // changing to accusative case for 'past' and 'future' formats // (only singular feminine unit words are different in accusative, each of which ends with 'a') - if ((format === 'past' || format === 'future') && num === 1) { - text = text.replace(/a$/, 'ę'); + if ((format === "past" || format === "future") && num === 1) { + text = text.replace(/a$/, "ę"); } text = prefix + text; switch (format) { - case 'duration': return text; - case 'past': return text + ' temu'; - case 'future': return 'za ' + text; + case "duration": + return text; + case "past": + return text + " temu"; + case "future": + return "za " + text; } }, - 'parse': [ - '{num} {unit} {sign}', - '{sign} {num} {unit}', - '{months} {year?}', - '{shift} {unit:5-7}', - '{0} {shift?} {weekday}' + parse: [ + "{num} {unit} {sign}", + "{sign} {num} {unit}", + "{months} {year?}", + "{shift} {unit:5-7}", + "{0} {shift?} {weekday}", + ], + timeFrontParse: [ + "{day|weekday}", + "{date} {months} {year?} {1?}", + "{0?} {shift?} {weekday}", ], - 'timeFrontParse': [ - '{day|weekday}', - '{date} {months} {year?} {1?}', - '{0?} {shift?} {weekday}' - ] }); - /* * Portuguese locale definition. * See the readme for customization and more information. @@ -6081,53 +6332,56 @@ * Sugar.Date.setLocale('pt') * */ - Sugar.Date.addLocale('pt', { - 'plural': true, - 'units': 'milisegundo:|s,segundo:|s,minuto:|s,hora:|s,dia:|s,semana:|s,mês|mêses|mes|meses,ano:|s', - 'months': 'jan:eiro|,fev:ereiro|,mar:ço|,abr:il|,mai:o|,jun:ho|,jul:ho|,ago:sto|,set:embro|,out:ubro|,nov:embro|,dez:embro|', - 'weekdays': 'dom:ingo|,seg:unda-feira|,ter:ça-feira|,qua:rta-feira|,qui:nta-feira|,sex:ta-feira|,sáb:ado||ado', - 'numerals': 'zero,um:|a,dois|duas,três|tres,quatro,cinco,seis,sete,oito,nove,dez', - 'tokens': 'a,de', - 'short': '{dd}/{MM}/{yyyy}', - 'medium': '{d} de {Month} de {yyyy}', - 'long': '{d} de {Month} de {yyyy} {time}', - 'full': '{Weekday}, {d} de {Month} de {yyyy} {time}', - 'stamp': '{Dow} {d} {Mon} {yyyy} {time}', - 'time': '{H}:{mm}', - 'past': '{num} {unit} {sign}', - 'future': '{sign} {num} {unit}', - 'duration': '{num} {unit}', - 'timeMarkers': 'às', - 'ampm': 'am,pm', - 'modifiers': [ - { 'name': 'day', 'src': 'anteontem', 'value': -2 }, - { 'name': 'day', 'src': 'ontem', 'value': -1 }, - { 'name': 'day', 'src': 'hoje', 'value': 0 }, - { 'name': 'day', 'src': 'amanh:ã|a', 'value': 1 }, - { 'name': 'sign', 'src': 'atrás|atras|há|ha', 'value': -1 }, - { 'name': 'sign', 'src': 'daqui a', 'value': 1 }, - { 'name': 'shift', 'src': 'passad:o|a', 'value': -1 }, - { 'name': 'shift', 'src': 'próximo|próxima|proximo|proxima', 'value': 1 } + Sugar.Date.addLocale("pt", { + plural: true, + units: + "milisegundo:|s,segundo:|s,minuto:|s,hora:|s,dia:|s,semana:|s,mês|mêses|mes|meses,ano:|s", + months: + "jan:eiro|,fev:ereiro|,mar:ço|,abr:il|,mai:o|,jun:ho|,jul:ho|,ago:sto|,set:embro|,out:ubro|,nov:embro|,dez:embro|", + weekdays: + "dom:ingo|,seg:unda-feira|,ter:ça-feira|,qua:rta-feira|,qui:nta-feira|,sex:ta-feira|,sáb:ado||ado", + numerals: + "zero,um:|a,dois|duas,três|tres,quatro,cinco,seis,sete,oito,nove,dez", + tokens: "a,de", + short: "{dd}/{MM}/{yyyy}", + medium: "{d} de {Month} de {yyyy}", + long: "{d} de {Month} de {yyyy} {time}", + full: "{Weekday}, {d} de {Month} de {yyyy} {time}", + stamp: "{Dow} {d} {Mon} {yyyy} {time}", + time: "{H}:{mm}", + past: "{num} {unit} {sign}", + future: "{sign} {num} {unit}", + duration: "{num} {unit}", + timeMarkers: "às", + ampm: "am,pm", + modifiers: [ + { name: "day", src: "anteontem", value: -2 }, + { name: "day", src: "ontem", value: -1 }, + { name: "day", src: "hoje", value: 0 }, + { name: "day", src: "amanh:ã|a", value: 1 }, + { name: "sign", src: "atrás|atras|há|ha", value: -1 }, + { name: "sign", src: "daqui a", value: 1 }, + { name: "shift", src: "passad:o|a", value: -1 }, + { name: "shift", src: "próximo|próxima|proximo|proxima", value: 1 }, ], - 'parse': [ - '{months} {1?} {year?}', - '{num} {unit} {sign}', - '{sign} {num} {unit}', - '{0?} {unit:5-7} {shift}', - '{0?} {shift} {unit:5-7}' + parse: [ + "{months} {1?} {year?}", + "{num} {unit} {sign}", + "{sign} {num} {unit}", + "{0?} {unit:5-7} {shift}", + "{0?} {shift} {unit:5-7}", ], - 'timeParse': [ - '{shift?} {day|weekday}', - '{0?} {shift} {weekday}', - '{date} {1?} {months?} {1?} {year?}' + timeParse: [ + "{shift?} {day|weekday}", + "{0?} {shift} {weekday}", + "{date} {1?} {months?} {1?} {year?}", + ], + timeFrontParse: [ + "{shift?} {day|weekday}", + "{date} {1?} {months?} {1?} {year?}", ], - 'timeFrontParse': [ - '{shift?} {day|weekday}', - '{date} {1?} {months?} {1?} {year?}' - ] }); - /* * Russian locale definition. * See the readme for customization and more information. @@ -6136,65 +6390,80 @@ * Sugar.Date.setLocale('ru') * */ - Sugar.Date.addLocale('ru', { - 'firstDayOfWeekYear': 1, - 'units': 'миллисекунд:а|у|ы|,секунд:а|у|ы|,минут:а|у|ы|,час:||а|ов,день|день|дня|дней,недел:я|ю|и|ь|е,месяц:||а|ев|е,год|год|года|лет|году', - 'months': 'янв:аря||.|арь,фев:раля||р.|раль,мар:та||т,апр:еля||.|ель,мая|май,июн:я||ь,июл:я||ь,авг:уста||.|уст,сен:тября||т.|тябрь,окт:ября||.|ябрь,ноя:бря||брь,дек:абря||.|абрь', - 'weekdays': 'воскресенье|вс,понедельник|пн,вторник|вт,среда|ср,четверг|чт,пятница|пт,суббота|сб', - 'numerals': 'ноль,од:ин|ну,дв:а|е,три,четыре,пять,шесть,семь,восемь,девять,десять', - 'tokens': 'в|на,г\\.?(?:ода)?', - 'short': '{dd}.{MM}.{yyyy}', - 'medium': '{d} {month} {yyyy} г.', - 'long': '{d} {month} {yyyy} г., {time}', - 'full': '{weekday}, {d} {month} {yyyy} г., {time}', - 'stamp': '{dow} {d} {mon} {yyyy} {time}', - 'time': '{H}:{mm}', - 'timeMarkers': 'в', - 'ampm': ' утра, вечера', - 'modifiers': [ - { 'name': 'day', 'src': 'позавчера', 'value': -2 }, - { 'name': 'day', 'src': 'вчера', 'value': -1 }, - { 'name': 'day', 'src': 'сегодня', 'value': 0 }, - { 'name': 'day', 'src': 'завтра', 'value': 1 }, - { 'name': 'day', 'src': 'послезавтра', 'value': 2 }, - { 'name': 'sign', 'src': 'назад', 'value': -1 }, - { 'name': 'sign', 'src': 'через', 'value': 1 }, - { 'name': 'shift', 'src': 'прошл:ый|ой|ом', 'value': -1 }, - { 'name': 'shift', 'src': 'следующ:ий|ей|ем', 'value': 1 } + Sugar.Date.addLocale("ru", { + firstDayOfWeekYear: 1, + units: + "миллисекунд:а|у|ы|,секунд:а|у|ы|,минут:а|у|ы|,час:||а|ов,день|день|дня|дней,недел:я|ю|и|ь|е,месяц:||а|ев|е,год|год|года|лет|году", + months: + "янв:аря||.|арь,фев:раля||р.|раль,мар:та||т,апр:еля||.|ель,мая|май,июн:я||ь,июл:я||ь,авг:уста||.|уст,сен:тября||т.|тябрь,окт:ября||.|ябрь,ноя:бря||брь,дек:абря||.|абрь", + weekdays: + "воскресенье|вс,понедельник|пн,вторник|вт,среда|ср,четверг|чт,пятница|пт,суббота|сб", + numerals: + "ноль,од:ин|ну,дв:а|е,три,четыре,пять,шесть,семь,восемь,девять,десять", + tokens: "в|на,г\\.?(?:ода)?", + short: "{dd}.{MM}.{yyyy}", + medium: "{d} {month} {yyyy} г.", + long: "{d} {month} {yyyy} г., {time}", + full: "{weekday}, {d} {month} {yyyy} г., {time}", + stamp: "{dow} {d} {mon} {yyyy} {time}", + time: "{H}:{mm}", + timeMarkers: "в", + ampm: " утра, вечера", + modifiers: [ + { name: "day", src: "позавчера", value: -2 }, + { name: "day", src: "вчера", value: -1 }, + { name: "day", src: "сегодня", value: 0 }, + { name: "day", src: "завтра", value: 1 }, + { name: "day", src: "послезавтра", value: 2 }, + { name: "sign", src: "назад", value: -1 }, + { name: "sign", src: "через", value: 1 }, + { name: "shift", src: "прошл:ый|ой|ом", value: -1 }, + { name: "shift", src: "следующ:ий|ей|ем", value: 1 }, ], - 'relative': function(num, unit, ms, format) { - var numberWithUnit, last = num.toString().slice(-1), mult; - switch(true) { - case num >= 11 && num <= 15: mult = 3; break; - case last == 1: mult = 1; break; - case last >= 2 && last <= 4: mult = 2; break; - default: mult = 3; + relative: function (num, unit, ms, format) { + var numberWithUnit, + last = num.toString().slice(-1), + mult; + switch (true) { + case num >= 11 && num <= 15: + mult = 3; + break; + case last == 1: + mult = 1; + break; + case last >= 2 && last <= 4: + mult = 2; + break; + default: + mult = 3; } - numberWithUnit = num + ' ' + this['units'][(mult * 8) + unit]; - switch(format) { - case 'duration': return numberWithUnit; - case 'past': return numberWithUnit + ' назад'; - case 'future': return 'через ' + numberWithUnit; + numberWithUnit = num + " " + this["units"][mult * 8 + unit]; + switch (format) { + case "duration": + return numberWithUnit; + case "past": + return numberWithUnit + " назад"; + case "future": + return "через " + numberWithUnit; } }, - 'parse': [ - '{num} {unit} {sign}', - '{sign} {num} {unit}', - '{months} {year?}', - '{0?} {shift} {unit:5-7}' + parse: [ + "{num} {unit} {sign}", + "{sign} {num} {unit}", + "{months} {year?}", + "{0?} {shift} {unit:5-7}", ], - 'timeParse': [ - '{day|weekday}', - '{0?} {shift} {weekday}', - '{date} {months?} {year?} {1?}' + timeParse: [ + "{day|weekday}", + "{0?} {shift} {weekday}", + "{date} {months?} {year?} {1?}", + ], + timeFrontParse: [ + "{0?} {shift} {weekday}", + "{date} {months?} {year?} {1?}", ], - 'timeFrontParse': [ - '{0?} {shift} {weekday}', - '{date} {months?} {year?} {1?}' - ] }); - /* * Swedish locale definition. * See the readme for customization and more information. @@ -6203,56 +6472,66 @@ * Sugar.Date.setLocale('sv') * */ - Sugar.Date.addLocale('sv', { - 'plural': true, - 'units': 'millisekund:|er,sekund:|er,minut:|er,timm:e|ar,dag:|ar,veck:a|or|an,månad:|er|en+manad:|er|en,år:||et+ar:||et', - 'months': 'jan:uari|,feb:ruari|,mar:s|,apr:il|,maj,jun:i|,jul:i|,aug:usti|,sep:tember|,okt:ober|,nov:ember|,dec:ember|', - 'weekdays': 'sön:dag|+son:dag|,mån:dag||dagen+man:dag||dagen,tis:dag|,ons:dag|,tor:sdag|,fre:dag|,lör:dag||dag', - 'numerals': 'noll,en|ett,två|tva,tre,fyra,fem,sex,sju,åtta|atta,nio,tio', - 'tokens': 'den,för|for', - 'articles': 'den', - 'short': '{yyyy}-{MM}-{dd}', - 'medium': '{d} {month} {yyyy}', - 'long': '{d} {month} {yyyy} {time}', - 'full': '{weekday} {d} {month} {yyyy} {time}', - 'stamp': '{dow} {d} {mon} {yyyy} {time}', - 'time': '{H}:{mm}', - 'past': '{num} {unit} {sign}', - 'future': '{sign} {num} {unit}', - 'duration': '{num} {unit}', - 'ampm': 'am,pm', - 'modifiers': [ - { 'name': 'day', 'src': 'förrgår|i förrgår|iförrgår|forrgar|i forrgar|iforrgar', 'value': -2 }, - { 'name': 'day', 'src': 'går|i går|igår|gar|i gar|igar', 'value': -1 }, - { 'name': 'day', 'src': 'dag|i dag|idag', 'value': 0 }, - { 'name': 'day', 'src': 'morgon|i morgon|imorgon', 'value': 1 }, - { 'name': 'day', 'src': 'över morgon|övermorgon|i över morgon|i övermorgon|iövermorgon|over morgon|overmorgon|i over morgon|i overmorgon|iovermorgon', 'value': 2 }, - { 'name': 'sign', 'src': 'sedan|sen', 'value': -1 }, - { 'name': 'sign', 'src': 'om', 'value': 1 }, - { 'name': 'shift', 'src': 'i förra|förra|i forra|forra', 'value': -1 }, - { 'name': 'shift', 'src': 'denna', 'value': 0 }, - { 'name': 'shift', 'src': 'nästa|nasta', 'value': 1 } + Sugar.Date.addLocale("sv", { + plural: true, + units: + "millisekund:|er,sekund:|er,minut:|er,timm:e|ar,dag:|ar,veck:a|or|an,månad:|er|en+manad:|er|en,år:||et+ar:||et", + months: + "jan:uari|,feb:ruari|,mar:s|,apr:il|,maj,jun:i|,jul:i|,aug:usti|,sep:tember|,okt:ober|,nov:ember|,dec:ember|", + weekdays: + "sön:dag|+son:dag|,mån:dag||dagen+man:dag||dagen,tis:dag|,ons:dag|,tor:sdag|,fre:dag|,lör:dag||dag", + numerals: "noll,en|ett,två|tva,tre,fyra,fem,sex,sju,åtta|atta,nio,tio", + tokens: "den,för|for", + articles: "den", + short: "{yyyy}-{MM}-{dd}", + medium: "{d} {month} {yyyy}", + long: "{d} {month} {yyyy} {time}", + full: "{weekday} {d} {month} {yyyy} {time}", + stamp: "{dow} {d} {mon} {yyyy} {time}", + time: "{H}:{mm}", + past: "{num} {unit} {sign}", + future: "{sign} {num} {unit}", + duration: "{num} {unit}", + ampm: "am,pm", + modifiers: [ + { + name: "day", + src: "förrgår|i förrgår|iförrgår|forrgar|i forrgar|iforrgar", + value: -2, + }, + { name: "day", src: "går|i går|igår|gar|i gar|igar", value: -1 }, + { name: "day", src: "dag|i dag|idag", value: 0 }, + { name: "day", src: "morgon|i morgon|imorgon", value: 1 }, + { + name: "day", + src: "över morgon|övermorgon|i över morgon|i övermorgon|iövermorgon|over morgon|overmorgon|i over morgon|i overmorgon|iovermorgon", + value: 2, + }, + { name: "sign", src: "sedan|sen", value: -1 }, + { name: "sign", src: "om", value: 1 }, + { name: "shift", src: "i förra|förra|i forra|forra", value: -1 }, + { name: "shift", src: "denna", value: 0 }, + { name: "shift", src: "nästa|nasta", value: 1 }, ], - 'parse': [ - '{months} {year?}', - '{num} {unit} {sign}', - '{sign} {num} {unit}', - '{1?} {num} {unit} {sign}', - '{shift} {unit:5-7}' + parse: [ + "{months} {year?}", + "{num} {unit} {sign}", + "{sign} {num} {unit}", + "{1?} {num} {unit} {sign}", + "{shift} {unit:5-7}", ], - 'timeParse': [ - '{day|weekday}', - '{shift} {weekday}', - '{0?} {weekday?},? {date} {months?}\\.? {year?}' + timeParse: [ + "{day|weekday}", + "{shift} {weekday}", + "{0?} {weekday?},? {date} {months?}\\.? {year?}", + ], + timeFrontParse: [ + "{day|weekday}", + "{shift} {weekday}", + "{0?} {weekday?},? {date} {months?}\\.? {year?}", ], - 'timeFrontParse': [ - '{day|weekday}', - '{shift} {weekday}', - '{0?} {weekday?},? {date} {months?}\\.? {year?}' - ] }); - /* * Simplified Chinese locale definition. * See the readme for customization and more information. @@ -6261,54 +6540,50 @@ * Sugar.Date.setLocale('zh-CN') * */ - Sugar.Date.addLocale('zh-CN', { - 'ampmFront': true, - 'numeralUnits': true, - 'allowsFullWidth': true, - 'timeMarkerOptional': true, - 'units': '毫秒,秒钟,分钟,小时,天,个星期|周,个月,年', - 'weekdays': '星期日|日|周日|星期天,星期一|一|周一,星期二|二|周二,星期三|三|周三,星期四|四|周四,星期五|五|周五,星期六|六|周六', - 'numerals': '〇,一,二,三,四,五,六,七,八,九', - 'placeholders': '十,百,千,万', - 'short': '{yyyy}-{MM}-{dd}', - 'medium': '{yyyy}年{M}月{d}日', - 'long': '{yyyy}年{M}月{d}日{time}', - 'full': '{yyyy}年{M}月{d}日{weekday}{time}', - 'stamp': '{yyyy}年{M}月{d}日{H}:{mm}{dow}', - 'time': '{tt}{h}点{mm}分', - 'past': '{num}{unit}{sign}', - 'future': '{num}{unit}{sign}', - 'duration': '{num}{unit}', - 'timeSuffixes': ',秒,分钟?,点|时,日|号,,月,年', - 'ampm': '上午,下午', - 'modifiers': [ - { 'name': 'day', 'src': '大前天', 'value': -3 }, - { 'name': 'day', 'src': '前天', 'value': -2 }, - { 'name': 'day', 'src': '昨天', 'value': -1 }, - { 'name': 'day', 'src': '今天', 'value': 0 }, - { 'name': 'day', 'src': '明天', 'value': 1 }, - { 'name': 'day', 'src': '后天', 'value': 2 }, - { 'name': 'day', 'src': '大后天', 'value': 3 }, - { 'name': 'sign', 'src': '前', 'value': -1 }, - { 'name': 'sign', 'src': '后', 'value': 1 }, - { 'name': 'shift', 'src': '上|去', 'value': -1 }, - { 'name': 'shift', 'src': '这', 'value': 0 }, - { 'name': 'shift', 'src': '下|明', 'value': 1 } + Sugar.Date.addLocale("zh-CN", { + ampmFront: true, + numeralUnits: true, + allowsFullWidth: true, + timeMarkerOptional: true, + units: "毫秒,秒钟,分钟,小时,天,个星期|周,个月,年", + weekdays: + "星期日|日|周日|星期天,星期一|一|周一,星期二|二|周二,星期三|三|周三,星期四|四|周四,星期五|五|周五,星期六|六|周六", + numerals: "〇,一,二,三,四,五,六,七,八,九", + placeholders: "十,百,千,万", + short: "{yyyy}-{MM}-{dd}", + medium: "{yyyy}年{M}月{d}日", + long: "{yyyy}年{M}月{d}日{time}", + full: "{yyyy}年{M}月{d}日{weekday}{time}", + stamp: "{yyyy}年{M}月{d}日{H}:{mm}{dow}", + time: "{tt}{h}点{mm}分", + past: "{num}{unit}{sign}", + future: "{num}{unit}{sign}", + duration: "{num}{unit}", + timeSuffixes: ",秒,分钟?,点|时,日|号,,月,年", + ampm: "上午,下午", + modifiers: [ + { name: "day", src: "大前天", value: -3 }, + { name: "day", src: "前天", value: -2 }, + { name: "day", src: "昨天", value: -1 }, + { name: "day", src: "今天", value: 0 }, + { name: "day", src: "明天", value: 1 }, + { name: "day", src: "后天", value: 2 }, + { name: "day", src: "大后天", value: 3 }, + { name: "sign", src: "前", value: -1 }, + { name: "sign", src: "后", value: 1 }, + { name: "shift", src: "上|去", value: -1 }, + { name: "shift", src: "这", value: 0 }, + { name: "shift", src: "下|明", value: 1 }, ], - 'parse': [ - '{num}{unit}{sign}', - '{shift}{unit:5-7}', - '{year?}{month}', - '{year}' + parse: [ + "{num}{unit}{sign}", + "{shift}{unit:5-7}", + "{year?}{month}", + "{year}", ], - 'timeParse': [ - '{day|weekday}', - '{shift}{weekday}', - '{year?}{month?}{date}' - ] + timeParse: ["{day|weekday}", "{shift}{weekday}", "{year?}{month?}{date}"], }); - /* * Traditional Chinese locale definition. * See the readme for customization and more information. @@ -6317,54 +6592,49 @@ * Sugar.Date.setLocale('zh-TW') * */ - Sugar.Date.addLocale('zh-TW', { - 'ampmFront': true, - 'numeralUnits': true, - 'allowsFullWidth': true, - 'timeMarkerOptional': true, - 'units': '毫秒,秒鐘,分鐘,小時,天,個星期|週,個月,年', - 'weekdays': '星期日|日|週日|星期天,星期一|一|週一,星期二|二|週二,星期三|三|週三,星期四|四|週四,星期五|五|週五,星期六|六|週六', - 'numerals': '〇,一,二,三,四,五,六,七,八,九', - 'placeholders': '十,百,千,万', - 'short': '{yyyy}/{MM}/{dd}', - 'medium': '{yyyy}年{M}月{d}日', - 'long': '{yyyy}年{M}月{d}日{time}', - 'full': '{yyyy}年{M}月{d}日{weekday}{time}', - 'stamp': '{yyyy}年{M}月{d}日{H}:{mm}{dow}', - 'time': '{tt}{h}點{mm}分', - 'past': '{num}{unit}{sign}', - 'future': '{num}{unit}{sign}', - 'duration': '{num}{unit}', - 'timeSuffixes': ',秒,分鐘?,點|時,日|號,,月,年', - 'ampm': '上午,下午', - 'modifiers': [ - { 'name': 'day', 'src': '大前天', 'value': -3 }, - { 'name': 'day', 'src': '前天', 'value': -2 }, - { 'name': 'day', 'src': '昨天', 'value': -1 }, - { 'name': 'day', 'src': '今天', 'value': 0 }, - { 'name': 'day', 'src': '明天', 'value': 1 }, - { 'name': 'day', 'src': '後天', 'value': 2 }, - { 'name': 'day', 'src': '大後天', 'value': 3 }, - { 'name': 'sign', 'src': '前', 'value': -1 }, - { 'name': 'sign', 'src': '後', 'value': 1 }, - { 'name': 'shift', 'src': '上|去', 'value': -1 }, - { 'name': 'shift', 'src': '這', 'value': 0 }, - { 'name': 'shift', 'src': '下|明', 'value': 1 } + Sugar.Date.addLocale("zh-TW", { + ampmFront: true, + numeralUnits: true, + allowsFullWidth: true, + timeMarkerOptional: true, + units: "毫秒,秒鐘,分鐘,小時,天,個星期|週,個月,年", + weekdays: + "星期日|日|週日|星期天,星期一|一|週一,星期二|二|週二,星期三|三|週三,星期四|四|週四,星期五|五|週五,星期六|六|週六", + numerals: "〇,一,二,三,四,五,六,七,八,九", + placeholders: "十,百,千,万", + short: "{yyyy}/{MM}/{dd}", + medium: "{yyyy}年{M}月{d}日", + long: "{yyyy}年{M}月{d}日{time}", + full: "{yyyy}年{M}月{d}日{weekday}{time}", + stamp: "{yyyy}年{M}月{d}日{H}:{mm}{dow}", + time: "{tt}{h}點{mm}分", + past: "{num}{unit}{sign}", + future: "{num}{unit}{sign}", + duration: "{num}{unit}", + timeSuffixes: ",秒,分鐘?,點|時,日|號,,月,年", + ampm: "上午,下午", + modifiers: [ + { name: "day", src: "大前天", value: -3 }, + { name: "day", src: "前天", value: -2 }, + { name: "day", src: "昨天", value: -1 }, + { name: "day", src: "今天", value: 0 }, + { name: "day", src: "明天", value: 1 }, + { name: "day", src: "後天", value: 2 }, + { name: "day", src: "大後天", value: 3 }, + { name: "sign", src: "前", value: -1 }, + { name: "sign", src: "後", value: 1 }, + { name: "shift", src: "上|去", value: -1 }, + { name: "shift", src: "這", value: 0 }, + { name: "shift", src: "下|明", value: 1 }, ], - 'parse': [ - '{num}{unit}{sign}', - '{shift}{unit:5-7}', - '{year?}{month}', - '{year}' + parse: [ + "{num}{unit}{sign}", + "{shift}{unit:5-7}", + "{year?}{month}", + "{year}", ], - 'timeParse': [ - '{day|weekday}', - '{shift}{weekday}', - '{year?}{month?}{date}' - ] + timeParse: ["{day|weekday}", "{shift}{weekday}", "{year?}{month?}{date}"], }); - - }).call(this); // When this script is loaded by the legacy column experiment, @@ -6372,6 +6642,6 @@ // object. However, the method that vanilla Sugar.js uses to // initialize somehow places itself outside of the object's scope. // So, we need to manually put it back in. -if (typeof LegacyColumn !== 'undefined') { +if (typeof LegacyColumn !== "undefined") { LegacyColumn.Sugar = Sugar; -} \ No newline at end of file +}