You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21436 lines
1.4 MiB

3 years ago
/*
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP
if you want to view the source visit the plugins github repository
*/
'use strict';
var obsidian = require('obsidian');
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
/** @deprecated */
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
/**
* Represents TODO items in Markdown.
*
* This class shouldn't break original line.
*/
class Todo {
constructor(lineIndex, prefix, check, suffix, body) {
this.lineIndex = lineIndex;
this.prefix = prefix;
this.check = check;
this.suffix = suffix;
this.body = body;
}
static parse(lineIndex, line) {
const match = Todo.regexp.exec(line);
if (match) {
return new Todo(lineIndex, match.groups['prefix'], match.groups['check'], match.groups['suffix'], match.groups['body']);
}
return null;
}
toMarkdown() {
return `${this.prefix}${this.check}${this.suffix}${this.body}`;
}
isChecked() {
return this.check === 'x';
}
setChecked(checked) {
this.check = checked ? 'x' : ' ';
}
clone() {
return Todo.parse(this.lineIndex, this.toMarkdown());
}
}
// e.g: ' - [x] hello'
// prefix: ' - [ '
// check: 'x'
// suffix: '] '
// body: hello
Todo.regexp = /^(?<prefix>\s*\- \[)(?<check>.)(?<suffix>\]\s+)(?<body>.*)$/;
class MarkdownDocument {
constructor(file, content) {
this.file = file;
this.lines = [];
this.todos = [];
this.parse(content);
}
parse(content) {
this.lines = content.split("\n");
this.todos = [];
this.lines.forEach((line, lineIndex) => {
const todo = Todo.parse(lineIndex, line);
if (todo) {
this.todos.push(todo);
}
});
}
getTodos() {
return this.todos;
}
insertTodo(lineIndex, todo) {
todo.lineIndex = lineIndex;
this.lines.splice(lineIndex, 0, todo.toMarkdown());
let todoIndex = -1;
for (const i in this.todos) {
const todo = this.todos[i];
if (todo.lineIndex >= lineIndex) {
if (todoIndex < 0) {
todoIndex = parseInt(i);
}
todo.lineIndex++;
}
}
if (todoIndex <= 0) {
this.todos.splice(0, 0, todo);
}
else {
this.todos.splice(todoIndex, 0, todo);
}
}
getTodo(lineIndex) {
const found = this.todos.find(todo => todo.lineIndex === lineIndex);
if (found == null) {
return null;
}
return found;
}
applyChanges() {
// apply changes of TODO items to lines
this.todos.forEach(todo => {
this.lines[todo.lineIndex] = todo.toMarkdown();
});
}
toMarkdown() {
this.applyChanges();
return this.lines.join('\n');
}
}
class ConstantReference {
constructor(_value) {
this._value = _value;
}
get value() {
return this._value;
}
}
class Reference {
constructor(_value) {
this._value = _value;
this.onChangeFunctions = [];
}
onChanged(listener) {
this.onChangeFunctions.push(listener);
}
get value() {
return this._value;
}
set value(value) {
const oldValue = this._value;
this._value = value;
this.onChangeFunctions.forEach((f) => {
f(oldValue, value);
});
}
}
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function createCommonjsModule(fn) {
var module = { exports: {} };
return fn(module, module.exports), module.exports;
}
function commonjsRequire (path) {
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
}
var moment = createCommonjsModule(function (module, exports) {
(function (global, factory) {
module.exports = factory() ;
}(commonjsGlobal, (function () {
var hookCallback;
function hooks() {
return hookCallback.apply(null, arguments);
}
// This is done to register the method called with moment()
// without creating circular dependencies.
function setHookCallback(callback) {
hookCallback = callback;
}
function isArray(input) {
return (
input instanceof Array ||
Object.prototype.toString.call(input) === '[object Array]'
);
}
function isObject(input) {
// IE8 will treat undefined and null as object if it wasn't for
// input != null
return (
input != null &&
Object.prototype.toString.call(input) === '[object Object]'
);
}
function hasOwnProp(a, b) {
return Object.prototype.hasOwnProperty.call(a, b);
}
function isObjectEmpty(obj) {
if (Object.getOwnPropertyNames) {
return Object.getOwnPropertyNames(obj).length === 0;
} else {
var k;
for (k in obj) {
if (hasOwnProp(obj, k)) {
return false;
}
}
return true;
}
}
function isUndefined(input) {
return input === void 0;
}
function isNumber(input) {
return (
typeof input === 'number' ||
Object.prototype.toString.call(input) === '[object Number]'
);
}
function isDate(input) {
return (
input instanceof Date ||
Object.prototype.toString.call(input) === '[object Date]'
);
}
function map(arr, fn) {
var res = [],
i;
for (i = 0; i < arr.length; ++i) {
res.push(fn(arr[i], i));
}
return res;
}
function extend(a, b) {
for (var i in b) {
if (hasOwnProp(b, i)) {
a[i] = b[i];
}
}
if (hasOwnProp(b, 'toString')) {
a.toString = b.toString;
}
if (hasOwnProp(b, 'valueOf')) {
a.valueOf = b.valueOf;
}
return a;
}
function createUTC(input, format, locale, strict) {
return createLocalOrUTC(input, format, locale, strict, true).utc();
}
function defaultParsingFlags() {
// We need to deep clone this object.
return {
empty: false,
unusedTokens: [],
unusedInput: [],
overflow: -2,
charsLeftOver: 0,
nullInput: false,
invalidEra: null,
invalidMonth: null,
invalidFormat: false,
userInvalidated: false,
iso: false,
parsedDateParts: [],
era: null,
meridiem: null,
rfc2822: false,
weekdayMismatch: false,
};
}
function getParsingFlags(m) {
if (m._pf == null) {
m._pf = defaultParsingFlags();
}
return m._pf;
}
var some;
if (Array.prototype.some) {
some = Array.prototype.some;
} else {
some = function (fun) {
var t = Object(this),
len = t.length >>> 0,
i;
for (i = 0; i < len; i++) {
if (i in t && fun.call(this, t[i], i, t)) {
return true;
}
}
return false;
};
}
function isValid(m) {
if (m._isValid == null) {
var flags = getParsingFlags(m),
parsedParts = some.call(flags.parsedDateParts, function (i) {
return i != null;
}),
isNowValid =
!isNaN(m._d.getTime()) &&
flags.overflow < 0 &&
!flags.empty &&
!flags.invalidEra &&
!flags.invalidMonth &&
!flags.invalidWeekday &&
!flags.weekdayMismatch &&
!flags.nullInput &&
!flags.invalidFormat &&
!flags.userInvalidated &&
(!flags.meridiem || (flags.meridiem && parsedParts));
if (m._strict) {
isNowValid =
isNowValid &&
flags.charsLeftOver === 0 &&
flags.unusedTokens.length === 0 &&
flags.bigHour === undefined;
}
if (Object.isFrozen == null || !Object.isFrozen(m)) {
m._isValid = isNowValid;
} else {
return isNowValid;
}
}
return m._isValid;
}
function createInvalid(flags) {
var m = createUTC(NaN);
if (flags != null) {
extend(getParsingFlags(m), flags);
} else {
getParsingFlags(m).userInvalidated = true;
}
return m;
}
// Plugins that add properties should also add the key here (null value),
// so we can properly clone ourselves.
var momentProperties = (hooks.momentProperties = []),
updateInProgress = false;
function copyConfig(to, from) {
var i, prop, val;
if (!isUndefined(from._isAMomentObject)) {
to._isAMomentObject = from._isAMomentObject;
}
if (!isUndefined(from._i)) {
to._i = from._i;
}
if (!isUndefined(from._f)) {
to._f = from._f;
}
if (!isUndefined(from._l)) {
to._l = from._l;
}
if (!isUndefined(from._strict)) {
to._strict = from._strict;
}
if (!isUndefined(from._tzm)) {
to._tzm = from._tzm;
}
if (!isUndefined(from._isUTC)) {
to._isUTC = from._isUTC;
}
if (!isUndefined(from._offset)) {
to._offset = from._offset;
}
if (!isUndefined(from._pf)) {
to._pf = getParsingFlags(from);
}
if (!isUndefined(from._locale)) {
to._locale = from._locale;
}
if (momentProperties.length > 0) {
for (i = 0; i < momentProperties.length; i++) {
prop = momentProperties[i];
val = from[prop];
if (!isUndefined(val)) {
to[prop] = val;
}
}
}
return to;
}
// Moment prototype object
function Moment(config) {
copyConfig(this, config);
this._d = new Date(config._d != null ? config._d.getTime() : NaN);
if (!this.isValid()) {
this._d = new Date(NaN);
}
// Prevent infinite loop in case updateOffset creates new moment
// objects.
if (updateInProgress === false) {
updateInProgress = true;
hooks.updateOffset(this);
updateInProgress = false;
}
}
function isMoment(obj) {
return (
obj instanceof Moment || (obj != null && obj._isAMomentObject != null)
);
}
function warn(msg) {
if (
hooks.suppressDeprecationWarnings === false &&
typeof console !== 'undefined' &&
console.warn
) {
console.warn('Deprecation warning: ' + msg);
}
}
function deprecate(msg, fn) {
var firstTime = true;
return extend(function () {
if (hooks.deprecationHandler != null) {
hooks.deprecationHandler(null, msg);
}
if (firstTime) {
var args = [],
arg,
i,
key;
for (i = 0; i < arguments.length; i++) {
arg = '';
if (typeof arguments[i] === 'object') {
arg += '\n[' + i + '] ';
for (key in arguments[0]) {
if (hasOwnProp(arguments[0], key)) {
arg += key + ': ' + arguments[0][key] + ', ';
}
}
arg = arg.slice(0, -2); // Remove trailing comma and space
} else {
arg = arguments[i];
}
args.push(arg);
}
warn(
msg +
'\nArguments: ' +
Array.prototype.slice.call(args).join('') +
'\n' +
new Error().stack
);
firstTime = false;
}
return fn.apply(this, arguments);
}, fn);
}
var deprecations = {};
function deprecateSimple(name, msg) {
if (hooks.deprecationHandler != null) {
hooks.deprecationHandler(name, msg);
}
if (!deprecations[name]) {
warn(msg);
deprecations[name] = true;
}
}
hooks.suppressDeprecationWarnings = false;
hooks.deprecationHandler = null;
function isFunction(input) {
return (
(typeof Function !== 'undefined' && input instanceof Function) ||
Object.prototype.toString.call(input) === '[object Function]'
);
}
function set(config) {
var prop, i;
for (i in config) {
if (hasOwnProp(config, i)) {
prop = config[i];
if (isFunction(prop)) {
this[i] = prop;
} else {
this['_' + i] = prop;
}
}
}
this._config = config;
// Lenient ordinal parsing accepts just a number in addition to
// number + (possibly) stuff coming from _dayOfMonthOrdinalParse.
// TODO: Remove "ordinalParse" fallback in next major release.
this._dayOfMonthOrdinalParseLenient = new RegExp(
(this._dayOfMonthOrdinalParse.source || this._ordinalParse.source) +
'|' +
/\d{1,2}/.source
);
}
function mergeConfigs(parentConfig, childConfig) {
var res = extend({}, parentConfig),
prop;
for (prop in childConfig) {
if (hasOwnProp(childConfig, prop)) {
if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
res[prop] = {};
extend(res[prop], parentConfig[prop]);
extend(res[prop], childConfig[prop]);
} else if (childConfig[prop] != null) {
res[prop] = childConfig[prop];
} else {
delete res[prop];
}
}
}
for (prop in parentConfig) {
if (
hasOwnProp(parentConfig, prop) &&
!hasOwnProp(childConfig, prop) &&
isObject(parentConfig[prop])
) {
// make sure changes to properties don't modify parent config
res[prop] = extend({}, res[prop]);
}
}
return res;
}
function Locale(config) {
if (config != null) {
this.set(config);
}
}
var keys;
if (Object.keys) {
keys = Object.keys;
} else {
keys = function (obj) {
var i,
res = [];
for (i in obj) {
if (hasOwnProp(obj, i)) {
res.push(i);
}
}
return res;
};
}
var defaultCalendar = {
sameDay: '[Today at] LT',
nextDay: '[Tomorrow at] LT',
nextWeek: 'dddd [at] LT',
lastDay: '[Yesterday at] LT',
lastWeek: '[Last] dddd [at] LT',
sameElse: 'L',
};
function calendar(key, mom, now) {
var output = this._calendar[key] || this._calendar['sameElse'];
return isFunction(output) ? output.call(mom, now) : output;
}
function zeroFill(number, targetLength, forceSign) {
var absNumber = '' + Math.abs(number),
zerosToFill = targetLength - absNumber.length,
sign = number >= 0;
return (
(sign ? (forceSign ? '+' : '') : '-') +
Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) +
absNumber
);
}
var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,
localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g,
formatFunctions = {},
formatTokenFunctions = {};
// token: 'M'
// padded: ['MM', 2]
// ordinal: 'Mo'
// callback: function () { this.month() + 1 }
function addFormatToken(token, padded, ordinal, callback) {
var func = callback;
if (typeof callback === 'string') {
func = function () {
return this[callback]();
};
}
if (token) {
formatTokenFunctions[token] = func;
}
if (padded) {
formatTokenFunctions[padded[0]] = function () {
return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
};
}
if (ordinal) {
formatTokenFunctions[ordinal] = function () {
return this.localeData().ordinal(
func.apply(this, arguments),
token
);
};
}
}
function removeFormattingTokens(input) {
if (input.match(/\[[\s\S]/)) {
return input.replace(/^\[|\]$/g, '');
}
return input.replace(/\\/g, '');
}
function makeFormatFunction(format) {
var array = format.match(formattingTokens),
i,
length;
for (i = 0, length = array.length; i < length; i++) {
if (formatTokenFunctions[array[i]]) {
array[i] = formatTokenFunctions[array[i]];
} else {
array[i] = removeFormattingTokens(array[i]);
}
}
return function (mom) {
var output = '',
i;
for (i = 0; i < length; i++) {
output += isFunction(array[i])
? array[i].call(mom, format)
: array[i];
}
return output;
};
}
// format date using native date object
function formatMoment(m, format) {
if (!m.isValid()) {
return m.localeData().invalidDate();
}
format = expandFormat(format, m.localeData());
formatFunctions[format] =
formatFunctions[format] || makeFormatFunction(format);
return formatFunctions[format](m);
}
function expandFormat(format, locale) {
var i = 5;
function replaceLongDateFormatTokens(input) {
return locale.longDateFormat(input) || input;
}
localFormattingTokens.lastIndex = 0;
while (i >= 0 && localFormattingTokens.test(format)) {
format = format.replace(
localFormattingTokens,
replaceLongDateFormatTokens
);
localFormattingTokens.lastIndex = 0;
i -= 1;
}
return format;
}
var defaultLongDateFormat = {
LTS: 'h:mm:ss A',
LT: 'h:mm A',
L: 'MM/DD/YYYY',
LL: 'MMMM D, YYYY',
LLL: 'MMMM D, YYYY h:mm A',
LLLL: 'dddd, MMMM D, YYYY h:mm A',
};
function longDateFormat(key) {
var format = this._longDateFormat[key],
formatUpper = this._longDateFormat[key.toUpperCase()];
if (format || !formatUpper) {
return format;
}
this._longDateFormat[key] = formatUpper
.match(formattingTokens)
.map(function (tok) {
if (
tok === 'MMMM' ||
tok === 'MM' ||
tok === 'DD' ||
tok === 'dddd'
) {
return tok.slice(1);
}
return tok;
})
.join('');
return this._longDateFormat[key];
}
var defaultInvalidDate = 'Invalid date';
function invalidDate() {
return this._invalidDate;
}
var defaultOrdinal = '%d',
defaultDayOfMonthOrdinalParse = /\d{1,2}/;
function ordinal(number) {
return this._ordinal.replace('%d', number);
}
var defaultRelativeTime = {
future: 'in %s',
past: '%s ago',
s: 'a few seconds',
ss: '%d seconds',
m: 'a minute',
mm: '%d minutes',
h: 'an hour',
hh: '%d hours',
d: 'a day',
dd: '%d days',
w: 'a week',
ww: '%d weeks',
M: 'a month',
MM: '%d months',
y: 'a year',
yy: '%d years',
};
function relativeTime(number, withoutSuffix, string, isFuture) {
var output = this._relativeTime[string];
return isFunction(output)
? output(number, withoutSuffix, string, isFuture)
: output.replace(/%d/i, number);
}
function pastFuture(diff, output) {
var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
return isFunction(format) ? format(output) : format.replace(/%s/i, output);
}
var aliases = {};
function addUnitAlias(unit, shorthand) {
var lowerCase = unit.toLowerCase();
aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
}
function normalizeUnits(units) {
return typeof units === 'string'
? aliases[units] || aliases[units.toLowerCase()]
: undefined;
}
function normalizeObjectUnits(inputObject) {
var normalizedInput = {},
normalizedProp,
prop;
for (prop in inputObject) {
if (hasOwnProp(inputObject, prop)) {
normalizedProp = normalizeUnits(prop);
if (normalizedProp) {
normalizedInput[normalizedProp] = inputObject[prop];
}
}
}
return normalizedInput;
}
var priorities = {};
function addUnitPriority(unit, priority) {
priorities[unit] = priority;
}
function getPrioritizedUnits(unitsObj) {
var units = [],
u;
for (u in unitsObj) {
if (hasOwnProp(unitsObj, u)) {
units.push({ unit: u, priority: priorities[u] });
}
}
units.sort(function (a, b) {
return a.priority - b.priority;
});
return units;
}
function isLeapYear(year) {
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
}
function absFloor(number) {
if (number < 0) {
// -0 -> 0
return Math.ceil(number) || 0;
} else {
return Math.floor(number);
}
}
function toInt(argumentForCoercion) {
var coercedNumber = +argumentForCoercion,
value = 0;
if (coercedNumber !== 0 && isFinite(coercedNumber)) {
value = absFloor(coercedNumber);
}
return value;
}
function makeGetSet(unit, keepTime) {
return function (value) {
if (value != null) {
set$1(this, unit, value);
hooks.updateOffset(this, keepTime);
return this;
} else {
return get(this, unit);
}
};
}
function get(mom, unit) {
return mom.isValid()
? mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]()
: NaN;
}
function set$1(mom, unit, value) {
if (mom.isValid() && !isNaN(value)) {
if (
unit === 'FullYear' &&
isLeapYear(mom.year()) &&
mom.month() === 1 &&
mom.date() === 29
) {
value = toInt(value);
mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](
value,
mom.month(),
daysInMonth(value, mom.month())
);
} else {
mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
}
}
}
// MOMENTS
function stringGet(units) {
units = normalizeUnits(units);
if (isFunction(this[units])) {
return this[units]();
}
return this;
}
function stringSet(units, value) {
if (typeof units === 'object') {
units = normalizeObjectUnits(units);
var prioritized = getPrioritizedUnits(units),
i;
for (i = 0; i < prioritized.length; i++) {
this[prioritized[i].unit](units[prioritized[i].unit]);
}
} else {
units = normalizeUnits(units);
if (isFunction(this[units])) {
return this[units](value);
}
}
return this;
}
var match1 = /\d/, // 0 - 9
match2 = /\d\d/, // 00 - 99
match3 = /\d{3}/, // 000 - 999
match4 = /\d{4}/, // 0000 - 9999
match6 = /[+-]?\d{6}/, // -999999 - 999999
match1to2 = /\d\d?/, // 0 - 99
match3to4 = /\d\d\d\d?/, // 999 - 9999
match5to6 = /\d\d\d\d\d\d?/, // 99999 - 999999
match1to3 = /\d{1,3}/, // 0 - 999
match1to4 = /\d{1,4}/, // 0 - 9999
match1to6 = /[+-]?\d{1,6}/, // -999999 - 999999
matchUnsigned = /\d+/, // 0 - inf
matchSigned = /[+-]?\d+/, // -inf - inf
matchOffset = /Z|[+-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z
matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi, // +00 -00 +00:00 -00:00 +0000 -0000 or Z
matchTimestamp = /[+-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123
// any word (or two) characters or numbers including two/three word month in arabic.
// includes scottish gaelic two word and hyphenated months
matchWord = /[0-9]{0,256}['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFF07\uFF10-\uFFEF]{1,256}|[\u0600-\u06FF\/]{1,256}(\s*?[\u0600-\u06FF]{1,256}){1,2}/i,
regexes;
regexes = {};
function addRegexToken(token, regex, strictRegex) {
regexes[token] = isFunction(regex)
? regex
: function (isStrict, localeData) {
return isStrict && strictRegex ? strictRegex : regex;
};
}
function getParseRegexForToken(token, config) {
if (!hasOwnProp(regexes, token)) {
return new RegExp(unescapeFormat(token));
}
return regexes[token](config._strict, config._locale);
}
// Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
function unescapeFormat(s) {
return regexEscape(
s
.replace('\\', '')
.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (
matched,
p1,
p2,
p3,
p4
) {
return p1 || p2 || p3 || p4;
})
);
}
function regexEscape(s) {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
var tokens = {};
function addParseToken(token, callback) {
var i,
func = callback;
if (typeof token === 'string') {
token = [token];
}
if (isNumber(callback)) {
func = function (input, array) {
array[callback] = toInt(input);
};
}
for (i = 0; i < token.length; i++) {
tokens[token[i]] = func;
}
}
function addWeekParseToken(token, callback) {
addParseToken(token, function (input, array, config, token) {
config._w = config._w || {};
callback(input, config._w, config, token);
});
}
function addTimeToArrayFromToken(token, input, config) {
if (input != null && hasOwnProp(tokens, token)) {
tokens[token](input, config._a, config, token);
}
}
var YEAR = 0,
MONTH = 1,
DATE = 2,
HOUR = 3,
MINUTE = 4,
SECOND = 5,
MILLISECOND = 6,
WEEK = 7,
WEEKDAY = 8;
function mod(n, x) {
return ((n % x) + x) % x;
}
var indexOf;
if (Array.prototype.indexOf) {
indexOf = Array.prototype.indexOf;
} else {
indexOf = function (o) {
// I know
var i;
for (i = 0; i < this.length; ++i) {
if (this[i] === o) {
return i;
}
}
return -1;
};
}
function daysInMonth(year, month) {
if (isNaN(year) || isNaN(month)) {
return NaN;
}
var modMonth = mod(month, 12);
year += (month - modMonth) / 12;
return modMonth === 1
? isLeapYear(year)
? 29
: 28
: 31 - ((modMonth % 7) % 2);
}
// FORMATTING
addFormatToken('M', ['MM', 2], 'Mo', function () {
return this.month() + 1;
});
addFormatToken('MMM', 0, 0, function (format) {
return this.localeData().monthsShort(this, format);
});
addFormatToken('MMMM', 0, 0, function (format) {
return this.localeData().months(this, format);
});
// ALIASES
addUnitAlias('month', 'M');
// PRIORITY
addUnitPriority('month', 8);
// PARSING
addRegexToken('M', match1to2);
addRegexToken('MM', match1to2, match2);
addRegexToken('MMM', function (isStrict, locale) {
return locale.monthsShortRegex(isStrict);
});
addRegexToken('MMMM', function (isStrict, locale) {
return locale.monthsRegex(isStrict);
});
addParseToken(['M', 'MM'], function (input, array) {
array[MONTH] = toInt(input) - 1;
});
addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
var month = config._locale.monthsParse(input, token, config._strict);
// if we didn't find a month name, mark the date as invalid.
if (month != null) {
array[MONTH] = month;
} else {
getParsingFlags(config).invalidMonth = input;
}
});
// LOCALES
var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split(
'_'
),
defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split(
'_'
),
MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s)+MMMM?/,
defaultMonthsShortRegex = matchWord,
defaultMonthsRegex = matchWord;
function localeMonths(m, format) {
if (!m) {
return isArray(this._months)
? this._months
: this._months['standalone'];
}
return isArray(this._months)
? this._months[m.month()]
: this._months[
(this._months.isFormat || MONTHS_IN_FORMAT).test(format)
? 'format'
: 'standalone'
][m.month()];
}
function localeMonthsShort(m, format) {
if (!m) {
return isArray(this._monthsShort)
? this._monthsShort
: this._monthsShort['standalone'];
}
return isArray(this._monthsShort)
? this._monthsShort[m.month()]
: this._monthsShort[
MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'
][m.month()];
}
function handleStrictParse(monthName, format, strict) {
var i,
ii,
mom,
llc = monthName.toLocaleLowerCase();
if (!this._monthsParse) {
// this is not used
this._monthsParse = [];
this._longMonthsParse = [];
this._shortMonthsParse = [];
for (i = 0; i < 12; ++i) {
mom = createUTC([2000, i]);
this._shortMonthsParse[i] = this.monthsShort(
mom,
''
).toLocaleLowerCase();
this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
}
}
if (strict) {
if (format === 'MMM') {
ii = indexOf.call(this._shortMonthsParse, llc);
return ii !== -1 ? ii : null;
} else {
ii = indexOf.call(this._longMonthsParse, llc);
return ii !== -1 ? ii : null;
}
} else {
if (format === 'MMM') {
ii = indexOf.call(this._shortMonthsParse, llc);
if (ii !== -1) {
return ii;
}
ii = indexOf.call(this._longMonthsParse, llc);
return ii !== -1 ? ii : null;
} else {
ii = indexOf.call(this._longMonthsParse, llc);
if (ii !== -1) {
return ii;
}
ii = indexOf.call(this._shortMonthsParse, llc);
return ii !== -1 ? ii : null;
}
}
}
function localeMonthsParse(monthName, format, strict) {
var i, mom, regex;
if (this._monthsParseExact) {
return handleStrictParse.call(this, monthName, format, strict);
}
if (!this._monthsParse) {
this._monthsParse = [];
this._longMonthsParse = [];
this._shortMonthsParse = [];
}
// TODO: add sorting
// Sorting makes sure if one month (or abbr) is a prefix of another
// see sorting in computeMonthsParse
for (i = 0; i < 12; i++) {
// make the regex if we don't have it already
mom = createUTC([2000, i]);
if (strict && !this._longMonthsParse[i]) {
this._longMonthsParse[i] = new RegExp(
'^' + this.months(mom, '').replace('.', '') + '$',
'i'
);
this._shortMonthsParse[i] = new RegExp(
'^' + this.monthsShort(mom, '').replace('.', '') + '$',
'i'
);
}
if (!strict && !this._monthsParse[i]) {
regex =
'^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
}
// test the regex
if (
strict &&
format === 'MMMM' &&
this._longMonthsParse[i].test(monthName)
) {
return i;
} else if (
strict &&
format === 'MMM' &&
this._shortMonthsParse[i].test(monthName)
) {
return i;
} else if (!strict && this._monthsParse[i].test(monthName)) {
return i;
}
}
}
// MOMENTS
function setMonth(mom, value) {
var dayOfMonth;
if (!mom.isValid()) {
// No op
return mom;
}
if (typeof value === 'string') {
if (/^\d+$/.test(value)) {
value = toInt(value);
} else {
value = mom.localeData().monthsParse(value);
// TODO: Another silent failure?
if (!isNumber(value)) {
return mom;
}
}
}
dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
return mom;
}
function getSetMonth(value) {
if (value != null) {
setMonth(this, value);
hooks.updateOffset(this, true);
return this;
} else {
return get(this, 'Month');
}
}
function getDaysInMonth() {
return daysInMonth(this.year(), this.month());
}
function monthsShortRegex(isStrict) {
if (this._monthsParseExact) {
if (!hasOwnProp(this, '_monthsRegex')) {
computeMonthsParse.call(this);
}
if (isStrict) {
return this._monthsShortStrictRegex;
} else {
return this._monthsShortRegex;
}
} else {
if (!hasOwnProp(this, '_monthsShortRegex')) {
this._monthsShortRegex = defaultMonthsShortRegex;
}
return this._monthsShortStrictRegex && isStrict
? this._monthsShortStrictRegex
: this._monthsShortRegex;
}
}
function monthsRegex(isStrict) {
if (this._monthsParseExact) {
if (!hasOwnProp(this, '_monthsRegex')) {
computeMonthsParse.call(this);
}
if (isStrict) {
return this._monthsStrictRegex;
} else {
return this._monthsRegex;
}
} else {
if (!hasOwnProp(this, '_monthsRegex')) {
this._monthsRegex = defaultMonthsRegex;
}
return this._monthsStrictRegex && isStrict
? this._monthsStrictRegex
: this._monthsRegex;
}
}
function computeMonthsParse() {
function cmpLenRev(a, b) {
return b.length - a.length;
}
var shortPieces = [],
longPieces = [],
mixedPieces = [],
i,
mom;
for (i = 0; i < 12; i++) {
// make the regex if we don't have it already
mom = createUTC([2000, i]);
shortPieces.push(this.monthsShort(mom, ''));
longPieces.push(this.months(mom, ''));
mixedPieces.push(this.months(mom, ''));
mixedPieces.push(this.monthsShort(mom, ''));
}
// Sorting makes sure if one month (or abbr) is a prefix of another it
// will match the longer piece.
shortPieces.sort(cmpLenRev);
longPieces.sort(cmpLenRev);
mixedPieces.sort(cmpLenRev);
for (i = 0; i < 12; i++) {
shortPieces[i] = regexEscape(shortPieces[i]);
longPieces[i] = regexEscape(longPieces[i]);
}
for (i = 0; i < 24; i++) {
mixedPieces[i] = regexEscape(mixedPieces[i]);
}
this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
this._monthsShortRegex = this._monthsRegex;
this._monthsStrictRegex = new RegExp(
'^(' + longPieces.join('|') + ')',
'i'
);
this._monthsShortStrictRegex = new RegExp(
'^(' + shortPieces.join('|') + ')',
'i'
);
}
// FORMATTING
addFormatToken('Y', 0, 0, function () {
var y = this.year();
return y <= 9999 ? zeroFill(y, 4) : '+' + y;
});
addFormatToken(0, ['YY', 2], 0, function () {
return this.year() % 100;
});
addFormatToken(0, ['YYYY', 4], 0, 'year');
addFormatToken(0, ['YYYYY', 5], 0, 'year');
addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
// ALIASES
addUnitAlias('year', 'y');
// PRIORITIES
addUnitPriority('year', 1);
// PARSING
addRegexToken('Y', matchSigned);
addRegexToken('YY', match1to2, match2);
addRegexToken('YYYY', match1to4, match4);
addRegexToken('YYYYY', match1to6, match6);
addRegexToken('YYYYYY', match1to6, match6);
addParseToken(['YYYYY', 'YYYYYY'], YEAR);
addParseToken('YYYY', function (input, array) {
array[YEAR] =
input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
});
addParseToken('YY', function (input, array) {
array[YEAR] = hooks.parseTwoDigitYear(input);
});
addParseToken('Y', function (input, array) {
array[YEAR] = parseInt(input, 10);
});
// HELPERS
function daysInYear(year) {
return isLeapYear(year) ? 366 : 365;
}
// HOOKS
hooks.parseTwoDigitYear = function (input) {
return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
};
// MOMENTS
var getSetYear = makeGetSet('FullYear', true);
function getIsLeapYear() {
return isLeapYear(this.year());
}
function createDate(y, m, d, h, M, s, ms) {
// can't just apply() to create a date:
// https://stackoverflow.com/q/181348
var date;
// the date constructor remaps years 0-99 to 1900-1999
if (y < 100 && y >= 0) {
// preserve leap years using a full 400 year cycle, then reset
date = new Date(y + 400, m, d, h, M, s, ms);
if (isFinite(date.getFullYear())) {
date.setFullYear(y);
}
} else {
date = new Date(y, m, d, h, M, s, ms);
}
return date;
}
function createUTCDate(y) {
var date, args;
// the Date.UTC function remaps years 0-99 to 1900-1999
if (y < 100 && y >= 0) {
args = Array.prototype.slice.call(arguments);
// preserve leap years using a full 400 year cycle, then reset
args[0] = y + 400;
date = new Date(Date.UTC.apply(null, args));
if (isFinite(date.getUTCFullYear())) {
date.setUTCFullYear(y);
}
} else {
date = new Date(Date.UTC.apply(null, arguments));
}
return date;
}
// start-of-first-week - start-of-year
function firstWeekOffset(year, dow, doy) {
var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
fwd = 7 + dow - doy,
// first-week day local weekday -- which local weekday is fwd
fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
return -fwdlw + fwd - 1;
}
// https://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
var localWeekday = (7 + weekday - dow) % 7,
weekOffset = firstWeekOffset(year, dow, doy),
dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
resYear,
resDayOfYear;
if (dayOfYear <= 0) {
resYear = year - 1;
resDayOfYear = daysInYear(resYear) + dayOfYear;
} else if (dayOfYear > daysInYear(year)) {
resYear = year + 1;
resDayOfYear = dayOfYear - daysInYear(year);
} else {
resYear = year;
resDayOfYear = dayOfYear;
}
return {
year: resYear,
dayOfYear: resDayOfYear,
};
}
function weekOfYear(mom, dow, doy) {
var weekOffset = firstWeekOffset(mom.year(), dow, doy),
week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
resWeek,
resYear;
if (week < 1) {
resYear = mom.year() - 1;
resWeek = week + weeksInYear(resYear, dow, doy);
} else if (week > weeksInYear(mom.year(), dow, doy)) {
resWeek = week - weeksInYear(mom.year(), dow, doy);
resYear = mom.year() + 1;
} else {
resYear = mom.year();
resWeek = week;
}
return {
week: resWeek,
year: resYear,
};
}
function weeksInYear(year, dow, doy) {
var weekOffset = firstWeekOffset(year, dow, doy),
weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
}
// FORMATTING
addFormatToken('w', ['ww', 2], 'wo', 'week');
addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
// ALIASES
addUnitAlias('week', 'w');
addUnitAlias('isoWeek', 'W');
// PRIORITIES
addUnitPriority('week', 5);
addUnitPriority('isoWeek', 5);
// PARSING
addRegexToken('w', match1to2);
addRegexToken('ww', match1to2, match2);
addRegexToken('W', match1to2);
addRegexToken('WW', match1to2, match2);
addWeekParseToken(['w', 'ww', 'W', 'WW'], function (
input,
week,
config,
token
) {
week[token.substr(0, 1)] = toInt(input);
});
// HELPERS
// LOCALES
function localeWeek(mom) {
return weekOfYear(mom, this._week.dow, this._week.doy).week;
}
var defaultLocaleWeek = {
dow: 0, // Sunday is the first day of the week.
doy: 6, // The week that contains Jan 6th is the first week of the year.
};
function localeFirstDayOfWeek() {
return this._week.dow;
}
function localeFirstDayOfYear() {
return this._week.doy;
}
// MOMENTS
function getSetWeek(input) {
var week = this.localeData().week(this);
return input == null ? week : this.add((input - week) * 7, 'd');
}
function getSetISOWeek(input) {
var week = weekOfYear(this, 1, 4).week;
return input == null ? week : this.add((input - week) * 7, 'd');
}
// FORMATTING
addFormatToken('d', 0, 'do', 'day');
addFormatToken('dd', 0, 0, function (format) {
return this.localeData().weekdaysMin(this, format);
});
addFormatToken('ddd', 0, 0, function (format) {
return this.localeData().weekdaysShort(this, format);
});
addFormatToken('dddd', 0, 0, function (format) {
return this.localeData().weekdays(this, format);
});
addFormatToken('e', 0, 0, 'weekday');
addFormatToken('E', 0, 0, 'isoWeekday');
// ALIASES
addUnitAlias('day', 'd');
addUnitAlias('weekday', 'e');
addUnitAlias('isoWeekday', 'E');
// PRIORITY
addUnitPriority('day', 11);
addUnitPriority('weekday', 11);
addUnitPriority('isoWeekday', 11);
// PARSING
addRegexToken('d', match1to2);
addRegexToken('e', match1to2);
addRegexToken('E', match1to2);
addRegexToken('dd', function (isStrict, locale) {
return locale.weekdaysMinRegex(isStrict);
});
addRegexToken('ddd', function (isStrict, locale) {
return locale.weekdaysShortRegex(isStrict);
});
addRegexToken('dddd', function (isStrict, locale) {
return locale.weekdaysRegex(isStrict);
});
addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
var weekday = config._locale.weekdaysParse(input, token, config._strict);
// if we didn't get a weekday name, mark the date as invalid
if (weekday != null) {
week.d = weekday;
} else {
getParsingFlags(config).invalidWeekday = input;
}
});
addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
week[token] = toInt(input);
});
// HELPERS
function parseWeekday(input, locale) {
if (typeof input !== 'string') {
return input;
}
if (!isNaN(input)) {
return parseInt(input, 10);
}
input = locale.weekdaysParse(input);
if (typeof input === 'number') {
return input;
}
return null;
}
function parseIsoWeekday(input, locale) {
if (typeof input === 'string') {
return locale.weekdaysParse(input) % 7 || 7;
}
return isNaN(input) ? null : input;
}
// LOCALES
function shiftWeekdays(ws, n) {
return ws.slice(n, 7).concat(ws.slice(0, n));
}
var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split(
'_'
),
defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
defaultWeekdaysRegex = matchWord,
defaultWeekdaysShortRegex = matchWord,
defaultWeekdaysMinRegex = matchWord;
function localeWeekdays(m, format) {
var weekdays = isArray(this._weekdays)
? this._weekdays
: this._weekdays[
m && m !== true && this._weekdays.isFormat.test(format)
? 'format'
: 'standalone'
];
return m === true
? shiftWeekdays(weekdays, this._week.dow)
: m
? weekdays[m.day()]
: weekdays;
}
function localeWeekdaysShort(m) {
return m === true
? shiftWeekdays(this._weekdaysShort, this._week.dow)
: m
? this._weekdaysShort[m.day()]
: this._weekdaysShort;
}
function localeWeekdaysMin(m) {
return m === true
? shiftWeekdays(this._weekdaysMin, this._week.dow)
: m
? this._weekdaysMin[m.day()]
: this._weekdaysMin;
}
function handleStrictParse$1(weekdayName, format, strict) {
var i,
ii,
mom,
llc = weekdayName.toLocaleLowerCase();
if (!this._weekdaysParse) {
this._weekdaysParse = [];
this._shortWeekdaysParse = [];
this._minWeekdaysParse = [];
for (i = 0; i < 7; ++i) {
mom = createUTC([2000, 1]).day(i);
this._minWeekdaysParse[i] = this.weekdaysMin(
mom,
''
).toLocaleLowerCase();
this._shortWeekdaysParse[i] = this.weekdaysShort(
mom,
''
).toLocaleLowerCase();
this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
}
}
if (strict) {
if (format === 'dddd') {
ii = indexOf.call(this._weekdaysParse, llc);
return ii !== -1 ? ii : null;
} else if (format === 'ddd') {
ii = indexOf.call(this._shortWeekdaysParse, llc);
return ii !== -1 ? ii : null;
} else {
ii = indexOf.call(this._minWeekdaysParse, llc);
return ii !== -1 ? ii : null;
}
} else {
if (format === 'dddd') {
ii = indexOf.call(this._weekdaysParse, llc);
if (ii !== -1) {
return ii;
}
ii = indexOf.call(this._shortWeekdaysParse, llc);
if (ii !== -1) {
return ii;
}
ii = indexOf.call(this._minWeekdaysParse, llc);
return ii !== -1 ? ii : null;
} else if (format === 'ddd') {
ii = indexOf.call(this._shortWeekdaysParse, llc);
if (ii !== -1) {
return ii;
}
ii = indexOf.call(this._weekdaysParse, llc);
if (ii !== -1) {
return ii;
}
ii = indexOf.call(this._minWeekdaysParse, llc);
return ii !== -1 ? ii : null;
} else {
ii = indexOf.call(this._minWeekdaysParse, llc);
if (ii !== -1) {
return ii;
}
ii = indexOf.call(this._weekdaysParse, llc);
if (ii !== -1) {
return ii;
}
ii = indexOf.call(this._shortWeekdaysParse, llc);
return ii !== -1 ? ii : null;
}
}
}
function localeWeekdaysParse(weekdayName, format, strict) {
var i, mom, regex;
if (this._weekdaysParseExact) {
return handleStrictParse$1.call(this, weekdayName, format, strict);
}
if (!this._weekdaysParse) {
this._weekdaysParse = [];
this._minWeekdaysParse = [];
this._shortWeekdaysParse = [];
this._fullWeekdaysParse = [];
}
for (i = 0; i < 7; i++) {
// make the regex if we don't have it already
mom = createUTC([2000, 1]).day(i);
if (strict && !this._fullWeekdaysParse[i]) {
this._fullWeekdaysParse[i] = new RegExp(
'^' + this.weekdays(mom, '').replace('.', '\\.?') + '$',
'i'
);
this._shortWeekdaysParse[i] = new RegExp(
'^' + this.weekdaysShort(mom, '').replace('.', '\\.?') + '$',
'i'
);
this._minWeekdaysParse[i] = new RegExp(
'^' + this.weekdaysMin(mom, '').replace('.', '\\.?') + '$',
'i'
);
}
if (!this._weekdaysParse[i]) {
regex =
'^' +
this.weekdays(mom, '') +
'|^' +
this.weekdaysShort(mom, '') +
'|^' +
this.weekdaysMin(mom, '');
this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
}
// test the regex
if (
strict &&
format === 'dddd' &&
this._fullWeekdaysParse[i].test(weekdayName)
) {
return i;
} else if (
strict &&
format === 'ddd' &&
this._shortWeekdaysParse[i].test(weekdayName)
) {
return i;
} else if (
strict &&
format === 'dd' &&
this._minWeekdaysParse[i].test(weekdayName)
) {
return i;
} else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
return i;
}
}
}
// MOMENTS
function getSetDayOfWeek(input) {
if (!this.isValid()) {
return input != null ? this : NaN;
}
var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
if (input != null) {
input = parseWeekday(input, this.localeData());
return this.add(input - day, 'd');
} else {
return day;
}
}
function getSetLocaleDayOfWeek(input) {
if (!this.isValid()) {
return input != null ? this : NaN;
}
var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
return input == null ? weekday : this.add(input - weekday, 'd');
}
function getSetISODayOfWeek(input) {
if (!this.isValid()) {
return input != null ? this : NaN;
}
// behaves the same as moment#day except
// as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
// as a setter, sunday should belong to the previous week.
if (input != null) {
var weekday = parseIsoWeekday(input, this.localeData());
return this.day(this.day() % 7 ? weekday : weekday - 7);
} else {
return this.day() || 7;
}
}
function weekdaysRegex(isStrict) {
if (this._weekdaysParseExact) {
if (!hasOwnProp(this, '_weekdaysRegex')) {
computeWeekdaysParse.call(this);
}
if (isStrict) {
return this._weekdaysStrictRegex;
} else {
return this._weekdaysRegex;
}
} else {
if (!hasOwnProp(this, '_weekdaysRegex')) {
this._weekdaysRegex = defaultWeekdaysRegex;
}
return this._weekdaysStrictRegex && isStrict
? this._weekdaysStrictRegex
: this._weekdaysRegex;
}
}
function weekdaysShortRegex(isStrict) {
if (this._weekdaysParseExact) {
if (!hasOwnProp(this, '_weekdaysRegex')) {
computeWeekdaysParse.call(this);
}
if (isStrict) {
return this._weekdaysShortStrictRegex;
} else {
return this._weekdaysShortRegex;
}
} else {
if (!hasOwnProp(this, '_weekdaysShortRegex')) {
this._weekdaysShortRegex = defaultWeekdaysShortRegex;
}
return this._weekdaysShortStrictRegex && isStrict
? this._weekdaysShortStrictRegex
: this._weekdaysShortRegex;
}
}
function weekdaysMinRegex(isStrict) {
if (this._weekdaysParseExact) {
if (!hasOwnProp(this, '_weekdaysRegex')) {
computeWeekdaysParse.call(this);
}
if (isStrict) {
return this._weekdaysMinStrictRegex;
} else {
return this._weekdaysMinRegex;
}
} else {
if (!hasOwnProp(this, '_weekdaysMinRegex')) {
this._weekdaysMinRegex = defaultWeekdaysMinRegex;
}
return this._weekdaysMinStrictRegex && isStrict
? this._weekdaysMinStrictRegex
: this._weekdaysMinRegex;
}
}
function computeWeekdaysParse() {
function cmpLenRev(a, b) {
return b.length - a.length;
}
var minPieces = [],
shortPieces = [],
longPieces = [],
mixedPieces = [],
i,
mom,
minp,
shortp,
longp;
for (i = 0; i < 7; i++) {
// make the regex if we don't have it already
mom = createUTC([2000, 1]).day(i);
minp = regexEscape(this.weekdaysMin(mom, ''));
shortp = regexEscape(this.weekdaysShort(mom, ''));
longp = regexEscape(this.weekdays(mom, ''));
minPieces.push(minp);
shortPieces.push(shortp);
longPieces.push(longp);
mixedPieces.push(minp);
mixedPieces.push(shortp);
mixedPieces.push(longp);
}
// Sorting makes sure if one weekday (or abbr) is a prefix of another it
// will match the longer piece.
minPieces.sort(cmpLenRev);
shortPieces.sort(cmpLenRev);
longPieces.sort(cmpLenRev);
mixedPieces.sort(cmpLenRev);
this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
this._weekdaysShortRegex = this._weekdaysRegex;
this._weekdaysMinRegex = this._weekdaysRegex;
this._weekdaysStrictRegex = new RegExp(
'^(' + longPieces.join('|') + ')',
'i'
);
this._weekdaysShortStrictRegex = new RegExp(
'^(' + shortPieces.join('|') + ')',
'i'
);
this._weekdaysMinStrictRegex = new RegExp(
'^(' + minPieces.join('|') + ')',
'i'
);
}
// FORMATTING
function hFormat() {
return this.hours() % 12 || 12;
}
function kFormat() {
return this.hours() || 24;
}
addFormatToken('H', ['HH', 2], 0, 'hour');
addFormatToken('h', ['hh', 2], 0, hFormat);
addFormatToken('k', ['kk', 2], 0, kFormat);
addFormatToken('hmm', 0, 0, function () {
return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
});
addFormatToken('hmmss', 0, 0, function () {
return (
'' +
hFormat.apply(this) +
zeroFill(this.minutes(), 2) +
zeroFill(this.seconds(), 2)
);
});
addFormatToken('Hmm', 0, 0, function () {
return '' + this.hours() + zeroFill(this.minutes(), 2);
});
addFormatToken('Hmmss', 0, 0, function () {
return (
'' +
this.hours() +
zeroFill(this.minutes(), 2) +
zeroFill(this.seconds(), 2)
);
});
function meridiem(token, lowercase) {
addFormatToken(token, 0, 0, function () {
return this.localeData().meridiem(
this.hours(),
this.minutes(),
lowercase
);
});
}
meridiem('a', true);
meridiem('A', false);
// ALIASES
addUnitAlias('hour', 'h');
// PRIORITY
addUnitPriority('hour', 13);
// PARSING
function matchMeridiem(isStrict, locale) {
return locale._meridiemParse;
}
addRegexToken('a', matchMeridiem);
addRegexToken('A', matchMeridiem);
addRegexToken('H', match1to2);
addRegexToken('h', match1to2);
addRegexToken('k', match1to2);
addRegexToken('HH', match1to2, match2);
addRegexToken('hh', match1to2, match2);
addRegexToken('kk', match1to2, match2);
addRegexToken('hmm', match3to4);
addRegexToken('hmmss', match5to6);
addRegexToken('Hmm', match3to4);
addRegexToken('Hmmss', match5to6);
addParseToken(['H', 'HH'], HOUR);
addParseToken(['k', 'kk'], function (input, array, config) {
var kInput = toInt(input);
array[HOUR] = kInput === 24 ? 0 : kInput;
});
addParseToken(['a', 'A'], function (input, array, config) {
config._isPm = config._locale.isPM(input);
config._meridiem = input;
});
addParseToken(['h', 'hh'], function (input, array, config) {
array[HOUR] = toInt(input);
getParsingFlags(config).bigHour = true;
});
addParseToken('hmm', function (input, array, config) {
var pos = input.length - 2;
array[HOUR] = toInt(input.substr(0, pos));
array[MINUTE] = toInt(input.substr(pos));
getParsingFlags(config).bigHour = true;
});
addParseToken('hmmss', function (input, array, config) {
var pos1 = input.length - 4,
pos2 = input.length - 2;
array[HOUR] = toInt(input.substr(0, pos1));
array[MINUTE] = toInt(input.substr(pos1, 2));
array[SECOND] = toInt(input.substr(pos2));
getParsingFlags(config).bigHour = true;
});
addParseToken('Hmm', function (input, array, config) {
var pos = input.length - 2;
array[HOUR] = toInt(input.substr(0, pos));
array[MINUTE] = toInt(input.substr(pos));
});
addParseToken('Hmmss', function (input, array, config) {
var pos1 = input.length - 4,
pos2 = input.length - 2;
array[HOUR] = toInt(input.substr(0, pos1));
array[MINUTE] = toInt(input.substr(pos1, 2));
array[SECOND] = toInt(input.substr(pos2));
});
// LOCALES
function localeIsPM(input) {
// IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
// Using charAt should be more compatible.
return (input + '').toLowerCase().charAt(0) === 'p';
}
var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i,
// Setting the hour should keep the time, because the user explicitly
// specified which hour they want. So trying to maintain the same hour (in
// a new timezone) makes sense. Adding/subtracting hours does not follow
// this rule.
getSetHour = makeGetSet('Hours', true);
function localeMeridiem(hours, minutes, isLower) {
if (hours > 11) {
return isLower ? 'pm' : 'PM';
} else {
return isLower ? 'am' : 'AM';
}
}
var baseConfig = {
calendar: defaultCalendar,
longDateFormat: defaultLongDateFormat,
invalidDate: defaultInvalidDate,
ordinal: defaultOrdinal,
dayOfMonthOrdinalParse: defaultDayOfMonthOrdinalParse,
relativeTime: defaultRelativeTime,
months: defaultLocaleMonths,
monthsShort: defaultLocaleMonthsShort,
week: defaultLocaleWeek,
weekdays: defaultLocaleWeekdays,
weekdaysMin: defaultLocaleWeekdaysMin,
weekdaysShort: defaultLocaleWeekdaysShort,
meridiemParse: defaultLocaleMeridiemParse,
};
// internal storage for locale config files
var locales = {},
localeFamilies = {},
globalLocale;
function commonPrefix(arr1, arr2) {
var i,
minl = Math.min(arr1.length, arr2.length);
for (i = 0; i < minl; i += 1) {
if (arr1[i] !== arr2[i]) {
return i;
}
}
return minl;
}
function normalizeLocale(key) {
return key ? key.toLowerCase().replace('_', '-') : key;
}
// pick the locale from the array
// try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
// substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
function chooseLocale(names) {
var i = 0,
j,
next,
locale,
split;
while (i < names.length) {
split = normalizeLocale(names[i]).split('-');
j = split.length;
next = normalizeLocale(names[i + 1]);
next = next ? next.split('-') : null;
while (j > 0) {
locale = loadLocale(split.slice(0, j).join('-'));
if (locale) {
return locale;
}
if (
next &&
next.length >= j &&
commonPrefix(split, next) >= j - 1
) {
//the next array item is better than a shallower substring of this one
break;
}
j--;
}
i++;
}
return globalLocale;
}
function loadLocale(name) {
var oldLocale = null,
aliasedRequire;
// TODO: Find a better way to register and load all the locales in Node
if (
locales[name] === undefined &&
'object' !== 'undefined' &&
module &&
module.exports
) {
try {
oldLocale = globalLocale._abbr;
aliasedRequire = commonjsRequire;
aliasedRequire('./locale/' + name);
getSetGlobalLocale(oldLocale);
} catch (e) {
// mark as not found to avoid repeating expensive file require call causing high CPU
// when trying to find en-US, en_US, en-us for every format call
locales[name] = null; // null means not found
}
}
return locales[name];
}
// This function will load locale and then set the global locale. If
// no arguments are passed in, it will simply return the current global
// locale key.
function getSetGlobalLocale(key, values) {
var data;
if (key) {
if (isUndefined(values)) {
data = getLocale(key);
} else {
data = defineLocale(key, values);
}
if (data) {
// moment.duration._locale = moment._locale = data;
globalLocale = data;
} else {
if (typeof console !== 'undefined' && console.warn) {
//warn user if arguments are passed but the locale could not be set
console.warn(
'Locale ' + key + ' not found. Did you forget to load it?'
);
}
}
}
return globalLocale._abbr;
}
function defineLocale(name, config) {
if (config !== null) {
var locale,
parentConfig = baseConfig;
config.abbr = name;
if (locales[name] != null) {
deprecateSimple(
'defineLocaleOverride',
'use moment.updateLocale(localeName, config) to change ' +
'an existing locale. moment.defineLocale(localeName, ' +
'config) should only be used for creating a new locale ' +
'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.'
);
parentConfig = locales[name]._config;
} else if (config.parentLocale != null) {
if (locales[config.parentLocale] != null) {
parentConfig = locales[config.parentLocale]._config;
} else {
locale = loadLocale(config.parentLocale);
if (locale != null) {
parentConfig = locale._config;
} else {
if (!localeFamilies[config.parentLocale]) {
localeFamilies[config.parentLocale] = [];
}
localeFamilies[config.parentLocale].push({
name: name,
config: config,
});
return null;
}
}
}
locales[name] = new Locale(mergeConfigs(parentConfig, config));
if (localeFamilies[name]) {
localeFamilies[name].forEach(function (x) {
defineLocale(x.name, x.config);
});
}
// backwards compat for now: also set the locale
// make sure we set the locale AFTER all child locales have been
// created, so we won't end up with the child locale set.
getSetGlobalLocale(name);
return locales[name];
} else {
// useful for testing
delete locales[name];
return null;
}
}
function updateLocale(name, config) {
if (config != null) {
var locale,
tmpLocale,
parentConfig = baseConfig;
if (locales[name] != null && locales[name].parentLocale != null) {
// Update existing child locale in-place to avoid memory-leaks
locales[name].set(mergeConfigs(locales[name]._config, config));
} else {
// MERGE
tmpLocale = loadLocale(name);
if (tmpLocale != null) {
parentConfig = tmpLocale._config;
}
config = mergeConfigs(parentConfig, config);
if (tmpLocale == null) {
// updateLocale is called for creating a new locale
// Set abbr so it will have a name (getters return
// undefined otherwise).
config.abbr = name;
}
locale = new Locale(config);
locale.parentLocale = locales[name];
locales[name] = locale;
}
// backwards compat for now: also set the locale
getSetGlobalLocale(name);
} else {
// pass null for config to unupdate, useful for tests
if (locales[name] != null) {
if (locales[name].parentLocale != null) {
locales[name] = locales[name].parentLocale;
if (name === getSetGlobalLocale()) {
getSetGlobalLocale(name);
}
} else if (locales[name] != null) {
delete locales[name];
}
}
}
return locales[name];
}
// returns locale data
function getLocale(key) {
var locale;
if (key && key._locale && key._locale._abbr) {
key = key._locale._abbr;
}
if (!key) {
return globalLocale;
}
if (!isArray(key)) {
//short-circuit everything else
locale = loadLocale(key);
if (locale) {
return locale;
}
key = [key];
}
return chooseLocale(key);
}
function listLocales() {
return keys(locales);
}
function checkOverflow(m) {
var overflow,
a = m._a;
if (a && getParsingFlags(m).overflow === -2) {
overflow =
a[MONTH] < 0 || a[MONTH] > 11
? MONTH
: a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH])
? DATE
: a[HOUR] < 0 ||
a[HOUR] > 24 ||
(a[HOUR] === 24 &&
(a[MINUTE] !== 0 ||
a[SECOND] !== 0 ||
a[MILLISECOND] !== 0))
? HOUR
: a[MINUTE] < 0 || a[MINUTE] > 59
? MINUTE
: a[SECOND] < 0 || a[SECOND] > 59
? SECOND
: a[MILLISECOND] < 0 || a[MILLISECOND] > 999
? MILLISECOND
: -1;
if (
getParsingFlags(m)._overflowDayOfYear &&
(overflow < YEAR || overflow > DATE)
) {
overflow = DATE;
}
if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
overflow = WEEK;
}
if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
overflow = WEEKDAY;
}
getParsingFlags(m).overflow = overflow;
}
return m;
}
// iso 8601 regex
// 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d|))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([+-]\d\d(?::?\d\d)?|\s*Z)?)?$/,
tzRegex = /Z|[+-]\d\d(?::?\d\d)?/,
isoDates = [
['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
['GGGG-[W]WW', /\d{4}-W\d\d/, false],
['YYYY-DDD', /\d{4}-\d{3}/],
['YYYY-MM', /\d{4}-\d\d/, false],
['YYYYYYMMDD', /[+-]\d{10}/],
['YYYYMMDD', /\d{8}/],
['GGGG[W]WWE', /\d{4}W\d{3}/],
['GGGG[W]WW', /\d{4}W\d{2}/, false],
['YYYYDDD', /\d{7}/],
['YYYYMM', /\d{6}/, false],
['YYYY', /\d{4}/, false],
],
// iso time formats and regexes
isoTimes = [
['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
['HH:mm:ss', /\d\d:\d\d:\d\d/],
['HH:mm', /\d\d:\d\d/],
['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
['HHmmss', /\d\d\d\d\d\d/],
['HHmm', /\d\d\d\d/],
['HH', /\d\d/],
],
aspNetJsonRegex = /^\/?Date\((-?\d+)/i,
// RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3
rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/,
obsOffsets = {
UT: 0,
GMT: 0,
EDT: -4 * 60,
EST: -5 * 60,
CDT: -5 * 60,
CST: -6 * 60,
MDT: -6 * 60,
MST: -7 * 60,
PDT: -7 * 60,
PST: -8 * 60,
};
// date from iso format
function configFromISO(config) {
var i,
l,
string = config._i,
match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
allowTime,
dateFormat,
timeFormat,
tzFormat;
if (match) {
getParsingFlags(config).iso = true;
for (i = 0, l = isoDates.length; i < l; i++) {
if (isoDates[i][1].exec(match[1])) {
dateFormat = isoDates[i][0];
allowTime = isoDates[i][2] !== false;
break;
}
}
if (dateFormat == null) {
config._isValid = false;
return;
}
if (match[3]) {
for (i = 0, l = isoTimes.length; i < l; i++) {
if (isoTimes[i][1].exec(match[3])) {
// match[2] should be 'T' or space
timeFormat = (match[2] || ' ') + isoTimes[i][0];
break;
}
}
if (timeFormat == null) {
config._isValid = false;
return;
}
}
if (!allowTime && timeFormat != null) {
config._isValid = false;
return;
}
if (match[4]) {
if (tzRegex.exec(match[4])) {
tzFormat = 'Z';
} else {
config._isValid = false;
return;
}
}
config._f = dateFormat + (timeFormat || '') + (tzFormat || '');
configFromStringAndFormat(config);
} else {
config._isValid = false;
}
}
function extractFromRFC2822Strings(
yearStr,
monthStr,
dayStr,
hourStr,
minuteStr,
secondStr
) {
var result = [
untruncateYear(yearStr),
defaultLocaleMonthsShort.indexOf(monthStr),
parseInt(dayStr, 10),
parseInt(hourStr, 10),
parseInt(minuteStr, 10),
];
if (secondStr) {
result.push(parseInt(secondStr, 10));
}
return result;
}
function untruncateYear(yearStr) {
var year = parseInt(yearStr, 10);
if (year <= 49) {
return 2000 + year;
} else if (year <= 999) {
return 1900 + year;
}
return year;
}
function preprocessRFC2822(s) {
// Remove comments and folding whitespace and replace multiple-spaces with a single space
return s
.replace(/\([^)]*\)|[\n\t]/g, ' ')
.replace(/(\s\s+)/g, ' ')
.replace(/^\s\s*/, '')
.replace(/\s\s*$/, '');
}
function checkWeekday(weekdayStr, parsedInput, config) {
if (weekdayStr) {
// TODO: Replace the vanilla JS Date object with an independent day-of-week check.
var weekdayProvided = defaultLocaleWeekdaysShort.indexOf(weekdayStr),
weekdayActual = new Date(
parsedInput[0],
parsedInput[1],
parsedInput[2]
).getDay();
if (weekdayProvided !== weekdayActual) {
getParsingFlags(config).weekdayMismatch = true;
config._isValid = false;
return false;
}
}
return true;
}
function calculateOffset(obsOffset, militaryOffset, numOffset) {
if (obsOffset) {
return obsOffsets[obsOffset];
} else if (militaryOffset) {
// the only allowed military tz is Z
return 0;
} else {
var hm = parseInt(numOffset, 10),
m = hm % 100,
h = (hm - m) / 100;
return h * 60 + m;
}
}
// date and time from ref 2822 format
function configFromRFC2822(config) {
var match = rfc2822.exec(preprocessRFC2822(config._i)),
parsedArray;
if (match) {
parsedArray = extractFromRFC2822Strings(
match[4],
match[3],
match[2],
match[5],
match[6],
match[7]
);
if (!checkWeekday(match[1], parsedArray, config)) {
return;
}
config._a = parsedArray;
config._tzm = calculateOffset(match[8], match[9], match[10]);
config._d = createUTCDate.apply(null, config._a);
config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
getParsingFlags(config).rfc2822 = true;
} else {
config._isValid = false;
}
}
// date from 1) ASP.NET, 2) ISO, 3) RFC 2822 formats, or 4) optional fallback if parsing isn't strict
function configFromString(config) {
var matched = aspNetJsonRegex.exec(config._i);
if (matched !== null) {
config._d = new Date(+matched[1]);
return;
}
configFromISO(config);
if (config._isValid === false) {
delete config._isValid;
} else {
return;
}
configFromRFC2822(config);
if (config._isValid === false) {
delete config._isValid;
} else {
return;
}
if (config._strict) {
config._isValid = false;
} else {
// Final attempt, use Input Fallback
hooks.createFromInputFallback(config);
}
}
hooks.createFromInputFallback = deprecate(
'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
'discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.',
function (config) {
config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
}
);
// Pick the first defined of two or three arguments.
function defaults(a, b, c) {
if (a != null) {
return a;
}
if (b != null) {
return b;
}
return c;
}
function currentDateArray(config) {
// hooks is actually the exported moment object
var nowValue = new Date(hooks.now());
if (config._useUTC) {
return [
nowValue.getUTCFullYear(),
nowValue.getUTCMonth(),
nowValue.getUTCDate(),
];
}
return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
}
// convert an array to a date.
// the array should mirror the parameters below
// note: all values past the year are optional and will default to the lowest possible value.
// [year, month, day , hour, minute, second, millisecond]
function configFromArray(config) {
var i,
date,
input = [],
currentDate,
expectedWeekday,
yearToUse;
if (config._d) {
return;
}
currentDate = currentDateArray(config);
//compute day of the year from weeks and weekdays
if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
dayOfYearFromWeekInfo(config);
}
//if the day of the year is set, figure out what it is
if (config._dayOfYear != null) {
yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
if (
config._dayOfYear > daysInYear(yearToUse) ||
config._dayOfYear === 0
) {
getParsingFlags(config)._overflowDayOfYear = true;
}
date = createUTCDate(yearToUse, 0, config._dayOfYear);
config._a[MONTH] = date.getUTCMonth();
config._a[DATE] = date.getUTCDate();
}
// Default to current date.
// * if no year, month, day of month are given, default to today
// * if day of month is given, default month and year
// * if month is given, default only year
// * if year is given, don't default anything
for (i = 0; i < 3 && config._a[i] == null; ++i) {
config._a[i] = input[i] = currentDate[i];
}
// Zero out whatever was not defaulted, including time
for (; i < 7; i++) {
config._a[i] = input[i] =
config._a[i] == null ? (i === 2 ? 1 : 0) : config._a[i];
}
// Check for 24:00:00.000
if (
config._a[HOUR] === 24 &&
config._a[MINUTE] === 0 &&
config._a[SECOND] === 0 &&
config._a[MILLISECOND] === 0
) {
config._nextDay = true;
config._a[HOUR] = 0;
}
config._d = (config._useUTC ? createUTCDate : createDate).apply(
null,
input
);
expectedWeekday = config._useUTC
? config._d.getUTCDay()
: config._d.getDay();
// Apply timezone offset from input. The actual utcOffset can be changed
// with parseZone.
if (config._tzm != null) {
config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
}
if (config._nextDay) {
config._a[HOUR] = 24;
}
// check for mismatching day of week
if (
config._w &&
typeof config._w.d !== 'undefined' &&
config._w.d !== expectedWeekday
) {
getParsingFlags(config).weekdayMismatch = true;
}
}
function dayOfYearFromWeekInfo(config) {
var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow, curWeek;
w = config._w;
if (w.GG != null || w.W != null || w.E != null) {
dow = 1;
doy = 4;
// TODO: We need to take the current isoWeekYear, but that depends on
// how we interpret now (local, utc, fixed offset). So create
// a now version of current config (take local/utc/offset flags, and
// create now).
weekYear = defaults(
w.GG,
config._a[YEAR],
weekOfYear(createLocal(), 1, 4).year
);
week = defaults(w.W, 1);
weekday = defaults(w.E, 1);
if (weekday < 1 || weekday > 7) {
weekdayOverflow = true;
}
} else {
dow = config._locale._week.dow;
doy = config._locale._week.doy;
curWeek = weekOfYear(createLocal(), dow, doy);
weekYear = defaults(w.gg, config._a[YEAR], curWeek.year);
// Default to current week.
week = defaults(w.w, curWeek.week);
if (w.d != null) {
// weekday -- low day numbers are considered next week
weekday = w.d;
if (weekday < 0 || weekday > 6) {
weekdayOverflow = true;
}
} else if (w.e != null) {
// local weekday -- counting starts from beginning of week
weekday = w.e + dow;
if (w.e < 0 || w.e > 6) {
weekdayOverflow = true;
}
} else {
// default to beginning of week
weekday = dow;
}
}
if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
getParsingFlags(config)._overflowWeeks = true;
} else if (weekdayOverflow != null) {
getParsingFlags(config)._overflowWeekday = true;
} else {
temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
config._a[YEAR] = temp.year;
config._dayOfYear = temp.dayOfYear;
}
}
// constant that refers to the ISO standard
hooks.ISO_8601 = function () {};
// constant that refers to the RFC 2822 form
hooks.RFC_2822 = function () {};
// date from string and format string
function configFromStringAndFormat(config) {
// TODO: Move this to another part of the creation flow to prevent circular deps
if (config._f === hooks.ISO_8601) {
configFromISO(config);
return;
}
if (config._f === hooks.RFC_2822) {
configFromRFC2822(config);
return;
}
config._a = [];
getParsingFlags(config).empty = true;
// This array is used to make a Date, either with `new Date` or `Date.UTC`
var string = '' + config._i,
i,
parsedInput,
tokens,
token,
skipped,
stringLength = string.length,
totalParsedInputLength = 0,
era;
tokens =
expandFormat(config._f, config._locale).match(formattingTokens) || [];
for (i = 0; i < tokens.length; i++) {
token = tokens[i];
parsedInput = (string.match(getParseRegexForToken(token, config)) ||
[])[0];
if (parsedInput) {
skipped = string.substr(0, string.indexOf(parsedInput));
if (skipped.length > 0) {
getParsingFlags(config).unusedInput.push(skipped);
}
string = string.slice(
string.indexOf(parsedInput) + parsedInput.length
);
totalParsedInputLength += parsedInput.length;
}
// don't parse if it's not a known token
if (formatTokenFunctions[token]) {
if (parsedInput) {
getParsingFlags(config).empty = false;
} else {
getParsingFlags(config).unusedTokens.push(token);
}
addTimeToArrayFromToken(token, parsedInput, config);
} else if (config._strict && !parsedInput) {
getParsingFlags(config).unusedTokens.push(token);
}
}
// add remaining unparsed input length to the string
getParsingFlags(config).charsLeftOver =
stringLength - totalParsedInputLength;
if (string.length > 0) {
getParsingFlags(config).unusedInput.push(string);
}
// clear _12h flag if hour is <= 12
if (
config._a[HOUR] <= 12 &&
getParsingFlags(config).bigHour === true &&
config._a[HOUR] > 0
) {
getParsingFlags(config).bigHour = undefined;
}
getParsingFlags(config).parsedDateParts = config._a.slice(0);
getParsingFlags(config).meridiem = config._meridiem;
// handle meridiem
config._a[HOUR] = meridiemFixWrap(
config._locale,
config._a[HOUR],
config._meridiem
);
// handle era
era = getParsingFlags(config).era;
if (era !== null) {
config._a[YEAR] = config._locale.erasConvertYear(era, config._a[YEAR]);
}
configFromArray(config);
checkOverflow(config);
}
function meridiemFixWrap(locale, hour, meridiem) {
var isPm;
if (meridiem == null) {
// nothing to do
return hour;
}
if (locale.meridiemHour != null) {
return locale.meridiemHour(hour, meridiem);
} else if (locale.isPM != null) {
// Fallback
isPm = locale.isPM(meridiem);
if (isPm && hour < 12) {
hour += 12;
}
if (!isPm && hour === 12) {
hour = 0;
}
return hour;
} else {
// this is not supposed to happen
return hour;
}
}
// date from string and array of format strings
function configFromStringAndArray(config) {
var tempConfig,
bestMoment,
scoreToBeat,
i,
currentScore,
validFormatFound,
bestFormatIsValid = false;
if (config._f.length === 0) {
getParsingFlags(config).invalidFormat = true;
config._d = new Date(NaN);
return;
}
for (i = 0; i < config._f.length; i++) {
currentScore = 0;
validFormatFound = false;
tempConfig = copyConfig({}, config);
if (config._useUTC != null) {
tempConfig._useUTC = config._useUTC;
}
tempConfig._f = config._f[i];
configFromStringAndFormat(tempConfig);
if (isValid(tempConfig)) {
validFormatFound = true;
}
// if there is any input that was not parsed add a penalty for that format
currentScore += getParsingFlags(tempConfig).charsLeftOver;
//or tokens
currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
getParsingFlags(tempConfig).score = currentScore;
if (!bestFormatIsValid) {
if (
scoreToBeat == null ||
currentScore < scoreToBeat ||
validFormatFound
) {
scoreToBeat = currentScore;
bestMoment = tempConfig;
if (validFormatFound) {
bestFormatIsValid = true;
}
}
} else {
if (currentScore < scoreToBeat) {
scoreToBeat = currentScore;
bestMoment = tempConfig;
}
}
}
extend(config, bestMoment || tempConfig);
}
function configFromObject(config) {
if (config._d) {
return;
}
var i = normalizeObjectUnits(config._i),
dayOrDate = i.day === undefined ? i.date : i.day;
config._a = map(
[i.year, i.month, dayOrDate, i.hour, i.minute, i.second, i.millisecond],
function (obj) {
return obj && parseInt(obj, 10);
}
);
configFromArray(config);
}
function createFromConfig(config) {
var res = new Moment(checkOverflow(prepareConfig(config)));
if (res._nextDay) {
// Adding is smart enough around DST
res.add(1, 'd');
res._nextDay = undefined;
}
return res;
}
function prepareConfig(config) {
var input = config._i,
format = config._f;
config._locale = config._locale || getLocale(config._l);
if (input === null || (format === undefined && input === '')) {
return createInvalid({ nullInput: true });
}
if (typeof input === 'string') {
config._i = input = config._locale.preparse(input);
}
if (isMoment(input)) {
return new Moment(checkOverflow(input));
} else if (isDate(input)) {
config._d = input;
} else if (isArray(format)) {
configFromStringAndArray(config);
} else if (format) {
configFromStringAndFormat(config);
} else {
configFromInput(config);
}
if (!isValid(config)) {
config._d = null;
}
return config;
}
function configFromInput(config) {
var input = config._i;
if (isUndefined(input)) {
config._d = new Date(hooks.now());
} else if (isDate(input)) {
config._d = new Date(input.valueOf());
} else if (typeof input === 'string') {
configFromString(config);
} else if (isArray(input)) {
config._a = map(input.slice(0), function (obj) {
return parseInt(obj, 10);
});
configFromArray(config);
} else if (isObject(input)) {
configFromObject(config);
} else if (isNumber(input)) {
// from milliseconds
config._d = new Date(input);
} else {
hooks.createFromInputFallback(config);
}
}
function createLocalOrUTC(input, format, locale, strict, isUTC) {
var c = {};
if (format === true || format === false) {
strict = format;
format = undefined;
}
if (locale === true || locale === false) {
strict = locale;
locale = undefined;
}
if (
(isObject(input) && isObjectEmpty(input)) ||
(isArray(input) && input.length === 0)
) {
input = undefined;
}
// object construction must be done this way.
// https://github.com/moment/moment/issues/1423
c._isAMomentObject = true;
c._useUTC = c._isUTC = isUTC;
c._l = locale;
c._i = input;
c._f = format;
c._strict = strict;
return createFromConfig(c);
}
function createLocal(input, format, locale, strict) {
return createLocalOrUTC(input, format, locale, strict, false);
}
var prototypeMin = deprecate(
'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
function () {
var other = createLocal.apply(null, arguments);
if (this.isValid() && other.isValid()) {
return other < this ? this : other;
} else {
return createInvalid();
}
}
),
prototypeMax = deprecate(
'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
function () {
var other = createLocal.apply(null, arguments);
if (this.isValid() && other.isValid()) {
return other > this ? this : other;
} else {
return createInvalid();
}
}
);
// Pick a moment m from moments so that m[fn](other) is true for all
// other. This relies on the function fn to be transitive.
//
// moments should either be an array of moment objects or an array, whose
// first element is an array of moment objects.
function pickBy(fn, moments) {
var res, i;
if (moments.length === 1 && isArray(moments[0])) {
moments = moments[0];
}
if (!moments.length) {
return createLocal();
}
res = moments[0];
for (i = 1; i < moments.length; ++i) {
if (!moments[i].isValid() || moments[i][fn](res)) {
res = moments[i];
}
}
return res;
}
// TODO: Use [].sort instead?
function min() {
var args = [].slice.call(arguments, 0);
return pickBy('isBefore', args);
}
function max() {
var args = [].slice.call(arguments, 0);
return pickBy('isAfter', args);
}
var now = function () {
return Date.now ? Date.now() : +new Date();
};
var ordering = [
'year',
'quarter',
'month',
'week',
'day',
'hour',
'minute',
'second',
'millisecond',
];
function isDurationValid(m) {
var key,
unitHasDecimal = false,
i;
for (key in m) {
if (
hasOwnProp(m, key) &&
!(
indexOf.call(ordering, key) !== -1 &&
(m[key] == null || !isNaN(m[key]))
)
) {
return false;
}
}
for (i = 0; i < ordering.length; ++i) {
if (m[ordering[i]]) {
if (unitHasDecimal) {
return false; // only allow non-integers for smallest unit
}
if (parseFloat(m[ordering[i]]) !== toInt(m[ordering[i]])) {
unitHasDecimal = true;
}
}
}
return true;
}
function isValid$1() {
return this._isValid;
}
function createInvalid$1() {
return createDuration(NaN);
}
function Duration(duration) {
var normalizedInput = normalizeObjectUnits(duration),
years = normalizedInput.year || 0,
quarters = normalizedInput.quarter || 0,
months = normalizedInput.month || 0,
weeks = normalizedInput.week || normalizedInput.isoWeek || 0,
days = normalizedInput.day || 0,
hours = normalizedInput.hour || 0,
minutes = normalizedInput.minute || 0,
seconds = normalizedInput.second || 0,
milliseconds = normalizedInput.millisecond || 0;
this._isValid = isDurationValid(normalizedInput);
// representation for dateAddRemove
this._milliseconds =
+milliseconds +
seconds * 1e3 + // 1000
minutes * 6e4 + // 1000 * 60
hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
// Because of dateAddRemove treats 24 hours as different from a
// day when working around DST, we need to store them separately
this._days = +days + weeks * 7;
// It is impossible to translate months into days without knowing
// which months you are are talking about, so we have to store
// it separately.
this._months = +months + quarters * 3 + years * 12;
this._data = {};
this._locale = getLocale();
this._bubble();
}
function isDuration(obj) {
return obj instanceof Duration;
}
function absRound(number) {
if (number < 0) {
return Math.round(-1 * number) * -1;
} else {
return Math.round(number);
}
}
// compare two arrays, return the number of differences
function compareArrays(array1, array2, dontConvert) {
var len = Math.min(array1.length, array2.length),
lengthDiff = Math.abs(array1.length - array2.length),
diffs = 0,
i;
for (i = 0; i < len; i++) {
if (
(dontConvert && array1[i] !== array2[i]) ||
(!dontConvert && toInt(array1[i]) !== toInt(array2[i]))
) {
diffs++;
}
}
return diffs + lengthDiff;
}
// FORMATTING
function offset(token, separator) {
addFormatToken(token, 0, 0, function () {
var offset = this.utcOffset(),
sign = '+';
if (offset < 0) {
offset = -offset;
sign = '-';
}
return (
sign +
zeroFill(~~(offset / 60), 2) +
separator +
zeroFill(~~offset % 60, 2)
);
});
}
offset('Z', ':');
offset('ZZ', '');
// PARSING
addRegexToken('Z', matchShortOffset);
addRegexToken('ZZ', matchShortOffset);
addParseToken(['Z', 'ZZ'], function (input, array, config) {
config._useUTC = true;
config._tzm = offsetFromString(matchShortOffset, input);
});
// HELPERS
// timezone chunker
// '+10:00' > ['10', '00']
// '-1530' > ['-15', '30']
var chunkOffset = /([\+\-]|\d\d)/gi;
function offsetFromString(matcher, string) {
var matches = (string || '').match(matcher),
chunk,
parts,
minutes;
if (matches === null) {
return null;
}
chunk = matches[matches.length - 1] || [];
parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
minutes = +(parts[1] * 60) + toInt(parts[2]);
return minutes === 0 ? 0 : parts[0] === '+' ? minutes : -minutes;
}
// Return a moment from input, that is local/utc/zone equivalent to model.
function cloneWithOffset(input, model) {
var res, diff;
if (model._isUTC) {
res = model.clone();
diff =
(isMoment(input) || isDate(input)
? input.valueOf()
: createLocal(input).valueOf()) - res.valueOf();
// Use low-level api, because this fn is low-level api.
res._d.setTime(res._d.valueOf() + diff);
hooks.updateOffset(res, false);
return res;
} else {
return createLocal(input).local();
}
}
function getDateOffset(m) {
// On Firefox.24 Date#getTimezoneOffset returns a floating point.
// https://github.com/moment/moment/pull/1871
return -Math.round(m._d.getTimezoneOffset());
}
// HOOKS
// This function will be called whenever a moment is mutated.
// It is intended to keep the offset in sync with the timezone.
hooks.updateOffset = function () {};
// MOMENTS
// keepLocalTime = true means only change the timezone, without
// affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
// 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
// +0200, so we adjust the time as needed, to be valid.
//
// Keeping the time actually adds/subtracts (one hour)
// from the actual represented time. That is why we call updateOffset
// a second time. In case it wants us to change the offset again
// _changeInProgress == true case, then we have to adjust, because
// there is no such time in the given timezone.
function getSetOffset(input, keepLocalTime, keepMinutes) {
var offset = this._offset || 0,
localAdjust;
if (!this.isValid()) {
return input != null ? this : NaN;
}
if (input != null) {
if (typeof input === 'string') {
input = offsetFromString(matchShortOffset, input);
if (input === null) {
return this;
}
} else if (Math.abs(input) < 16 && !keepMinutes) {
input = input * 60;
}
if (!this._isUTC && keepLocalTime) {
localAdjust = getDateOffset(this);
}
this._offset = input;
this._isUTC = true;
if (localAdjust != null) {
this.add(localAdjust, 'm');
}
if (offset !== input) {
if (!keepLocalTime || this._changeInProgress) {
addSubtract(
this,
createDuration(input - offset, 'm'),
1,
false
);
} else if (!this._changeInProgress) {
this._changeInProgress = true;
hooks.updateOffset(this, true);
this._changeInProgress = null;
}
}
return this;
} else {
return this._isUTC ? offset : getDateOffset(this);
}
}
function getSetZone(input, keepLocalTime) {
if (input != null) {
if (typeof input !== 'string') {
input = -input;
}
this.utcOffset(input, keepLocalTime);
return this;
} else {
return -this.utcOffset();
}
}
function setOffsetToUTC(keepLocalTime) {
return this.utcOffset(0, keepLocalTime);
}
function setOffsetToLocal(keepLocalTime) {
if (this._isUTC) {
this.utcOffset(0, keepLocalTime);
this._isUTC = false;
if (keepLocalTime) {
this.subtract(getDateOffset(this), 'm');
}
}
return this;
}
function setOffsetToParsedOffset() {
if (this._tzm != null) {
this.utcOffset(this._tzm, false, true);
} else if (typeof this._i === 'string') {
var tZone = offsetFromString(matchOffset, this._i);
if (tZone != null) {
this.utcOffset(tZone);
} else {
this.utcOffset(0, true);
}
}
return this;
}
function hasAlignedHourOffset(input) {
if (!this.isValid()) {
return false;
}
input = input ? createLocal(input).utcOffset() : 0;
return (this.utcOffset() - input) % 60 === 0;
}
function isDaylightSavingTime() {
return (
this.utcOffset() > this.clone().month(0).utcOffset() ||
this.utcOffset() > this.clone().month(5).utcOffset()
);
}
function isDaylightSavingTimeShifted() {
if (!isUndefined(this._isDSTShifted)) {
return this._isDSTShifted;
}
var c = {},
other;
copyConfig(c, this);
c = prepareConfig(c);
if (c._a) {
other = c._isUTC ? createUTC(c._a) : createLocal(c._a);
this._isDSTShifted =
this.isValid() && compareArrays(c._a, other.toArray()) > 0;
} else {
this._isDSTShifted = false;
}
return this._isDSTShifted;
}
function isLocal() {
return this.isValid() ? !this._isUTC : false;
}
function isUtcOffset() {
return this.isValid() ? this._isUTC : false;
}
function isUtc() {
return this.isValid() ? this._isUTC && this._offset === 0 : false;
}
// ASP.NET json date format regex
var aspNetRegex = /^(-|\+)?(?:(\d*)[. ])?(\d+):(\d+)(?::(\d+)(\.\d*)?)?$/,
// from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
// somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
// and further modified to allow for strings containing both week and day
isoRegex = /^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;
function createDuration(input, key) {
var duration = input,
// matching against regexp is expensive, do it on demand
match = null,
sign,
ret,
diffRes;
if (isDuration(input)) {
duration = {
ms: input._milliseconds,
d: input._days,
M: input._months,
};
} else if (isNumber(input) || !isNaN(+input)) {
duration = {};
if (key) {
duration[key] = +input;
} else {
duration.milliseconds = +input;
}
} else if ((match = aspNetRegex.exec(input))) {
sign = match[1] === '-' ? -1 : 1;
duration = {
y: 0,
d: toInt(match[DATE]) * sign,
h: toInt(match[HOUR]) * sign,
m: toInt(match[MINUTE]) * sign,
s: toInt(match[SECOND]) * sign,
ms: toInt(absRound(match[MILLISECOND] * 1000)) * sign, // the millisecond decimal point is included in the match
};
} else if ((match = isoRegex.exec(input))) {
sign = match[1] === '-' ? -1 : 1;
duration = {
y: parseIso(match[2], sign),
M: parseIso(match[3], sign),
w: parseIso(match[4], sign),
d: parseIso(match[5], sign),
h: parseIso(match[6], sign),
m: parseIso(match[7], sign),
s: parseIso(match[8], sign),
};
} else if (duration == null) {
// checks for null or undefined
duration = {};
} else if (
typeof duration === 'object' &&
('from' in duration || 'to' in duration)
) {
diffRes = momentsDifference(
createLocal(duration.from),
createLocal(duration.to)
);
duration = {};
duration.ms = diffRes.milliseconds;
duration.M = diffRes.months;
}
ret = new Duration(duration);
if (isDuration(input) && hasOwnProp(input, '_locale')) {
ret._locale = input._locale;
}
if (isDuration(input) && hasOwnProp(input, '_isValid')) {
ret._isValid = input._isValid;
}
return ret;
}
createDuration.fn = Duration.prototype;
createDuration.invalid = createInvalid$1;
function parseIso(inp, sign) {
// We'd normally use ~~inp for this, but unfortunately it also
// converts floats to ints.
// inp may be undefined, so careful calling replace on it.
var res = inp && parseFloat(inp.replace(',', '.'));
// apply sign while we're at it
return (isNaN(res) ? 0 : res) * sign;
}
function positiveMomentsDifference(base, other) {
var res = {};
res.months =
other.month() - base.month() + (other.year() - base.year()) * 12;
if (base.clone().add(res.months, 'M').isAfter(other)) {
--res.months;
}
res.milliseconds = +other - +base.clone().add(res.months, 'M');
return res;
}
function momentsDifference(base, other) {
var res;
if (!(base.isValid() && other.isValid())) {
return { milliseconds: 0, months: 0 };
}
other = cloneWithOffset(other, base);
if (base.isBefore(other)) {
res = positiveMomentsDifference(base, other);
} else {
res = positiveMomentsDifference(other, base);
res.milliseconds = -res.milliseconds;
res.months = -res.months;
}
return res;
}
// TODO: remove 'name' arg after deprecation is removed
function createAdder(direction, name) {
return function (val, period) {
var dur, tmp;
//invert the arguments, but complain about it
if (period !== null && !isNaN(+period)) {
deprecateSimple(
name,
'moment().' +
name +
'(period, number) is deprecated. Please use moment().' +
name +
'(number, period). ' +
'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.'
);
tmp = val;
val = period;
period = tmp;
}
dur = createDuration(val, period);
addSubtract(this, dur, direction);
return this;
};
}
function addSubtract(mom, duration, isAdding, updateOffset) {
var milliseconds = duration._milliseconds,
days = absRound(duration._days),
months = absRound(duration._months);
if (!mom.isValid()) {
// No op
return;
}
updateOffset = updateOffset == null ? true : updateOffset;
if (months) {
setMonth(mom, get(mom, 'Month') + months * isAdding);
}
if (days) {
set$1(mom, 'Date', get(mom, 'Date') + days * isAdding);
}
if (milliseconds) {
mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
}
if (updateOffset) {
hooks.updateOffset(mom, days || months);
}
}
var add = createAdder(1, 'add'),
subtract = createAdder(-1, 'subtract');
function isString(input) {
return typeof input === 'string' || input instanceof String;
}
// type MomentInput = Moment | Date | string | number | (number | string)[] | MomentInputObject | void; // null | undefined
function isMomentInput(input) {
return (
isMoment(input) ||
isDate(input) ||
isString(input) ||
isNumber(input) ||
isNumberOrStringArray(input) ||
isMomentInputObject(input) ||
input === null ||
input === undefined
);
}
function isMomentInputObject(input) {
var objectTest = isObject(input) && !isObjectEmpty(input),
propertyTest = false,
properties = [
'years',
'year',
'y',
'months',
'month',
'M',
'days',
'day',
'd',
'dates',
'date',
'D',
'hours',
'hour',
'h',
'minutes',
'minute',
'm',
'seconds',
'second',
's',
'milliseconds',
'millisecond',
'ms',
],
i,
property;
for (i = 0; i < properties.length; i += 1) {
property = properties[i];
propertyTest = propertyTest || hasOwnProp(input, property);
}
return objectTest && propertyTest;
}
function isNumberOrStringArray(input) {
var arrayTest = isArray(input),
dataTypeTest = false;
if (arrayTest) {
dataTypeTest =
input.filter(function (item) {
return !isNumber(item) && isString(input);
}).length === 0;
}
return arrayTest && dataTypeTest;
}
function isCalendarSpec(input) {
var objectTest = isObject(input) && !isObjectEmpty(input),
propertyTest = false,
properties = [
'sameDay',
'nextDay',
'lastDay',
'nextWeek',
'lastWeek',
'sameElse',
],
i,
property;
for (i = 0; i < properties.length; i += 1) {
property = properties[i];
propertyTest = propertyTest || hasOwnProp(input, property);
}
return objectTest && propertyTest;
}
function getCalendarFormat(myMoment, now) {
var diff = myMoment.diff(now, 'days', true);
return diff < -6
? 'sameElse'
: diff < -1
? 'lastWeek'
: diff < 0
? 'lastDay'
: diff < 1
? 'sameDay'
: diff < 2
? 'nextDay'
: diff < 7
? 'nextWeek'
: 'sameElse';
}
function calendar$1(time, formats) {
// Support for single parameter, formats only overload to the calendar function
if (arguments.length === 1) {
if (!arguments[0]) {
time = undefined;
formats = undefined;
} else if (isMomentInput(arguments[0])) {
time = arguments[0];
formats = undefined;
} else if (isCalendarSpec(arguments[0])) {
formats = arguments[0];
time = undefined;
}
}
// We want to compare the start of today, vs this.
// Getting start-of-today depends on whether we're local/utc/offset or not.
var now = time || createLocal(),
sod = cloneWithOffset(now, this).startOf('day'),
format = hooks.calendarFormat(this, sod) || 'sameElse',
output =
formats &&
(isFunction(formats[format])
? formats[format].call(this, now)
: formats[format]);
return this.format(
output || this.localeData().calendar(format, this, createLocal(now))
);
}
function clone() {
return new Moment(this);
}
function isAfter(input, units) {
var localInput = isMoment(input) ? input : createLocal(input);
if (!(this.isValid() && localInput.isValid())) {
return false;
}
units = normalizeUnits(units) || 'millisecond';
if (units === 'millisecond') {
return this.valueOf() > localInput.valueOf();
} else {
return localInput.valueOf() < this.clone().startOf(units).valueOf();
}
}
function isBefore(input, units) {
var localInput = isMoment(input) ? input : createLocal(input);
if (!(this.isValid() && localInput.isValid())) {
return false;
}
units = normalizeUnits(units) || 'millisecond';
if (units === 'millisecond') {
return this.valueOf() < localInput.valueOf();
} else {
return this.clone().endOf(units).valueOf() < localInput.valueOf();
}
}
function isBetween(from, to, units, inclusivity) {
var localFrom = isMoment(from) ? from : createLocal(from),
localTo = isMoment(to) ? to : createLocal(to);
if (!(this.isValid() && localFrom.isValid() && localTo.isValid())) {
return false;
}
inclusivity = inclusivity || '()';
return (
(inclusivity[0] === '('
? this.isAfter(localFrom, units)
: !this.isBefore(localFrom, units)) &&
(inclusivity[1] === ')'
? this.isBefore(localTo, units)
: !this.isAfter(localTo, units))
);
}
function isSame(input, units) {
var localInput = isMoment(input) ? input : createLocal(input),
inputMs;
if (!(this.isValid() && localInput.isValid())) {
return false;
}
units = normalizeUnits(units) || 'millisecond';
if (units === 'millisecond') {
return this.valueOf() === localInput.valueOf();
} else {
inputMs = localInput.valueOf();
return (
this.clone().startOf(units).valueOf() <= inputMs &&
inputMs <= this.clone().endOf(units).valueOf()
);
}
}
function isSameOrAfter(input, units) {
return this.isSame(input, units) || this.isAfter(input, units);
}
function isSameOrBefore(input, units) {
return this.isSame(input, units) || this.isBefore(input, units);
}
function diff(input, units, asFloat) {
var that, zoneDelta, output;
if (!this.isValid()) {
return NaN;
}
that = cloneWithOffset(input, this);
if (!that.isValid()) {
return NaN;
}
zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
units = normalizeUnits(units);
switch (units) {
case 'year':
output = monthDiff(this, that) / 12;
break;
case 'month':
output = monthDiff(this, that);
break;
case 'quarter':
output = monthDiff(this, that) / 3;
break;
case 'second':
output = (this - that) / 1e3;
break; // 1000
case 'minute':
output = (this - that) / 6e4;
break; // 1000 * 60
case 'hour':
output = (this - that) / 36e5;
break; // 1000 * 60 * 60
case 'day':
output = (this - that - zoneDelta) / 864e5;
break; // 1000 * 60 * 60 * 24, negate dst
case 'week':
output = (this - that - zoneDelta) / 6048e5;
break; // 1000 * 60 * 60 * 24 * 7, negate dst
default:
output = this - that;
}
return asFloat ? output : absFloor(output);
}
function monthDiff(a, b) {
if (a.date() < b.date()) {
// end-of-month calculations work correct when the start month has more
// days than the end month.
return -monthDiff(b, a);
}
// difference in months
var wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month()),
// b is in (anchor - 1 month, anchor + 1 month)
anchor = a.clone().add(wholeMonthDiff, 'months'),
anchor2,
adjust;
if (b - anchor < 0) {
anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
// linear across the month
adjust = (b - anchor) / (anchor - anchor2);
} else {
anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
// linear across the month
adjust = (b - anchor) / (anchor2 - anchor);
}
//check for negative zero, return zero if negative zero
return -(wholeMonthDiff + adjust) || 0;
}
hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
function toString() {
return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
}
function toISOString(keepOffset) {
if (!this.isValid()) {
return null;
}
var utc = keepOffset !== true,
m = utc ? this.clone().utc() : this;
if (m.year() < 0 || m.year() > 9999) {
return formatMoment(
m,
utc
? 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]'
: 'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ'
);
}
if (isFunction(Date.prototype.toISOString)) {
// native implementation is ~50x faster, use it when we can
if (utc) {
return this.toDate().toISOString();
} else {
return new Date(this.valueOf() + this.utcOffset() * 60 * 1000)
.toISOString()
.replace('Z', formatMoment(m, 'Z'));
}
}
return formatMoment(
m,
utc ? 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]' : 'YYYY-MM-DD[T]HH:mm:ss.SSSZ'
);
}
/**
* Return a human readable representation of a moment that can
* also be evaluated to get a new moment which is the same
*
* @link https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
*/
function inspect() {
if (!this.isValid()) {
return 'moment.invalid(/* ' + this._i + ' */)';
}
var func = 'moment',
zone = '',
prefix,
year,
datetime,
suffix;
if (!this.isLocal()) {
func = this.utcOffset() === 0 ? 'moment.utc' : 'moment.parseZone';
zone = 'Z';
}
prefix = '[' + func + '("]';
year = 0 <= this.year() && this.year() <= 9999 ? 'YYYY' : 'YYYYYY';
datetime = '-MM-DD[T]HH:mm:ss.SSS';
suffix = zone + '[")]';
return this.format(prefix + year + datetime + suffix);
}
function format(inputString) {
if (!inputString) {
inputString = this.isUtc()
? hooks.defaultFormatUtc
: hooks.defaultFormat;
}
var output = formatMoment(this, inputString);
return this.localeData().postformat(output);
}
function from(time, withoutSuffix) {
if (
this.isValid() &&
((isMoment(time) && time.isValid()) || createLocal(time).isValid())
) {
return createDuration({ to: this, from: time })
.locale(this.locale())
.humanize(!withoutSuffix);
} else {
return this.localeData().invalidDate();
}
}
function fromNow(withoutSuffix) {
return this.from(createLocal(), withoutSuffix);
}
function to(time, withoutSuffix) {
if (
this.isValid() &&
((isMoment(time) && time.isValid()) || createLocal(time).isValid())
) {
return createDuration({ from: this, to: time })
.locale(this.locale())
.humanize(!withoutSuffix);
} else {
return this.localeData().invalidDate();
}
}
function toNow(withoutSuffix) {
return this.to(createLocal(), withoutSuffix);
}
// If passed a locale key, it will set the locale for this
// instance. Otherwise, it will return the locale configuration
// variables for this instance.
function locale(key) {
var newLocaleData;
if (key === undefined) {
return this._locale._abbr;
} else {
newLocaleData = getLocale(key);
if (newLocaleData != null) {
this._locale = newLocaleData;
}
return this;
}
}
var lang = deprecate(
'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
function (key) {
if (key === undefined) {
return this.localeData();
} else {
return this.locale(key);
}
}
);
function localeData() {
return this._locale;
}
var MS_PER_SECOND = 1000,
MS_PER_MINUTE = 60 * MS_PER_SECOND,
MS_PER_HOUR = 60 * MS_PER_MINUTE,
MS_PER_400_YEARS = (365 * 400 + 97) * 24 * MS_PER_HOUR;
// actual modulo - handles negative numbers (for dates before 1970):
function mod$1(dividend, divisor) {
return ((dividend % divisor) + divisor) % divisor;
}
function localStartOfDate(y, m, d) {
// the date constructor remaps years 0-99 to 1900-1999
if (y < 100 && y >= 0) {
// preserve leap years using a full 400 year cycle, then reset
return new Date(y + 400, m, d) - MS_PER_400_YEARS;
} else {
return new Date(y, m, d).valueOf();
}
}
function utcStartOfDate(y, m, d) {
// Date.UTC remaps years 0-99 to 1900-1999
if (y < 100 && y >= 0) {
// preserve leap years using a full 400 year cycle, then reset
return Date.UTC(y + 400, m, d) - MS_PER_400_YEARS;
} else {
return Date.UTC(y, m, d);
}
}
function startOf(units) {
var time, startOfDate;
units = normalizeUnits(units);
if (units === undefined || units === 'millisecond' || !this.isValid()) {
return this;
}
startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
switch (units) {
case 'year':
time = startOfDate(this.year(), 0, 1);
break;
case 'quarter':
time = startOfDate(
this.year(),
this.month() - (this.month() % 3),
1
);
break;
case 'month':
time = startOfDate(this.year(), this.month(), 1);
break;
case 'week':
time = startOfDate(
this.year(),
this.month(),
this.date() - this.weekday()
);
break;
case 'isoWeek':
time = startOfDate(
this.year(),
this.month(),
this.date() - (this.isoWeekday() - 1)
);
break;
case 'day':
case 'date':
time = startOfDate(this.year(), this.month(), this.date());
break;
case 'hour':
time = this._d.valueOf();
time -= mod$1(
time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE),
MS_PER_HOUR
);
break;
case 'minute':
time = this._d.valueOf();
time -= mod$1(time, MS_PER_MINUTE);
break;
case 'second':
time = this._d.valueOf();
time -= mod$1(time, MS_PER_SECOND);
break;
}
this._d.setTime(time);
hooks.updateOffset(this, true);
return this;
}
function endOf(units) {
var time, startOfDate;
units = normalizeUnits(units);
if (units === undefined || units === 'millisecond' || !this.isValid()) {
return this;
}
startOfDate = this._isUTC ? utcStartOfDate : localStartOfDate;
switch (units) {
case 'year':
time = startOfDate(this.year() + 1, 0, 1) - 1;
break;
case 'quarter':
time =
startOfDate(
this.year(),
this.month() - (this.month() % 3) + 3,
1
) - 1;
break;
case 'month':
time = startOfDate(this.year(), this.month() + 1, 1) - 1;
break;
case 'week':
time =
startOfDate(
this.year(),
this.month(),
this.date() - this.weekday() + 7
) - 1;
break;
case 'isoWeek':
time =
startOfDate(
this.year(),
this.month(),
this.date() - (this.isoWeekday() - 1) + 7
) - 1;
break;
case 'day':
case 'date':
time = startOfDate(this.year(), this.month(), this.date() + 1) - 1;
break;
case 'hour':
time = this._d.valueOf();
time +=
MS_PER_HOUR -
mod$1(
time + (this._isUTC ? 0 : this.utcOffset() * MS_PER_MINUTE),
MS_PER_HOUR
) -
1;
break;
case 'minute':
time = this._d.valueOf();
time += MS_PER_MINUTE - mod$1(time, MS_PER_MINUTE) - 1;
break;
case 'second':
time = this._d.valueOf();
time += MS_PER_SECOND - mod$1(time, MS_PER_SECOND) - 1;
break;
}
this._d.setTime(time);
hooks.updateOffset(this, true);
return this;
}
function valueOf() {
return this._d.valueOf() - (this._offset || 0) * 60000;
}
function unix() {
return Math.floor(this.valueOf() / 1000);
}
function toDate() {
return new Date(this.valueOf());
}
function toArray() {
var m = this;
return [
m.year(),
m.month(),
m.date(),
m.hour(),
m.minute(),
m.second(),
m.millisecond(),
];
}
function toObject() {
var m = this;
return {
years: m.year(),
months: m.month(),
date: m.date(),
hours: m.hours(),
minutes: m.minutes(),
seconds: m.seconds(),
milliseconds: m.milliseconds(),
};
}
function toJSON() {
// new Date(NaN).toJSON() === null
return this.isValid() ? this.toISOString() : null;
}
function isValid$2() {
return isValid(this);
}
function parsingFlags() {
return extend({}, getParsingFlags(this));
}
function invalidAt() {
return getParsingFlags(this).overflow;
}
function creationData() {
return {
input: this._i,
format: this._f,
locale: this._locale,
isUTC: this._isUTC,
strict: this._strict,
};
}
addFormatToken('N', 0, 0, 'eraAbbr');
addFormatToken('NN', 0, 0, 'eraAbbr');
addFormatToken('NNN', 0, 0, 'eraAbbr');
addFormatToken('NNNN', 0, 0, 'eraName');
addFormatToken('NNNNN', 0, 0, 'eraNarrow');
addFormatToken('y', ['y', 1], 'yo', 'eraYear');
addFormatToken('y', ['yy', 2], 0, 'eraYear');
addFormatToken('y', ['yyy', 3], 0, 'eraYear');
addFormatToken('y', ['yyyy', 4], 0, 'eraYear');
addRegexToken('N', matchEraAbbr);
addRegexToken('NN', matchEraAbbr);
addRegexToken('NNN', matchEraAbbr);
addRegexToken('NNNN', matchEraName);
addRegexToken('NNNNN', matchEraNarrow);
addParseToken(['N', 'NN', 'NNN', 'NNNN', 'NNNNN'], function (
input,
array,
config,
token
) {
var era = config._locale.erasParse(input, token, config._strict);
if (era) {
getParsingFlags(config).era = era;
} else {
getParsingFlags(config).invalidEra = input;
}
});
addRegexToken('y', matchUnsigned);
addRegexToken('yy', matchUnsigned);
addRegexToken('yyy', matchUnsigned);
addRegexToken('yyyy', matchUnsigned);
addRegexToken('yo', matchEraYearOrdinal);
addParseToken(['y', 'yy', 'yyy', 'yyyy'], YEAR);
addParseToken(['yo'], function (input, array, config, token) {
var match;
if (config._locale._eraYearOrdinalRegex) {
match = input.match(config._locale._eraYearOrdinalRegex);
}
if (config._locale.eraYearOrdinalParse) {
array[YEAR] = config._locale.eraYearOrdinalParse(input, match);
} else {
array[YEAR] = parseInt(input, 10);
}
});
function localeEras(m, format) {
var i,
l,
date,
eras = this._eras || getLocale('en')._eras;
for (i = 0, l = eras.length; i < l; ++i) {
switch (typeof eras[i].since) {
case 'string':
// truncate time
date = hooks(eras[i].since).startOf('day');
eras[i].since = date.valueOf();
break;
}
switch (typeof eras[i].until) {
case 'undefined':
eras[i].until = +Infinity;
break;
case 'string':
// truncate time
date = hooks(eras[i].until).startOf('day').valueOf();
eras[i].until = date.valueOf();
break;
}
}
return eras;
}
function localeErasParse(eraName, format, strict) {
var i,
l,
eras = this.eras(),
name,
abbr,
narrow;
eraName = eraName.toUpperCase();
for (i = 0, l = eras.length; i < l; ++i) {
name = eras[i].name.toUpperCase();
abbr = eras[i].abbr.toUpperCase();
narrow = eras[i].narrow.toUpperCase();
if (strict) {
switch (format) {
case 'N':
case 'NN':
case 'NNN':
if (abbr === eraName) {
return eras[i];
}
break;
case 'NNNN':
if (name === eraName) {
return eras[i];
}
break;
case 'NNNNN':
if (narrow === eraName) {
return eras[i];
}
break;
}
} else if ([name, abbr, narrow].indexOf(eraName) >= 0) {
return eras[i];
}
}
}
function localeErasConvertYear(era, year) {
var dir = era.since <= era.until ? +1 : -1;
if (year === undefined) {
return hooks(era.since).year();
} else {
return hooks(era.since).year() + (year - era.offset) * dir;
}
}
function getEraName() {
var i,
l,
val,
eras = this.localeData().eras();
for (i = 0, l = eras.length; i < l; ++i) {
// truncate time
val = this.clone().startOf('day').valueOf();
if (eras[i].since <= val && val <= eras[i].until) {
return eras[i].name;
}
if (eras[i].until <= val && val <= eras[i].since) {
return eras[i].name;
}
}
return '';
}
function getEraNarrow() {
var i,
l,
val,
eras = this.localeData().eras();
for (i = 0, l = eras.length; i < l; ++i) {
// truncate time
val = this.clone().startOf('day').valueOf();
if (eras[i].since <= val && val <= eras[i].until) {
return eras[i].narrow;
}
if (eras[i].until <= val && val <= eras[i].since) {
return eras[i].narrow;
}
}
return '';
}
function getEraAbbr() {
var i,
l,
val,
eras = this.localeData().eras();
for (i = 0, l = eras.length; i < l; ++i) {
// truncate time
val = this.clone().startOf('day').valueOf();
if (eras[i].since <= val && val <= eras[i].until) {
return eras[i].abbr;
}
if (eras[i].until <= val && val <= eras[i].since) {
return eras[i].abbr;
}
}
return '';
}
function getEraYear() {
var i,
l,
dir,
val,
eras = this.localeData().eras();
for (i = 0, l = eras.length; i < l; ++i) {
dir = eras[i].since <= eras[i].until ? +1 : -1;
// truncate time
val = this.clone().startOf('day').valueOf();
if (
(eras[i].since <= val && val <= eras[i].until) ||
(eras[i].until <= val && val <= eras[i].since)
) {
return (
(this.year() - hooks(eras[i].since).year()) * dir +
eras[i].offset
);
}
}
return this.year();
}
function erasNameRegex(isStrict) {
if (!hasOwnProp(this, '_erasNameRegex')) {
computeErasParse.call(this);
}
return isStrict ? this._erasNameRegex : this._erasRegex;
}
function erasAbbrRegex(isStrict) {
if (!hasOwnProp(this, '_erasAbbrRegex')) {
computeErasParse.call(this);
}
return isStrict ? this._erasAbbrRegex : this._erasRegex;
}
function erasNarrowRegex(isStrict) {
if (!hasOwnProp(this, '_erasNarrowRegex')) {
computeErasParse.call(this);
}
return isStrict ? this._erasNarrowRegex : this._erasRegex;
}
function matchEraAbbr(isStrict, locale) {
return locale.erasAbbrRegex(isStrict);
}
function matchEraName(isStrict, locale) {
return locale.erasNameRegex(isStrict);
}
function matchEraNarrow(isStrict, locale) {
return locale.erasNarrowRegex(isStrict);
}
function matchEraYearOrdinal(isStrict, locale) {
return locale._eraYearOrdinalRegex || matchUnsigned;
}
function computeErasParse() {
var abbrPieces = [],
namePieces = [],
narrowPieces = [],
mixedPieces = [],
i,
l,
eras = this.eras();
for (i = 0, l = eras.length; i < l; ++i) {
namePieces.push(regexEscape(eras[i].name));
abbrPieces.push(regexEscape(eras[i].abbr));
narrowPieces.push(regexEscape(eras[i].narrow));
mixedPieces.push(regexEscape(eras[i].name));
mixedPieces.push(regexEscape(eras[i].abbr));
mixedPieces.push(regexEscape(eras[i].narrow));
}
this._erasRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
this._erasNameRegex = new RegExp('^(' + namePieces.join('|') + ')', 'i');
this._erasAbbrRegex = new RegExp('^(' + abbrPieces.join('|') + ')', 'i');
this._erasNarrowRegex = new RegExp(
'^(' + narrowPieces.join('|') + ')',
'i'
);
}
// FORMATTING
addFormatToken(0, ['gg', 2], 0, function () {
return this.weekYear() % 100;
});
addFormatToken(0, ['GG', 2], 0, function () {
return this.isoWeekYear() % 100;
});
function addWeekYearFormatToken(token, getter) {
addFormatToken(0, [token, token.length], 0, getter);
}
addWeekYearFormatToken('gggg', 'weekYear');
addWeekYearFormatToken('ggggg', 'weekYear');
addWeekYearFormatToken('GGGG', 'isoWeekYear');
addWeekYearFormatToken('GGGGG', 'isoWeekYear');
// ALIASES
addUnitAlias('weekYear', 'gg');
addUnitAlias('isoWeekYear', 'GG');
// PRIORITY
addUnitPriority('weekYear', 1);
addUnitPriority('isoWeekYear', 1);
// PARSING
addRegexToken('G', matchSigned);
addRegexToken('g', matchSigned);
addRegexToken('GG', match1to2, match2);
addRegexToken('gg', match1to2, match2);
addRegexToken('GGGG', match1to4, match4);
addRegexToken('gggg', match1to4, match4);
addRegexToken('GGGGG', match1to6, match6);
addRegexToken('ggggg', match1to6, match6);
addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (
input,
week,
config,
token
) {
week[token.substr(0, 2)] = toInt(input);
});
addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
week[token] = hooks.parseTwoDigitYear(input);
});
// MOMENTS
function getSetWeekYear(input) {
return getSetWeekYearHelper.call(
this,
input,
this.week(),
this.weekday(),
this.localeData()._week.dow,
this.localeData()._week.doy
);
}
function getSetISOWeekYear(input) {
return getSetWeekYearHelper.call(
this,
input,
this.isoWeek(),
this.isoWeekday(),
1,
4
);
}
function getISOWeeksInYear() {
return weeksInYear(this.year(), 1, 4);
}
function getISOWeeksInISOWeekYear() {
return weeksInYear(this.isoWeekYear(), 1, 4);
}
function getWeeksInYear() {
var weekInfo = this.localeData()._week;
return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
}
function getWeeksInWeekYear() {
var weekInfo = this.localeData()._week;
return weeksInYear(this.weekYear(), weekInfo.dow, weekInfo.doy);
}
function getSetWeekYearHelper(input, week, weekday, dow, doy) {
var weeksTarget;
if (input == null) {
return weekOfYear(this, dow, doy).year;
} else {
weeksTarget = weeksInYear(input, dow, doy);
if (week > weeksTarget) {
week = weeksTarget;
}
return setWeekAll.call(this, input, week, weekday, dow, doy);
}
}
function setWeekAll(weekYear, week, weekday, dow, doy) {
var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
this.year(date.getUTCFullYear());
this.month(date.getUTCMonth());
this.date(date.getUTCDate());
return this;
}
// FORMATTING
addFormatToken('Q', 0, 'Qo', 'quarter');
// ALIASES
addUnitAlias('quarter', 'Q');
// PRIORITY
addUnitPriority('quarter', 7);
// PARSING
addRegexToken('Q', match1);
addParseToken('Q', function (input, array) {
array[MONTH] = (toInt(input) - 1) * 3;
});
// MOMENTS
function getSetQuarter(input) {
return input == null
? Math.ceil((this.month() + 1) / 3)
: this.month((input - 1) * 3 + (this.month() % 3));
}
// FORMATTING
addFormatToken('D', ['DD', 2], 'Do', 'date');
// ALIASES
addUnitAlias('date', 'D');
// PRIORITY
addUnitPriority('date', 9);
// PARSING
addRegexToken('D', match1to2);
addRegexToken('DD', match1to2, match2);
addRegexToken('Do', function (isStrict, locale) {
// TODO: Remove "ordinalParse" fallback in next major release.
return isStrict
? locale._dayOfMonthOrdinalParse || locale._ordinalParse
: locale._dayOfMonthOrdinalParseLenient;
});
addParseToken(['D', 'DD'], DATE);
addParseToken('Do', function (input, array) {
array[DATE] = toInt(input.match(match1to2)[0]);
});
// MOMENTS
var getSetDayOfMonth = makeGetSet('Date', true);
// FORMATTING
addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
// ALIASES
addUnitAlias('dayOfYear', 'DDD');
// PRIORITY
addUnitPriority('dayOfYear', 4);
// PARSING
addRegexToken('DDD', match1to3);
addRegexToken('DDDD', match3);
addParseToken(['DDD', 'DDDD'], function (input, array, config) {
config._dayOfYear = toInt(input);
});
// HELPERS
// MOMENTS
function getSetDayOfYear(input) {
var dayOfYear =
Math.round(
(this.clone().startOf('day') - this.clone().startOf('year')) / 864e5
) + 1;
return input == null ? dayOfYear : this.add(input - dayOfYear, 'd');
}
// FORMATTING
addFormatToken('m', ['mm', 2], 0, 'minute');
// ALIASES
addUnitAlias('minute', 'm');
// PRIORITY
addUnitPriority('minute', 14);
// PARSING
addRegexToken('m', match1to2);
addRegexToken('mm', match1to2, match2);
addParseToken(['m', 'mm'], MINUTE);
// MOMENTS
var getSetMinute = makeGetSet('Minutes', false);
// FORMATTING
addFormatToken('s', ['ss', 2], 0, 'second');
// ALIASES
addUnitAlias('second', 's');
// PRIORITY
addUnitPriority('second', 15);
// PARSING
addRegexToken('s', match1to2);
addRegexToken('ss', match1to2, match2);
addParseToken(['s', 'ss'], SECOND);
// MOMENTS
var getSetSecond = makeGetSet('Seconds', false);
// FORMATTING
addFormatToken('S', 0, 0, function () {
return ~~(this.millisecond() / 100);
});
addFormatToken(0, ['SS', 2], 0, function () {
return ~~(this.millisecond() / 10);
});
addFormatToken(0, ['SSS', 3], 0, 'millisecond');
addFormatToken(0, ['SSSS', 4], 0, function () {
return this.millisecond() * 10;
});
addFormatToken(0, ['SSSSS', 5], 0, function () {
return this.millisecond() * 100;
});
addFormatToken(0, ['SSSSSS', 6], 0, function () {
return this.millisecond() * 1000;
});
addFormatToken(0, ['SSSSSSS', 7], 0, function () {
return this.millisecond() * 10000;
});
addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
return this.millisecond() * 100000;
});
addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
return this.millisecond() * 1000000;
});
// ALIASES
addUnitAlias('millisecond', 'ms');
// PRIORITY
addUnitPriority('millisecond', 16);
// PARSING
addRegexToken('S', match1to3, match1);
addRegexToken('SS', match1to3, match2);
addRegexToken('SSS', match1to3, match3);
var token, getSetMillisecond;
for (token = 'SSSS'; token.length <= 9; token += 'S') {
addRegexToken(token, matchUnsigned);
}
function parseMs(input, array) {
array[MILLISECOND] = toInt(('0.' + input) * 1000);
}
for (token = 'S'; token.length <= 9; token += 'S') {
addParseToken(token, parseMs);
}
getSetMillisecond = makeGetSet('Milliseconds', false);
// FORMATTING
addFormatToken('z', 0, 0, 'zoneAbbr');
addFormatToken('zz', 0, 0, 'zoneName');
// MOMENTS
function getZoneAbbr() {
return this._isUTC ? 'UTC' : '';
}
function getZoneName() {
return this._isUTC ? 'Coordinated Universal Time' : '';
}
var proto = Moment.prototype;
proto.add = add;
proto.calendar = calendar$1;
proto.clone = clone;
proto.diff = diff;
proto.endOf = endOf;
proto.format = format;
proto.from = from;
proto.fromNow = fromNow;
proto.to = to;
proto.toNow = toNow;
proto.get = stringGet;
proto.invalidAt = invalidAt;
proto.isAfter = isAfter;
proto.isBefore = isBefore;
proto.isBetween = isBetween;
proto.isSame = isSame;
proto.isSameOrAfter = isSameOrAfter;
proto.isSameOrBefore = isSameOrBefore;
proto.isValid = isValid$2;
proto.lang = lang;
proto.locale = locale;
proto.localeData = localeData;
proto.max = prototypeMax;
proto.min = prototypeMin;
proto.parsingFlags = parsingFlags;
proto.set = stringSet;
proto.startOf = startOf;
proto.subtract = subtract;
proto.toArray = toArray;
proto.toObject = toObject;
proto.toDate = toDate;
proto.toISOString = toISOString;
proto.inspect = inspect;
if (typeof Symbol !== 'undefined' && Symbol.for != null) {
proto[Symbol.for('nodejs.util.inspect.custom')] = function () {
return 'Moment<' + this.format() + '>';
};
}
proto.toJSON = toJSON;
proto.toString = toString;
proto.unix = unix;
proto.valueOf = valueOf;
proto.creationData = creationData;
proto.eraName = getEraName;
proto.eraNarrow = getEraNarrow;
proto.eraAbbr = getEraAbbr;
proto.eraYear = getEraYear;
proto.year = getSetYear;
proto.isLeapYear = getIsLeapYear;
proto.weekYear = getSetWeekYear;
proto.isoWeekYear = getSetISOWeekYear;
proto.quarter = proto.quarters = getSetQuarter;
proto.month = getSetMonth;
proto.daysInMonth = getDaysInMonth;
proto.week = proto.weeks = getSetWeek;
proto.isoWeek = proto.isoWeeks = getSetISOWeek;
proto.weeksInYear = getWeeksInYear;
proto.weeksInWeekYear = getWeeksInWeekYear;
proto.isoWeeksInYear = getISOWeeksInYear;
proto.isoWeeksInISOWeekYear = getISOWeeksInISOWeekYear;
proto.date = getSetDayOfMonth;
proto.day = proto.days = getSetDayOfWeek;
proto.weekday = getSetLocaleDayOfWeek;
proto.isoWeekday = getSetISODayOfWeek;
proto.dayOfYear = getSetDayOfYear;
proto.hour = proto.hours = getSetHour;
proto.minute = proto.minutes = getSetMinute;
proto.second = proto.seconds = getSetSecond;
proto.millisecond = proto.milliseconds = getSetMillisecond;
proto.utcOffset = getSetOffset;
proto.utc = setOffsetToUTC;
proto.local = setOffsetToLocal;
proto.parseZone = setOffsetToParsedOffset;
proto.hasAlignedHourOffset = hasAlignedHourOffset;
proto.isDST = isDaylightSavingTime;
proto.isLocal = isLocal;
proto.isUtcOffset = isUtcOffset;
proto.isUtc = isUtc;
proto.isUTC = isUtc;
proto.zoneAbbr = getZoneAbbr;
proto.zoneName = getZoneName;
proto.dates = deprecate(
'dates accessor is deprecated. Use date instead.',
getSetDayOfMonth
);
proto.months = deprecate(
'months accessor is deprecated. Use month instead',
getSetMonth
);
proto.years = deprecate(
'years accessor is deprecated. Use year instead',
getSetYear
);
proto.zone = deprecate(
'moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/',
getSetZone
);
proto.isDSTShifted = deprecate(
'isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information',
isDaylightSavingTimeShifted
);
function createUnix(input) {
return createLocal(input * 1000);
}
function createInZone() {
return createLocal.apply(null, arguments).parseZone();
}
function preParsePostFormat(string) {
return string;
}
var proto$1 = Locale.prototype;
proto$1.calendar = calendar;
proto$1.longDateFormat = longDateFormat;
proto$1.invalidDate = invalidDate;
proto$1.ordinal = ordinal;
proto$1.preparse = preParsePostFormat;
proto$1.postformat = preParsePostFormat;
proto$1.relativeTime = relativeTime;
proto$1.pastFuture = pastFuture;
proto$1.set = set;
proto$1.eras = localeEras;
proto$1.erasParse = localeErasParse;
proto$1.erasConvertYear = localeErasConvertYear;
proto$1.erasAbbrRegex = erasAbbrRegex;
proto$1.erasNameRegex = erasNameRegex;
proto$1.erasNarrowRegex = erasNarrowRegex;
proto$1.months = localeMonths;
proto$1.monthsShort = localeMonthsShort;
proto$1.monthsParse = localeMonthsParse;
proto$1.monthsRegex = monthsRegex;
proto$1.monthsShortRegex = monthsShortRegex;
proto$1.week = localeWeek;
proto$1.firstDayOfYear = localeFirstDayOfYear;
proto$1.firstDayOfWeek = localeFirstDayOfWeek;
proto$1.weekdays = localeWeekdays;
proto$1.weekdaysMin = localeWeekdaysMin;
proto$1.weekdaysShort = localeWeekdaysShort;
proto$1.weekdaysParse = localeWeekdaysParse;
proto$1.weekdaysRegex = weekdaysRegex;
proto$1.weekdaysShortRegex = weekdaysShortRegex;
proto$1.weekdaysMinRegex = weekdaysMinRegex;
proto$1.isPM = localeIsPM;
proto$1.meridiem = localeMeridiem;
function get$1(format, index, field, setter) {
var locale = getLocale(),
utc = createUTC().set(setter, index);
return locale[field](utc, format);
}
function listMonthsImpl(format, index, field) {
if (isNumber(format)) {
index = format;
format = undefined;
}
format = format || '';
if (index != null) {
return get$1(format, index, field, 'month');
}
var i,
out = [];
for (i = 0; i < 12; i++) {
out[i] = get$1(format, i, field, 'month');
}
return out;
}
// ()
// (5)
// (fmt, 5)
// (fmt)
// (true)
// (true, 5)
// (true, fmt, 5)
// (true, fmt)
function listWeekdaysImpl(localeSorted, format, index, field) {
if (typeof localeSorted === 'boolean') {
if (isNumber(format)) {
index = format;
format = undefined;
}
format = format || '';
} else {
format = localeSorted;
index = format;
localeSorted = false;
if (isNumber(format)) {
index = format;
format = undefined;
}
format = format || '';
}
var locale = getLocale(),
shift = localeSorted ? locale._week.dow : 0,
i,
out = [];
if (index != null) {
return get$1(format, (index + shift) % 7, field, 'day');
}
for (i = 0; i < 7; i++) {
out[i] = get$1(format, (i + shift) % 7, field, 'day');
}
return out;
}
function listMonths(format, index) {
return listMonthsImpl(format, index, 'months');
}
function listMonthsShort(format, index) {
return listMonthsImpl(format, index, 'monthsShort');
}
function listWeekdays(localeSorted, format, index) {
return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
}
function listWeekdaysShort(localeSorted, format, index) {
return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
}
function listWeekdaysMin(localeSorted, format, index) {
return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
}
getSetGlobalLocale('en', {
eras: [
{
since: '0001-01-01',
until: +Infinity,
offset: 1,
name: 'Anno Domini',
narrow: 'AD',
abbr: 'AD',
},
{
since: '0000-12-31',
until: -Infinity,
offset: 1,
name: 'Before Christ',
narrow: 'BC',
abbr: 'BC',
},
],
dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/,
ordinal: function (number) {
var b = number % 10,
output =
toInt((number % 100) / 10) === 1
? 'th'
: b === 1
? 'st'
: b === 2
? 'nd'
: b === 3
? 'rd'
: 'th';
return number + output;
},
});
// Side effect imports
hooks.lang = deprecate(
'moment.lang is deprecated. Use moment.locale instead.',
getSetGlobalLocale
);
hooks.langData = deprecate(
'moment.langData is deprecated. Use moment.localeData instead.',
getLocale
);
var mathAbs = Math.abs;
function abs() {
var data = this._data;
this._milliseconds = mathAbs(this._milliseconds);
this._days = mathAbs(this._days);
this._months = mathAbs(this._months);
data.milliseconds = mathAbs(data.milliseconds);
data.seconds = mathAbs(data.seconds);
data.minutes = mathAbs(data.minutes);
data.hours = mathAbs(data.hours);
data.months = mathAbs(data.months);
data.years = mathAbs(data.years);
return this;
}
function addSubtract$1(duration, input, value, direction) {
var other = createDuration(input, value);
duration._milliseconds += direction * other._milliseconds;
duration._days += direction * other._days;
duration._months += direction * other._months;
return duration._bubble();
}
// supports only 2.0-style add(1, 's') or add(duration)
function add$1(input, value) {
return addSubtract$1(this, input, value, 1);
}
// supports only 2.0-style subtract(1, 's') or subtract(duration)
function subtract$1(input, value) {
return addSubtract$1(this, input, value, -1);
}
function absCeil(number) {
if (number < 0) {
return Math.floor(number);
} else {
return Math.ceil(number);
}
}
function bubble() {
var milliseconds = this._milliseconds,
days = this._days,
months = this._months,
data = this._data,
seconds,
minutes,
hours,
years,
monthsFromDays;
// if we have a mix of positive and negative values, bubble down first
// check: https://github.com/moment/moment/issues/2166
if (
!(
(milliseconds >= 0 && days >= 0 && months >= 0) ||
(milliseconds <= 0 && days <= 0 && months <= 0)
)
) {
milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
days = 0;
months = 0;
}
// The following code bubbles up values, see the tests for
// examples of what that means.
data.milliseconds = milliseconds % 1000;
seconds = absFloor(milliseconds / 1000);
data.seconds = seconds % 60;
minutes = absFloor(seconds / 60);
data.minutes = minutes % 60;
hours = absFloor(minutes / 60);
data.hours = hours % 24;
days += absFloor(hours / 24);
// convert days to months
monthsFromDays = absFloor(daysToMonths(days));
months += monthsFromDays;
days -= absCeil(monthsToDays(monthsFromDays));
// 12 months -> 1 year
years = absFloor(months / 12);
months %= 12;
data.days = days;
data.months = months;
data.years = years;
return this;
}
function daysToMonths(days) {
// 400 years have 146097 days (taking into account leap year rules)
// 400 years have 12 months === 4800
return (days * 4800) / 146097;
}
function monthsToDays(months) {
// the reverse of daysToMonths
return (months * 146097) / 4800;
}
function as(units) {
if (!this.isValid()) {
return NaN;
}
var days,
months,
milliseconds = this._milliseconds;
units = normalizeUnits(units);
if (units === 'month' || units === 'quarter' || units === 'year') {
days = this._days + milliseconds / 864e5;
months = this._months + daysToMonths(days);
switch (units) {
case 'month':
return months;
case 'quarter':
return months / 3;
case 'year':
return months / 12;
}
} else {
// handle milliseconds separately because of floating point math errors (issue #1867)
days = this._days + Math.round(monthsToDays(this._months));
switch (units) {
case 'week':
return days / 7 + milliseconds / 6048e5;
case 'day':
return days + milliseconds / 864e5;
case 'hour':
return days * 24 + milliseconds / 36e5;
case 'minute':
return days * 1440 + milliseconds / 6e4;
case 'second':
return days * 86400 + milliseconds / 1000;
// Math.floor prevents floating point math errors here
case 'millisecond':
return Math.floor(days * 864e5) + milliseconds;
default:
throw new Error('Unknown unit ' + units);
}
}
}
// TODO: Use this.as('ms')?
function valueOf$1() {
if (!this.isValid()) {
return NaN;
}
return (
this._milliseconds +
this._days * 864e5 +
(this._months % 12) * 2592e6 +
toInt(this._months / 12) * 31536e6
);
}
function makeAs(alias) {
return function () {
return this.as(alias);
};
}
var asMilliseconds = makeAs('ms'),
asSeconds = makeAs('s'),
asMinutes = makeAs('m'),
asHours = makeAs('h'),
asDays = makeAs('d'),
asWeeks = makeAs('w'),
asMonths = makeAs('M'),
asQuarters = makeAs('Q'),
asYears = makeAs('y');
function clone$1() {
return createDuration(this);
}
function get$2(units) {
units = normalizeUnits(units);
return this.isValid() ? this[units + 's']() : NaN;
}
function makeGetter(name) {
return function () {
return this.isValid() ? this._data[name] : NaN;
};
}
var milliseconds = makeGetter('milliseconds'),
seconds = makeGetter('seconds'),
minutes = makeGetter('minutes'),
hours = makeGetter('hours'),
days = makeGetter('days'),
months = makeGetter('months'),
years = makeGetter('years');
function weeks() {
return absFloor(this.days() / 7);
}
var round = Math.round,
thresholds = {
ss: 44, // a few seconds to seconds
s: 45, // seconds to minute
m: 45, // minutes to hour
h: 22, // hours to day
d: 26, // days to month/week
w: null, // weeks to month
M: 11, // months to year
};
// helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
}
function relativeTime$1(posNegDuration, withoutSuffix, thresholds, locale) {
var duration = createDuration(posNegDuration).abs(),
seconds = round(duration.as('s')),
minutes = round(duration.as('m')),
hours = round(duration.as('h')),
days = round(duration.as('d')),
months = round(duration.as('M')),
weeks = round(duration.as('w')),
years = round(duration.as('y')),
a =
(seconds <= thresholds.ss && ['s', seconds]) ||
(seconds < thresholds.s && ['ss', seconds]) ||
(minutes <= 1 && ['m']) ||
(minutes < thresholds.m && ['mm', minutes]) ||
(hours <= 1 && ['h']) ||
(hours < thresholds.h && ['hh', hours]) ||
(days <= 1 && ['d']) ||
(days < thresholds.d && ['dd', days]);
if (thresholds.w != null) {
a =
a ||
(weeks <= 1 && ['w']) ||
(weeks < thresholds.w && ['ww', weeks]);
}
a = a ||
(months <= 1 && ['M']) ||
(months < thresholds.M && ['MM', months]) ||
(years <= 1 && ['y']) || ['yy', years];
a[2] = withoutSuffix;
a[3] = +posNegDuration > 0;
a[4] = locale;
return substituteTimeAgo.apply(null, a);
}
// This function allows you to set the rounding function for relative time strings
function getSetRelativeTimeRounding(roundingFunction) {
if (roundingFunction === undefined) {
return round;
}
if (typeof roundingFunction === 'function') {
round = roundingFunction;
return true;
}
return false;
}
// This function allows you to set a threshold for relative time strings
function getSetRelativeTimeThreshold(threshold, limit) {
if (thresholds[threshold] === undefined) {
return false;
}
if (limit === undefined) {
return thresholds[threshold];
}
thresholds[threshold] = limit;
if (threshold === 's') {
thresholds.ss = limit - 1;
}
return true;
}
function humanize(argWithSuffix, argThresholds) {
if (!this.isValid()) {
return this.localeData().invalidDate();
}
var withSuffix = false,
th = thresholds,
locale,
output;
if (typeof argWithSuffix === 'object') {
argThresholds = argWithSuffix;
argWithSuffix = false;
}
if (typeof argWithSuffix === 'boolean') {
withSuffix = argWithSuffix;
}
if (typeof argThresholds === 'object') {
th = Object.assign({}, thresholds, argThresholds);
if (argThresholds.s != null && argThresholds.ss == null) {
th.ss = argThresholds.s - 1;
}
}
locale = this.localeData();
output = relativeTime$1(this, !withSuffix, th, locale);
if (withSuffix) {
output = locale.pastFuture(+this, output);
}
return locale.postformat(output);
}
var abs$1 = Math.abs;
function sign(x) {
return (x > 0) - (x < 0) || +x;
}
function toISOString$1() {
// for ISO strings we do not use the normal bubbling rules:
// * milliseconds bubble up until they become hours
// * days do not bubble at all
// * months bubble up until they become years
// This is because there is no context-free conversion between hours and days
// (think of clock changes)
// and also not between days and months (28-31 days per month)
if (!this.isValid()) {
return this.localeData().invalidDate();
}
var seconds = abs$1(this._milliseconds) / 1000,
days = abs$1(this._days),
months = abs$1(this._months),
minutes,
hours,
years,
s,
total = this.asSeconds(),
totalSign,
ymSign,
daysSign,
hmsSign;
if (!total) {
// this is the same as C#'s (Noda) and python (isodate)...
// but not other JS (goog.date)
return 'P0D';
}
// 3600 seconds -> 60 minutes -> 1 hour
minutes = absFloor(seconds / 60);
hours = absFloor(minutes / 60);
seconds %= 60;
minutes %= 60;
// 12 months -> 1 year
years = absFloor(months / 12);
months %= 12;
// inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
s = seconds ? seconds.toFixed(3).replace(/\.?0+$/, '') : '';
totalSign = total < 0 ? '-' : '';
ymSign = sign(this._months) !== sign(total) ? '-' : '';
daysSign = sign(this._days) !== sign(total) ? '-' : '';
hmsSign = sign(this._milliseconds) !== sign(total) ? '-' : '';
return (
totalSign +
'P' +
(years ? ymSign + years + 'Y' : '') +
(months ? ymSign + months + 'M' : '') +
(days ? daysSign + days + 'D' : '') +
(hours || minutes || seconds ? 'T' : '') +
(hours ? hmsSign + hours + 'H' : '') +
(minutes ? hmsSign + minutes + 'M' : '') +
(seconds ? hmsSign + s + 'S' : '')
);
}
var proto$2 = Duration.prototype;
proto$2.isValid = isValid$1;
proto$2.abs = abs;
proto$2.add = add$1;
proto$2.subtract = subtract$1;
proto$2.as = as;
proto$2.asMilliseconds = asMilliseconds;
proto$2.asSeconds = asSeconds;
proto$2.asMinutes = asMinutes;
proto$2.asHours = asHours;
proto$2.asDays = asDays;
proto$2.asWeeks = asWeeks;
proto$2.asMonths = asMonths;
proto$2.asQuarters = asQuarters;
proto$2.asYears = asYears;
proto$2.valueOf = valueOf$1;
proto$2._bubble = bubble;
proto$2.clone = clone$1;
proto$2.get = get$2;
proto$2.milliseconds = milliseconds;
proto$2.seconds = seconds;
proto$2.minutes = minutes;
proto$2.hours = hours;
proto$2.days = days;
proto$2.weeks = weeks;
proto$2.months = months;
proto$2.years = years;
proto$2.humanize = humanize;
proto$2.toISOString = toISOString$1;
proto$2.toString = toISOString$1;
proto$2.toJSON = toISOString$1;
proto$2.locale = locale;
proto$2.localeData = localeData;
proto$2.toIsoString = deprecate(
'toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)',
toISOString$1
);
proto$2.lang = lang;
// FORMATTING
addFormatToken('X', 0, 0, 'unix');
addFormatToken('x', 0, 0, 'valueOf');
// PARSING
addRegexToken('x', matchSigned);
addRegexToken('X', matchTimestamp);
addParseToken('X', function (input, array, config) {
config._d = new Date(parseFloat(input) * 1000);
});
addParseToken('x', function (input, array, config) {
config._d = new Date(toInt(input));
});
//! moment.js
hooks.version = '2.29.1';
setHookCallback(createLocal);
hooks.fn = proto;
hooks.min = min;
hooks.max = max;
hooks.now = now;
hooks.utc = createUTC;
hooks.unix = createUnix;
hooks.months = listMonths;
hooks.isDate = isDate;
hooks.locale = getSetGlobalLocale;
hooks.invalid = createInvalid;
hooks.duration = createDuration;
hooks.isMoment = isMoment;
hooks.weekdays = listWeekdays;
hooks.parseZone = createInZone;
hooks.localeData = getLocale;
hooks.isDuration = isDuration;
hooks.monthsShort = listMonthsShort;
hooks.weekdaysMin = listWeekdaysMin;
hooks.defineLocale = defineLocale;
hooks.updateLocale = updateLocale;
hooks.locales = listLocales;
hooks.weekdaysShort = listWeekdaysShort;
hooks.normalizeUnits = normalizeUnits;
hooks.relativeTimeRounding = getSetRelativeTimeRounding;
hooks.relativeTimeThreshold = getSetRelativeTimeThreshold;
hooks.calendarFormat = getCalendarFormat;
hooks.prototype = proto;
// currently HTML5 input type only supports 24-hour formats
hooks.HTML5_FMT = {
DATETIME_LOCAL: 'YYYY-MM-DDTHH:mm', // <input type="datetime-local" />
DATETIME_LOCAL_SECONDS: 'YYYY-MM-DDTHH:mm:ss', // <input type="datetime-local" step="1" />
DATETIME_LOCAL_MS: 'YYYY-MM-DDTHH:mm:ss.SSS', // <input type="datetime-local" step="0.001" />
DATE: 'YYYY-MM-DD', // <input type="date" />
TIME: 'HH:mm', // <input type="time" />
TIME_SECONDS: 'HH:mm:ss', // <input type="time" step="1" />
TIME_MS: 'HH:mm:ss.SSS', // <input type="time" step="0.001" />
WEEK: 'GGGG-[W]WW', // <input type="week" />
MONTH: 'YYYY-MM', // <input type="month" />
};
return hooks;
})));
});
class DateTime$2 {
constructor(time, _hasTimePart) {
this.time = time;
this._hasTimePart = _hasTimePart;
}
static now() {
return new DateTime$2(moment(), true);
}
static parse(time) {
if (time.length > 10) {
return new DateTime$2(moment(time, "YYYY-MM-DD HH:mm"), true);
}
else {
return new DateTime$2(moment(time, "YYYY-MM-DD"), false);
}
}
static duration(from, to, unit, defaultTime) {
return to.fixedTime(defaultTime).diff(from.fixedTime(defaultTime), unit);
}
getTimeInMillis(defaultTime) {
return this.fixedTime(defaultTime).valueOf();
}
format(format, defaultTime) {
return this.fixedTime(defaultTime).format(format);
}
toYYYYMMMM(defaultTime) {
return this.fixedTime(defaultTime).format("YYYY, MMMM");
}
toYYYYMMDD(defaultTime) {
return this.fixedTime(defaultTime).format("YYYY-MM-DD");
}
add(amount, unit, defaultTime) {
return new DateTime$2(this.fixedTime(defaultTime).clone().add(amount, unit), this._hasTimePart);
}
fixedTime(defaultTime) {
if (this._hasTimePart) {
return this.time;
}
if (defaultTime === undefined) {
return this.time;
}
return this.time.clone().add(defaultTime.minutes, "minutes");
}
get hasTimePart() {
return this._hasTimePart;
}
moment() {
return this.time;
}
isValid() {
return this.time.isValid();
}
clone(hasTimePart) {
const withTimePart = hasTimePart == null ? this._hasTimePart : hasTimePart;
const clone = this.time.clone();
return new DateTime$2(clone, withTimePart);
}
toString() {
if (this._hasTimePart) {
return this.format("YYYY-MM-DD HH:mm");
}
else {
return this.format("YYYY-MM-DD");
}
}
equals(time) {
return this._hasTimePart === time._hasTimePart
&& this.time.isSame(time.time);
}
}
class Time$1 {
constructor(hour, minute) {
this.hour = hour;
this.minute = minute;
}
static parse(text) {
if (!text.match(/^\d{1,2}:\d{1,2}$/)) {
throw `Unexpected format time(${text}). Time must be HH:mm.`;
}
const s = text.split(":");
if (s.length !== 2) {
throw `Unexpected format time(${text}). time must be HH:mm.`;
}
const hour = parseInt(s[0]);
const minute = parseInt(s[1]);
if (hour > 23 || hour < 0) {
throw `hour must be 0~23`;
}
if (minute > 59 || minute < 0) {
throw `minute must be 0~59`;
}
return new Time$1(hour, minute);
}
get minutes() {
return this.hour * 60 + this.minute;
}
toString() {
const pad = (n) => {
if (n < 10) {
return "0" + n;
}
return "" + n;
};
return `${pad(this.hour)}:${pad(this.minute)}`;
}
}
function add(amount, unit) {
return () => {
return new DateTime$2(moment(), true).add(amount, unit);
};
}
function inMinutes(minutes) {
return add(minutes, "minutes");
}
function inHours(hours) {
return add(hours, "hours");
}
function nextWeekday(weekday) {
return () => {
const today = moment();
if (today.isoWeekday() <= weekday) {
return new DateTime$2(today.isoWeekday(weekday), false);
}
else {
return new DateTime$2(today.add(1, "weeks").isoWeekday(weekday), false);
}
};
}
function tomorrow() {
return () => {
return new DateTime$2(moment().add(1, "days"), false);
};
}
function nextWeek() {
return () => {
return new DateTime$2(moment().add(1, "weeks"), false);
};
}
function nextMonth() {
return () => {
return new DateTime$2(moment().add(1, "months"), false);
};
}
function nextYear() {
return () => {
return new DateTime$2(moment().add(1, "years"), false);
};
}
class Later {
constructor(label, later) {
this.label = label;
this.later = later;
}
}
function parseLaters(laters) {
return laters.split("\n").map(l => parseLater(l.trim()));
}
function parseLater(later) {
later = later.toLowerCase();
if (later.startsWith("in")) {
const tokens = later.split(" ");
if (tokens.length !== 3) {
throw `Unsupported format. Should be 'In N (minutes|hours)'`;
}
const n = parseInt(tokens[1]);
switch (tokens[2]) {
case "minute":
case "minutes":
{
const unit = n == 1 ? "minute" : "minutes";
return new Later(`In ${n} ${unit}`, inMinutes(n));
}
case "hour":
case "hours":
{
const unit = n == 1 ? "hour" : "hours";
return new Later(`In ${n} ${unit}`, inHours(n));
}
}
}
else if (later.startsWith("next")) {
const weekday = later.substring(5);
switch (weekday) {
case "sunday":
return new Later("Next Sunday", nextWeekday(0));
case "monday":
return new Later("Next Monday", nextWeekday(1));
case "tuesday":
return new Later("Next Tuesday", nextWeekday(2));
case "wednesday":
return new Later("Next Wednesday", nextWeekday(3));
case "thursday":
return new Later("Next Thursday", nextWeekday(4));
case "friday":
return new Later("Next Friday", nextWeekday(5));
case "saturday":
return new Later("Next Saturday", nextWeekday(6));
case "day":
return new Later("Tomorrow", tomorrow());
case "week":
return new Later("Next week", nextWeek());
case "month":
return new Later("Next month", nextMonth());
case "year":
return new Later("Next year", nextYear());
default:
throw `Unsupported weekday: ${weekday}`;
}
}
else if (later === "tomorrow") {
return new Later("Tomorrow", tomorrow());
}
throw `Unsupported format: ${later}`;
}
[
new Later("In 30 minutes", inMinutes(30)),
new Later("In 1 hours", inHours(1)),
new Later("In 3 hours", inHours(3)),
new Later("Tomorrow", tomorrow()),
new Later("Next week", nextWeek()),
];
class DateTimeFormatter {
constructor() {
this.dateFormat = new ConstantReference("YYYY-MM-DD");
this.dateTimeFormat = new ConstantReference("YYYY-MM-DD HH:mm");
this.strict = new ConstantReference(false);
}
setTimeFormat(dateFormat, dateTimeFormat, strict) {
this.dateFormat = dateFormat;
this.dateTimeFormat = dateTimeFormat;
this.strict = strict;
}
parse(text) {
const parsed = this.doParse(text, true);
if (parsed != null) {
return parsed;
}
if (this.strict.value) {
return null;
}
return this.doParse(text, false);
}
doParse(text, strict) {
const dateTime = moment(text, this.dateTimeFormat.value, strict);
if (dateTime.isValid()) {
return new DateTime$2(dateTime, true);
}
const date = moment(text, this.dateFormat.value, strict);
if (date.isValid()) {
return new DateTime$2(date, false);
}
return null;
}
toString(time) {
if (time.hasTimePart) {
return time.format(this.dateTimeFormat.value);
}
else {
return time.format(this.dateFormat.value);
}
}
}
const DATE_TIME_FORMATTER = new DateTimeFormatter();
class Reminder$1 {
constructor(file, title, time, rowNumber, done) {
this.file = file;
this.title = title;
this.time = time;
this.rowNumber = rowNumber;
this.done = done;
// To avoid duplicate notification, set this flag true before notification and set false on notification done.
this.muteNotification = false;
}
key() {
return this.file + this.title + this.time.toString();
}
equals(reminder) {
return this.rowNumber === reminder.rowNumber
&& this.title === reminder.title
&& this.time.equals(reminder.time)
&& this.file === reminder.file;
}
getFileName() {
const p = this.file.split(/[\/\\]/);
return p[p.length - 1].replace(/^(.*?)(\..+)?$/, "$1");
}
static extractFileName(path) {
const p = path.split(/[\/\\]/);
return p[p.length - 1].replace(/^(.*?)(\..+)?$/, "$1");
}
}
class Reminders {
constructor(onChange) {
this.onChange = onChange;
this.fileToReminders = new Map();
this.reminders = [];
}
getExpiredReminders(defaultTime) {
const now = new Date().getTime();
const result = [];
for (let i = 0; i < this.reminders.length; i++) {
const reminder = this.reminders[i];
if (reminder.time.getTimeInMillis(defaultTime) <= now) {
result.push(reminder);
}
else {
break;
}
}
return result;
}
byDate(date) {
return this.reminders.filter(reminder => reminder.time.toYYYYMMDD() === date.toYYYYMMDD());
}
removeReminder(reminder) {
console.debug("Remove reminder: %o", reminder);
this.reminders.remove(reminder);
const file = this.fileToReminders.get(reminder.file);
if (file) {
file.remove(reminder);
if (file.length === 0) {
this.fileToReminders.delete(reminder.file);
}
}
this.onChange();
}
clear() {
this.fileToReminders.clear();
this.reminders = [];
this.onChange();
}
removeFile(filePath) {
if (this.fileToReminders.delete(filePath)) {
this.sortReminders();
return true;
}
return false;
}
replaceFile(filePath, reminders) {
// migrate notificationVisible property
const oldReminders = this.fileToReminders.get(filePath);
if (oldReminders) {
if (this.equals(oldReminders, reminders)) {
return false;
}
const reminderToNotificationVisible = new Map();
for (const reminder of oldReminders) {
reminderToNotificationVisible.set(reminder.key(), reminder.muteNotification);
}
for (const reminder of reminders) {
const visible = reminderToNotificationVisible.get(reminder.key());
reminderToNotificationVisible.set(reminder.key(), reminder.muteNotification);
if (visible !== undefined) {
reminder.muteNotification = visible;
}
}
}
// update
this.fileToReminders.set(filePath, reminders);
this.sortReminders();
return true;
}
equals(r1, r2) {
if (r1.length !== r2.length) {
return false;
}
this.sort(r1);
this.sort(r2);
for (const i in r1) {
const reminder1 = r1[i];
const reminder2 = r2[i];
if (reminder1 == null && reminder2 != null) {
return false;
}
if (reminder2 == null && reminder1 != null) {
return false;
}
if (reminder1 == null && reminder2 == null) {
continue;
}
if (!reminder1.equals(reminder2)) {
return false;
}
}
return true;
}
sortReminders() {
const reminders = [];
for (const r of this.fileToReminders.values()) {
reminders.push(...r);
}
this.sort(reminders);
this.reminders = reminders;
this.onChange();
}
sort(reminders) {
reminders.sort((a, b) => {
var _a, _b;
const d = a.time.getTimeInMillis((_a = this.reminderTime) === null || _a === void 0 ? void 0 : _a.value) -
b.time.getTimeInMillis((_b = this.reminderTime) === null || _b === void 0 ? void 0 : _b.value);
return d > 0 ? 1 : d < 0 ? -1 : 0;
});
}
}
function generateGroup(time, now, reminderTime) {
const days = DateTime$2.duration(now, time, "days", reminderTime);
if (days > 30) {
return new Group(time.toYYYYMMMM(reminderTime), (time) => time.format("MM/DD", reminderTime));
}
if (days >= 7) {
return new Group("Over 1 week", (time) => time.format("MM/DD", reminderTime));
}
if (time.toYYYYMMDD(reminderTime) === now.toYYYYMMDD(reminderTime)) {
const todaysGroup = new Group("Today", (time) => time.format("HH:mm", reminderTime));
todaysGroup.isToday = true;
return todaysGroup;
}
if (time.toYYYYMMDD(reminderTime) ===
now.add(1, "days", reminderTime).toYYYYMMDD()) {
return new Group("Tomorrow", (time) => time.format("HH:mm", reminderTime));
}
return new Group(time.format("M/DD (ddd)", reminderTime), (time) => time.format("HH:mm", reminderTime));
}
class Group {
constructor(name, timeToStringFunc) {
this.name = name;
this.timeToStringFunc = timeToStringFunc;
this.isToday = false;
this.isOverdue = false;
}
timeToString(time) {
return this.timeToStringFunc(time);
}
}
function groupReminders(sortedReminders, reminderTime) {
const now = DateTime$2.now();
const result = [];
let currentReminders = [];
const overdueReminders = [];
// Always shows today's group
let previousGroup = generateGroup(now, now, reminderTime);
for (let i = 0; i < sortedReminders.length; i++) {
const r = sortedReminders[i];
if (r.muteNotification) {
overdueReminders.push(r);
continue;
}
const group = generateGroup(r.time, now, reminderTime);
if (group.name !== previousGroup.name) {
if (currentReminders.length > 0 || previousGroup.isToday) {
result.push(new GroupedReminder(previousGroup, currentReminders));
}
currentReminders = [];
}
currentReminders.push(r);
previousGroup = group;
}
if (currentReminders.length > 0) {
result.push(new GroupedReminder(previousGroup, currentReminders));
}
if (overdueReminders.length > 0) {
const overdueGroup = new Group("Overdue", (time) => time.format("HH:mm", reminderTime));
overdueGroup.isOverdue = true;
result.splice(0, 0, new GroupedReminder(overdueGroup, overdueReminders));
console.log(overdueGroup);
console.log(result);
}
return result;
}
class GroupedReminder {
constructor(group, reminders) {
this.group = group;
this.reminders = reminders;
}
get name() {
return this.group.name;
}
get isOverdue() {
return this.group.isOverdue;
}
timeToString(time) {
return this.group.timeToString(time);
}
}
class ReminderFormatParameterKey {
constructor(key, defaultValue) {
this.key = key;
this.defaultValue = defaultValue;
}
}
ReminderFormatParameterKey.now = new ReminderFormatParameterKey("now", DateTime$2.now());
ReminderFormatParameterKey.useCustomEmojiForTasksPlugin = new ReminderFormatParameterKey("useCustomEmojiForTasksPlugin", false);
ReminderFormatParameterKey.linkDatesToDailyNotes = new ReminderFormatParameterKey("linkDatesToDailyNotes", false);
ReminderFormatParameterKey.strictDateFormat = new ReminderFormatParameterKey("strictDateFormat", false);
class ReminderFormatConfig {
constructor() {
this.parameters = new Map();
}
/**
* Set parameter for this format.
*
* @param key parameter key
*/
setParameter(key, value) {
this.parameters.set(key.key, () => value.value);
}
/**
* Set parameter for this format.
*
* @param key parameter key
*/
setParameterFunc(key, f) {
this.parameters.set(key.key, f);
}
setParameterValue(key, value) {
this.parameters.set(key.key, () => value);
}
getParameter(key) {
const value = this.parameters.get(key.key);
if (value == null) {
return key.defaultValue;
}
return value();
}
}
class TodoBasedReminderFormat {
constructor() {
this.config = new ReminderFormatConfig();
}
setConfig(config) {
this.config = config;
}
parse(doc) {
return doc.getTodos()
.map(todo => {
const parsed = this.parseValidReminder(todo);
if (parsed == null) {
return null;
}
const title = parsed.getTitle();
if (title == null) {
return null;
}
const time = parsed.getTime();
if (time == null) {
return null;
}
return new Reminder$1(doc.file, title, time, todo.lineIndex, todo.isChecked());
})
.filter((reminder) => reminder != null);
}
modify(doc, reminder, edit) {
return __awaiter(this, void 0, void 0, function* () {
const todo = doc.getTodo(reminder.rowNumber);
if (todo === null) {
console.warn("Not a todo: reminder=%o", reminder);
return false;
}
const parsed = this.parseValidReminder(todo);
if (parsed === null) {
return false;
}
if (!this.modifyReminder(doc, todo, parsed, edit)) {
return false;
}
todo.body = parsed.toMarkdown();
return true;
});
}
parseValidReminder(todo) {
const parsed = this.parseReminder(todo);
if (parsed === null) {
return null;
}
if (!this.isValidReminder(parsed)) {
return null;
}
return parsed;
}
isValidReminder(reminder) {
return reminder.getTime() !== null;
}
modifyReminder(doc, todo, parsed, edit) {
if (edit.rawTime !== undefined) {
if (!parsed.setRawTime(edit.rawTime)) {
console.warn("The reminder doesn't support raw time: parsed=%o", parsed);
return false;
}
}
else if (edit.time !== undefined) {
parsed.setTime(edit.time);
}
if (edit.checked !== undefined) {
todo.setChecked(edit.checked);
}
return true;
}
appendReminder(line, time) {
const todo = Todo.parse(0, line);
if (todo == null) {
return null;
}
let parsed = this.parseReminder(todo);
if (parsed != null) {
parsed.setTime(time);
}
else {
parsed = this.newReminder(todo.body, time);
parsed.setTime(time);
}
todo.body = parsed.toMarkdown();
return todo.toMarkdown();
}
isStrictDateFormat() {
return this.config.getParameter(ReminderFormatParameterKey.strictDateFormat);
}
}
class CompositeReminderFormat {
constructor() {
this.formats = [];
}
setConfig(config) {
this.config = config;
this.syncConfig();
}
parse(doc) {
const reminders = [];
for (const format of this.formats) {
const parsed = format.parse(doc);
if (parsed == null) {
continue;
}
reminders.push(...parsed);
}
return reminders;
}
modify(doc, reminder, edit) {
return __awaiter(this, void 0, void 0, function* () {
for (const format of this.formats) {
const modified = yield format.modify(doc, reminder, edit);
if (modified) {
return true;
}
}
return false;
});
}
resetFormat(formats) {
this.formats = formats;
this.syncConfig();
}
syncConfig() {
if (this.config == null) {
return;
}
this.formats.forEach(f => f.setConfig(this.config));
}
appendReminder(line, time) {
if (this.formats[0] == null) {
return null;
}
return this.formats[0].appendReminder(line, time);
}
}
class DefaultReminderModel {
constructor(linkDatesToDailyNotes, title1, time, title2) {
this.linkDatesToDailyNotes = linkDatesToDailyNotes;
this.title1 = title1;
this.time = time;
this.title2 = title2;
}
static parse(line, linkDatesToDailyNotes) {
if (linkDatesToDailyNotes == null) {
linkDatesToDailyNotes = false;
}
const result = DefaultReminderModel.regexp.exec(line);
if (result == null) {
return null;
}
const title1 = result.groups['title1'];
let time = result.groups['time'];
if (time == null) {
return null;
}
const title2 = result.groups['title2'];
if (linkDatesToDailyNotes) {
time = time.replace("[[", "");
time = time.replace("]]", "");
}
return new DefaultReminderModel(linkDatesToDailyNotes, title1, time, title2);
}
getTitle() {
return `${this.title1.trim()} ${this.title2.trim()}`.trim();
}
getTime() {
return DATE_TIME_FORMATTER.parse(this.time);
}
setTime(time) {
this.time = DATE_TIME_FORMATTER.toString(time);
}
setRawTime(rawTime) {
this.time = rawTime;
return true;
}
toMarkdown() {
let result = `${this.title1}(@${this.time})${this.title2}`;
if (!this.linkDatesToDailyNotes) {
return result;
}
let time = DATE_TIME_FORMATTER.parse(this.time);
if (!time) {
return result;
}
const date = DATE_TIME_FORMATTER.toString(time.clone(false));
return result.replace(date, `[[${date}]]`);
}
}
DefaultReminderModel.regexp = /^(?<title1>.*?)\(@(?<time>.+?)\)(?<title2>.*)$/;
class DefaultReminderFormat extends TodoBasedReminderFormat {
parseReminder(todo) {
return DefaultReminderModel.parse(todo.body, this.linkDatesToDailyNotes());
}
newReminder(title, time) {
return new DefaultReminderModel(this.linkDatesToDailyNotes(), title, time.toString(), "");
}
linkDatesToDailyNotes() {
return this.config.getParameter(ReminderFormatParameterKey.linkDatesToDailyNotes);
}
}
DefaultReminderFormat.instance = new DefaultReminderFormat();
function escapeRegExpChars(text) {
return text.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
}
const kanbanSetting = new (class KanbanSetting {
get dateTrigger() {
return this.get("date-trigger", "@");
}
get dateFormat() {
return this.get("date-format", "YYYY-MM-DD");
}
get timeTrigger() {
return this.get("time-trigger", "@@");
}
get timeFormat() {
return this.get("time-format", "HH:mm");
}
get linkDateToDailyNote() {
return this.get("link-date-to-daily-note", false);
}
get(key, defaultValue) {
var _a, _b, _c;
if (!window) {
return defaultValue;
}
const plugins = (_c = (_b = (_a = window) === null || _a === void 0 ? void 0 : _a.app) === null || _b === void 0 ? void 0 : _b.plugins) === null || _c === void 0 ? void 0 : _c.plugins;
if (!plugins) {
return defaultValue;
}
const plugin = plugins["obsidian-kanban"];
if (!plugin) {
return defaultValue;
}
const settings = plugin.settings;
if (!settings) {
return defaultValue;
}
const value = plugin.settings[key];
if (value === null || value === undefined) {
return defaultValue;
}
return value;
}
});
class KanbanDateTimeFormat {
constructor(setting) {
this.setting = setting;
let dateRegExpStr;
if (setting.linkDateToDailyNote) {
dateRegExpStr = `${escapeRegExpChars(this.setting.dateTrigger)}\\[\\[(?<date>.+?)\\]\\]`;
}
else {
dateRegExpStr = `${escapeRegExpChars(this.setting.dateTrigger)}\\{(?<date>.+?)\\}`;
}
const timeRegExpStr = `${escapeRegExpChars(this.setting.timeTrigger)}\\{(?<time>.+?)\\}`;
this.dateRegExp = new RegExp(dateRegExpStr);
this.timeRegExp = new RegExp(timeRegExpStr);
}
format(time) {
let datePart;
if (this.setting.linkDateToDailyNote) {
datePart = `${this.setting.dateTrigger}[[${time.format(this.setting.dateFormat)}]]`;
}
else {
datePart = `${this.setting.dateTrigger}{${time.format(this.setting.dateFormat)}}`;
}
if (!time.hasTimePart) {
return datePart;
}
return `${datePart} ${this.setting.timeTrigger}{${time.format(this.setting.timeFormat)}}`;
}
split(text, strictDateFormat) {
const originalText = text;
let title;
let date;
let time;
const dateMatch = this.dateRegExp.exec(text);
if (dateMatch) {
date = dateMatch.groups["date"];
text = text.replace(this.dateRegExp, "");
}
else {
return { title: originalText };
}
const timeMatch = this.timeRegExp.exec(text);
if (timeMatch) {
time = timeMatch.groups["time"];
text = text.replace(this.timeRegExp, "");
}
title = text.trim();
let parsedTime;
const strict = strictDateFormat !== null && strictDateFormat !== void 0 ? strictDateFormat : true;
if (time) {
parsedTime = new DateTime$2(moment(`${date} ${time}`, `${this.setting.dateFormat} ${this.setting.timeFormat}`, strict), true);
}
else {
parsedTime = new DateTime$2(moment(date, this.setting.dateFormat, strict), false);
}
if (parsedTime.isValid()) {
return { title, time: parsedTime };
}
return { title: originalText };
}
}
KanbanDateTimeFormat.instance = new KanbanDateTimeFormat(kanbanSetting);
class KanbanReminderModel {
constructor(title, time) {
this.title = title;
this.time = time;
}
static parse(line, strictDateFormat) {
const splitted = KanbanDateTimeFormat.instance.split(line, strictDateFormat);
if (splitted.time == null) {
return null;
}
return new KanbanReminderModel(splitted.title, splitted.time);
}
getTitle() {
return this.title.trim();
}
getTime() {
if (this.time) {
return this.time;
}
return null;
}
setTime(time) {
this.time = time;
}
setRawTime() {
return false;
}
toMarkdown() {
return `${this.title.trim()} ${KanbanDateTimeFormat.instance.format(this.time)}`;
}
}
class KanbanReminderFormat extends TodoBasedReminderFormat {
parseReminder(todo) {
return KanbanReminderModel.parse(todo.body, this.isStrictDateFormat());
}
newReminder(title, time) {
const parsed = new KanbanReminderModel(title, time);
parsed.setTime(time);
return parsed;
}
}
KanbanReminderFormat.instance = new KanbanReminderFormat();
// =============================================================================
// Weekday
// =============================================================================
var ALL_WEEKDAYS = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'];
var Weekday = /** @class */ (function () {
function Weekday(weekday, n) {
if (n === 0)
throw new Error("Can't create weekday with n == 0");
this.weekday = weekday;
this.n = n;
}
Weekday.fromStr = function (str) {
return new Weekday(ALL_WEEKDAYS.indexOf(str));
};
// __call__ - Cannot call the object directly, do it through
// e.g. RRule.TH.nth(-1) instead,
Weekday.prototype.nth = function (n) {
return this.n === n ? this : new Weekday(this.weekday, n);
};
// __eq__
Weekday.prototype.equals = function (other) {
return this.weekday === other.weekday && this.n === other.n;
};
// __repr__
Weekday.prototype.toString = function () {
var s = ALL_WEEKDAYS[this.weekday];
if (this.n)
s = (this.n > 0 ? '+' : '') + String(this.n) + s;
return s;
};
Weekday.prototype.getJsWeekday = function () {
return this.weekday === 6 ? 0 : this.weekday + 1;
};
return Weekday;
}());
// =============================================================================
var isPresent = function (value) {
return value !== null && value !== undefined;
};
var isNumber$1 = function (value) {
return typeof value === 'number';
};
var isWeekdayStr = function (value) {
return ALL_WEEKDAYS.indexOf(value) >= 0;
};
var isArray = Array.isArray;
/**
* Simplified version of python's range()
*/
var range = function (start, end) {
if (end === void 0) { end = start; }
if (arguments.length === 1) {
end = start;
start = 0;
}
var rang = [];
for (var i = start; i < end; i++)
rang.push(i);
return rang;
};
var repeat = function (value, times) {
var i = 0;
var array = [];
if (isArray(value)) {
for (; i < times; i++)
array[i] = [].concat(value);
}
else {
for (; i < times; i++)
array[i] = value;
}
return array;
};
var toArray = function (item) {
if (isArray(item)) {
return item;
}
return [item];
};
function padStart$1(item, targetLength, padString) {
if (padString === void 0) { padString = ' '; }
var str = String(item);
targetLength = targetLength >> 0;
if (str.length > targetLength) {
return String(str);
}
targetLength = targetLength - str.length;
if (targetLength > padString.length) {
padString += repeat(padString, targetLength / padString.length);
}
return padString.slice(0, targetLength) + String(str);
}
/**
* Python like split
*/
var split = function (str, sep, num) {
var splits = str.split(sep);
return num
? splits.slice(0, num).concat([splits.slice(num).join(sep)])
: splits;
};
/**
* closure/goog/math/math.js:modulo
* Copyright 2006 The Closure Library Authors.
* The % operator in JavaScript returns the remainder of a / b, but differs from
* some other languages in that the result will have the same sign as the
* dividend. For example, -1 % 8 == -1, whereas in some other languages
* (such as Python) the result would be 7. This function emulates the more
* correct modulo behavior, which is useful for certain applications such as
* calculating an offset index in a circular list.
*
* @param {number} a The dividend.
* @param {number} b The divisor.
* @return {number} a % b where the result is between 0 and b (either 0 <= x < b
* or b < x <= 0, depending on the sign of b).
*/
var pymod = function (a, b) {
var r = a % b;
// If r and b differ in sign, add b to wrap the result to the correct sign.
return r * b < 0 ? r + b : r;
};
/**
* @see: <http://docs.python.org/library/functions.html#divmod>
*/
var divmod = function (a, b) {
return { div: Math.floor(a / b), mod: pymod(a, b) };
};
var empty = function (obj) {
return !isPresent(obj) || obj.length === 0;
};
/**
* Python-like boolean
* @return {Boolean} value of an object/primitive, taking into account
* the fact that in Python an empty list's/tuple's
* boolean value is False, whereas in JS it's true
*/
var notEmpty = function (obj) {
return !empty(obj);
};
/**
* Return true if a value is in an array
*/
var includes = function (arr, val) {
return notEmpty(arr) && arr.indexOf(val) !== -1;
};
/**
* General date-related utilities.
* Also handles several incompatibilities between JavaScript and Python
*
*/
var dateutil;
(function (dateutil) {
dateutil.MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
/**
* Number of milliseconds of one day
*/
dateutil.ONE_DAY = 1000 * 60 * 60 * 24;
/**
* @see: <http://docs.python.org/library/datetime.html#datetime.MAXYEAR>
*/
dateutil.MAXYEAR = 9999;
/**
* Python uses 1-Jan-1 as the base for calculating ordinals but we don't
* want to confuse the JS engine with milliseconds > Number.MAX_NUMBER,
* therefore we use 1-Jan-1970 instead
*/
dateutil.ORDINAL_BASE = new Date(Date.UTC(1970, 0, 1));
/**
* Python: MO-SU: 0 - 6
* JS: SU-SAT 0 - 6
*/
dateutil.PY_WEEKDAYS = [6, 0, 1, 2, 3, 4, 5];
/**
* py_date.timetuple()[7]
*/
dateutil.getYearDay = function (date) {
var dateNoTime = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
return (Math.ceil((dateNoTime.valueOf() -
new Date(date.getUTCFullYear(), 0, 1).valueOf()) /
dateutil.ONE_DAY) + 1);
};
dateutil.isLeapYear = function (year) {
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
};
dateutil.isDate = function (value) {
return value instanceof Date;
};
dateutil.isValidDate = function (value) {
return dateutil.isDate(value) && !isNaN(value.getTime());
};
/**
* @return {Number} the date's timezone offset in ms
*/
dateutil.tzOffset = function (date) {
return date.getTimezoneOffset() * 60 * 1000;
};
/**
* @see: <http://www.mcfedries.com/JavaScript/DaysBetween.asp>
*/
dateutil.daysBetween = function (date1, date2) {
// The number of milliseconds in one day
// Convert both dates to milliseconds
var date1ms = date1.getTime() - dateutil.tzOffset(date1);
var date2ms = date2.getTime() - dateutil.tzOffset(date2);
// Calculate the difference in milliseconds
var differencems = date1ms - date2ms;
// Convert back to days and return
return Math.round(differencems / dateutil.ONE_DAY);
};
/**
* @see: <http://docs.python.org/library/datetime.html#datetime.date.toordinal>
*/
dateutil.toOrdinal = function (date) {
return dateutil.daysBetween(date, dateutil.ORDINAL_BASE);
};
/**
* @see - <http://docs.python.org/library/datetime.html#datetime.date.fromordinal>
*/
dateutil.fromOrdinal = function (ordinal) {
return new Date(dateutil.ORDINAL_BASE.getTime() + ordinal * dateutil.ONE_DAY);
};
dateutil.getMonthDays = function (date) {
var month = date.getUTCMonth();
return month === 1 && dateutil.isLeapYear(date.getUTCFullYear())
? 29
: dateutil.MONTH_DAYS[month];
};
/**
* @return {Number} python-like weekday
*/
dateutil.getWeekday = function (date) {
return dateutil.PY_WEEKDAYS[date.getUTCDay()];
};
/**
* @see: <http://docs.python.org/library/calendar.html#calendar.monthrange>
*/
dateutil.monthRange = function (year, month) {
var date = new Date(Date.UTC(year, month, 1));
return [dateutil.getWeekday(date), dateutil.getMonthDays(date)];
};
/**
* @see: <http://docs.python.org/library/datetime.html#datetime.datetime.combine>
*/
dateutil.combine = function (date, time) {
time = time || date;
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), time.getHours(), time.getMinutes(), time.getSeconds(), time.getMilliseconds()));
};
dateutil.clone = function (date) {
var dolly = new Date(date.getTime());
return dolly;
};
dateutil.cloneDates = function (dates) {
var clones = [];
for (var i = 0; i < dates.length; i++) {
clones.push(dateutil.clone(dates[i]));
}
return clones;
};
/**
* Sorts an array of Date or dateutil.Time objects
*/
dateutil.sort = function (dates) {
dates.sort(function (a, b) {
return a.getTime() - b.getTime();
});
};
dateutil.timeToUntilString = function (time, utc) {
if (utc === void 0) { utc = true; }
var date = new Date(time);
return [
padStart$1(date.getUTCFullYear().toString(), 4, '0'),
padStart$1(date.getUTCMonth() + 1, 2, '0'),
padStart$1(date.getUTCDate(), 2, '0'),
'T',
padStart$1(date.getUTCHours(), 2, '0'),
padStart$1(date.getUTCMinutes(), 2, '0'),
padStart$1(date.getUTCSeconds(), 2, '0'),
utc ? 'Z' : ''
].join('');
};
dateutil.untilStringToDate = function (until) {
var re = /^(\d{4})(\d{2})(\d{2})(T(\d{2})(\d{2})(\d{2})Z?)?$/;
var bits = re.exec(until);
if (!bits)
throw new Error("Invalid UNTIL value: " + until);
return new Date(Date.UTC(parseInt(bits[1], 10), parseInt(bits[2], 10) - 1, parseInt(bits[3], 10), parseInt(bits[5], 10) || 0, parseInt(bits[6], 10) || 0, parseInt(bits[7], 10) || 0));
};
})(dateutil || (dateutil = {}));
var dateutil$1 = dateutil;
/**
* This class helps us to emulate python's generators, sorta.
*/
var IterResult = /** @class */ (function () {
function IterResult(method, args) {
this.minDate = null;
this.maxDate = null;
this._result = [];
this.total = 0;
this.method = method;
this.args = args;
if (method === 'between') {
this.maxDate = args.inc
? args.before
: new Date(args.before.getTime() - 1);
this.minDate = args.inc ? args.after : new Date(args.after.getTime() + 1);
}
else if (method === 'before') {
this.maxDate = args.inc ? args.dt : new Date(args.dt.getTime() - 1);
}
else if (method === 'after') {
this.minDate = args.inc ? args.dt : new Date(args.dt.getTime() + 1);
}
}
/**
* Possibly adds a date into the result.
*
* @param {Date} date - the date isn't necessarly added to the result
* list (if it is too late/too early)
* @return {Boolean} true if it makes sense to continue the iteration
* false if we're done.
*/
IterResult.prototype.accept = function (date) {
++this.total;
var tooEarly = this.minDate && date < this.minDate;
var tooLate = this.maxDate && date > this.maxDate;
if (this.method === 'between') {
if (tooEarly)
return true;
if (tooLate)
return false;
}
else if (this.method === 'before') {
if (tooLate)
return false;
}
else if (this.method === 'after') {
if (tooEarly)
return true;
this.add(date);
return false;
}
return this.add(date);
};
/**
*
* @param {Date} date that is part of the result.
* @return {Boolean} whether we are interested in more values.
*/
IterResult.prototype.add = function (date) {
this._result.push(date);
return true;
};
/**
* 'before' and 'after' return only one date, whereas 'all'
* and 'between' an array.
* @return {Date,Array?}
*/
IterResult.prototype.getValue = function () {
var res = this._result;
switch (this.method) {
case 'all':
case 'between':
return res;
case 'before':
case 'after':
default:
return (res.length ? res[res.length - 1] : null);
}
};
IterResult.prototype.clone = function () {
return new IterResult(this.method, this.args);
};
return IterResult;
}());
/**
* IterResult subclass that calls a callback function on each add,
* and stops iterating when the callback returns false.
*/
var CallbackIterResult = /** @class */ (function (_super) {
__extends(CallbackIterResult, _super);
function CallbackIterResult(method, args, iterator) {
var _this = _super.call(this, method, args) || this;
_this.iterator = iterator;
return _this;
}
CallbackIterResult.prototype.add = function (date) {
if (this.iterator(date, this._result.length)) {
this._result.push(date);
return true;
}
return false;
};
return CallbackIterResult;
}(IterResult));
// =============================================================================
// i18n
// =============================================================================
var ENGLISH = {
dayNames: [
'Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday'
],
monthNames: [
'January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October',
'November', 'December'
],
tokens: {
'SKIP': /^[ \r\n\t]+|^\.$/,
'number': /^[1-9][0-9]*/,
'numberAsText': /^(one|two|three)/i,
'every': /^every/i,
'day(s)': /^days?/i,
'weekday(s)': /^weekdays?/i,
'week(s)': /^weeks?/i,
'hour(s)': /^hours?/i,
'minute(s)': /^minutes?/i,
'month(s)': /^months?/i,
'year(s)': /^years?/i,
'on': /^(on|in)/i,
'at': /^(at)/i,
'the': /^the/i,
'first': /^first/i,
'second': /^second/i,
'third': /^third/i,
'nth': /^([1-9][0-9]*)(\.|th|nd|rd|st)/i,
'last': /^last/i,
'for': /^for/i,
'time(s)': /^times?/i,
'until': /^(un)?til/i,
'monday': /^mo(n(day)?)?/i,
'tuesday': /^tu(e(s(day)?)?)?/i,
'wednesday': /^we(d(n(esday)?)?)?/i,
'thursday': /^th(u(r(sday)?)?)?/i,
'friday': /^fr(i(day)?)?/i,
'saturday': /^sa(t(urday)?)?/i,
'sunday': /^su(n(day)?)?/i,
'january': /^jan(uary)?/i,
'february': /^feb(ruary)?/i,
'march': /^mar(ch)?/i,
'april': /^apr(il)?/i,
'may': /^may/i,
'june': /^june?/i,
'july': /^july?/i,
'august': /^aug(ust)?/i,
'september': /^sep(t(ember)?)?/i,
'october': /^oct(ober)?/i,
'november': /^nov(ember)?/i,
'december': /^dec(ember)?/i,
'comma': /^(,\s*|(and|or)\s*)+/i
}
};
// =============================================================================
// Helper functions
// =============================================================================
/**
* Return true if a value is in an array
*/
var contains = function (arr, val) {
return arr.indexOf(val) !== -1;
};
var defaultGetText = function (id) { return id.toString(); };
var defaultDateFormatter = function (year, month, day) { return month + " " + day + ", " + year; };
/**
*
* @param {RRule} rrule
* Optional:
* @param {Function} gettext function
* @param {Object} language definition
* @constructor
*/
var ToText = /** @class */ (function () {
function ToText(rrule, gettext, language, dateFormatter) {
if (gettext === void 0) { gettext = defaultGetText; }
if (language === void 0) { language = ENGLISH; }
if (dateFormatter === void 0) { dateFormatter = defaultDateFormatter; }
this.text = [];
this.language = language || ENGLISH;
this.gettext = gettext;
this.dateFormatter = dateFormatter;
this.rrule = rrule;
this.options = rrule.options;
this.origOptions = rrule.origOptions;
if (this.origOptions.bymonthday) {
var bymonthday = [].concat(this.options.bymonthday);
var bynmonthday = [].concat(this.options.bynmonthday);
bymonthday.sort(function (a, b) { return a - b; });
bynmonthday.sort(function (a, b) { return b - a; });
// 1, 2, 3, .., -5, -4, -3, ..
this.bymonthday = bymonthday.concat(bynmonthday);
if (!this.bymonthday.length)
this.bymonthday = null;
}
if (isPresent(this.origOptions.byweekday)) {
var byweekday = !isArray(this.origOptions.byweekday)
? [this.origOptions.byweekday]
: this.origOptions.byweekday;
var days = String(byweekday);
this.byweekday = {
allWeeks: byweekday.filter(function (weekday) {
return !weekday.n;
}),
someWeeks: byweekday.filter(function (weekday) {
return Boolean(weekday.n);
}),
isWeekdays: days.indexOf('MO') !== -1 &&
days.indexOf('TU') !== -1 &&
days.indexOf('WE') !== -1 &&
days.indexOf('TH') !== -1 &&
days.indexOf('FR') !== -1 &&
days.indexOf('SA') === -1 &&
days.indexOf('SU') === -1,
isEveryDay: days.indexOf('MO') !== -1 &&
days.indexOf('TU') !== -1 &&
days.indexOf('WE') !== -1 &&
days.indexOf('TH') !== -1 &&
days.indexOf('FR') !== -1 &&
days.indexOf('SA') !== -1 &&
days.indexOf('SU') !== -1
};
var sortWeekDays = function (a, b) {
return a.weekday - b.weekday;
};
this.byweekday.allWeeks.sort(sortWeekDays);
this.byweekday.someWeeks.sort(sortWeekDays);
if (!this.byweekday.allWeeks.length)
this.byweekday.allWeeks = null;
if (!this.byweekday.someWeeks.length)
this.byweekday.someWeeks = null;
}
else {
this.byweekday = null;
}
}
/**
* Test whether the rrule can be fully converted to text.
* @param {RRule} rrule
* @return {Boolean}
*/
ToText.isFullyConvertible = function (rrule) {
var canConvert = true;
if (!(rrule.options.freq in ToText.IMPLEMENTED))
return false;
if (rrule.origOptions.until && rrule.origOptions.count)
return false;
for (var key in rrule.origOptions) {
if (contains(['dtstart', 'wkst', 'freq'], key))
return true;
if (!contains(ToText.IMPLEMENTED[rrule.options.freq], key))
return false;
}
return canConvert;
};
ToText.prototype.isFullyConvertible = function () {
return ToText.isFullyConvertible(this.rrule);
};
/**
* Perform the conversion. Only some of the frequencies are supported.
* If some of the rrule's options aren't supported, they'll
* be omitted from the output an "(~ approximate)" will be appended.
* @return {*}
*/
ToText.prototype.toString = function () {
var gettext = this.gettext;
if (!(this.options.freq in ToText.IMPLEMENTED)) {
return gettext('RRule error: Unable to fully convert this rrule to text');
}
this.text = [gettext('every')];
// @ts-ignore
this[RRule.FREQUENCIES[this.options.freq]]();
if (this.options.until) {
this.add(gettext('until'));
var until = this.options.until;
this.add(this.dateFormatter(until.getUTCFullYear(), this.language.monthNames[until.getUTCMonth()], until.getUTCDate()));
}
else if (this.options.count) {
this.add(gettext('for'))
.add(this.options.count.toString())
.add(this.plural(this.options.count) ? gettext('times') : gettext('time'));
}
if (!this.isFullyConvertible())
this.add(gettext('(~ approximate)'));
return this.text.join('');
};
ToText.prototype.HOURLY = function () {
var gettext = this.gettext;
if (this.options.interval !== 1)
this.add(this.options.interval.toString());
this.add(this.plural(this.options.interval) ? gettext('hours') : gettext('hour'));
};
ToText.prototype.MINUTELY = function () {
var gettext = this.gettext;
if (this.options.interval !== 1)
this.add(this.options.interval.toString());
this.add(this.plural(this.options.interval)
? gettext('minutes')
: gettext('minute'));
};
ToText.prototype.DAILY = function () {
var gettext = this.gettext;
if (this.options.interval !== 1)
this.add(this.options.interval.toString());
if (this.byweekday && this.byweekday.isWeekdays) {
this.add(this.plural(this.options.interval)
? gettext('weekdays')
: gettext('weekday'));
}
else {
this.add(this.plural(this.options.interval) ? gettext('days') : gettext('day'));
}
if (this.origOptions.bymonth) {
this.add(gettext('in'));
this._bymonth();
}
if (this.bymonthday) {
this._bymonthday();
}
else if (this.byweekday) {
this._byweekday();
}
else if (this.origOptions.byhour) {
this._byhour();
}
};
ToText.prototype.WEEKLY = function () {
var gettext = this.gettext;
if (this.options.interval !== 1) {
this.add(this.options.interval.toString()).add(this.plural(this.options.interval) ? gettext('weeks') : gettext('week'));
}
if (this.byweekday && this.byweekday.isWeekdays) {
if (this.options.interval === 1) {
this.add(this.plural(this.options.interval)
? gettext('weekdays')
: gettext('weekday'));
}
else {
this.add(gettext('on')).add(gettext('weekdays'));
}
}
else if (this.byweekday && this.byweekday.isEveryDay) {
this.add(this.plural(this.options.interval) ? gettext('days') : gettext('day'));
}
else {
if (this.options.interval === 1)
this.add(gettext('week'));
if (this.origOptions.bymonth) {
this.add(gettext('in'));
this._bymonth();
}
if (this.bymonthday) {
this._bymonthday();
}
else if (this.byweekday) {
this._byweekday();
}
}
};
ToText.prototype.MONTHLY = function () {
var gettext = this.gettext;
if (this.origOptions.bymonth) {
if (this.options.interval !== 1) {
this.add(this.options.interval.toString()).add(gettext('months'));
if (this.plural(this.options.interval))
this.add(gettext('in'));
}
this._bymonth();
}
else {
if (this.options.interval !== 1)
this.add(this.options.interval.toString());
this.add(this.plural(this.options.interval)
? gettext('months')
: gettext('month'));
}
if (this.bymonthday) {
this._bymonthday();
}
else if (this.byweekday && this.byweekday.isWeekdays) {
this.add(gettext('on')).add(gettext('weekdays'));
}
else if (this.byweekday) {
this._byweekday();
}
};
ToText.prototype.YEARLY = function () {
var gettext = this.gettext;
if (this.origOptions.bymonth) {
if (this.options.interval !== 1) {
this.add(this.options.interval.toString());
this.add(gettext('years'));
}
this._bymonth();
}
else {
if (this.options.interval !== 1)
this.add(this.options.interval.toString());
this.add(this.plural(this.options.interval) ? gettext('years') : gettext('year'));
}
if (this.bymonthday) {
this._bymonthday();
}
else if (this.byweekday) {
this._byweekday();
}
if (this.options.byyearday) {
this.add(gettext('on the'))
.add(this.list(this.options.byyearday, this.nth, gettext('and')))
.add(gettext('day'));
}
if (this.options.byweekno) {
this.add(gettext('in'))
.add(this.plural(this.options.byweekno.length)
? gettext('weeks')
: gettext('week'))
.add(this.list(this.options.byweekno, undefined, gettext('and')));
}
};
ToText.prototype._bymonthday = function () {
var gettext = this.gettext;
if (this.byweekday && this.byweekday.allWeeks) {
this.add(gettext('on'))
.add(this.list(this.byweekday.allWeeks, this.weekdaytext, gettext('or')))
.add(gettext('the'))
.add(this.list(this.bymonthday, this.nth, gettext('or')));
}
else {
this.add(gettext('on the')).add(this.list(this.bymonthday, this.nth, gettext('and')));
}
// this.add(gettext('DAY'))
};
ToText.prototype._byweekday = function () {
var gettext = this.gettext;
if (this.byweekday.allWeeks && !this.byweekday.isWeekdays) {
this.add(gettext('on')).add(this.list(this.byweekday.allWeeks, this.weekdaytext));
}
if (this.byweekday.someWeeks) {
if (this.byweekday.allWeeks)
this.add(gettext('and'));
this.add(gettext('on the')).add(this.list(this.byweekday.someWeeks, this.weekdaytext, gettext('and')));
}
};
ToText.prototype._byhour = function () {
var gettext = this.gettext;
this.add(gettext('at')).add(this.list(this.origOptions.byhour, undefined, gettext('and')));
};
ToText.prototype._bymonth = function () {
this.add(this.list(this.options.bymonth, this.monthtext, this.gettext('and')));
};
ToText.prototype.nth = function (n) {
n = parseInt(n.toString(), 10);
var nth;
var npos;
var gettext = this.gettext;
if (n === -1)
return gettext('last');
npos = Math.abs(n);
switch (npos) {
case 1:
case 21:
case 31:
nth = npos + gettext('st');
break;
case 2:
case 22:
nth = npos + gettext('nd');
break;
case 3:
case 23:
nth = npos + gettext('rd');
break;
default:
nth = npos + gettext('th');
}
return n < 0 ? nth + ' ' + gettext('last') : nth;
};
ToText.prototype.monthtext = function (m) {
return this.language.monthNames[m - 1];
};
ToText.prototype.weekdaytext = function (wday) {
var weekday = isNumber$1(wday) ? (wday + 1) % 7 : wday.getJsWeekday();
return ((wday.n ? this.nth(wday.n) + ' ' : '') + this.language.dayNames[weekday]);
};
ToText.prototype.plural = function (n) {
return n % 100 !== 1;
};
ToText.prototype.add = function (s) {
this.text.push(' ');
this.text.push(s);
return this;
};
ToText.prototype.list = function (arr, callback, finalDelim, delim) {
if (delim === void 0) { delim = ','; }
if (!isArray(arr)) {
arr = [arr];
}
var delimJoin = function (array, delimiter, finalDelimiter) {
var list = '';
for (var i = 0; i < array.length; i++) {
if (i !== 0) {
if (i === array.length - 1) {
list += ' ' + finalDelimiter + ' ';
}
else {
list += delimiter + ' ';
}
}
list += array[i];
}
return list;
};
callback =
callback ||
function (o) {
return o.toString();
};
var self = this;
var realCallback = function (arg) {
return callback && callback.call(self, arg);
};
if (finalDelim) {
return delimJoin(arr.map(realCallback), delim, finalDelim);
}
else {
return arr.map(realCallback).join(delim + ' ');
}
};
return ToText;
}());
// =============================================================================
// Parser
// =============================================================================
var Parser = /** @class */ (function () {
function Parser(rules) {
this.done = true;
this.rules = rules;
}
Parser.prototype.start = function (text) {
this.text = text;
this.done = false;
return this.nextSymbol();
};
Parser.prototype.isDone = function () {
return this.done && this.symbol === null;
};
Parser.prototype.nextSymbol = function () {
var best;
var bestSymbol;
var p = this;
this.symbol = null;
this.value = null;
do {
if (this.done)
return false;
var rule = void 0;
best = null;
for (var name_1 in this.rules) {
rule = this.rules[name_1];
var match = rule.exec(p.text);
if (match) {
if (best === null || match[0].length > best[0].length) {
best = match;
bestSymbol = name_1;
}
}
}
if (best != null) {
this.text = this.text.substr(best[0].length);
if (this.text === '')
this.done = true;
}
if (best == null) {
this.done = true;
this.symbol = null;
this.value = null;
return;
}
// @ts-ignore
} while (bestSymbol === 'SKIP');
// @ts-ignore
this.symbol = bestSymbol;
this.value = best;
return true;
};
Parser.prototype.accept = function (name) {
if (this.symbol === name) {
if (this.value) {
var v = this.value;
this.nextSymbol();
return v;
}
this.nextSymbol();
return true;
}
return false;
};
Parser.prototype.acceptNumber = function () {
return this.accept('number');
};
Parser.prototype.expect = function (name) {
if (this.accept(name))
return true;
throw new Error('expected ' + name + ' but found ' + this.symbol);
};
return Parser;
}());
function parseText(text, language) {
if (language === void 0) { language = ENGLISH; }
var options = {};
var ttr = new Parser(language.tokens);
if (!ttr.start(text))
return null;
S();
return options;
function S() {
// every [n]
ttr.expect('every');
var n = ttr.acceptNumber();
if (n)
options.interval = parseInt(n[0], 10);
if (ttr.isDone())
throw new Error('Unexpected end');
switch (ttr.symbol) {
case 'day(s)':
options.freq = RRule.DAILY;
if (ttr.nextSymbol()) {
AT();
F();
}
break;
// FIXME Note: every 2 weekdays != every two weeks on weekdays.
// DAILY on weekdays is not a valid rule
case 'weekday(s)':
options.freq = RRule.WEEKLY;
options.byweekday = [
RRule.MO,
RRule.TU,
RRule.WE,
RRule.TH,
RRule.FR
];
ttr.nextSymbol();
F();
break;
case 'week(s)':
options.freq = RRule.WEEKLY;
if (ttr.nextSymbol()) {
ON();
F();
}
break;
case 'hour(s)':
options.freq = RRule.HOURLY;
if (ttr.nextSymbol()) {
ON();
F();
}
break;
case 'minute(s)':
options.freq = RRule.MINUTELY;
if (ttr.nextSymbol()) {
ON();
F();
}
break;
case 'month(s)':
options.freq = RRule.MONTHLY;
if (ttr.nextSymbol()) {
ON();
F();
}
break;
case 'year(s)':
options.freq = RRule.YEARLY;
if (ttr.nextSymbol()) {
ON();
F();
}
break;
case 'monday':
case 'tuesday':
case 'wednesday':
case 'thursday':
case 'friday':
case 'saturday':
case 'sunday':
options.freq = RRule.WEEKLY;
var key = ttr.symbol.substr(0, 2).toUpperCase();
options.byweekday = [RRule[key]];
if (!ttr.nextSymbol())
return;
// TODO check for duplicates
while (ttr.accept('comma')) {
if (ttr.isDone())
throw new Error('Unexpected end');
var wkd = decodeWKD();
if (!wkd) {
throw new Error('Unexpected symbol ' + ttr.symbol + ', expected weekday');
}
// @ts-ignore
options.byweekday.push(RRule[wkd]);
ttr.nextSymbol();
}
MDAYs();
F();
break;
case 'january':
case 'february':
case 'march':
case 'april':
case 'may':
case 'june':
case 'july':
case 'august':
case 'september':
case 'october':
case 'november':
case 'december':
options.freq = RRule.YEARLY;
options.bymonth = [decodeM()];
if (!ttr.nextSymbol())
return;
// TODO check for duplicates
while (ttr.accept('comma')) {
if (ttr.isDone())
throw new Error('Unexpected end');
var m = decodeM();
if (!m) {
throw new Error('Unexpected symbol ' + ttr.symbol + ', expected month');
}
options.bymonth.push(m);
ttr.nextSymbol();
}
ON();
F();
break;
default:
throw new Error('Unknown symbol');
}
}
function ON() {
var on = ttr.accept('on');
var the = ttr.accept('the');
if (!(on || the))
return;
do {
var nth = decodeNTH();
var wkd = decodeWKD();
var m = decodeM();
// nth <weekday> | <weekday>
if (nth) {
// ttr.nextSymbol()
if (wkd) {
ttr.nextSymbol();
if (!options.byweekday)
options.byweekday = [];
// @ts-ignore
options.byweekday.push(RRule[wkd].nth(nth));
}
else {
if (!options.bymonthday)
options.bymonthday = [];
// @ts-ignore
options.bymonthday.push(nth);
ttr.accept('day(s)');
}
// <weekday>
}
else if (wkd) {
ttr.nextSymbol();
if (!options.byweekday)
options.byweekday = [];
// @ts-ignore
options.byweekday.push(RRule[wkd]);
}
else if (ttr.symbol === 'weekday(s)') {
ttr.nextSymbol();
if (!options.byweekday) {
options.byweekday = [
RRule.MO,
RRule.TU,
RRule.WE,
RRule.TH,
RRule.FR
];
}
}
else if (ttr.symbol === 'week(s)') {
ttr.nextSymbol();
var n = ttr.acceptNumber();
if (!n) {
throw new Error('Unexpected symbol ' + ttr.symbol + ', expected week number');
}
options.byweekno = [parseInt(n[0], 10)];
while (ttr.accept('comma')) {
n = ttr.acceptNumber();
if (!n) {
throw new Error('Unexpected symbol ' + ttr.symbol + '; expected monthday');
}
options.byweekno.push(parseInt(n[0], 10));
}
}
else if (m) {
ttr.nextSymbol();
if (!options.bymonth)
options.bymonth = [];
// @ts-ignore
options.bymonth.push(m);
}
else {
return;
}
} while (ttr.accept('comma') || ttr.accept('the') || ttr.accept('on'));
}
function AT() {
var at = ttr.accept('at');
if (!at)
return;
do {
var n = ttr.acceptNumber();
if (!n) {
throw new Error('Unexpected symbol ' + ttr.symbol + ', expected hour');
}
options.byhour = [parseInt(n[0], 10)];
while (ttr.accept('comma')) {
n = ttr.acceptNumber();
if (!n) {
throw new Error('Unexpected symbol ' + ttr.symbol + '; expected hour');
}
options.byhour.push(parseInt(n[0], 10));
}
} while (ttr.accept('comma') || ttr.accept('at'));
}
function decodeM() {
switch (ttr.symbol) {
case 'january':
return 1;
case 'february':
return 2;
case 'march':
return 3;
case 'april':
return 4;
case 'may':
return 5;
case 'june':
return 6;
case 'july':
return 7;
case 'august':
return 8;
case 'september':
return 9;
case 'october':
return 10;
case 'november':
return 11;
case 'december':
return 12;
default:
return false;
}
}
function decodeWKD() {
switch (ttr.symbol) {
case 'monday':
case 'tuesday':
case 'wednesday':
case 'thursday':
case 'friday':
case 'saturday':
case 'sunday':
return ttr.symbol.substr(0, 2).toUpperCase();
default:
return false;
}
}
function decodeNTH() {
switch (ttr.symbol) {
case 'last':
ttr.nextSymbol();
return -1;
case 'first':
ttr.nextSymbol();
return 1;
case 'second':
ttr.nextSymbol();
return ttr.accept('last') ? -2 : 2;
case 'third':
ttr.nextSymbol();
return ttr.accept('last') ? -3 : 3;
case 'nth':
var v = parseInt(ttr.value[1], 10);
if (v < -366 || v > 366)
throw new Error('Nth out of range: ' + v);
ttr.nextSymbol();
return ttr.accept('last') ? -v : v;
default:
return false;
}
}
function MDAYs() {
ttr.accept('on');
ttr.accept('the');
var nth = decodeNTH();
if (!nth)
return;
options.bymonthday = [nth];
ttr.nextSymbol();
while (ttr.accept('comma')) {
nth = decodeNTH();
if (!nth) {
throw new Error('Unexpected symbol ' + ttr.symbol + '; expected monthday');
}
options.bymonthday.push(nth);
ttr.nextSymbol();
}
}
function F() {
if (ttr.symbol === 'until') {
var date = Date.parse(ttr.text);
if (!date)
throw new Error('Cannot parse until date:' + ttr.text);
options.until = new Date(date);
}
else if (ttr.accept('for')) {
options.count = parseInt(ttr.value[0], 10);
ttr.expect('number');
// ttr.expect('times')
}
}
}
var Frequency;
(function (Frequency) {
Frequency[Frequency["YEARLY"] = 0] = "YEARLY";
Frequency[Frequency["MONTHLY"] = 1] = "MONTHLY";
Frequency[Frequency["WEEKLY"] = 2] = "WEEKLY";
Frequency[Frequency["DAILY"] = 3] = "DAILY";
Frequency[Frequency["HOURLY"] = 4] = "HOURLY";
Frequency[Frequency["MINUTELY"] = 5] = "MINUTELY";
Frequency[Frequency["SECONDLY"] = 6] = "SECONDLY";
})(Frequency || (Frequency = {}));
function freqIsDailyOrGreater(freq) {
return freq < Frequency.HOURLY;
}
/*!
* rrule.js - Library for working with recurrence rules for calendar dates.
* https://github.com/jakubroztocil/rrule
*
* Copyright 2010, Jakub Roztocil and Lars Schoning
* Licenced under the BSD licence.
* https://github.com/jakubroztocil/rrule/blob/master/LICENCE
*
*/
/**
*
* Implementation of RRule.fromText() and RRule::toText().
*
*
* On the client side, this file needs to be included
* when those functions are used.
*
*/
// =============================================================================
// fromText
// =============================================================================
/**
* Will be able to convert some of the below described rules from
* text format to a rule object.
*
*
* RULES
*
* Every ([n])
* day(s)
* | [weekday], ..., (and) [weekday]
* | weekday(s)
* | week(s)
* | month(s)
* | [month], ..., (and) [month]
* | year(s)
*
*
* Plus 0, 1, or multiple of these:
*
* on [weekday], ..., (or) [weekday] the [monthday], [monthday], ... (or) [monthday]
*
* on [weekday], ..., (and) [weekday]
*
* on the [monthday], [monthday], ... (and) [monthday] (day of the month)
*
* on the [nth-weekday], ..., (and) [nth-weekday] (of the month/year)
*
*
* Plus 0 or 1 of these:
*
* for [n] time(s)
*
* until [date]
*
* Plus (.)
*
*
* Definitely no supported for parsing:
*
* (for year):
* in week(s) [n], ..., (and) [n]
*
* on the [yearday], ..., (and) [n] day of the year
* on day [yearday], ..., (and) [n]
*
*
* NON-TERMINALS
*
* [n]: 1, 2 ..., one, two, three ..
* [month]: January, February, March, April, May, ... December
* [weekday]: Monday, ... Sunday
* [nth-weekday]: first [weekday], 2nd [weekday], ... last [weekday], ...
* [monthday]: first, 1., 2., 1st, 2nd, second, ... 31st, last day, 2nd last day, ..
* [date]:
* [month] (0-31(,) ([year])),
* (the) 0-31.(1-12.([year])),
* (the) 0-31/(1-12/([year])),
* [weekday]
*
* [year]: 0000, 0001, ... 01, 02, ..
*
* Definitely not supported for parsing:
*
* [yearday]: first, 1., 2., 1st, 2nd, second, ... 366th, last day, 2nd last day, ..
*
* @param {String} text
* @return {Object, Boolean} the rule, or null.
*/
var fromText = function (text, language) {
if (language === void 0) { language = ENGLISH; }
return new RRule(parseText(text, language) || undefined);
};
var common = [
'count',
'until',
'interval',
'byweekday',
'bymonthday',
'bymonth'
];
ToText.IMPLEMENTED = [];
ToText.IMPLEMENTED[Frequency.HOURLY] = common;
ToText.IMPLEMENTED[Frequency.MINUTELY] = common;
ToText.IMPLEMENTED[Frequency.DAILY] = ['byhour'].concat(common);
ToText.IMPLEMENTED[Frequency.WEEKLY] = common;
ToText.IMPLEMENTED[Frequency.MONTHLY] = common;
ToText.IMPLEMENTED[Frequency.YEARLY] = ['byweekno', 'byyearday'].concat(common);
// =============================================================================
// Export
// =============================================================================
var toText = function (rrule, gettext, language, dateFormatter) {
return new ToText(rrule, gettext, language, dateFormatter).toString();
};
var isFullyConvertible = ToText.isFullyConvertible;
var Time = /** @class */ (function () {
function Time(hour, minute, second, millisecond) {
this.hour = hour;
this.minute = minute;
this.second = second;
this.millisecond = millisecond || 0;
}
Time.prototype.getHours = function () {
return this.hour;
};
Time.prototype.getMinutes = function () {
return this.minute;
};
Time.prototype.getSeconds = function () {
return this.second;
};
Time.prototype.getMilliseconds = function () {
return this.millisecond;
};
Time.prototype.getTime = function () {
return ((this.hour * 60 * 60 + this.minute * 60 + this.second) * 1000 +
this.millisecond);
};
return Time;
}());
var DateTime$1 = /** @class */ (function (_super) {
__extends(DateTime, _super);
function DateTime(year, month, day, hour, minute, second, millisecond) {
var _this = _super.call(this, hour, minute, second, millisecond) || this;
_this.year = year;
_this.month = month;
_this.day = day;
return _this;
}
DateTime.fromDate = function (date) {
return new this(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.valueOf() % 1000);
};
DateTime.prototype.getWeekday = function () {
return dateutil.getWeekday(new Date(this.getTime()));
};
DateTime.prototype.getTime = function () {
return new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, this.millisecond)).getTime();
};
DateTime.prototype.getDay = function () {
return this.day;
};
DateTime.prototype.getMonth = function () {
return this.month;
};
DateTime.prototype.getYear = function () {
return this.year;
};
DateTime.prototype.addYears = function (years) {
this.year += years;
};
DateTime.prototype.addMonths = function (months) {
this.month += months;
if (this.month > 12) {
var yearDiv = Math.floor(this.month / 12);
var monthMod = pymod(this.month, 12);
this.month = monthMod;
this.year += yearDiv;
if (this.month === 0) {
this.month = 12;
--this.year;
}
}
};
DateTime.prototype.addWeekly = function (days, wkst) {
if (wkst > this.getWeekday()) {
this.day += -(this.getWeekday() + 1 + (6 - wkst)) + days * 7;
}
else {
this.day += -(this.getWeekday() - wkst) + days * 7;
}
this.fixDay();
};
DateTime.prototype.addDaily = function (days) {
this.day += days;
this.fixDay();
};
DateTime.prototype.addHours = function (hours, filtered, byhour) {
if (filtered) {
// Jump to one iteration before next day
this.hour += Math.floor((23 - this.hour) / hours) * hours;
}
while (true) {
this.hour += hours;
var _a = divmod(this.hour, 24), dayDiv = _a.div, hourMod = _a.mod;
if (dayDiv) {
this.hour = hourMod;
this.addDaily(dayDiv);
}
if (empty(byhour) || includes(byhour, this.hour))
break;
}
};
DateTime.prototype.addMinutes = function (minutes, filtered, byhour, byminute) {
if (filtered) {
// Jump to one iteration before next day
this.minute +=
Math.floor((1439 - (this.hour * 60 + this.minute)) / minutes) * minutes;
}
while (true) {
this.minute += minutes;
var _a = divmod(this.minute, 60), hourDiv = _a.div, minuteMod = _a.mod;
if (hourDiv) {
this.minute = minuteMod;
this.addHours(hourDiv, false, byhour);
}
if ((empty(byhour) || includes(byhour, this.hour)) &&
(empty(byminute) || includes(byminute, this.minute))) {
break;
}
}
};
DateTime.prototype.addSeconds = function (seconds, filtered, byhour, byminute, bysecond) {
if (filtered) {
// Jump to one iteration before next day
this.second +=
Math.floor((86399 - (this.hour * 3600 + this.minute * 60 + this.second)) / seconds) * seconds;
}
while (true) {
this.second += seconds;
var _a = divmod(this.second, 60), minuteDiv = _a.div, secondMod = _a.mod;
if (minuteDiv) {
this.second = secondMod;
this.addMinutes(minuteDiv, false, byhour, byminute);
}
if ((empty(byhour) || includes(byhour, this.hour)) &&
(empty(byminute) || includes(byminute, this.minute)) &&
(empty(bysecond) || includes(bysecond, this.second))) {
break;
}
}
};
DateTime.prototype.fixDay = function () {
if (this.day <= 28) {
return;
}
var daysinmonth = dateutil.monthRange(this.year, this.month - 1)[1];
if (this.day <= daysinmonth) {
return;
}
while (this.day > daysinmonth) {
this.day -= daysinmonth;
++this.month;
if (this.month === 13) {
this.month = 1;
++this.year;
if (this.year > dateutil.MAXYEAR) {
return;
}
}
daysinmonth = dateutil.monthRange(this.year, this.month - 1)[1];
}
};
DateTime.prototype.add = function (options, filtered) {
var freq = options.freq, interval = options.interval, wkst = options.wkst, byhour = options.byhour, byminute = options.byminute, bysecond = options.bysecond;
switch (freq) {
case Frequency.YEARLY: return this.addYears(interval);
case Frequency.MONTHLY: return this.addMonths(interval);
case Frequency.WEEKLY: return this.addWeekly(interval, wkst);
case Frequency.DAILY: return this.addDaily(interval);
case Frequency.HOURLY: return this.addHours(interval, filtered, byhour);
case Frequency.MINUTELY: return this.addMinutes(interval, filtered, byhour, byminute);
case Frequency.SECONDLY: return this.addSeconds(interval, filtered, byhour, byminute, bysecond);
}
};
return DateTime;
}(Time));
function initializeOptions$1(options) {
var invalid = [];
var keys = Object.keys(options);
// Shallow copy for options and origOptions and check for invalid
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
var key = keys_1[_i];
if (!includes(defaultKeys, key))
invalid.push(key);
if (dateutil$1.isDate(options[key]) && !dateutil$1.isValidDate(options[key]))
invalid.push(key);
}
if (invalid.length) {
throw new Error('Invalid options: ' + invalid.join(', '));
}
return __assign({}, options);
}
function parseOptions(options) {
var opts = __assign(__assign({}, DEFAULT_OPTIONS$1), initializeOptions$1(options));
if (isPresent(opts.byeaster))
opts.freq = RRule.YEARLY;
if (!(isPresent(opts.freq) && RRule.FREQUENCIES[opts.freq])) {
throw new Error("Invalid frequency: " + opts.freq + " " + options.freq);
}
if (!opts.dtstart)
opts.dtstart = new Date(new Date().setMilliseconds(0));
if (!isPresent(opts.wkst)) {
opts.wkst = RRule.MO.weekday;
}
else if (isNumber$1(opts.wkst)) ;
else {
opts.wkst = opts.wkst.weekday;
}
if (isPresent(opts.bysetpos)) {
if (isNumber$1(opts.bysetpos))
opts.bysetpos = [opts.bysetpos];
for (var i = 0; i < opts.bysetpos.length; i++) {
var v = opts.bysetpos[i];
if (v === 0 || !(v >= -366 && v <= 366)) {
throw new Error('bysetpos must be between 1 and 366,' + ' or between -366 and -1');
}
}
}
if (!(Boolean(opts.byweekno) ||
notEmpty(opts.byweekno) ||
notEmpty(opts.byyearday) ||
Boolean(opts.bymonthday) ||
notEmpty(opts.bymonthday) ||
isPresent(opts.byweekday) ||
isPresent(opts.byeaster))) {
switch (opts.freq) {
case RRule.YEARLY:
if (!opts.bymonth)
opts.bymonth = opts.dtstart.getUTCMonth() + 1;
opts.bymonthday = opts.dtstart.getUTCDate();
break;
case RRule.MONTHLY:
opts.bymonthday = opts.dtstart.getUTCDate();
break;
case RRule.WEEKLY:
opts.byweekday = [dateutil$1.getWeekday(opts.dtstart)];
break;
}
}
// bymonth
if (isPresent(opts.bymonth) && !isArray(opts.bymonth)) {
opts.bymonth = [opts.bymonth];
}
// byyearday
if (isPresent(opts.byyearday) &&
!isArray(opts.byyearday) &&
isNumber$1(opts.byyearday)) {
opts.byyearday = [opts.byyearday];
}
// bymonthday
if (!isPresent(opts.bymonthday)) {
opts.bymonthday = [];
opts.bynmonthday = [];
}
else if (isArray(opts.bymonthday)) {
var bymonthday = [];
var bynmonthday = [];
for (var i = 0; i < opts.bymonthday.length; i++) {
var v = opts.bymonthday[i];
if (v > 0) {
bymonthday.push(v);
}
else if (v < 0) {
bynmonthday.push(v);
}
}
opts.bymonthday = bymonthday;
opts.bynmonthday = bynmonthday;
}
else if (opts.bymonthday < 0) {
opts.bynmonthday = [opts.bymonthday];
opts.bymonthday = [];
}
else {
opts.bynmonthday = [];
opts.bymonthday = [opts.bymonthday];
}
// byweekno
if (isPresent(opts.byweekno) && !isArray(opts.byweekno)) {
opts.byweekno = [opts.byweekno];
}
// byweekday / bynweekday
if (!isPresent(opts.byweekday)) {
opts.bynweekday = null;
}
else if (isNumber$1(opts.byweekday)) {
opts.byweekday = [opts.byweekday];
opts.bynweekday = null;
}
else if (isWeekdayStr(opts.byweekday)) {
opts.byweekday = [Weekday.fromStr(opts.byweekday).weekday];
opts.bynweekday = null;
}
else if (opts.byweekday instanceof Weekday) {
if (!opts.byweekday.n || opts.freq > RRule.MONTHLY) {
opts.byweekday = [opts.byweekday.weekday];
opts.bynweekday = null;
}
else {
opts.bynweekday = [[opts.byweekday.weekday, opts.byweekday.n]];
opts.byweekday = null;
}
}
else {
var byweekday = [];
var bynweekday = [];
for (var i = 0; i < opts.byweekday.length; i++) {
var wday = opts.byweekday[i];
if (isNumber$1(wday)) {
byweekday.push(wday);
continue;
}
else if (isWeekdayStr(wday)) {
byweekday.push(Weekday.fromStr(wday).weekday);
continue;
}
if (!wday.n || opts.freq > RRule.MONTHLY) {
byweekday.push(wday.weekday);
}
else {
bynweekday.push([wday.weekday, wday.n]);
}
}
opts.byweekday = notEmpty(byweekday) ? byweekday : null;
opts.bynweekday = notEmpty(bynweekday) ? bynweekday : null;
}
// byhour
if (!isPresent(opts.byhour)) {
opts.byhour =
opts.freq < RRule.HOURLY ? [opts.dtstart.getUTCHours()] : null;
}
else if (isNumber$1(opts.byhour)) {
opts.byhour = [opts.byhour];
}
// byminute
if (!isPresent(opts.byminute)) {
opts.byminute =
opts.freq < RRule.MINUTELY ? [opts.dtstart.getUTCMinutes()] : null;
}
else if (isNumber$1(opts.byminute)) {
opts.byminute = [opts.byminute];
}
// bysecond
if (!isPresent(opts.bysecond)) {
opts.bysecond =
opts.freq < RRule.SECONDLY ? [opts.dtstart.getUTCSeconds()] : null;
}
else if (isNumber$1(opts.bysecond)) {
opts.bysecond = [opts.bysecond];
}
return { parsedOptions: opts };
}
function buildTimeset(opts) {
var millisecondModulo = opts.dtstart.getTime() % 1000;
if (!freqIsDailyOrGreater(opts.freq)) {
return [];
}
var timeset = [];
opts.byhour.forEach(function (hour) {
opts.byminute.forEach(function (minute) {
opts.bysecond.forEach(function (second) {
timeset.push(new Time(hour, minute, second, millisecondModulo));
});
});
});
return timeset;
}
function parseString(rfcString) {
var options = rfcString.split('\n').map(parseLine).filter(function (x) { return x !== null; });
return __assign(__assign({}, options[0]), options[1]);
}
function parseDtstart(line) {
var options = {};
var dtstartWithZone = /DTSTART(?:;TZID=([^:=]+?))?(?::|=)([^;\s]+)/i.exec(line);
if (!dtstartWithZone) {
return options;
}
dtstartWithZone[0]; var tzid = dtstartWithZone[1], dtstart = dtstartWithZone[2];
if (tzid) {
options.tzid = tzid;
}
options.dtstart = dateutil$1.untilStringToDate(dtstart);
return options;
}
function parseLine(rfcString) {
rfcString = rfcString.replace(/^\s+|\s+$/, '');
if (!rfcString.length)
return null;
var header = /^([A-Z]+?)[:;]/.exec(rfcString.toUpperCase());
if (!header) {
return parseRrule(rfcString);
}
header[0]; var key = header[1];
switch (key.toUpperCase()) {
case 'RRULE':
case 'EXRULE':
return parseRrule(rfcString);
case 'DTSTART':
return parseDtstart(rfcString);
default:
throw new Error("Unsupported RFC prop " + key + " in " + rfcString);
}
}
function parseRrule(line) {
var strippedLine = line.replace(/^RRULE:/i, '');
var options = parseDtstart(strippedLine);
var attrs = line.replace(/^(?:RRULE|EXRULE):/i, '').split(';');
attrs.forEach(function (attr) {
var _a = attr.split('='), key = _a[0], value = _a[1];
switch (key.toUpperCase()) {
case 'FREQ':
options.freq = Frequency[value.toUpperCase()];
break;
case 'WKST':
options.wkst = Days[value.toUpperCase()];
break;
case 'COUNT':
case 'INTERVAL':
case 'BYSETPOS':
case 'BYMONTH':
case 'BYMONTHDAY':
case 'BYYEARDAY':
case 'BYWEEKNO':
case 'BYHOUR':
case 'BYMINUTE':
case 'BYSECOND':
var num = parseNumber(value);
var optionKey = key.toLowerCase();
// @ts-ignore
options[optionKey] = num;
break;
case 'BYWEEKDAY':
case 'BYDAY':
options.byweekday = parseWeekday(value);
break;
case 'DTSTART':
case 'TZID':
// for backwards compatibility
var dtstart = parseDtstart(line);
options.tzid = dtstart.tzid;
options.dtstart = dtstart.dtstart;
break;
case 'UNTIL':
options.until = dateutil$1.untilStringToDate(value);
break;
case 'BYEASTER':
options.byeaster = Number(value);
break;
default:
throw new Error("Unknown RRULE property '" + key + "'");
}
});
return options;
}
function parseNumber(value) {
if (value.indexOf(',') !== -1) {
var values = value.split(',');
return values.map(parseIndividualNumber);
}
return parseIndividualNumber(value);
}
function parseIndividualNumber(value) {
if (/^[+-]?\d+$/.test(value)) {
return Number(value);
}
return value;
}
function parseWeekday(value) {
var days = value.split(',');
return days.map(function (day) {
if (day.length === 2) {
// MO, TU, ...
return Days[day]; // wday instanceof Weekday
}
// -1MO, +3FR, 1SO, 13TU ...
var parts = day.match(/^([+-]?\d{1,2})([A-Z]{2})$/);
var n = Number(parts[1]);
var wdaypart = parts[2];
var wday = Days[wdaypart].weekday;
return new Weekday(wday, n);
});
}
// these aren't really private, but nor are they really useful to document
/**
* @private
*/
class LuxonError extends Error {}
/**
* @private
*/
class InvalidDateTimeError extends LuxonError {
constructor(reason) {
super(`Invalid DateTime: ${reason.toMessage()}`);
}
}
/**
* @private
*/
class InvalidIntervalError extends LuxonError {
constructor(reason) {
super(`Invalid Interval: ${reason.toMessage()}`);
}
}
/**
* @private
*/
class InvalidDurationError extends LuxonError {
constructor(reason) {
super(`Invalid Duration: ${reason.toMessage()}`);
}
}
/**
* @private
*/
class ConflictingSpecificationError extends LuxonError {}
/**
* @private
*/
class InvalidUnitError extends LuxonError {
constructor(unit) {
super(`Invalid unit ${unit}`);
}
}
/**
* @private
*/
class InvalidArgumentError extends LuxonError {}
/**
* @private
*/
class ZoneIsAbstractError extends LuxonError {
constructor() {
super("Zone is an abstract class");
}
}
/**
* @private
*/
const n = "numeric",
s = "short",
l = "long";
const DATE_SHORT = {
year: n,
month: n,
day: n
};
const DATE_MED = {
year: n,
month: s,
day: n
};
const DATE_MED_WITH_WEEKDAY = {
year: n,
month: s,
day: n,
weekday: s
};
const DATE_FULL = {
year: n,
month: l,
day: n
};
const DATE_HUGE = {
year: n,
month: l,
day: n,
weekday: l
};
const TIME_SIMPLE = {
hour: n,
minute: n
};
const TIME_WITH_SECONDS = {
hour: n,
minute: n,
second: n
};
const TIME_WITH_SHORT_OFFSET = {
hour: n,
minute: n,
second: n,
timeZoneName: s
};
const TIME_WITH_LONG_OFFSET = {
hour: n,
minute: n,
second: n,
timeZoneName: l
};
const TIME_24_SIMPLE = {
hour: n,
minute: n,
hour12: false
};
/**
* {@link toLocaleString}; format like '09:30:23', always 24-hour.
*/
const TIME_24_WITH_SECONDS = {
hour: n,
minute: n,
second: n,
hour12: false
};
/**
* {@link toLocaleString}; format like '09:30:23 EDT', always 24-hour.
*/
const TIME_24_WITH_SHORT_OFFSET = {
hour: n,
minute: n,
second: n,
hour12: false,
timeZoneName: s
};
/**
* {@link toLocaleString}; format like '09:30:23 Eastern Daylight Time', always 24-hour.
*/
const TIME_24_WITH_LONG_OFFSET = {
hour: n,
minute: n,
second: n,
hour12: false,
timeZoneName: l
};
/**
* {@link toLocaleString}; format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is.
*/
const DATETIME_SHORT = {
year: n,
month: n,
day: n,
hour: n,
minute: n
};
/**
* {@link toLocaleString}; format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is.
*/
const DATETIME_SHORT_WITH_SECONDS = {
year: n,
month: n,
day: n,
hour: n,
minute: n,
second: n
};
const DATETIME_MED = {
year: n,
month: s,
day: n,
hour: n,
minute: n
};
const DATETIME_MED_WITH_SECONDS = {
year: n,
month: s,
day: n,
hour: n,
minute: n,
second: n
};
const DATETIME_MED_WITH_WEEKDAY = {
year: n,
month: s,
day: n,
weekday: s,
hour: n,
minute: n
};
const DATETIME_FULL = {
year: n,
month: l,
day: n,
hour: n,
minute: n,
timeZoneName: s
};
const DATETIME_FULL_WITH_SECONDS = {
year: n,
month: l,
day: n,
hour: n,
minute: n,
second: n,
timeZoneName: s
};
const DATETIME_HUGE = {
year: n,
month: l,
day: n,
weekday: l,
hour: n,
minute: n,
timeZoneName: l
};
const DATETIME_HUGE_WITH_SECONDS = {
year: n,
month: l,
day: n,
weekday: l,
hour: n,
minute: n,
second: n,
timeZoneName: l
};
/*
This is just a junk drawer, containing anything used across multiple classes.
Because Luxon is small(ish), this should stay small and we won't worry about splitting
it up into, say, parsingUtil.js and basicUtil.js and so on. But they are divided up by feature area.
*/
/**
* @private
*/
// TYPES
function isUndefined(o) {
return typeof o === "undefined";
}
function isNumber(o) {
return typeof o === "number";
}
function isInteger(o) {
return typeof o === "number" && o % 1 === 0;
}
function isString(o) {
return typeof o === "string";
}
function isDate(o) {
return Object.prototype.toString.call(o) === "[object Date]";
} // CAPABILITIES
function hasIntl() {
try {
return typeof Intl !== "undefined" && Intl.DateTimeFormat;
} catch (e) {
return false;
}
}
function hasFormatToParts() {
return !isUndefined(Intl.DateTimeFormat.prototype.formatToParts);
}
function hasRelative() {
try {
return typeof Intl !== "undefined" && !!Intl.RelativeTimeFormat;
} catch (e) {
return false;
}
} // OBJECTS AND ARRAYS
function maybeArray(thing) {
return Array.isArray(thing) ? thing : [thing];
}
function bestBy(arr, by, compare) {
if (arr.length === 0) {
return undefined;
}
return arr.reduce((best, next) => {
const pair = [by(next), next];
if (!best) {
return pair;
} else if (compare(best[0], pair[0]) === best[0]) {
return best;
} else {
return pair;
}
}, null)[1];
}
function pick(obj, keys) {
return keys.reduce((a, k) => {
a[k] = obj[k];
return a;
}, {});
}
function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
} // NUMBERS AND STRINGS
function integerBetween(thing, bottom, top) {
return isInteger(thing) && thing >= bottom && thing <= top;
} // x % n but takes the sign of n instead of x
function floorMod(x, n) {
return x - n * Math.floor(x / n);
}
function padStart(input, n = 2) {
const minus = input < 0 ? "-" : "";
const target = minus ? input * -1 : input;
let result;
if (target.toString().length < n) {
result = ("0".repeat(n) + target).slice(-n);
} else {
result = target.toString();
}
return `${minus}${result}`;
}
function parseInteger(string) {
if (isUndefined(string) || string === null || string === "") {
return undefined;
} else {
return parseInt(string, 10);
}
}
function parseMillis(fraction) {
// Return undefined (instead of 0) in these cases, where fraction is not set
if (isUndefined(fraction) || fraction === null || fraction === "") {
return undefined;
} else {
const f = parseFloat("0." + fraction) * 1000;
return Math.floor(f);
}
}
function roundTo(number, digits, towardZero = false) {
const factor = Math.pow(10, digits),
rounder = towardZero ? Math.trunc : Math.round;
return rounder(number * factor) / factor;
} // DATE BASICS
function isLeapYear(year) {
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
}
function daysInYear(year) {
return isLeapYear(year) ? 366 : 365;
}
function daysInMonth(year, month) {
const modMonth = floorMod(month - 1, 12) + 1,
modYear = year + (month - modMonth) / 12;
if (modMonth === 2) {
return isLeapYear(modYear) ? 29 : 28;
} else {
return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][modMonth - 1];
}
} // covert a calendar object to a local timestamp (epoch, but with the offset baked in)
function objToLocalTS(obj) {
let d = Date.UTC(obj.year, obj.month - 1, obj.day, obj.hour, obj.minute, obj.second, obj.millisecond); // for legacy reasons, years between 0 and 99 are interpreted as 19XX; revert that
if (obj.year < 100 && obj.year >= 0) {
d = new Date(d);
d.setUTCFullYear(d.getUTCFullYear() - 1900);
}
return +d;
}
function weeksInWeekYear(weekYear) {
const p1 = (weekYear + Math.floor(weekYear / 4) - Math.floor(weekYear / 100) + Math.floor(weekYear / 400)) % 7,
last = weekYear - 1,
p2 = (last + Math.floor(last / 4) - Math.floor(last / 100) + Math.floor(last / 400)) % 7;
return p1 === 4 || p2 === 3 ? 53 : 52;
}
function untruncateYear(year) {
if (year > 99) {
return year;
} else return year > 60 ? 1900 + year : 2000 + year;
} // PARSING
function parseZoneInfo(ts, offsetFormat, locale, timeZone = null) {
const date = new Date(ts),
intlOpts = {
hour12: false,
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit"
};
if (timeZone) {
intlOpts.timeZone = timeZone;
}
const modified = Object.assign({
timeZoneName: offsetFormat
}, intlOpts),
intl = hasIntl();
if (intl && hasFormatToParts()) {
const parsed = new Intl.DateTimeFormat(locale, modified).formatToParts(date).find(m => m.type.toLowerCase() === "timezonename");
return parsed ? parsed.value : null;
} else if (intl) {
// this probably doesn't work for all locales
const without = new Intl.DateTimeFormat(locale, intlOpts).format(date),
included = new Intl.DateTimeFormat(locale, modified).format(date),
diffed = included.substring(without.length),
trimmed = diffed.replace(/^[, \u200e]+/, "");
return trimmed;
} else {
return null;
}
} // signedOffset('-5', '30') -> -330
function signedOffset(offHourStr, offMinuteStr) {
let offHour = parseInt(offHourStr, 10); // don't || this because we want to preserve -0
if (Number.isNaN(offHour)) {
offHour = 0;
}
const offMin = parseInt(offMinuteStr, 10) || 0,
offMinSigned = offHour < 0 || Object.is(offHour, -0) ? -offMin : offMin;
return offHour * 60 + offMinSigned;
} // COERCION
function asNumber(value) {
const numericValue = Number(value);
if (typeof value === "boolean" || value === "" || Number.isNaN(numericValue)) throw new InvalidArgumentError(`Invalid unit value ${value}`);
return numericValue;
}
function normalizeObject(obj, normalizer, nonUnitKeys) {
const normalized = {};
for (const u in obj) {
if (hasOwnProperty(obj, u)) {
if (nonUnitKeys.indexOf(u) >= 0) continue;
const v = obj[u];
if (v === undefined || v === null) continue;
normalized[normalizer(u)] = asNumber(v);
}
}
return normalized;
}
function formatOffset(offset, format) {
const hours = Math.trunc(Math.abs(offset / 60)),
minutes = Math.trunc(Math.abs(offset % 60)),
sign = offset >= 0 ? "+" : "-";
switch (format) {
case "short":
return `${sign}${padStart(hours, 2)}:${padStart(minutes, 2)}`;
case "narrow":
return `${sign}${hours}${minutes > 0 ? `:${minutes}` : ""}`;
case "techie":
return `${sign}${padStart(hours, 2)}${padStart(minutes, 2)}`;
default:
throw new RangeError(`Value format ${format} is out of range for property format`);
}
}
function timeObject(obj) {
return pick(obj, ["hour", "minute", "second", "millisecond"]);
}
const ianaRegex = /[A-Za-z_+-]{1,256}(:?\/[A-Za-z_+-]{1,256}(\/[A-Za-z_+-]{1,256})?)?/;
function stringify(obj) {
return JSON.stringify(obj, Object.keys(obj).sort());
}
/**
* @private
*/
const monthsLong = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const monthsShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const monthsNarrow = ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"];
function months(length) {
switch (length) {
case "narrow":
return [...monthsNarrow];
case "short":
return [...monthsShort];
case "long":
return [...monthsLong];
case "numeric":
return ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
case "2-digit":
return ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
default:
return null;
}
}
const weekdaysLong = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
const weekdaysShort = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
const weekdaysNarrow = ["M", "T", "W", "T", "F", "S", "S"];
function weekdays(length) {
switch (length) {
case "narrow":
return [...weekdaysNarrow];
case "short":
return [...weekdaysShort];
case "long":
return [...weekdaysLong];
case "numeric":
return ["1", "2", "3", "4", "5", "6", "7"];
default:
return null;
}
}
const meridiems = ["AM", "PM"];
const erasLong = ["Before Christ", "Anno Domini"];
const erasShort = ["BC", "AD"];
const erasNarrow = ["B", "A"];
function eras(length) {
switch (length) {
case "narrow":
return [...erasNarrow];
case "short":
return [...erasShort];
case "long":
return [...erasLong];
default:
return null;
}
}
function meridiemForDateTime(dt) {
return meridiems[dt.hour < 12 ? 0 : 1];
}
function weekdayForDateTime(dt, length) {
return weekdays(length)[dt.weekday - 1];
}
function monthForDateTime(dt, length) {
return months(length)[dt.month - 1];
}
function eraForDateTime(dt, length) {
return eras(length)[dt.year < 0 ? 0 : 1];
}
function formatRelativeTime(unit, count, numeric = "always", narrow = false) {
const units = {
years: ["year", "yr."],
quarters: ["quarter", "qtr."],
months: ["month", "mo."],
weeks: ["week", "wk."],
days: ["day", "day", "days"],
hours: ["hour", "hr."],
minutes: ["minute", "min."],
seconds: ["second", "sec."]
};
const lastable = ["hours", "minutes", "seconds"].indexOf(unit) === -1;
if (numeric === "auto" && lastable) {
const isDay = unit === "days";
switch (count) {
case 1:
return isDay ? "tomorrow" : `next ${units[unit][0]}`;
case -1:
return isDay ? "yesterday" : `last ${units[unit][0]}`;
case 0:
return isDay ? "today" : `this ${units[unit][0]}`;
}
}
const isInPast = Object.is(count, -0) || count < 0,
fmtValue = Math.abs(count),
singular = fmtValue === 1,
lilUnits = units[unit],
fmtUnit = narrow ? singular ? lilUnits[1] : lilUnits[2] || lilUnits[1] : singular ? units[unit][0] : unit;
return isInPast ? `${fmtValue} ${fmtUnit} ago` : `in ${fmtValue} ${fmtUnit}`;
}
function formatString(knownFormat) {
// these all have the offsets removed because we don't have access to them
// without all the intl stuff this is backfilling
const filtered = pick(knownFormat, ["weekday", "era", "year", "month", "day", "hour", "minute", "second", "timeZoneName", "hour12"]),
key = stringify(filtered),
dateTimeHuge = "EEEE, LLLL d, yyyy, h:mm a";
switch (key) {
case stringify(DATE_SHORT):
return "M/d/yyyy";
case stringify(DATE_MED):
return "LLL d, yyyy";
case stringify(DATE_MED_WITH_WEEKDAY):
return "EEE, LLL d, yyyy";
case stringify(DATE_FULL):
return "LLLL d, yyyy";
case stringify(DATE_HUGE):
return "EEEE, LLLL d, yyyy";
case stringify(TIME_SIMPLE):
return "h:mm a";
case stringify(TIME_WITH_SECONDS):
return "h:mm:ss a";
case stringify(TIME_WITH_SHORT_OFFSET):
return "h:mm a";
case stringify(TIME_WITH_LONG_OFFSET):
return "h:mm a";
case stringify(TIME_24_SIMPLE):
return "HH:mm";
case stringify(TIME_24_WITH_SECONDS):
return "HH:mm:ss";
case stringify(TIME_24_WITH_SHORT_OFFSET):
return "HH:mm";
case stringify(TIME_24_WITH_LONG_OFFSET):
return "HH:mm";
case stringify(DATETIME_SHORT):
return "M/d/yyyy, h:mm a";
case stringify(DATETIME_MED):
return "LLL d, yyyy, h:mm a";
case stringify(DATETIME_FULL):
return "LLLL d, yyyy, h:mm a";
case stringify(DATETIME_HUGE):
return dateTimeHuge;
case stringify(DATETIME_SHORT_WITH_SECONDS):
return "M/d/yyyy, h:mm:ss a";
case stringify(DATETIME_MED_WITH_SECONDS):
return "LLL d, yyyy, h:mm:ss a";
case stringify(DATETIME_MED_WITH_WEEKDAY):
return "EEE, d LLL yyyy, h:mm a";
case stringify(DATETIME_FULL_WITH_SECONDS):
return "LLLL d, yyyy, h:mm:ss a";
case stringify(DATETIME_HUGE_WITH_SECONDS):
return "EEEE, LLLL d, yyyy, h:mm:ss a";
default:
return dateTimeHuge;
}
}
function stringifyTokens(splits, tokenToString) {
let s = "";
for (const token of splits) {
if (token.literal) {
s += token.val;
} else {
s += tokenToString(token.val);
}
}
return s;
}
const macroTokenToFormatOpts = {
D: DATE_SHORT,
DD: DATE_MED,
DDD: DATE_FULL,
DDDD: DATE_HUGE,
t: TIME_SIMPLE,
tt: TIME_WITH_SECONDS,
ttt: TIME_WITH_SHORT_OFFSET,
tttt: TIME_WITH_LONG_OFFSET,
T: TIME_24_SIMPLE,
TT: TIME_24_WITH_SECONDS,
TTT: TIME_24_WITH_SHORT_OFFSET,
TTTT: TIME_24_WITH_LONG_OFFSET,
f: DATETIME_SHORT,
ff: DATETIME_MED,
fff: DATETIME_FULL,
ffff: DATETIME_HUGE,
F: DATETIME_SHORT_WITH_SECONDS,
FF: DATETIME_MED_WITH_SECONDS,
FFF: DATETIME_FULL_WITH_SECONDS,
FFFF: DATETIME_HUGE_WITH_SECONDS
};
/**
* @private
*/
class Formatter {
static create(locale, opts = {}) {
return new Formatter(locale, opts);
}
static parseFormat(fmt) {
let current = null,
currentFull = "",
bracketed = false;
const splits = [];
for (let i = 0; i < fmt.length; i++) {
const c = fmt.charAt(i);
if (c === "'") {
if (currentFull.length > 0) {
splits.push({
literal: bracketed,
val: currentFull
});
}
current = null;
currentFull = "";
bracketed = !bracketed;
} else if (bracketed) {
currentFull += c;
} else if (c === current) {
currentFull += c;
} else {
if (currentFull.length > 0) {
splits.push({
literal: false,
val: currentFull
});
}
currentFull = c;
current = c;
}
}
if (currentFull.length > 0) {
splits.push({
literal: bracketed,
val: currentFull
});
}
return splits;
}
static macroTokenToFormatOpts(token) {
return macroTokenToFormatOpts[token];
}
constructor(locale, formatOpts) {
this.opts = formatOpts;
this.loc = locale;
this.systemLoc = null;
}
formatWithSystemDefault(dt, opts) {
if (this.systemLoc === null) {
this.systemLoc = this.loc.redefaultToSystem();
}
const df = this.systemLoc.dtFormatter(dt, Object.assign({}, this.opts, opts));
return df.format();
}
formatDateTime(dt, opts = {}) {
const df = this.loc.dtFormatter(dt, Object.assign({}, this.opts, opts));
return df.format();
}
formatDateTimeParts(dt, opts = {}) {
const df = this.loc.dtFormatter(dt, Object.assign({}, this.opts, opts));
return df.formatToParts();
}
resolvedOptions(dt, opts = {}) {
const df = this.loc.dtFormatter(dt, Object.assign({}, this.opts, opts));
return df.resolvedOptions();
}
num(n, p = 0) {
// we get some perf out of doing this here, annoyingly
if (this.opts.forceSimple) {
return padStart(n, p);
}
const opts = Object.assign({}, this.opts);
if (p > 0) {
opts.padTo = p;
}
return this.loc.numberFormatter(opts).format(n);
}
formatDateTimeFromString(dt, fmt) {
const knownEnglish = this.loc.listingMode() === "en",
useDateTimeFormatter = this.loc.outputCalendar && this.loc.outputCalendar !== "gregory" && hasFormatToParts(),
string = (opts, extract) => this.loc.extract(dt, opts, extract),
formatOffset = opts => {
if (dt.isOffsetFixed && dt.offset === 0 && opts.allowZ) {
return "Z";
}
return dt.isValid ? dt.zone.formatOffset(dt.ts, opts.format) : "";
},
meridiem = () => knownEnglish ? meridiemForDateTime(dt) : string({
hour: "numeric",
hour12: true
}, "dayperiod"),
month = (length, standalone) => knownEnglish ? monthForDateTime(dt, length) : string(standalone ? {
month: length
} : {
month: length,
day: "numeric"
}, "month"),
weekday = (length, standalone) => knownEnglish ? weekdayForDateTime(dt, length) : string(standalone ? {
weekday: length
} : {
weekday: length,
month: "long",
day: "numeric"
}, "weekday"),
maybeMacro = token => {
const formatOpts = Formatter.macroTokenToFormatOpts(token);
if (formatOpts) {
return this.formatWithSystemDefault(dt, formatOpts);
} else {
return token;
}
},
era = length => knownEnglish ? eraForDateTime(dt, length) : string({
era: length
}, "era"),
tokenToString = token => {
// Where possible: http://cldr.unicode.org/translation/date-time-1/date-time#TOC-Standalone-vs.-Format-Styles
switch (token) {
// ms
case "S":
return this.num(dt.millisecond);
case "u": // falls through
case "SSS":
return this.num(dt.millisecond, 3);
// seconds
case "s":
return this.num(dt.second);
case "ss":
return this.num(dt.second, 2);
// minutes
case "m":
return this.num(dt.minute);
case "mm":
return this.num(dt.minute, 2);
// hours
case "h":
return this.num(dt.hour % 12 === 0 ? 12 : dt.hour % 12);
case "hh":
return this.num(dt.hour % 12 === 0 ? 12 : dt.hour % 12, 2);
case "H":
return this.num(dt.hour);
case "HH":
return this.num(dt.hour, 2);
// offset
case "Z":
// like +6
return formatOffset({
format: "narrow",
allowZ: this.opts.allowZ
});
case "ZZ":
// like +06:00
return formatOffset({
format: "short",
allowZ: this.opts.allowZ
});
case "ZZZ":
// like +0600
return formatOffset({
format: "techie",
allowZ: this.opts.allowZ
});
case "ZZZZ":
// like EST
return dt.zone.offsetName(dt.ts, {
format: "short",
locale: this.loc.locale
});
case "ZZZZZ":
// like Eastern Standard Time
return dt.zone.offsetName(dt.ts, {
format: "long",
locale: this.loc.locale
});
// zone
case "z":
// like America/New_York
return dt.zoneName;
// meridiems
case "a":
return meridiem();
// dates
case "d":
return useDateTimeFormatter ? string({
day: "numeric"
}, "day") : this.num(dt.day);
case "dd":
return useDateTimeFormatter ? string({
day: "2-digit"
}, "day") : this.num(dt.day, 2);
// weekdays - standalone
case "c":
// like 1
return this.num(dt.weekday);
case "ccc":
// like 'Tues'
return weekday("short", true);
case "cccc":
// like 'Tuesday'
return weekday("long", true);
case "ccccc":
// like 'T'
return weekday("narrow", true);
// weekdays - format
case "E":
// like 1
return this.num(dt.weekday);
case "EEE":
// like 'Tues'
return weekday("short", false);
case "EEEE":
// like 'Tuesday'
return weekday("long", false);
case "EEEEE":
// like 'T'
return weekday("narrow", false);
// months - standalone
case "L":
// like 1
return useDateTimeFormatter ? string({
month: "numeric",
day: "numeric"
}, "month") : this.num(dt.month);
case "LL":
// like 01, doesn't seem to work
return useDateTimeFormatter ? string({
month: "2-digit",
day: "numeric"
}, "month") : this.num(dt.month, 2);
case "LLL":
// like Jan
return month("short", true);
case "LLLL":
// like January
return month("long", true);
case "LLLLL":
// like J
return month("narrow", true);
// months - format
case "M":
// like 1
return useDateTimeFormatter ? string({
month: "numeric"
}, "month") : this.num(dt.month);
case "MM":
// like 01
return useDateTimeFormatter ? string({
month: "2-digit"
}, "month") : this.num(dt.month, 2);
case "MMM":
// like Jan
return month("short", false);
case "MMMM":
// like January
return month("long", false);
case "MMMMM":
// like J
return month("narrow", false);
// years
case "y":
// like 2014
return useDateTimeFormatter ? string({
year: "numeric"
}, "year") : this.num(dt.year);
case "yy":
// like 14
return useDateTimeFormatter ? string({
year: "2-digit"
}, "year") : this.num(dt.year.toString().slice(-2), 2);
case "yyyy":
// like 0012
return useDateTimeFormatter ? string({
year: "numeric"
}, "year") : this.num(dt.year, 4);
case "yyyyyy":
// like 000012
return useDateTimeFormatter ? string({
year: "numeric"
}, "year") : this.num(dt.year, 6);
// eras
case "G":
// like AD
return era("short");
case "GG":
// like Anno Domini
return era("long");
case "GGGGG":
return era("narrow");
case "kk":
return this.num(dt.weekYear.toString().slice(-2), 2);
case "kkkk":
return this.num(dt.weekYear, 4);
case "W":
return this.num(dt.weekNumber);
case "WW":
return this.num(dt.weekNumber, 2);
case "o":
return this.num(dt.ordinal);
case "ooo":
return this.num(dt.ordinal, 3);
case "q":
// like 1
return this.num(dt.quarter);
case "qq":
// like 01
return this.num(dt.quarter, 2);
case "X":
return this.num(Math.floor(dt.ts / 1000));
case "x":
return this.num(dt.ts);
default:
return maybeMacro(token);
}
};
return stringifyTokens(Formatter.parseFormat(fmt), tokenToString);
}
formatDurationFromString(dur, fmt) {
const tokenToField = token => {
switch (token[0]) {
case "S":
return "millisecond";
case "s":
return "second";
case "m":
return "minute";
case "h":
return "hour";
case "d":
return "day";
case "M":
return "month";
case "y":
return "year";
default:
return null;
}
},
tokenToString = lildur => token => {
const mapped = tokenToField(token);
if (mapped) {
return this.num(lildur.get(mapped), token.length);
} else {
return token;
}
},
tokens = Formatter.parseFormat(fmt),
realTokens = tokens.reduce((found, {
literal,
val
}) => literal ? found : found.concat(val), []),
collapsed = dur.shiftTo(...realTokens.map(tokenToField).filter(t => t));
return stringifyTokens(tokens, tokenToString(collapsed));
}
}
class Invalid {
constructor(reason, explanation) {
this.reason = reason;
this.explanation = explanation;
}
toMessage() {
if (this.explanation) {
return `${this.reason}: ${this.explanation}`;
} else {
return this.reason;
}
}
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
/* eslint no-unused-vars: "off" */
/**
* @interface
*/
class Zone {
/**
* The type of zone
* @abstract
* @type {string}
*/
get type() {
throw new ZoneIsAbstractError();
}
/**
* The name of this zone.
* @abstract
* @type {string}
*/
get name() {
throw new ZoneIsAbstractError();
}
/**
* Returns whether the offset is known to be fixed for the whole year.
* @abstract
* @type {boolean}
*/
get universal() {
throw new ZoneIsAbstractError();
}
/**
* Returns the offset's common name (such as EST) at the specified timestamp
* @abstract
* @param {number} ts - Epoch milliseconds for which to get the name
* @param {Object} opts - Options to affect the format
* @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'.
* @param {string} opts.locale - What locale to return the offset name in.
* @return {string}
*/
offsetName(ts, opts) {
throw new ZoneIsAbstractError();
}
/**
* Returns the offset's value as a string
* @abstract
* @param {number} ts - Epoch milliseconds for which to get the offset
* @param {string} format - What style of offset to return.
* Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
* @return {string}
*/
formatOffset(ts, format) {
throw new ZoneIsAbstractError();
}
/**
* Return the offset in minutes for this zone at the specified timestamp.
* @abstract
* @param {number} ts - Epoch milliseconds for which to compute the offset
* @return {number}
*/
offset(ts) {
throw new ZoneIsAbstractError();
}
/**
* Return whether this Zone is equal to another zone
* @abstract
* @param {Zone} otherZone - the zone to compare
* @return {boolean}
*/
equals(otherZone) {
throw new ZoneIsAbstractError();
}
/**
* Return whether this Zone is valid.
* @abstract
* @type {boolean}
*/
get isValid() {
throw new ZoneIsAbstractError();
}
}
let singleton = null;
/**
* Represents the local zone for this JavaScript environment.
* @implements {Zone}
*/
class LocalZone extends Zone {
/**
* Get a singleton instance of the local zone
* @return {LocalZone}
*/
static get instance() {
if (singleton === null) {
singleton = new LocalZone();
}
return singleton;
}
/** @override **/
get type() {
return "local";
}
/** @override **/
get name() {
if (hasIntl()) {
return new Intl.DateTimeFormat().resolvedOptions().timeZone;
} else return "local";
}
/** @override **/
get universal() {
return false;
}
/** @override **/
offsetName(ts, {
format,
locale
}) {
return parseZoneInfo(ts, format, locale);
}
/** @override **/
formatOffset(ts, format) {
return formatOffset(this.offset(ts), format);
}
/** @override **/
offset(ts) {
return -new Date(ts).getTimezoneOffset();
}
/** @override **/
equals(otherZone) {
return otherZone.type === "local";
}
/** @override **/
get isValid() {
return true;
}
}
const matchingRegex = RegExp(`^${ianaRegex.source}$`);
let dtfCache = {};
function makeDTF(zone) {
if (!dtfCache[zone]) {
dtfCache[zone] = new Intl.DateTimeFormat("en-US", {
hour12: false,
timeZone: zone,
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit"
});
}
return dtfCache[zone];
}
const typeToPos = {
year: 0,
month: 1,
day: 2,
hour: 3,
minute: 4,
second: 5
};
function hackyOffset(dtf, date) {
const formatted = dtf.format(date).replace(/\u200E/g, ""),
parsed = /(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(formatted),
[, fMonth, fDay, fYear, fHour, fMinute, fSecond] = parsed;
return [fYear, fMonth, fDay, fHour, fMinute, fSecond];
}
function partsOffset(dtf, date) {
const formatted = dtf.formatToParts(date),
filled = [];
for (let i = 0; i < formatted.length; i++) {
const {
type,
value
} = formatted[i],
pos = typeToPos[type];
if (!isUndefined(pos)) {
filled[pos] = parseInt(value, 10);
}
}
return filled;
}
let ianaZoneCache = {};
/**
* A zone identified by an IANA identifier, like America/New_York
* @implements {Zone}
*/
class IANAZone extends Zone {
/**
* @param {string} name - Zone name
* @return {IANAZone}
*/
static create(name) {
if (!ianaZoneCache[name]) {
ianaZoneCache[name] = new IANAZone(name);
}
return ianaZoneCache[name];
}
/**
* Reset local caches. Should only be necessary in testing scenarios.
* @return {void}
*/
static resetCache() {
ianaZoneCache = {};
dtfCache = {};
}
/**
* Returns whether the provided string is a valid specifier. This only checks the string's format, not that the specifier identifies a known zone; see isValidZone for that.
* @param {string} s - The string to check validity on
* @example IANAZone.isValidSpecifier("America/New_York") //=> true
* @example IANAZone.isValidSpecifier("Fantasia/Castle") //=> true
* @example IANAZone.isValidSpecifier("Sport~~blorp") //=> false
* @return {boolean}
*/
static isValidSpecifier(s) {
return !!(s && s.match(matchingRegex));
}
/**
* Returns whether the provided string identifies a real zone
* @param {string} zone - The string to check
* @example IANAZone.isValidZone("America/New_York") //=> true
* @example IANAZone.isValidZone("Fantasia/Castle") //=> false
* @example IANAZone.isValidZone("Sport~~blorp") //=> false
* @return {boolean}
*/
static isValidZone(zone) {
try {
new Intl.DateTimeFormat("en-US", {
timeZone: zone
}).format();
return true;
} catch (e) {
return false;
}
} // Etc/GMT+8 -> -480
/** @ignore */
static parseGMTOffset(specifier) {
if (specifier) {
const match = specifier.match(/^Etc\/GMT(0|[+-]\d{1,2})$/i);
if (match) {
return -60 * parseInt(match[1]);
}
}
return null;
}
constructor(name) {
super();
/** @private **/
this.zoneName = name;
/** @private **/
this.valid = IANAZone.isValidZone(name);
}
/** @override **/
get type() {
return "iana";
}
/** @override **/
get name() {
return this.zoneName;
}
/** @override **/
get universal() {
return false;
}
/** @override **/
offsetName(ts, {
format,
locale
}) {
return parseZoneInfo(ts, format, locale, this.name);
}
/** @override **/
formatOffset(ts, format) {
return formatOffset(this.offset(ts), format);
}
/** @override **/
offset(ts) {
const date = new Date(ts);
if (isNaN(date)) return NaN;
const dtf = makeDTF(this.name),
[year, month, day, hour, minute, second] = dtf.formatToParts ? partsOffset(dtf, date) : hackyOffset(dtf, date),
// work around https://bugs.chromium.org/p/chromium/issues/detail?id=1025564&can=2&q=%2224%3A00%22%20datetimeformat
adjustedHour = hour === 24 ? 0 : hour;
const asUTC = objToLocalTS({
year,
month,
day,
hour: adjustedHour,
minute,
second,
millisecond: 0
});
let asTS = +date;
const over = asTS % 1000;
asTS -= over >= 0 ? over : 1000 + over;
return (asUTC - asTS) / (60 * 1000);
}
/** @override **/
equals(otherZone) {
return otherZone.type === "iana" && otherZone.name === this.name;
}
/** @override **/
get isValid() {
return this.valid;
}
}
let singleton$1 = null;
/**
* A zone with a fixed offset (meaning no DST)
* @implements {Zone}
*/
class FixedOffsetZone extends Zone {
/**
* Get a singleton instance of UTC
* @return {FixedOffsetZone}
*/
static get utcInstance() {
if (singleton$1 === null) {
singleton$1 = new FixedOffsetZone(0);
}
return singleton$1;
}
/**
* Get an instance with a specified offset
* @param {number} offset - The offset in minutes
* @return {FixedOffsetZone}
*/
static instance(offset) {
return offset === 0 ? FixedOffsetZone.utcInstance : new FixedOffsetZone(offset);
}
/**
* Get an instance of FixedOffsetZone from a UTC offset string, like "UTC+6"
* @param {string} s - The offset string to parse
* @example FixedOffsetZone.parseSpecifier("UTC+6")
* @example FixedOffsetZone.parseSpecifier("UTC+06")
* @example FixedOffsetZone.parseSpecifier("UTC-6:00")
* @return {FixedOffsetZone}
*/
static parseSpecifier(s) {
if (s) {
const r = s.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);
if (r) {
return new FixedOffsetZone(signedOffset(r[1], r[2]));
}
}
return null;
}
constructor(offset) {
super();
/** @private **/
this.fixed = offset;
}
/** @override **/
get type() {
return "fixed";
}
/** @override **/
get name() {
return this.fixed === 0 ? "UTC" : `UTC${formatOffset(this.fixed, "narrow")}`;
}
/** @override **/
offsetName() {
return this.name;
}
/** @override **/
formatOffset(ts, format) {
return formatOffset(this.fixed, format);
}
/** @override **/
get universal() {
return true;
}
/** @override **/
offset() {
return this.fixed;
}
/** @override **/
equals(otherZone) {
return otherZone.type === "fixed" && otherZone.fixed === this.fixed;
}
/** @override **/
get isValid() {
return true;
}
}
/**
* A zone that failed to parse. You should never need to instantiate this.
* @implements {Zone}
*/
class InvalidZone extends Zone {
constructor(zoneName) {
super();
/** @private */
this.zoneName = zoneName;
}
/** @override **/
get type() {
return "invalid";
}
/** @override **/
get name() {
return this.zoneName;
}
/** @override **/
get universal() {
return false;
}
/** @override **/
offsetName() {
return null;
}
/** @override **/
formatOffset() {
return "";
}
/** @override **/
offset() {
return NaN;
}
/** @override **/
equals() {
return false;
}
/** @override **/
get isValid() {
return false;
}
}
/**
* @private
*/
function normalizeZone(input, defaultZone) {
let offset;
if (isUndefined(input) || input === null) {
return defaultZone;
} else if (input instanceof Zone) {
return input;
} else if (isString(input)) {
const lowered = input.toLowerCase();
if (lowered === "local") return defaultZone;else if (lowered === "utc" || lowered === "gmt") return FixedOffsetZone.utcInstance;else if ((offset = IANAZone.parseGMTOffset(input)) != null) {
// handle Etc/GMT-4, which V8 chokes on
return FixedOffsetZone.instance(offset);
} else if (IANAZone.isValidSpecifier(lowered)) return IANAZone.create(input);else return FixedOffsetZone.parseSpecifier(lowered) || new InvalidZone(input);
} else if (isNumber(input)) {
return FixedOffsetZone.instance(input);
} else if (typeof input === "object" && input.offset && typeof input.offset === "number") {
// This is dumb, but the instanceof check above doesn't seem to really work
// so we're duck checking it
return input;
} else {
return new InvalidZone(input);
}
}
let now = () => Date.now(),
defaultZone = null,
// not setting this directly to LocalZone.instance bc loading order issues
defaultLocale = null,
defaultNumberingSystem = null,
defaultOutputCalendar = null,
throwOnInvalid = false;
/**
* Settings contains static getters and setters that control Luxon's overall behavior. Luxon is a simple library with few options, but the ones it does have live here.
*/
class Settings$1 {
/**
* Get the callback for returning the current timestamp.
* @type {function}
*/
static get now() {
return now;
}
/**
* Set the callback for returning the current timestamp.
* The function should return a number, which will be interpreted as an Epoch millisecond count
* @type {function}
* @example Settings.now = () => Date.now() + 3000 // pretend it is 3 seconds in the future
* @example Settings.now = () => 0 // always pretend it's Jan 1, 1970 at midnight in UTC time
*/
static set now(n) {
now = n;
}
/**
* Get the default time zone to create DateTimes in.
* @type {string}
*/
static get defaultZoneName() {
return Settings$1.defaultZone.name;
}
/**
* Set the default time zone to create DateTimes in. Does not affect existing instances.
* @type {string}
*/
static set defaultZoneName(z) {
if (!z) {
defaultZone = null;
} else {
defaultZone = normalizeZone(z);
}
}
/**
* Get the default time zone object to create DateTimes in. Does not affect existing instances.
* @type {Zone}
*/
static get defaultZone() {
return defaultZone || LocalZone.instance;
}
/**
* Get the default locale to create DateTimes with. Does not affect existing instances.
* @type {string}
*/
static get defaultLocale() {
return defaultLocale;
}
/**
* Set the default locale to create DateTimes with. Does not affect existing instances.
* @type {string}
*/
static set defaultLocale(locale) {
defaultLocale = locale;
}
/**
* Get the default numbering system to create DateTimes with. Does not affect existing instances.
* @type {string}
*/
static get defaultNumberingSystem() {
return defaultNumberingSystem;
}
/**
* Set the default numbering system to create DateTimes with. Does not affect existing instances.
* @type {string}
*/
static set defaultNumberingSystem(numberingSystem) {
defaultNumberingSystem = numberingSystem;
}
/**
* Get the default output calendar to create DateTimes with. Does not affect existing instances.
* @type {string}
*/
static get defaultOutputCalendar() {
return defaultOutputCalendar;
}
/**
* Set the default output calendar to create DateTimes with. Does not affect existing instances.
* @type {string}
*/
static set defaultOutputCalendar(outputCalendar) {
defaultOutputCalendar = outputCalendar;
}
/**
* Get whether Luxon will throw when it encounters invalid DateTimes, Durations, or Intervals
* @type {boolean}
*/
static get throwOnInvalid() {
return throwOnInvalid;
}
/**
* Set whether Luxon will throw when it encounters invalid DateTimes, Durations, or Intervals
* @type {boolean}
*/
static set throwOnInvalid(t) {
throwOnInvalid = t;
}
/**
* Reset Luxon's global caches. Should only be necessary in testing scenarios.
* @return {void}
*/
static resetCaches() {
Locale.resetCache();
IANAZone.resetCache();
}
}
let intlDTCache = {};
function getCachedDTF(locString, opts = {}) {
const key = JSON.stringify([locString, opts]);
let dtf = intlDTCache[key];
if (!dtf) {
dtf = new Intl.DateTimeFormat(locString, opts);
intlDTCache[key] = dtf;
}
return dtf;
}
let intlNumCache = {};
function getCachedINF(locString, opts = {}) {
const key = JSON.stringify([locString, opts]);
let inf = intlNumCache[key];
if (!inf) {
inf = new Intl.NumberFormat(locString, opts);
intlNumCache[key] = inf;
}
return inf;
}
let intlRelCache = {};
function getCachedRTF(locString, opts = {}) {
const cacheKeyOpts = _objectWithoutPropertiesLoose(opts, ["base"]); // exclude `base` from the options
const key = JSON.stringify([locString, cacheKeyOpts]);
let inf = intlRelCache[key];
if (!inf) {
inf = new Intl.RelativeTimeFormat(locString, opts);
intlRelCache[key] = inf;
}
return inf;
}
let sysLocaleCache = null;
function systemLocale() {
if (sysLocaleCache) {
return sysLocaleCache;
} else if (hasIntl()) {
const computedSys = new Intl.DateTimeFormat().resolvedOptions().locale; // node sometimes defaults to "und". Override that because that is dumb
sysLocaleCache = !computedSys || computedSys === "und" ? "en-US" : computedSys;
return sysLocaleCache;
} else {
sysLocaleCache = "en-US";
return sysLocaleCache;
}
}
function parseLocaleString(localeStr) {
// I really want to avoid writing a BCP 47 parser
// see, e.g. https://github.com/wooorm/bcp-47
// Instead, we'll do this:
// a) if the string has no -u extensions, just leave it alone
// b) if it does, use Intl to resolve everything
// c) if Intl fails, try again without the -u
const uIndex = localeStr.indexOf("-u-");
if (uIndex === -1) {
return [localeStr];
} else {
let options;
const smaller = localeStr.substring(0, uIndex);
try {
options = getCachedDTF(localeStr).resolvedOptions();
} catch (e) {
options = getCachedDTF(smaller).resolvedOptions();
}
const {
numberingSystem,
calendar
} = options; // return the smaller one so that we can append the calendar and numbering overrides to it
return [smaller, numberingSystem, calendar];
}
}
function intlConfigString(localeStr, numberingSystem, outputCalendar) {
if (hasIntl()) {
if (outputCalendar || numberingSystem) {
localeStr += "-u";
if (outputCalendar) {
localeStr += `-ca-${outputCalendar}`;
}
if (numberingSystem) {
localeStr += `-nu-${numberingSystem}`;
}
return localeStr;
} else {
return localeStr;
}
} else {
return [];
}
}
function mapMonths(f) {
const ms = [];
for (let i = 1; i <= 12; i++) {
const dt = DateTime.utc(2016, i, 1);
ms.push(f(dt));
}
return ms;
}
function mapWeekdays(f) {
const ms = [];
for (let i = 1; i <= 7; i++) {
const dt = DateTime.utc(2016, 11, 13 + i);
ms.push(f(dt));
}
return ms;
}
function listStuff(loc, length, defaultOK, englishFn, intlFn) {
const mode = loc.listingMode(defaultOK);
if (mode === "error") {
return null;
} else if (mode === "en") {
return englishFn(length);
} else {
return intlFn(length);
}
}
function supportsFastNumbers(loc) {
if (loc.numberingSystem && loc.numberingSystem !== "latn") {
return false;
} else {
return loc.numberingSystem === "latn" || !loc.locale || loc.locale.startsWith("en") || hasIntl() && new Intl.DateTimeFormat(loc.intl).resolvedOptions().numberingSystem === "latn";
}
}
/**
* @private
*/
class PolyNumberFormatter {
constructor(intl, forceSimple, opts) {
this.padTo = opts.padTo || 0;
this.floor = opts.floor || false;
if (!forceSimple && hasIntl()) {
const intlOpts = {
useGrouping: false
};
if (opts.padTo > 0) intlOpts.minimumIntegerDigits = opts.padTo;
this.inf = getCachedINF(intl, intlOpts);
}
}
format(i) {
if (this.inf) {
const fixed = this.floor ? Math.floor(i) : i;
return this.inf.format(fixed);
} else {
// to match the browser's numberformatter defaults
const fixed = this.floor ? Math.floor(i) : roundTo(i, 3);
return padStart(fixed, this.padTo);
}
}
}
/**
* @private
*/
class PolyDateFormatter {
constructor(dt, intl, opts) {
this.opts = opts;
this.hasIntl = hasIntl();
let z;
if (dt.zone.universal && this.hasIntl) {
// UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like.
// That is why fixed-offset TZ is set to that unless it is:
// 1. Representing offset 0 when UTC is used to maintain previous behavior and does not become GMT.
// 2. Unsupported by the browser:
// - some do not support Etc/
// - < Etc/GMT-14, > Etc/GMT+12, and 30-minute or 45-minute offsets are not part of tzdata
const gmtOffset = -1 * (dt.offset / 60);
const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`;
const isOffsetZoneSupported = IANAZone.isValidZone(offsetZ);
if (dt.offset !== 0 && isOffsetZoneSupported) {
z = offsetZ;
this.dt = dt;
} else {
// Not all fixed-offset zones like Etc/+4:30 are present in tzdata.
// So we have to make do. Two cases:
// 1. The format options tell us to show the zone. We can't do that, so the best
// we can do is format the date in UTC.
// 2. The format options don't tell us to show the zone. Then we can adjust them
// the time and tell the formatter to show it to us in UTC, so that the time is right
// and the bad zone doesn't show up.
z = "UTC";
if (opts.timeZoneName) {
this.dt = dt;
} else {
this.dt = dt.offset === 0 ? dt : DateTime.fromMillis(dt.ts + dt.offset * 60 * 1000);
}
}
} else if (dt.zone.type === "local") {
this.dt = dt;
} else {
this.dt = dt;
z = dt.zone.name;
}
if (this.hasIntl) {
const intlOpts = Object.assign({}, this.opts);
if (z) {
intlOpts.timeZone = z;
}
this.dtf = getCachedDTF(intl, intlOpts);
}
}
format() {
if (this.hasIntl) {
return this.dtf.format(this.dt.toJSDate());
} else {
const tokenFormat = formatString(this.opts),
loc = Locale.create("en-US");
return Formatter.create(loc).formatDateTimeFromString(this.dt, tokenFormat);
}
}
formatToParts() {
if (this.hasIntl && hasFormatToParts()) {
return this.dtf.formatToParts(this.dt.toJSDate());
} else {
// This is kind of a cop out. We actually could do this for English. However, we couldn't do it for intl strings
// and IMO it's too weird to have an uncanny valley like that
return [];
}
}
resolvedOptions() {
if (this.hasIntl) {
return this.dtf.resolvedOptions();
} else {
return {
locale: "en-US",
numberingSystem: "latn",
outputCalendar: "gregory"
};
}
}
}
/**
* @private
*/
class PolyRelFormatter {
constructor(intl, isEnglish, opts) {
this.opts = Object.assign({
style: "long"
}, opts);
if (!isEnglish && hasRelative()) {
this.rtf = getCachedRTF(intl, opts);
}
}
format(count, unit) {
if (this.rtf) {
return this.rtf.format(count, unit);
} else {
return formatRelativeTime(unit, count, this.opts.numeric, this.opts.style !== "long");
}
}
formatToParts(count, unit) {
if (this.rtf) {
return this.rtf.formatToParts(count, unit);
} else {
return [];
}
}
}
/**
* @private
*/
class Locale {
static fromOpts(opts) {
return Locale.create(opts.locale, opts.numberingSystem, opts.outputCalendar, opts.defaultToEN);
}
static create(locale, numberingSystem, outputCalendar, defaultToEN = false) {
const specifiedLocale = locale || Settings$1.defaultLocale,
// the system locale is useful for human readable strings but annoying for parsing/formatting known formats
localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale()),
numberingSystemR = numberingSystem || Settings$1.defaultNumberingSystem,
outputCalendarR = outputCalendar || Settings$1.defaultOutputCalendar;
return new Locale(localeR, numberingSystemR, outputCalendarR, specifiedLocale);
}
static resetCache() {
sysLocaleCache = null;
intlDTCache = {};
intlNumCache = {};
intlRelCache = {};
}
static fromObject({
locale,
numberingSystem,
outputCalendar
} = {}) {
return Locale.create(locale, numberingSystem, outputCalendar);
}
constructor(locale, numbering, outputCalendar, specifiedLocale) {
const [parsedLocale, parsedNumberingSystem, parsedOutputCalendar] = parseLocaleString(locale);
this.locale = parsedLocale;
this.numberingSystem = numbering || parsedNumberingSystem || null;
this.outputCalendar = outputCalendar || parsedOutputCalendar || null;
this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar);
this.weekdaysCache = {
format: {},
standalone: {}
};
this.monthsCache = {
format: {},
standalone: {}
};
this.meridiemCache = null;
this.eraCache = {};
this.specifiedLocale = specifiedLocale;
this.fastNumbersCached = null;
}
get fastNumbers() {
if (this.fastNumbersCached == null) {
this.fastNumbersCached = supportsFastNumbers(this);
}
return this.fastNumbersCached;
}
listingMode(defaultOK = true) {
const intl = hasIntl(),
hasFTP = intl && hasFormatToParts(),
isActuallyEn = this.isEnglish(),
hasNoWeirdness = (this.numberingSystem === null || this.numberingSystem === "latn") && (this.outputCalendar === null || this.outputCalendar === "gregory");
if (!hasFTP && !(isActuallyEn && hasNoWeirdness) && !defaultOK) {
return "error";
} else if (!hasFTP || isActuallyEn && hasNoWeirdness) {
return "en";
} else {
return "intl";
}
}
clone(alts) {
if (!alts || Object.getOwnPropertyNames(alts).length === 0) {
return this;
} else {
return Locale.create(alts.locale || this.specifiedLocale, alts.numberingSystem || this.numberingSystem, alts.outputCalendar || this.outputCalendar, alts.defaultToEN || false);
}
}
redefaultToEN(alts = {}) {
return this.clone(Object.assign({}, alts, {
defaultToEN: true
}));
}
redefaultToSystem(alts = {}) {
return this.clone(Object.assign({}, alts, {
defaultToEN: false
}));
}
months(length, format = false, defaultOK = true) {
return listStuff(this, length, defaultOK, months, () => {
const intl = format ? {
month: length,
day: "numeric"
} : {
month: length
},
formatStr = format ? "format" : "standalone";
if (!this.monthsCache[formatStr][length]) {
this.monthsCache[formatStr][length] = mapMonths(dt => this.extract(dt, intl, "month"));
}
return this.monthsCache[formatStr][length];
});
}
weekdays(length, format = false, defaultOK = true) {
return listStuff(this, length, defaultOK, weekdays, () => {
const intl = format ? {
weekday: length,
year: "numeric",
month: "long",
day: "numeric"
} : {
weekday: length
},
formatStr = format ? "format" : "standalone";
if (!this.weekdaysCache[formatStr][length]) {
this.weekdaysCache[formatStr][length] = mapWeekdays(dt => this.extract(dt, intl, "weekday"));
}
return this.weekdaysCache[formatStr][length];
});
}
meridiems(defaultOK = true) {
return listStuff(this, undefined, defaultOK, () => meridiems, () => {
// In theory there could be aribitrary day periods. We're gonna assume there are exactly two
// for AM and PM. This is probably wrong, but it's makes parsing way easier.
if (!this.meridiemCache) {
const intl = {
hour: "numeric",
hour12: true
};
this.meridiemCache = [DateTime.utc(2016, 11, 13, 9), DateTime.utc(2016, 11, 13, 19)].map(dt => this.extract(dt, intl, "dayperiod"));
}
return this.meridiemCache;
});
}
eras(length, defaultOK = true) {
return listStuff(this, length, defaultOK, eras, () => {
const intl = {
era: length
}; // This is problematic. Different calendars are going to define eras totally differently. What I need is the minimum set of dates
// to definitely enumerate them.
if (!this.eraCache[length]) {
this.eraCache[length] = [DateTime.utc(-40, 1, 1), DateTime.utc(2017, 1, 1)].map(dt => this.extract(dt, intl, "era"));
}
return this.eraCache[length];
});
}
extract(dt, intlOpts, field) {
const df = this.dtFormatter(dt, intlOpts),
results = df.formatToParts(),
matching = results.find(m => m.type.toLowerCase() === field);
return matching ? matching.value : null;
}
numberFormatter(opts = {}) {
// this forcesimple option is never used (the only caller short-circuits on it, but it seems safer to leave)
// (in contrast, the rest of the condition is used heavily)
return new PolyNumberFormatter(this.intl, opts.forceSimple || this.fastNumbers, opts);
}
dtFormatter(dt, intlOpts = {}) {
return new PolyDateFormatter(dt, this.intl, intlOpts);
}
relFormatter(opts = {}) {
return new PolyRelFormatter(this.intl, this.isEnglish(), opts);
}
isEnglish() {
return this.locale === "en" || this.locale.toLowerCase() === "en-us" || hasIntl() && new Intl.DateTimeFormat(this.intl).resolvedOptions().locale.startsWith("en-us");
}
equals(other) {
return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar;
}
}
/*
* This file handles parsing for well-specified formats. Here's how it works:
* Two things go into parsing: a regex to match with and an extractor to take apart the groups in the match.
* An extractor is just a function that takes a regex match array and returns a { year: ..., month: ... } object
* parse() does the work of executing the regex and applying the extractor. It takes multiple regex/extractor pairs to try in sequence.
* Extractors can take a "cursor" representing the offset in the match to look at. This makes it easy to combine extractors.
* combineExtractors() does the work of combining them, keeping track of the cursor through multiple extractions.
* Some extractions are super dumb and simpleParse and fromStrings help DRY them.
*/
function combineRegexes(...regexes) {
const full = regexes.reduce((f, r) => f + r.source, "");
return RegExp(`^${full}$`);
}
function combineExtractors(...extractors) {
return m => extractors.reduce(([mergedVals, mergedZone, cursor], ex) => {
const [val, zone, next] = ex(m, cursor);
return [Object.assign(mergedVals, val), mergedZone || zone, next];
}, [{}, null, 1]).slice(0, 2);
}
function parse(s, ...patterns) {
if (s == null) {
return [null, null];
}
for (const [regex, extractor] of patterns) {
const m = regex.exec(s);
if (m) {
return extractor(m);
}
}
return [null, null];
}
function simpleParse(...keys) {
return (match, cursor) => {
const ret = {};
let i;
for (i = 0; i < keys.length; i++) {
ret[keys[i]] = parseInteger(match[cursor + i]);
}
return [ret, null, cursor + i];
};
} // ISO and SQL parsing
const offsetRegex = /(?:(Z)|([+-]\d\d)(?::?(\d\d))?)/,
isoTimeBaseRegex = /(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,
isoTimeRegex = RegExp(`${isoTimeBaseRegex.source}${offsetRegex.source}?`),
isoTimeExtensionRegex = RegExp(`(?:T${isoTimeRegex.source})?`),
isoYmdRegex = /([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,
isoWeekRegex = /(\d{4})-?W(\d\d)(?:-?(\d))?/,
isoOrdinalRegex = /(\d{4})-?(\d{3})/,
extractISOWeekData = simpleParse("weekYear", "weekNumber", "weekDay"),
extractISOOrdinalData = simpleParse("year", "ordinal"),
sqlYmdRegex = /(\d{4})-(\d\d)-(\d\d)/,
// dumbed-down version of the ISO one
sqlTimeRegex = RegExp(`${isoTimeBaseRegex.source} ?(?:${offsetRegex.source}|(${ianaRegex.source}))?`),
sqlTimeExtensionRegex = RegExp(`(?: ${sqlTimeRegex.source})?`);
function int(match, pos, fallback) {
const m = match[pos];
return isUndefined(m) ? fallback : parseInteger(m);
}
function extractISOYmd(match, cursor) {
const item = {
year: int(match, cursor),
month: int(match, cursor + 1, 1),
day: int(match, cursor + 2, 1)
};
return [item, null, cursor + 3];
}
function extractISOTime(match, cursor) {
const item = {
hours: int(match, cursor, 0),
minutes: int(match, cursor + 1, 0),
seconds: int(match, cursor + 2, 0),
milliseconds: parseMillis(match[cursor + 3])
};
return [item, null, cursor + 4];
}
function extractISOOffset(match, cursor) {
const local = !match[cursor] && !match[cursor + 1],
fullOffset = signedOffset(match[cursor + 1], match[cursor + 2]),
zone = local ? null : FixedOffsetZone.instance(fullOffset);
return [{}, zone, cursor + 3];
}
function extractIANAZone(match, cursor) {
const zone = match[cursor] ? IANAZone.create(match[cursor]) : null;
return [{}, zone, cursor + 1];
} // ISO time parsing
const isoTimeOnly = RegExp(`^T?${isoTimeBaseRegex.source}$`); // ISO duration parsing
const isoDuration = /^-?P(?:(?:(-?\d{1,9})Y)?(?:(-?\d{1,9})M)?(?:(-?\d{1,9})W)?(?:(-?\d{1,9})D)?(?:T(?:(-?\d{1,9})H)?(?:(-?\d{1,9})M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,9}))?S)?)?)$/;
function extractISODuration(match) {
const [s, yearStr, monthStr, weekStr, dayStr, hourStr, minuteStr, secondStr, millisecondsStr] = match;
const hasNegativePrefix = s[0] === "-";
const negativeSeconds = secondStr && secondStr[0] === "-";
const maybeNegate = (num, force = false) => num !== undefined && (force || num && hasNegativePrefix) ? -num : num;
return [{
years: maybeNegate(parseInteger(yearStr)),
months: maybeNegate(parseInteger(monthStr)),
weeks: maybeNegate(parseInteger(weekStr)),
days: maybeNegate(parseInteger(dayStr)),
hours: maybeNegate(parseInteger(hourStr)),
minutes: maybeNegate(parseInteger(minuteStr)),
seconds: maybeNegate(parseInteger(secondStr), secondStr === "-0"),
milliseconds: maybeNegate(parseMillis(millisecondsStr), negativeSeconds)
}];
} // These are a little braindead. EDT *should* tell us that we're in, say, America/New_York
// and not just that we're in -240 *right now*. But since I don't think these are used that often
// I'm just going to ignore that
const obsOffsets = {
GMT: 0,
EDT: -4 * 60,
EST: -5 * 60,
CDT: -5 * 60,
CST: -6 * 60,
MDT: -6 * 60,
MST: -7 * 60,
PDT: -7 * 60,
PST: -8 * 60
};
function fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr) {
const result = {
year: yearStr.length === 2 ? untruncateYear(parseInteger(yearStr)) : parseInteger(yearStr),
month: monthsShort.indexOf(monthStr) + 1,
day: parseInteger(dayStr),
hour: parseInteger(hourStr),
minute: parseInteger(minuteStr)
};
if (secondStr) result.second = parseInteger(secondStr);
if (weekdayStr) {
result.weekday = weekdayStr.length > 3 ? weekdaysLong.indexOf(weekdayStr) + 1 : weekdaysShort.indexOf(weekdayStr) + 1;
}
return result;
} // RFC 2822/5322
const rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/;
function extractRFC2822(match) {
const [, weekdayStr, dayStr, monthStr, yearStr, hourStr, minuteStr, secondStr, obsOffset, milOffset, offHourStr, offMinuteStr] = match,
result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr);
let offset;
if (obsOffset) {
offset = obsOffsets[obsOffset];
} else if (milOffset) {
offset = 0;
} else {
offset = signedOffset(offHourStr, offMinuteStr);
}
return [result, new FixedOffsetZone(offset)];
}
function preprocessRFC2822(s) {
// Remove comments and folding whitespace and replace multiple-spaces with a single space
return s.replace(/\([^)]*\)|[\n\t]/g, " ").replace(/(\s\s+)/g, " ").trim();
} // http date
const rfc1123 = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/,
rfc850 = /^(Monday|Tuesday|Wedsday|Thursday|Friday|Saturday|Sunday), (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d) (\d\d):(\d\d):(\d\d) GMT$/,
ascii = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d\d) (\d\d):(\d\d):(\d\d) (\d{4})$/;
function extractRFC1123Or850(match) {
const [, weekdayStr, dayStr, monthStr, yearStr, hourStr, minuteStr, secondStr] = match,
result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr);
return [result, FixedOffsetZone.utcInstance];
}
function extractASCII(match) {
const [, weekdayStr, monthStr, dayStr, hourStr, minuteStr, secondStr, yearStr] = match,
result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr);
return [result, FixedOffsetZone.utcInstance];
}
const isoYmdWithTimeExtensionRegex = combineRegexes(isoYmdRegex, isoTimeExtensionRegex);
const isoWeekWithTimeExtensionRegex = combineRegexes(isoWeekRegex, isoTimeExtensionRegex);
const isoOrdinalWithTimeExtensionRegex = combineRegexes(isoOrdinalRegex, isoTimeExtensionRegex);
const isoTimeCombinedRegex = combineRegexes(isoTimeRegex);
const extractISOYmdTimeAndOffset = combineExtractors(extractISOYmd, extractISOTime, extractISOOffset);
const extractISOWeekTimeAndOffset = combineExtractors(extractISOWeekData, extractISOTime, extractISOOffset);
const extractISOOrdinalDateAndTime = combineExtractors(extractISOOrdinalData, extractISOTime, extractISOOffset);
const extractISOTimeAndOffset = combineExtractors(extractISOTime, extractISOOffset);
/**
* @private
*/
function parseISODate(s) {
return parse(s, [isoYmdWithTimeExtensionRegex, extractISOYmdTimeAndOffset], [isoWeekWithTimeExtensionRegex, extractISOWeekTimeAndOffset], [isoOrdinalWithTimeExtensionRegex, extractISOOrdinalDateAndTime], [isoTimeCombinedRegex, extractISOTimeAndOffset]);
}
function parseRFC2822Date(s) {
return parse(preprocessRFC2822(s), [rfc2822, extractRFC2822]);
}
function parseHTTPDate(s) {
return parse(s, [rfc1123, extractRFC1123Or850], [rfc850, extractRFC1123Or850], [ascii, extractASCII]);
}
function parseISODuration(s) {
return parse(s, [isoDuration, extractISODuration]);
}
const extractISOTimeOnly = combineExtractors(extractISOTime);
function parseISOTimeOnly(s) {
return parse(s, [isoTimeOnly, extractISOTimeOnly]);
}
const sqlYmdWithTimeExtensionRegex = combineRegexes(sqlYmdRegex, sqlTimeExtensionRegex);
const sqlTimeCombinedRegex = combineRegexes(sqlTimeRegex);
const extractISOYmdTimeOffsetAndIANAZone = combineExtractors(extractISOYmd, extractISOTime, extractISOOffset, extractIANAZone);
const extractISOTimeOffsetAndIANAZone = combineExtractors(extractISOTime, extractISOOffset, extractIANAZone);
function parseSQL(s) {
return parse(s, [sqlYmdWithTimeExtensionRegex, extractISOYmdTimeOffsetAndIANAZone], [sqlTimeCombinedRegex, extractISOTimeOffsetAndIANAZone]);
}
const INVALID = "Invalid Duration"; // unit conversion constants
const lowOrderMatrix = {
weeks: {
days: 7,
hours: 7 * 24,
minutes: 7 * 24 * 60,
seconds: 7 * 24 * 60 * 60,
milliseconds: 7 * 24 * 60 * 60 * 1000
},
days: {
hours: 24,
minutes: 24 * 60,
seconds: 24 * 60 * 60,
milliseconds: 24 * 60 * 60 * 1000
},
hours: {
minutes: 60,
seconds: 60 * 60,
milliseconds: 60 * 60 * 1000
},
minutes: {
seconds: 60,
milliseconds: 60 * 1000
},
seconds: {
milliseconds: 1000
}
},
casualMatrix = Object.assign({
years: {
quarters: 4,
months: 12,
weeks: 52,
days: 365,
hours: 365 * 24,
minutes: 365 * 24 * 60,
seconds: 365 * 24 * 60 * 60,
milliseconds: 365 * 24 * 60 * 60 * 1000
},
quarters: {
months: 3,
weeks: 13,
days: 91,
hours: 91 * 24,
minutes: 91 * 24 * 60,
seconds: 91 * 24 * 60 * 60,
milliseconds: 91 * 24 * 60 * 60 * 1000
},
months: {
weeks: 4,
days: 30,
hours: 30 * 24,
minutes: 30 * 24 * 60,
seconds: 30 * 24 * 60 * 60,
milliseconds: 30 * 24 * 60 * 60 * 1000
}
}, lowOrderMatrix),
daysInYearAccurate = 146097.0 / 400,
daysInMonthAccurate = 146097.0 / 4800,
accurateMatrix = Object.assign({
years: {
quarters: 4,
months: 12,
weeks: daysInYearAccurate / 7,
days: daysInYearAccurate,
hours: daysInYearAccurate * 24,
minutes: daysInYearAccurate * 24 * 60,
seconds: daysInYearAccurate * 24 * 60 * 60,
milliseconds: daysInYearAccurate * 24 * 60 * 60 * 1000
},
quarters: {
months: 3,
weeks: daysInYearAccurate / 28,
days: daysInYearAccurate / 4,
hours: daysInYearAccurate * 24 / 4,
minutes: daysInYearAccurate * 24 * 60 / 4,
seconds: daysInYearAccurate * 24 * 60 * 60 / 4,
milliseconds: daysInYearAccurate * 24 * 60 * 60 * 1000 / 4
},
months: {
weeks: daysInMonthAccurate / 7,
days: daysInMonthAccurate,
hours: daysInMonthAccurate * 24,
minutes: daysInMonthAccurate * 24 * 60,
seconds: daysInMonthAccurate * 24 * 60 * 60,
milliseconds: daysInMonthAccurate * 24 * 60 * 60 * 1000
}
}, lowOrderMatrix); // units ordered by size
const orderedUnits = ["years", "quarters", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds"];
const reverseUnits = orderedUnits.slice(0).reverse(); // clone really means "create another instance just like this one, but with these changes"
function clone(dur, alts, clear = false) {
// deep merge for vals
const conf = {
values: clear ? alts.values : Object.assign({}, dur.values, alts.values || {}),
loc: dur.loc.clone(alts.loc),
conversionAccuracy: alts.conversionAccuracy || dur.conversionAccuracy
};
return new Duration(conf);
}
function antiTrunc(n) {
return n < 0 ? Math.floor(n) : Math.ceil(n);
} // NB: mutates parameters
function convert(matrix, fromMap, fromUnit, toMap, toUnit) {
const conv = matrix[toUnit][fromUnit],
raw = fromMap[fromUnit] / conv,
sameSign = Math.sign(raw) === Math.sign(toMap[toUnit]),
// ok, so this is wild, but see the matrix in the tests
added = !sameSign && toMap[toUnit] !== 0 && Math.abs(raw) <= 1 ? antiTrunc(raw) : Math.trunc(raw);
toMap[toUnit] += added;
fromMap[fromUnit] -= added * conv;
} // NB: mutates parameters
function normalizeValues(matrix, vals) {
reverseUnits.reduce((previous, current) => {
if (!isUndefined(vals[current])) {
if (previous) {
convert(matrix, vals, previous, vals, current);
}
return current;
} else {
return previous;
}
}, null);
}
/**
* A Duration object represents a period of time, like "2 months" or "1 day, 1 hour". Conceptually, it's just a map of units to their quantities, accompanied by some additional configuration and methods for creating, parsing, interrogating, transforming, and formatting them. They can be used on their own or in conjunction with other Luxon types; for example, you can use {@link DateTime.plus} to add a Duration object to a DateTime, producing another DateTime.
*
* Here is a brief overview of commonly used methods and getters in Duration:
*
* * **Creation** To create a Duration, use {@link Duration.fromMillis}, {@link Duration.fromObject}, or {@link Duration.fromISO}.
* * **Unit values** See the {@link Duration.years}, {@link Duration.months}, {@link Duration.weeks}, {@link Duration.days}, {@link Duration.hours}, {@link Duration.minutes}, {@link Duration.seconds}, {@link Duration.milliseconds} accessors.
* * **Configuration** See {@link Duration.locale} and {@link Duration.numberingSystem} accessors.
* * **Transformation** To create new Durations out of old ones use {@link Duration.plus}, {@link Duration.minus}, {@link Duration.normalize}, {@link Duration.set}, {@link Duration.reconfigure}, {@link Duration.shiftTo}, and {@link Duration.negate}.
* * **Output** To convert the Duration into other representations, see {@link Duration.as}, {@link Duration.toISO}, {@link Duration.toFormat}, and {@link Duration.toJSON}
*
* There's are more methods documented below. In addition, for more information on subtler topics like internationalization and validity, see the external documentation.
*/
class Duration {
/**
* @private
*/
constructor(config) {
const accurate = config.conversionAccuracy === "longterm" || false;
/**
* @access private
*/
this.values = config.values;
/**
* @access private
*/
this.loc = config.loc || Locale.create();
/**
* @access private
*/
this.conversionAccuracy = accurate ? "longterm" : "casual";
/**
* @access private
*/
this.invalid = config.invalid || null;
/**
* @access private
*/
this.matrix = accurate ? accurateMatrix : casualMatrix;
/**
* @access private
*/
this.isLuxonDuration = true;
}
/**
* Create Duration from a number of milliseconds.
* @param {number} count of milliseconds
* @param {Object} opts - options for parsing
* @param {string} [opts.locale='en-US'] - the locale to use
* @param {string} opts.numberingSystem - the numbering system to use
* @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
* @return {Duration}
*/
static fromMillis(count, opts) {
return Duration.fromObject(Object.assign({
milliseconds: count
}, opts));
}
/**
* Create a Duration from a JavaScript object with keys like 'years' and 'hours'.
* If this object is empty then a zero milliseconds duration is returned.
* @param {Object} obj - the object to create the DateTime from
* @param {number} obj.years
* @param {number} obj.quarters
* @param {number} obj.months
* @param {number} obj.weeks
* @param {number} obj.days
* @param {number} obj.hours
* @param {number} obj.minutes
* @param {number} obj.seconds
* @param {number} obj.milliseconds
* @param {string} [obj.locale='en-US'] - the locale to use
* @param {string} obj.numberingSystem - the numbering system to use
* @param {string} [obj.conversionAccuracy='casual'] - the conversion system to use
* @return {Duration}
*/
static fromObject(obj) {
if (obj == null || typeof obj !== "object") {
throw new InvalidArgumentError(`Duration.fromObject: argument expected to be an object, got ${obj === null ? "null" : typeof obj}`);
}
return new Duration({
values: normalizeObject(obj, Duration.normalizeUnit, ["locale", "numberingSystem", "conversionAccuracy", "zone" // a bit of debt; it's super inconvenient internally not to be able to blindly pass this
]),
loc: Locale.fromObject(obj),
conversionAccuracy: obj.conversionAccuracy
});
}
/**
* Create a Duration from an ISO 8601 duration string.
* @param {string} text - text to parse
* @param {Object} opts - options for parsing
* @param {string} [opts.locale='en-US'] - the locale to use
* @param {string} opts.numberingSystem - the numbering system to use
* @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
* @see https://en.wikipedia.org/wiki/ISO_8601#Durations
* @example Duration.fromISO('P3Y6M1W4DT12H30M5S').toObject() //=> { years: 3, months: 6, weeks: 1, days: 4, hours: 12, minutes: 30, seconds: 5 }
* @example Duration.fromISO('PT23H').toObject() //=> { hours: 23 }
* @example Duration.fromISO('P5Y3M').toObject() //=> { years: 5, months: 3 }
* @return {Duration}
*/
static fromISO(text, opts) {
const [parsed] = parseISODuration(text);
if (parsed) {
const obj = Object.assign(parsed, opts);
return Duration.fromObject(obj);
} else {
return Duration.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`);
}
}
/**
* Create a Duration from an ISO 8601 time string.
* @param {string} text - text to parse
* @param {Object} opts - options for parsing
* @param {string} [opts.locale='en-US'] - the locale to use
* @param {string} opts.numberingSystem - the numbering system to use
* @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
* @see https://en.wikipedia.org/wiki/ISO_8601#Times
* @example Duration.fromISOTime('11:22:33.444').toObject() //=> { hours: 11, minutes: 22, seconds: 33, milliseconds: 444 }
* @example Duration.fromISOTime('11:00').toObject() //=> { hours: 11, minutes: 0, seconds: 0 }
* @example Duration.fromISOTime('T11:00').toObject() //=> { hours: 11, minutes: 0, seconds: 0 }
* @example Duration.fromISOTime('1100').toObject() //=> { hours: 11, minutes: 0, seconds: 0 }
* @example Duration.fromISOTime('T1100').toObject() //=> { hours: 11, minutes: 0, seconds: 0 }
* @return {Duration}
*/
static fromISOTime(text, opts) {
const [parsed] = parseISOTimeOnly(text);
if (parsed) {
const obj = Object.assign(parsed, opts);
return Duration.fromObject(obj);
} else {
return Duration.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`);
}
}
/**
* Create an invalid Duration.
* @param {string} reason - simple string of why this datetime is invalid. Should not contain parameters or anything else data-dependent
* @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information
* @return {Duration}
*/
static invalid(reason, explanation = null) {
if (!reason) {
throw new InvalidArgumentError("need to specify a reason the Duration is invalid");
}
const invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
if (Settings$1.throwOnInvalid) {
throw new InvalidDurationError(invalid);
} else {
return new Duration({
invalid
});
}
}
/**
* @private
*/
static normalizeUnit(unit) {
const normalized = {
year: "years",
years: "years",
quarter: "quarters",
quarters: "quarters",
month: "months",
months: "months",
week: "weeks",
weeks: "weeks",
day: "days",
days: "days",
hour: "hours",
hours: "hours",
minute: "minutes",
minutes: "minutes",
second: "seconds",
seconds: "seconds",
millisecond: "milliseconds",
milliseconds: "milliseconds"
}[unit ? unit.toLowerCase() : unit];
if (!normalized) throw new InvalidUnitError(unit);
return normalized;
}
/**
* Check if an object is a Duration. Works across context boundaries
* @param {object} o
* @return {boolean}
*/
static isDuration(o) {
return o && o.isLuxonDuration || false;
}
/**
* Get the locale of a Duration, such 'en-GB'
* @type {string}
*/
get locale() {
return this.isValid ? this.loc.locale : null;
}
/**
* Get the numbering system of a Duration, such 'beng'. The numbering system is used when formatting the Duration
*
* @type {string}
*/
get numberingSystem() {
return this.isValid ? this.loc.numberingSystem : null;
}
/**
* Returns a string representation of this Duration formatted according to the specified format string. You may use these tokens:
* * `S` for milliseconds
* * `s` for seconds
* * `m` for minutes
* * `h` for hours
* * `d` for days
* * `M` for months
* * `y` for years
* Notes:
* * Add padding by repeating the token, e.g. "yy" pads the years to two digits, "hhhh" pads the hours out to four digits
* * The duration will be converted to the set of units in the format string using {@link Duration.shiftTo} and the Durations's conversion accuracy setting.
* @param {string} fmt - the format string
* @param {Object} opts - options
* @param {boolean} [opts.floor=true] - floor numerical values
* @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("y d s") //=> "1 6 2"
* @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("yy dd sss") //=> "01 06 002"
* @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("M S") //=> "12 518402000"
* @return {string}
*/
toFormat(fmt, opts = {}) {
// reverse-compat since 1.2; we always round down now, never up, and we do it by default
const fmtOpts = Object.assign({}, opts, {
floor: opts.round !== false && opts.floor !== false
});
return this.isValid ? Formatter.create(this.loc, fmtOpts).formatDurationFromString(this, fmt) : INVALID;
}
/**
* Returns a JavaScript object with this Duration's values.
* @param opts - options for generating the object
* @param {boolean} [opts.includeConfig=false] - include configuration attributes in the output
* @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toObject() //=> { years: 1, days: 6, seconds: 2 }
* @return {Object}
*/
toObject(opts = {}) {
if (!this.isValid) return {};
const base = Object.assign({}, this.values);
if (opts.includeConfig) {
base.conversionAccuracy = this.conversionAccuracy;
base.numberingSystem = this.loc.numberingSystem;
base.locale = this.loc.locale;
}
return base;
}
/**
* Returns an ISO 8601-compliant string representation of this Duration.
* @see https://en.wikipedia.org/wiki/ISO_8601#Durations
* @example Duration.fromObject({ years: 3, seconds: 45 }).toISO() //=> 'P3YT45S'
* @example Duration.fromObject({ months: 4, seconds: 45 }).toISO() //=> 'P4MT45S'
* @example Duration.fromObject({ months: 5 }).toISO() //=> 'P5M'
* @example Duration.fromObject({ minutes: 5 }).toISO() //=> 'PT5M'
* @example Duration.fromObject({ milliseconds: 6 }).toISO() //=> 'PT0.006S'
* @return {string}
*/
toISO() {
// we could use the formatter, but this is an easier way to get the minimum string
if (!this.isValid) return null;
let s = "P";
if (this.years !== 0) s += this.years + "Y";
if (this.months !== 0 || this.quarters !== 0) s += this.months + this.quarters * 3 + "M";
if (this.weeks !== 0) s += this.weeks + "W";
if (this.days !== 0) s += this.days + "D";
if (this.hours !== 0 || this.minutes !== 0 || this.seconds !== 0 || this.milliseconds !== 0) s += "T";
if (this.hours !== 0) s += this.hours + "H";
if (this.minutes !== 0) s += this.minutes + "M";
if (this.seconds !== 0 || this.milliseconds !== 0) // this will handle "floating point madness" by removing extra decimal places
// https://stackoverflow.com/questions/588004/is-floating-point-math-broken
s += roundTo(this.seconds + this.milliseconds / 1000, 3) + "S";
if (s === "P") s += "T0S";
return s;
}
/**
* Returns an ISO 8601-compliant string representation of this Duration, formatted as a time of day.
* Note that this will return null if the duration is invalid, negative, or equal to or greater than 24 hours.
* @see https://en.wikipedia.org/wiki/ISO_8601#Times
* @param {Object} opts - options
* @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0
* @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0
* @param {boolean} [opts.includePrefix=false] - include the `T` prefix
* @param {string} [opts.format='extended'] - choose between the basic and extended format
* @example Duration.fromObject({ hours: 11 }).toISOTime() //=> '11:00:00.000'
* @example Duration.fromObject({ hours: 11 }).toISOTime({ suppressMilliseconds: true }) //=> '11:00:00'
* @example Duration.fromObject({ hours: 11 }).toISOTime({ suppressSeconds: true }) //=> '11:00'
* @example Duration.fromObject({ hours: 11 }).toISOTime({ includePrefix: true }) //=> 'T11:00:00.000'
* @example Duration.fromObject({ hours: 11 }).toISOTime({ format: 'basic' }) //=> '110000.000'
* @return {string}
*/
toISOTime(opts = {}) {
if (!this.isValid) return null;
const millis = this.toMillis();
if (millis < 0 || millis >= 86400000) return null;
opts = Object.assign({
suppressMilliseconds: false,
suppressSeconds: false,
includePrefix: false,
format: "extended"
}, opts);
const value = this.shiftTo("hours", "minutes", "seconds", "milliseconds");
let fmt = opts.format === "basic" ? "hhmm" : "hh:mm";
if (!opts.suppressSeconds || value.seconds !== 0 || value.milliseconds !== 0) {
fmt += opts.format === "basic" ? "ss" : ":ss";
if (!opts.suppressMilliseconds || value.milliseconds !== 0) {
fmt += ".SSS";
}
}
let str = value.toFormat(fmt);
if (opts.includePrefix) {
str = "T" + str;
}
return str;
}
/**
* Returns an ISO 8601 representation of this Duration appropriate for use in JSON.
* @return {string}
*/
toJSON() {
return this.toISO();
}
/**
* Returns an ISO 8601 representation of this Duration appropriate for use in debugging.
* @return {string}
*/
toString() {
return this.toISO();
}
/**
* Returns an milliseconds value of this Duration.
* @return {number}
*/
toMillis() {
return this.as("milliseconds");
}
/**
* Returns an milliseconds value of this Duration. Alias of {@link toMillis}
* @return {number}
*/
valueOf() {
return this.toMillis();
}
/**
* Make this Duration longer by the specified amount. Return a newly-constructed Duration.
* @param {Duration|Object|number} duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
* @return {Duration}
*/
plus(duration) {
if (!this.isValid) return this;
const dur = friendlyDuration(duration),
result = {};
for (const k of orderedUnits) {
if (hasOwnProperty(dur.values, k) || hasOwnProperty(this.values, k)) {
result[k] = dur.get(k) + this.get(k);
}
}
return clone(this, {
values: result
}, true);
}
/**
* Make this Duration shorter by the specified amount. Return a newly-constructed Duration.
* @param {Duration|Object|number} duration - The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
* @return {Duration}
*/
minus(duration) {
if (!this.isValid) return this;
const dur = friendlyDuration(duration);
return this.plus(dur.negate());
}
/**
* Scale this Duration by the specified amount. Return a newly-constructed Duration.
* @param {function} fn - The function to apply to each unit. Arity is 1 or 2: the value of the unit and, optionally, the unit name. Must return a number.
* @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnit(x => x * 2) //=> { hours: 2, minutes: 60 }
* @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnit((x, u) => u === "hour" ? x * 2 : x) //=> { hours: 2, minutes: 30 }
* @return {Duration}
*/
mapUnits(fn) {
if (!this.isValid) return this;
const result = {};
for (const k of Object.keys(this.values)) {
result[k] = asNumber(fn(this.values[k], k));
}
return clone(this, {
values: result
}, true);
}
/**
* Get the value of unit.
* @param {string} unit - a unit such as 'minute' or 'day'
* @example Duration.fromObject({years: 2, days: 3}).get('years') //=> 2
* @example Duration.fromObject({years: 2, days: 3}).get('months') //=> 0
* @example Duration.fromObject({years: 2, days: 3}).get('days') //=> 3
* @return {number}
*/
get(unit) {
return this[Duration.normalizeUnit(unit)];
}
/**
* "Set" the values of specified units. Return a newly-constructed Duration.
* @param {Object} values - a mapping of units to numbers
* @example dur.set({ years: 2017 })
* @example dur.set({ hours: 8, minutes: 30 })
* @return {Duration}
*/
set(values) {
if (!this.isValid) return this;
const mixed = Object.assign(this.values, normalizeObject(values, Duration.normalizeUnit, []));
return clone(this, {
values: mixed
});
}
/**
* "Set" the locale and/or numberingSystem. Returns a newly-constructed Duration.
* @example dur.reconfigure({ locale: 'en-GB' })
* @return {Duration}
*/
reconfigure({
locale,
numberingSystem,
conversionAccuracy
} = {}) {
const loc = this.loc.clone({
locale,
numberingSystem
}),
opts = {
loc
};
if (conversionAccuracy) {
opts.conversionAccuracy = conversionAccuracy;
}
return clone(this, opts);
}
/**
* Return the length of the duration in the specified unit.
* @param {string} unit - a unit such as 'minutes' or 'days'
* @example Duration.fromObject({years: 1}).as('days') //=> 365
* @example Duration.fromObject({years: 1}).as('months') //=> 12
* @example Duration.fromObject({hours: 60}).as('days') //=> 2.5
* @return {number}
*/
as(unit) {
return this.isValid ? this.shiftTo(unit).get(unit) : NaN;
}
/**
* Reduce this Duration to its canonical representation in its current units.
* @example Duration.fromObject({ years: 2, days: 5000 }).normalize().toObject() //=> { years: 15, days: 255 }
* @example Duration.fromObject({ hours: 12, minutes: -45 }).normalize().toObject() //=> { hours: 11, minutes: 15 }
* @return {Duration}
*/
normalize() {
if (!this.isValid) return this;
const vals = this.toObject();
normalizeValues(this.matrix, vals);
return clone(this, {
values: vals
}, true);
}
/**
* Convert this Duration into its representation in a different set of units.
* @example Duration.fromObject({ hours: 1, seconds: 30 }).shiftTo('minutes', 'milliseconds').toObject() //=> { minutes: 60, milliseconds: 30000 }
* @return {Duration}
*/
shiftTo(...units) {
if (!this.isValid) return this;
if (units.length === 0) {
return this;
}
units = units.map(u => Duration.normalizeUnit(u));
const built = {},
accumulated = {},
vals = this.toObject();
let lastUnit;
for (const k of orderedUnits) {
if (units.indexOf(k) >= 0) {
lastUnit = k;
let own = 0; // anything we haven't boiled down yet should get boiled to this unit
for (const ak in accumulated) {
own += this.matrix[ak][k] * accumulated[ak];
accumulated[ak] = 0;
} // plus anything that's already in this unit
if (isNumber(vals[k])) {
own += vals[k];
}
const i = Math.trunc(own);
built[k] = i;
accumulated[k] = own - i; // we'd like to absorb these fractions in another unit
// plus anything further down the chain that should be rolled up in to this
for (const down in vals) {
if (orderedUnits.indexOf(down) > orderedUnits.indexOf(k)) {
convert(this.matrix, vals, down, built, k);
}
} // otherwise, keep it in the wings to boil it later
} else if (isNumber(vals[k])) {
accumulated[k] = vals[k];
}
} // anything leftover becomes the decimal for the last unit
// lastUnit must be defined since units is not empty
for (const key in accumulated) {
if (accumulated[key] !== 0) {
built[lastUnit] += key === lastUnit ? accumulated[key] : accumulated[key] / this.matrix[lastUnit][key];
}
}
return clone(this, {
values: built
}, true).normalize();
}
/**
* Return the negative of this Duration.
* @example Duration.fromObject({ hours: 1, seconds: 30 }).negate().toObject() //=> { hours: -1, seconds: -30 }
* @return {Duration}
*/
negate() {
if (!this.isValid) return this;
const negated = {};
for (const k of Object.keys(this.values)) {
negated[k] = -this.values[k];
}
return clone(this, {
values: negated
}, true);
}
/**
* Get the years.
* @type {number}
*/
get years() {
return this.isValid ? this.values.years || 0 : NaN;
}
/**
* Get the quarters.
* @type {number}
*/
get quarters() {
return this.isValid ? this.values.quarters || 0 : NaN;
}
/**
* Get the months.
* @type {number}
*/
get months() {
return this.isValid ? this.values.months || 0 : NaN;
}
/**
* Get the weeks
* @type {number}
*/
get weeks() {
return this.isValid ? this.values.weeks || 0 : NaN;
}
/**
* Get the days.
* @type {number}
*/
get days() {
return this.isValid ? this.values.days || 0 : NaN;
}
/**
* Get the hours.
* @type {number}
*/
get hours() {
return this.isValid ? this.values.hours || 0 : NaN;
}
/**
* Get the minutes.
* @type {number}
*/
get minutes() {
return this.isValid ? this.values.minutes || 0 : NaN;
}
/**
* Get the seconds.
* @return {number}
*/
get seconds() {
return this.isValid ? this.values.seconds || 0 : NaN;
}
/**
* Get the milliseconds.
* @return {number}
*/
get milliseconds() {
return this.isValid ? this.values.milliseconds || 0 : NaN;
}
/**
* Returns whether the Duration is invalid. Invalid durations are returned by diff operations
* on invalid DateTimes or Intervals.
* @return {boolean}
*/
get isValid() {
return this.invalid === null;
}
/**
* Returns an error code if this Duration became invalid, or null if the Duration is valid
* @return {string}
*/
get invalidReason() {
return this.invalid ? this.invalid.reason : null;
}
/**
* Returns an explanation of why this Duration became invalid, or null if the Duration is valid
* @type {string}
*/
get invalidExplanation() {
return this.invalid ? this.invalid.explanation : null;
}
/**
* Equality check
* Two Durations are equal iff they have the same units and the same values for each unit.
* @param {Duration} other
* @return {boolean}
*/
equals(other) {
if (!this.isValid || !other.isValid) {
return false;
}
if (!this.loc.equals(other.loc)) {
return false;
}
function eq(v1, v2) {
// Consider 0 and undefined as equal
if (v1 === undefined || v1 === 0) return v2 === undefined || v2 === 0;
return v1 === v2;
}
for (const u of orderedUnits) {
if (!eq(this.values[u], other.values[u])) {
return false;
}
}
return true;
}
}
/**
* @private
*/
function friendlyDuration(durationish) {
if (isNumber(durationish)) {
return Duration.fromMillis(durationish);
} else if (Duration.isDuration(durationish)) {
return durationish;
} else if (typeof durationish === "object") {
return Duration.fromObject(durationish);
} else {
throw new InvalidArgumentError(`Unknown duration argument ${durationish} of type ${typeof durationish}`);
}
}
const INVALID$1 = "Invalid Interval"; // checks if the start is equal to or before the end
function validateStartEnd(start, end) {
if (!start || !start.isValid) {
return Interval.invalid("missing or invalid start");
} else if (!end || !end.isValid) {
return Interval.invalid("missing or invalid end");
} else if (end < start) {
return Interval.invalid("end before start", `The end of an interval must be after its start, but you had start=${start.toISO()} and end=${end.toISO()}`);
} else {
return null;
}
}
/**
* An Interval object represents a half-open interval of time, where each endpoint is a {@link DateTime}. Conceptually, it's a container for those two endpoints, accompanied by methods for creating, parsing, interrogating, comparing, transforming, and formatting them.
*
* Here is a brief overview of the most commonly used methods and getters in Interval:
*
* * **Creation** To create an Interval, use {@link fromDateTimes}, {@link after}, {@link before}, or {@link fromISO}.
* * **Accessors** Use {@link start} and {@link end} to get the start and end.
* * **Interrogation** To analyze the Interval, use {@link count}, {@link length}, {@link hasSame}, {@link contains}, {@link isAfter}, or {@link isBefore}.
* * **Transformation** To create other Intervals out of this one, use {@link set}, {@link splitAt}, {@link splitBy}, {@link divideEqually}, {@link merge}, {@link xor}, {@link union}, {@link intersection}, or {@link difference}.
* * **Comparison** To compare this Interval to another one, use {@link equals}, {@link overlaps}, {@link abutsStart}, {@link abutsEnd}, {@link engulfs}.
* * **Output** To convert the Interval into other representations, see {@link toString}, {@link toISO}, {@link toISODate}, {@link toISOTime}, {@link toFormat}, and {@link toDuration}.
*/
class Interval {
/**
* @private
*/
constructor(config) {
/**
* @access private
*/
this.s = config.start;
/**
* @access private
*/
this.e = config.end;
/**
* @access private
*/
this.invalid = config.invalid || null;
/**
* @access private
*/
this.isLuxonInterval = true;
}
/**
* Create an invalid Interval.
* @param {string} reason - simple string of why this Interval is invalid. Should not contain parameters or anything else data-dependent
* @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information
* @return {Interval}
*/
static invalid(reason, explanation = null) {
if (!reason) {
throw new InvalidArgumentError("need to specify a reason the Interval is invalid");
}
const invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
if (Settings$1.throwOnInvalid) {
throw new InvalidIntervalError(invalid);
} else {
return new Interval({
invalid
});
}
}
/**
* Create an Interval from a start DateTime and an end DateTime. Inclusive of the start but not the end.
* @param {DateTime|Date|Object} start
* @param {DateTime|Date|Object} end
* @return {Interval}
*/
static fromDateTimes(start, end) {
const builtStart = friendlyDateTime(start),
builtEnd = friendlyDateTime(end);
const validateError = validateStartEnd(builtStart, builtEnd);
if (validateError == null) {
return new Interval({
start: builtStart,
end: builtEnd
});
} else {
return validateError;
}
}
/**
* Create an Interval from a start DateTime and a Duration to extend to.
* @param {DateTime|Date|Object} start
* @param {Duration|Object|number} duration - the length of the Interval.
* @return {Interval}
*/
static after(start, duration) {
const dur = friendlyDuration(duration),
dt = friendlyDateTime(start);
return Interval.fromDateTimes(dt, dt.plus(dur));
}
/**
* Create an Interval from an end DateTime and a Duration to extend backwards to.
* @param {DateTime|Date|Object} end
* @param {Duration|Object|number} duration - the length of the Interval.
* @return {Interval}
*/
static before(end, duration) {
const dur = friendlyDuration(duration),
dt = friendlyDateTime(end);
return Interval.fromDateTimes(dt.minus(dur), dt);
}
/**
* Create an Interval from an ISO 8601 string.
* Accepts `<start>/<end>`, `<start>/<duration>`, and `<duration>/<end>` formats.
* @param {string} text - the ISO string to parse
* @param {Object} [opts] - options to pass {@link DateTime.fromISO} and optionally {@link Duration.fromISO}
* @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
* @return {Interval}
*/
static fromISO(text, opts) {
const [s, e] = (text || "").split("/", 2);
if (s && e) {
let start, startIsValid;
try {
start = DateTime.fromISO(s, opts);
startIsValid = start.isValid;
} catch (e) {
startIsValid = false;
}
let end, endIsValid;
try {
end = DateTime.fromISO(e, opts);
endIsValid = end.isValid;
} catch (e) {
endIsValid = false;
}
if (startIsValid && endIsValid) {
return Interval.fromDateTimes(start, end);
}
if (startIsValid) {
const dur = Duration.fromISO(e, opts);
if (dur.isValid) {
return Interval.after(start, dur);
}
} else if (endIsValid) {
const dur = Duration.fromISO(s, opts);
if (dur.isValid) {
return Interval.before(end, dur);
}
}
}
return Interval.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`);
}
/**
* Check if an object is an Interval. Works across context boundaries
* @param {object} o
* @return {boolean}
*/
static isInterval(o) {
return o && o.isLuxonInterval || false;
}
/**
* Returns the start of the Interval
* @type {DateTime}
*/
get start() {
return this.isValid ? this.s : null;
}
/**
* Returns the end of the Interval
* @type {DateTime}
*/
get end() {
return this.isValid ? this.e : null;
}
/**
* Returns whether this Interval's end is at least its start, meaning that the Interval isn't 'backwards'.
* @type {boolean}
*/
get isValid() {
return this.invalidReason === null;
}
/**
* Returns an error code if this Interval is invalid, or null if the Interval is valid
* @type {string}
*/
get invalidReason() {
return this.invalid ? this.invalid.reason : null;
}
/**
* Returns an explanation of why this Interval became invalid, or null if the Interval is valid
* @type {string}
*/
get invalidExplanation() {
return this.invalid ? this.invalid.explanation : null;
}
/**
* Returns the length of the Interval in the specified unit.
* @param {string} unit - the unit (such as 'hours' or 'days') to return the length in.
* @return {number}
*/
length(unit = "milliseconds") {
return this.isValid ? this.toDuration(...[unit]).get(unit) : NaN;
}
/**
* Returns the count of minutes, hours, days, months, or years included in the Interval, even in part.
* Unlike {@link length} this counts sections of the calendar, not periods of time, e.g. specifying 'day'
* asks 'what dates are included in this interval?', not 'how many days long is this interval?'
* @param {string} [unit='milliseconds'] - the unit of time to count.
* @return {number}
*/
count(unit = "milliseconds") {
if (!this.isValid) return NaN;
const start = this.start.startOf(unit),
end = this.end.startOf(unit);
return Math.floor(end.diff(start, unit).get(unit)) + 1;
}
/**
* Returns whether this Interval's start and end are both in the same unit of time
* @param {string} unit - the unit of time to check sameness on
* @return {boolean}
*/
hasSame(unit) {
return this.isValid ? this.isEmpty() || this.e.minus(1).hasSame(this.s, unit) : false;
}
/**
* Return whether this Interval has the same start and end DateTimes.
* @return {boolean}
*/
isEmpty() {
return this.s.valueOf() === this.e.valueOf();
}
/**
* Return whether this Interval's start is after the specified DateTime.
* @param {DateTime} dateTime
* @return {boolean}
*/
isAfter(dateTime) {
if (!this.isValid) return false;
return this.s > dateTime;
}
/**
* Return whether this Interval's end is before the specified DateTime.
* @param {DateTime} dateTime
* @return {boolean}
*/
isBefore(dateTime) {
if (!this.isValid) return false;
return this.e <= dateTime;
}
/**
* Return whether this Interval contains the specified DateTime.
* @param {DateTime} dateTime
* @return {boolean}
*/
contains(dateTime) {
if (!this.isValid) return false;
return this.s <= dateTime && this.e > dateTime;
}
/**
* "Sets" the start and/or end dates. Returns a newly-constructed Interval.
* @param {Object} values - the values to set
* @param {DateTime} values.start - the starting DateTime
* @param {DateTime} values.end - the ending DateTime
* @return {Interval}
*/
set({
start,
end
} = {}) {
if (!this.isValid) return this;
return Interval.fromDateTimes(start || this.s, end || this.e);
}
/**
* Split this Interval at each of the specified DateTimes
* @param {...[DateTime]} dateTimes - the unit of time to count.
* @return {[Interval]}
*/
splitAt(...dateTimes) {
if (!this.isValid) return [];
const sorted = dateTimes.map(friendlyDateTime).filter(d => this.contains(d)).sort(),
results = [];
let {
s
} = this,
i = 0;
while (s < this.e) {
const added = sorted[i] || this.e,
next = +added > +this.e ? this.e : added;
results.push(Interval.fromDateTimes(s, next));
s = next;
i += 1;
}
return results;
}
/**
* Split this Interval into smaller Intervals, each of the specified length.
* Left over time is grouped into a smaller interval
* @param {Duration|Object|number} duration - The length of each resulting interval.
* @return {[Interval]}
*/
splitBy(duration) {
const dur = friendlyDuration(duration);
if (!this.isValid || !dur.isValid || dur.as("milliseconds") === 0) {
return [];
}
let {
s
} = this,
idx = 1,
next;
const results = [];
while (s < this.e) {
const added = this.start.plus(dur.mapUnits(x => x * idx));
next = +added > +this.e ? this.e : added;
results.push(Interval.fromDateTimes(s, next));
s = next;
idx += 1;
}
return results;
}
/**
* Split this Interval into the specified number of smaller intervals.
* @param {number} numberOfParts - The number of Intervals to divide the Interval into.
* @return {[Interval]}
*/
divideEqually(numberOfParts) {
if (!this.isValid) return [];
return this.splitBy(this.length() / numberOfParts).slice(0, numberOfParts);
}
/**
* Return whether this Interval overlaps with the specified Interval
* @param {Interval} other
* @return {boolean}
*/
overlaps(other) {
return this.e > other.s && this.s < other.e;
}
/**
* Return whether this Interval's end is adjacent to the specified Interval's start.
* @param {Interval} other
* @return {boolean}
*/
abutsStart(other) {
if (!this.isValid) return false;
return +this.e === +other.s;
}
/**
* Return whether this Interval's start is adjacent to the specified Interval's end.
* @param {Interval} other
* @return {boolean}
*/
abutsEnd(other) {
if (!this.isValid) return false;
return +other.e === +this.s;
}
/**
* Return whether this Interval engulfs the start and end of the specified Interval.
* @param {Interval} other
* @return {boolean}
*/
engulfs(other) {
if (!this.isValid) return false;
return this.s <= other.s && this.e >= other.e;
}
/**
* Return whether this Interval has the same start and end as the specified Interval.
* @param {Interval} other
* @return {boolean}
*/
equals(other) {
if (!this.isValid || !other.isValid) {
return false;
}
return this.s.equals(other.s) && this.e.equals(other.e);
}
/**
* Return an Interval representing the intersection of this Interval and the specified Interval.
* Specifically, the resulting Interval has the maximum start time and the minimum end time of the two Intervals.
* Returns null if the intersection is empty, meaning, the intervals don't intersect.
* @param {Interval} other
* @return {Interval}
*/
intersection(other) {
if (!this.isValid) return this;
const s = this.s > other.s ? this.s : other.s,
e = this.e < other.e ? this.e : other.e;
if (s >= e) {
return null;
} else {
return Interval.fromDateTimes(s, e);
}
}
/**
* Return an Interval representing the union of this Interval and the specified Interval.
* Specifically, the resulting Interval has the minimum start time and the maximum end time of the two Intervals.
* @param {Interval} other
* @return {Interval}
*/
union(other) {
if (!this.isValid) return this;
const s = this.s < other.s ? this.s : other.s,
e = this.e > other.e ? this.e : other.e;
return Interval.fromDateTimes(s, e);
}
/**
* Merge an array of Intervals into a equivalent minimal set of Intervals.
* Combines overlapping and adjacent Intervals.
* @param {[Interval]} intervals
* @return {[Interval]}
*/
static merge(intervals) {
const [found, final] = intervals.sort((a, b) => a.s - b.s).reduce(([sofar, current], item) => {
if (!current) {
return [sofar, item];
} else if (current.overlaps(item) || current.abutsStart(item)) {
return [sofar, current.union(item)];
} else {
return [sofar.concat([current]), item];
}
}, [[], null]);
if (final) {
found.push(final);
}
return found;
}
/**
* Return an array of Intervals representing the spans of time that only appear in one of the specified Intervals.
* @param {[Interval]} intervals
* @return {[Interval]}
*/
static xor(intervals) {
let start = null,
currentCount = 0;
const results = [],
ends = intervals.map(i => [{
time: i.s,
type: "s"
}, {
time: i.e,
type: "e"
}]),
flattened = Array.prototype.concat(...ends),
arr = flattened.sort((a, b) => a.time - b.time);
for (const i of arr) {
currentCount += i.type === "s" ? 1 : -1;
if (currentCount === 1) {
start = i.time;
} else {
if (start && +start !== +i.time) {
results.push(Interval.fromDateTimes(start, i.time));
}
start = null;
}
}
return Interval.merge(results);
}
/**
* Return an Interval representing the span of time in this Interval that doesn't overlap with any of the specified Intervals.
* @param {...Interval} intervals
* @return {[Interval]}
*/
difference(...intervals) {
return Interval.xor([this].concat(intervals)).map(i => this.intersection(i)).filter(i => i && !i.isEmpty());
}
/**
* Returns a string representation of this Interval appropriate for debugging.
* @return {string}
*/
toString() {
if (!this.isValid) return INVALID$1;
return `[${this.s.toISO()} ${this.e.toISO()})`;
}
/**
* Returns an ISO 8601-compliant string representation of this Interval.
* @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
* @param {Object} opts - The same options as {@link DateTime.toISO}
* @return {string}
*/
toISO(opts) {
if (!this.isValid) return INVALID$1;
return `${this.s.toISO(opts)}/${this.e.toISO(opts)}`;
}
/**
* Returns an ISO 8601-compliant string representation of date of this Interval.
* The time components are ignored.
* @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
* @return {string}
*/
toISODate() {
if (!this.isValid) return INVALID$1;
return `${this.s.toISODate()}/${this.e.toISODate()}`;
}
/**
* Returns an ISO 8601-compliant string representation of time of this Interval.
* The date components are ignored.
* @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
* @param {Object} opts - The same options as {@link DateTime.toISO}
* @return {string}
*/
toISOTime(opts) {
if (!this.isValid) return INVALID$1;
return `${this.s.toISOTime(opts)}/${this.e.toISOTime(opts)}`;
}
/**
* Returns a string representation of this Interval formatted according to the specified format string.
* @param {string} dateFormat - the format string. This string formats the start and end time. See {@link DateTime.toFormat} for details.
* @param {Object} opts - options
* @param {string} [opts.separator = ' '] - a separator to place between the start and end representations
* @return {string}
*/
toFormat(dateFormat, {
separator = " "
} = {}) {
if (!this.isValid) return INVALID$1;
return `${this.s.toFormat(dateFormat)}${separator}${this.e.toFormat(dateFormat)}`;
}
/**
* Return a Duration representing the time spanned by this interval.
* @param {string|string[]} [unit=['milliseconds']] - the unit or units (such as 'hours' or 'days') to include in the duration.
* @param {Object} opts - options that affect the creation of the Duration
* @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
* @example Interval.fromDateTimes(dt1, dt2).toDuration().toObject() //=> { milliseconds: 88489257 }
* @example Interval.fromDateTimes(dt1, dt2).toDuration('days').toObject() //=> { days: 1.0241812152777778 }
* @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes']).toObject() //=> { hours: 24, minutes: 34.82095 }
* @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes', 'seconds']).toObject() //=> { hours: 24, minutes: 34, seconds: 49.257 }
* @example Interval.fromDateTimes(dt1, dt2).toDuration('seconds').toObject() //=> { seconds: 88489.257 }
* @return {Duration}
*/
toDuration(unit, opts) {
if (!this.isValid) {
return Duration.invalid(this.invalidReason);
}
return this.e.diff(this.s, unit, opts);
}
/**
* Run mapFn on the interval start and end, returning a new Interval from the resulting DateTimes
* @param {function} mapFn
* @return {Interval}
* @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.toUTC())
* @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.plus({ hours: 2 }))
*/
mapEndpoints(mapFn) {
return Interval.fromDateTimes(mapFn(this.s), mapFn(this.e));
}
}
/**
* The Info class contains static methods for retrieving general time and date related data. For example, it has methods for finding out if a time zone has a DST, for listing the months in any supported locale, and for discovering which of Luxon features are available in the current environment.
*/
class Info {
/**
* Return whether the specified zone contains a DST.
* @param {string|Zone} [zone='local'] - Zone to check. Defaults to the environment's local zone.
* @return {boolean}
*/
static hasDST(zone = Settings$1.defaultZone) {
const proto = DateTime.now().setZone(zone).set({
month: 12
});
return !zone.universal && proto.offset !== proto.set({
month: 6
}).offset;
}
/**
* Return whether the specified zone is a valid IANA specifier.
* @param {string} zone - Zone to check
* @return {boolean}
*/
static isValidIANAZone(zone) {
return IANAZone.isValidSpecifier(zone) && IANAZone.isValidZone(zone);
}
/**
* Converts the input into a {@link Zone} instance.
*
* * If `input` is already a Zone instance, it is returned unchanged.
* * If `input` is a string containing a valid time zone name, a Zone instance
* with that name is returned.
* * If `input` is a string that doesn't refer to a known time zone, a Zone
* instance with {@link Zone.isValid} == false is returned.
* * If `input is a number, a Zone instance with the specified fixed offset
* in minutes is returned.
* * If `input` is `null` or `undefined`, the default zone is returned.
* @param {string|Zone|number} [input] - the value to be converted
* @return {Zone}
*/
static normalizeZone(input) {
return normalizeZone(input, Settings$1.defaultZone);
}
/**
* Return an array of standalone month names.
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
* @param {string} [length='long'] - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long"
* @param {Object} opts - options
* @param {string} [opts.locale] - the locale code
* @param {string} [opts.numberingSystem=null] - the numbering system
* @param {string} [opts.locObj=null] - an existing locale object to use
* @param {string} [opts.outputCalendar='gregory'] - the calendar
* @example Info.months()[0] //=> 'January'
* @example Info.months('short')[0] //=> 'Jan'
* @example Info.months('numeric')[0] //=> '1'
* @example Info.months('short', { locale: 'fr-CA' } )[0] //=> 'janv.'
* @example Info.months('numeric', { locale: 'ar' })[0] //=> '١'
* @example Info.months('long', { outputCalendar: 'islamic' })[0] //=> 'Rabiʻ I'
* @return {[string]}
*/
static months(length = "long", {
locale = null,
numberingSystem = null,
locObj = null,
outputCalendar = "gregory"
} = {}) {
return (locObj || Locale.create(locale, numberingSystem, outputCalendar)).months(length);
}
/**
* Return an array of format month names.
* Format months differ from standalone months in that they're meant to appear next to the day of the month. In some languages, that
* changes the string.
* See {@link months}
* @param {string} [length='long'] - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long"
* @param {Object} opts - options
* @param {string} [opts.locale] - the locale code
* @param {string} [opts.numberingSystem=null] - the numbering system
* @param {string} [opts.locObj=null] - an existing locale object to use
* @param {string} [opts.outputCalendar='gregory'] - the calendar
* @return {[string]}
*/
static monthsFormat(length = "long", {
locale = null,
numberingSystem = null,
locObj = null,
outputCalendar = "gregory"
} = {}) {
return (locObj || Locale.create(locale, numberingSystem, outputCalendar)).months(length, true);
}
/**
* Return an array of standalone week names.
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
* @param {string} [length='long'] - the length of the weekday representation, such as "narrow", "short", "long".
* @param {Object} opts - options
* @param {string} [opts.locale] - the locale code
* @param {string} [opts.numberingSystem=null] - the numbering system
* @param {string} [opts.locObj=null] - an existing locale object to use
* @example Info.weekdays()[0] //=> 'Monday'
* @example Info.weekdays('short')[0] //=> 'Mon'
* @example Info.weekdays('short', { locale: 'fr-CA' })[0] //=> 'lun.'
* @example Info.weekdays('short', { locale: 'ar' })[0] //=> 'الاثنين'
* @return {[string]}
*/
static weekdays(length = "long", {
locale = null,
numberingSystem = null,
locObj = null
} = {}) {
return (locObj || Locale.create(locale, numberingSystem, null)).weekdays(length);
}
/**
* Return an array of format week names.
* Format weekdays differ from standalone weekdays in that they're meant to appear next to more date information. In some languages, that
* changes the string.
* See {@link weekdays}
* @param {string} [length='long'] - the length of the weekday representation, such as "narrow", "short", "long".
* @param {Object} opts - options
* @param {string} [opts.locale=null] - the locale code
* @param {string} [opts.numberingSystem=null] - the numbering system
* @param {string} [opts.locObj=null] - an existing locale object to use
* @return {[string]}
*/
static weekdaysFormat(length = "long", {
locale = null,
numberingSystem = null,
locObj = null
} = {}) {
return (locObj || Locale.create(locale, numberingSystem, null)).weekdays(length, true);
}
/**
* Return an array of meridiems.
* @param {Object} opts - options
* @param {string} [opts.locale] - the locale code
* @example Info.meridiems() //=> [ 'AM', 'PM' ]
* @example Info.meridiems({ locale: 'my' }) //=> [ 'နံနက်', 'ညနေ' ]
* @return {[string]}
*/
static meridiems({
locale = null
} = {}) {
return Locale.create(locale).meridiems();
}
/**
* Return an array of eras, such as ['BC', 'AD']. The locale can be specified, but the calendar system is always Gregorian.
* @param {string} [length='short'] - the length of the era representation, such as "short" or "long".
* @param {Object} opts - options
* @param {string} [opts.locale] - the locale code
* @example Info.eras() //=> [ 'BC', 'AD' ]
* @example Info.eras('long') //=> [ 'Before Christ', 'Anno Domini' ]
* @example Info.eras('long', { locale: 'fr' }) //=> [ 'avant Jésus-Christ', 'après Jésus-Christ' ]
* @return {[string]}
*/
static eras(length = "short", {
locale = null
} = {}) {
return Locale.create(locale, null, "gregory").eras(length);
}
/**
* Return the set of available features in this environment.
* Some features of Luxon are not available in all environments. For example, on older browsers, timezone support is not available. Use this function to figure out if that's the case.
* Keys:
* * `zones`: whether this environment supports IANA timezones
* * `intlTokens`: whether this environment supports internationalized token-based formatting/parsing
* * `intl`: whether this environment supports general internationalization
* * `relative`: whether this environment supports relative time formatting
* @example Info.features() //=> { intl: true, intlTokens: false, zones: true, relative: false }
* @return {Object}
*/
static features() {
let intl = false,
intlTokens = false,
zones = false,
relative = false;
if (hasIntl()) {
intl = true;
intlTokens = hasFormatToParts();
relative = hasRelative();
try {
zones = new Intl.DateTimeFormat("en", {
timeZone: "America/New_York"
}).resolvedOptions().timeZone === "America/New_York";
} catch (e) {
zones = false;
}
}
return {
intl,
intlTokens,
zones,
relative
};
}
}
function dayDiff(earlier, later) {
const utcDayStart = dt => dt.toUTC(0, {
keepLocalTime: true
}).startOf("day").valueOf(),
ms = utcDayStart(later) - utcDayStart(earlier);
return Math.floor(Duration.fromMillis(ms).as("days"));
}
function highOrderDiffs(cursor, later, units) {
const differs = [["years", (a, b) => b.year - a.year], ["quarters", (a, b) => b.quarter - a.quarter], ["months", (a, b) => b.month - a.month + (b.year - a.year) * 12], ["weeks", (a, b) => {
const days = dayDiff(a, b);
return (days - days % 7) / 7;
}], ["days", dayDiff]];
const results = {};
let lowestOrder, highWater;
for (const [unit, differ] of differs) {
if (units.indexOf(unit) >= 0) {
lowestOrder = unit;
let delta = differ(cursor, later);
highWater = cursor.plus({
[unit]: delta
});
if (highWater > later) {
cursor = cursor.plus({
[unit]: delta - 1
});
delta -= 1;
} else {
cursor = highWater;
}
results[unit] = delta;
}
}
return [cursor, results, highWater, lowestOrder];
}
function diff (earlier, later, units, opts) {
let [cursor, results, highWater, lowestOrder] = highOrderDiffs(earlier, later, units);
const remainingMillis = later - cursor;
const lowerOrderUnits = units.filter(u => ["hours", "minutes", "seconds", "milliseconds"].indexOf(u) >= 0);
if (lowerOrderUnits.length === 0) {
if (highWater < later) {
highWater = cursor.plus({
[lowestOrder]: 1
});
}
if (highWater !== cursor) {
results[lowestOrder] = (results[lowestOrder] || 0) + remainingMillis / (highWater - cursor);
}
}
const duration = Duration.fromObject(Object.assign(results, opts));
if (lowerOrderUnits.length > 0) {
return Duration.fromMillis(remainingMillis, opts).shiftTo(...lowerOrderUnits).plus(duration);
} else {
return duration;
}
}
const numberingSystems = {
arab: "[\u0660-\u0669]",
arabext: "[\u06F0-\u06F9]",
bali: "[\u1B50-\u1B59]",
beng: "[\u09E6-\u09EF]",
deva: "[\u0966-\u096F]",
fullwide: "[\uFF10-\uFF19]",
gujr: "[\u0AE6-\u0AEF]",
hanidec: "[|一|二|三|四|五|六|七|八|九]",
khmr: "[\u17E0-\u17E9]",
knda: "[\u0CE6-\u0CEF]",
laoo: "[\u0ED0-\u0ED9]",
limb: "[\u1946-\u194F]",
mlym: "[\u0D66-\u0D6F]",
mong: "[\u1810-\u1819]",
mymr: "[\u1040-\u1049]",
orya: "[\u0B66-\u0B6F]",
tamldec: "[\u0BE6-\u0BEF]",
telu: "[\u0C66-\u0C6F]",
thai: "[\u0E50-\u0E59]",
tibt: "[\u0F20-\u0F29]",
latn: "\\d"
};
const numberingSystemsUTF16 = {
arab: [1632, 1641],
arabext: [1776, 1785],
bali: [6992, 7001],
beng: [2534, 2543],
deva: [2406, 2415],
fullwide: [65296, 65303],
gujr: [2790, 2799],
khmr: [6112, 6121],
knda: [3302, 3311],
laoo: [3792, 3801],
limb: [6470, 6479],
mlym: [3430, 3439],
mong: [6160, 6169],
mymr: [4160, 4169],
orya: [2918, 2927],
tamldec: [3046, 3055],
telu: [3174, 3183],
thai: [3664, 3673],
tibt: [3872, 3881]
}; // eslint-disable-next-line
const hanidecChars = numberingSystems.hanidec.replace(/[\[|\]]/g, "").split("");
function parseDigits(str) {
let value = parseInt(str, 10);
if (isNaN(value)) {
value = "";
for (let i = 0; i < str.length; i++) {
const code = str.charCodeAt(i);
if (str[i].search(numberingSystems.hanidec) !== -1) {
value += hanidecChars.indexOf(str[i]);
} else {
for (const key in numberingSystemsUTF16) {
const [min, max] = numberingSystemsUTF16[key];
if (code >= min && code <= max) {
value += code - min;
}
}
}
}
return parseInt(value, 10);
} else {
return value;
}
}
function digitRegex({
numberingSystem
}, append = "") {
return new RegExp(`${numberingSystems[numberingSystem || "latn"]}${append}`);
}
const MISSING_FTP = "missing Intl.DateTimeFormat.formatToParts support";
function intUnit(regex, post = i => i) {
return {
regex,
deser: ([s]) => post(parseDigits(s))
};
}
const NBSP = String.fromCharCode(160);
const spaceOrNBSP = `( |${NBSP})`;
const spaceOrNBSPRegExp = new RegExp(spaceOrNBSP, "g");
function fixListRegex(s) {
// make dots optional and also make them literal
// make space and non breakable space characters interchangeable
return s.replace(/\./g, "\\.?").replace(spaceOrNBSPRegExp, spaceOrNBSP);
}
function stripInsensitivities(s) {
return s.replace(/\./g, "") // ignore dots that were made optional
.replace(spaceOrNBSPRegExp, " ") // interchange space and nbsp
.toLowerCase();
}
function oneOf(strings, startIndex) {
if (strings === null) {
return null;
} else {
return {
regex: RegExp(strings.map(fixListRegex).join("|")),
deser: ([s]) => strings.findIndex(i => stripInsensitivities(s) === stripInsensitivities(i)) + startIndex
};
}
}
function offset(regex, groups) {
return {
regex,
deser: ([, h, m]) => signedOffset(h, m),
groups
};
}
function simple(regex) {
return {
regex,
deser: ([s]) => s
};
}
function escapeToken(value) {
// eslint-disable-next-line no-useless-escape
return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
}
function unitForToken(token, loc) {
const one = digitRegex(loc),
two = digitRegex(loc, "{2}"),
three = digitRegex(loc, "{3}"),
four = digitRegex(loc, "{4}"),
six = digitRegex(loc, "{6}"),
oneOrTwo = digitRegex(loc, "{1,2}"),
oneToThree = digitRegex(loc, "{1,3}"),
oneToSix = digitRegex(loc, "{1,6}"),
oneToNine = digitRegex(loc, "{1,9}"),
twoToFour = digitRegex(loc, "{2,4}"),
fourToSix = digitRegex(loc, "{4,6}"),
literal = t => ({
regex: RegExp(escapeToken(t.val)),
deser: ([s]) => s,
literal: true
}),
unitate = t => {
if (token.literal) {
return literal(t);
}
switch (t.val) {
// era
case "G":
return oneOf(loc.eras("short", false), 0);
case "GG":
return oneOf(loc.eras("long", false), 0);
// years
case "y":
return intUnit(oneToSix);
case "yy":
return intUnit(twoToFour, untruncateYear);
case "yyyy":
return intUnit(four);
case "yyyyy":
return intUnit(fourToSix);
case "yyyyyy":
return intUnit(six);
// months
case "M":
return intUnit(oneOrTwo);
case "MM":
return intUnit(two);
case "MMM":
return oneOf(loc.months("short", true, false), 1);
case "MMMM":
return oneOf(loc.months("long", true, false), 1);
case "L":
return intUnit(oneOrTwo);
case "LL":
return intUnit(two);
case "LLL":
return oneOf(loc.months("short", false, false), 1);
case "LLLL":
return oneOf(loc.months("long", false, false), 1);
// dates
case "d":
return intUnit(oneOrTwo);
case "dd":
return intUnit(two);
// ordinals
case "o":
return intUnit(oneToThree);
case "ooo":
return intUnit(three);
// time
case "HH":
return intUnit(two);
case "H":
return intUnit(oneOrTwo);
case "hh":
return intUnit(two);
case "h":
return intUnit(oneOrTwo);
case "mm":
return intUnit(two);
case "m":
return intUnit(oneOrTwo);
case "q":
return intUnit(oneOrTwo);
case "qq":
return intUnit(two);
case "s":
return intUnit(oneOrTwo);
case "ss":
return intUnit(two);
case "S":
return intUnit(oneToThree);
case "SSS":
return intUnit(three);
case "u":
return simple(oneToNine);
// meridiem
case "a":
return oneOf(loc.meridiems(), 0);
// weekYear (k)
case "kkkk":
return intUnit(four);
case "kk":
return intUnit(twoToFour, untruncateYear);
// weekNumber (W)
case "W":
return intUnit(oneOrTwo);
case "WW":
return intUnit(two);
// weekdays
case "E":
case "c":
return intUnit(one);
case "EEE":
return oneOf(loc.weekdays("short", false, false), 1);
case "EEEE":
return oneOf(loc.weekdays("long", false, false), 1);
case "ccc":
return oneOf(loc.weekdays("short", true, false), 1);
case "cccc":
return oneOf(loc.weekdays("long", true, false), 1);
// offset/zone
case "Z":
case "ZZ":
return offset(new RegExp(`([+-]${oneOrTwo.source})(?::(${two.source}))?`), 2);
case "ZZZ":
return offset(new RegExp(`([+-]${oneOrTwo.source})(${two.source})?`), 2);
// we don't support ZZZZ (PST) or ZZZZZ (Pacific Standard Time) in parsing
// because we don't have any way to figure out what they are
case "z":
return simple(/[a-z_+-/]{1,256}?/i);
default:
return literal(t);
}
};
const unit = unitate(token) || {
invalidReason: MISSING_FTP
};
unit.token = token;
return unit;
}
const partTypeStyleToTokenVal = {
year: {
"2-digit": "yy",
numeric: "yyyyy"
},
month: {
numeric: "M",
"2-digit": "MM",
short: "MMM",
long: "MMMM"
},
day: {
numeric: "d",
"2-digit": "dd"
},
weekday: {
short: "EEE",
long: "EEEE"
},
dayperiod: "a",
dayPeriod: "a",
hour: {
numeric: "h",
"2-digit": "hh"
},
minute: {
numeric: "m",
"2-digit": "mm"
},
second: {
numeric: "s",
"2-digit": "ss"
}
};
function tokenForPart(part, locale, formatOpts) {
const {
type,
value
} = part;
if (type === "literal") {
return {
literal: true,
val: value
};
}
const style = formatOpts[type];
let val = partTypeStyleToTokenVal[type];
if (typeof val === "object") {
val = val[style];
}
if (val) {
return {
literal: false,
val
};
}
return undefined;
}
function buildRegex(units) {
const re = units.map(u => u.regex).reduce((f, r) => `${f}(${r.source})`, "");
return [`^${re}$`, units];
}
function match(input, regex, handlers) {
const matches = input.match(regex);
if (matches) {
const all = {};
let matchIndex = 1;
for (const i in handlers) {
if (hasOwnProperty(handlers, i)) {
const h = handlers[i],
groups = h.groups ? h.groups + 1 : 1;
if (!h.literal && h.token) {
all[h.token.val[0]] = h.deser(matches.slice(matchIndex, matchIndex + groups));
}
matchIndex += groups;
}
}
return [matches, all];
} else {
return [matches, {}];
}
}
function dateTimeFromMatches(matches) {
const toField = token => {
switch (token) {
case "S":
return "millisecond";
case "s":
return "second";
case "m":
return "minute";
case "h":
case "H":
return "hour";
case "d":
return "day";
case "o":
return "ordinal";
case "L":
case "M":
return "month";
case "y":
return "year";
case "E":
case "c":
return "weekday";
case "W":
return "weekNumber";
case "k":
return "weekYear";
case "q":
return "quarter";
default:
return null;
}
};
let zone;
if (!isUndefined(matches.Z)) {
zone = new FixedOffsetZone(matches.Z);
} else if (!isUndefined(matches.z)) {
zone = IANAZone.create(matches.z);
} else {
zone = null;
}
if (!isUndefined(matches.q)) {
matches.M = (matches.q - 1) * 3 + 1;
}
if (!isUndefined(matches.h)) {
if (matches.h < 12 && matches.a === 1) {
matches.h += 12;
} else if (matches.h === 12 && matches.a === 0) {
matches.h = 0;
}
}
if (matches.G === 0 && matches.y) {
matches.y = -matches.y;
}
if (!isUndefined(matches.u)) {
matches.S = parseMillis(matches.u);
}
const vals = Object.keys(matches).reduce((r, k) => {
const f = toField(k);
if (f) {
r[f] = matches[k];
}
return r;
}, {});
return [vals, zone];
}
let dummyDateTimeCache = null;
function getDummyDateTime() {
if (!dummyDateTimeCache) {
dummyDateTimeCache = DateTime.fromMillis(1555555555555);
}
return dummyDateTimeCache;
}
function maybeExpandMacroToken(token, locale) {
if (token.literal) {
return token;
}
const formatOpts = Formatter.macroTokenToFormatOpts(token.val);
if (!formatOpts) {
return token;
}
const formatter = Formatter.create(locale, formatOpts);
const parts = formatter.formatDateTimeParts(getDummyDateTime());
const tokens = parts.map(p => tokenForPart(p, locale, formatOpts));
if (tokens.includes(undefined)) {
return token;
}
return tokens;
}
function expandMacroTokens(tokens, locale) {
return Array.prototype.concat(...tokens.map(t => maybeExpandMacroToken(t, locale)));
}
/**
* @private
*/
function explainFromTokens(locale, input, format) {
const tokens = expandMacroTokens(Formatter.parseFormat(format), locale),
units = tokens.map(t => unitForToken(t, locale)),
disqualifyingUnit = units.find(t => t.invalidReason);
if (disqualifyingUnit) {
return {
input,
tokens,
invalidReason: disqualifyingUnit.invalidReason
};
} else {
const [regexString, handlers] = buildRegex(units),
regex = RegExp(regexString, "i"),
[rawMatches, matches] = match(input, regex, handlers),
[result, zone] = matches ? dateTimeFromMatches(matches) : [null, null];
if (hasOwnProperty(matches, "a") && hasOwnProperty(matches, "H")) {
throw new ConflictingSpecificationError("Can't include meridiem when specifying 24-hour format");
}
return {
input,
tokens,
regex,
rawMatches,
matches,
result,
zone
};
}
}
function parseFromTokens(locale, input, format) {
const {
result,
zone,
invalidReason
} = explainFromTokens(locale, input, format);
return [result, zone, invalidReason];
}
const nonLeapLadder = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334],
leapLadder = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335];
function unitOutOfRange(unit, value) {
return new Invalid("unit out of range", `you specified ${value} (of type ${typeof value}) as a ${unit}, which is invalid`);
}
function dayOfWeek(year, month, day) {
const js = new Date(Date.UTC(year, month - 1, day)).getUTCDay();
return js === 0 ? 7 : js;
}
function computeOrdinal(year, month, day) {
return day + (isLeapYear(year) ? leapLadder : nonLeapLadder)[month - 1];
}
function uncomputeOrdinal(year, ordinal) {
const table = isLeapYear(year) ? leapLadder : nonLeapLadder,
month0 = table.findIndex(i => i < ordinal),
day = ordinal - table[month0];
return {
month: month0 + 1,
day
};
}
/**
* @private
*/
function gregorianToWeek(gregObj) {
const {
year,
month,
day
} = gregObj,
ordinal = computeOrdinal(year, month, day),
weekday = dayOfWeek(year, month, day);
let weekNumber = Math.floor((ordinal - weekday + 10) / 7),
weekYear;
if (weekNumber < 1) {
weekYear = year - 1;
weekNumber = weeksInWeekYear(weekYear);
} else if (weekNumber > weeksInWeekYear(year)) {
weekYear = year + 1;
weekNumber = 1;
} else {
weekYear = year;
}
return Object.assign({
weekYear,
weekNumber,
weekday
}, timeObject(gregObj));
}
function weekToGregorian(weekData) {
const {
weekYear,
weekNumber,
weekday
} = weekData,
weekdayOfJan4 = dayOfWeek(weekYear, 1, 4),
yearInDays = daysInYear(weekYear);
let ordinal = weekNumber * 7 + weekday - weekdayOfJan4 - 3,
year;
if (ordinal < 1) {
year = weekYear - 1;
ordinal += daysInYear(year);
} else if (ordinal > yearInDays) {
year = weekYear + 1;
ordinal -= daysInYear(weekYear);
} else {
year = weekYear;
}
const {
month,
day
} = uncomputeOrdinal(year, ordinal);
return Object.assign({
year,
month,
day
}, timeObject(weekData));
}
function gregorianToOrdinal(gregData) {
const {
year,
month,
day
} = gregData,
ordinal = computeOrdinal(year, month, day);
return Object.assign({
year,
ordinal
}, timeObject(gregData));
}
function ordinalToGregorian(ordinalData) {
const {
year,
ordinal
} = ordinalData,
{
month,
day
} = uncomputeOrdinal(year, ordinal);
return Object.assign({
year,
month,
day
}, timeObject(ordinalData));
}
function hasInvalidWeekData(obj) {
const validYear = isInteger(obj.weekYear),
validWeek = integerBetween(obj.weekNumber, 1, weeksInWeekYear(obj.weekYear)),
validWeekday = integerBetween(obj.weekday, 1, 7);
if (!validYear) {
return unitOutOfRange("weekYear", obj.weekYear);
} else if (!validWeek) {
return unitOutOfRange("week", obj.week);
} else if (!validWeekday) {
return unitOutOfRange("weekday", obj.weekday);
} else return false;
}
function hasInvalidOrdinalData(obj) {
const validYear = isInteger(obj.year),
validOrdinal = integerBetween(obj.ordinal, 1, daysInYear(obj.year));
if (!validYear) {
return unitOutOfRange("year", obj.year);
} else if (!validOrdinal) {
return unitOutOfRange("ordinal", obj.ordinal);
} else return false;
}
function hasInvalidGregorianData(obj) {
const validYear = isInteger(obj.year),
validMonth = integerBetween(obj.month, 1, 12),
validDay = integerBetween(obj.day, 1, daysInMonth(obj.year, obj.month));
if (!validYear) {
return unitOutOfRange("year", obj.year);
} else if (!validMonth) {
return unitOutOfRange("month", obj.month);
} else if (!validDay) {
return unitOutOfRange("day", obj.day);
} else return false;
}
function hasInvalidTimeData(obj) {
const {
hour,
minute,
second,
millisecond
} = obj;
const validHour = integerBetween(hour, 0, 23) || hour === 24 && minute === 0 && second === 0 && millisecond === 0,
validMinute = integerBetween(minute, 0, 59),
validSecond = integerBetween(second, 0, 59),
validMillisecond = integerBetween(millisecond, 0, 999);
if (!validHour) {
return unitOutOfRange("hour", hour);
} else if (!validMinute) {
return unitOutOfRange("minute", minute);
} else if (!validSecond) {
return unitOutOfRange("second", second);
} else if (!validMillisecond) {
return unitOutOfRange("millisecond", millisecond);
} else return false;
}
const INVALID$2 = "Invalid DateTime";
const MAX_DATE = 8.64e15;
function unsupportedZone(zone) {
return new Invalid("unsupported zone", `the zone "${zone.name}" is not supported`);
} // we cache week data on the DT object and this intermediates the cache
function possiblyCachedWeekData(dt) {
if (dt.weekData === null) {
dt.weekData = gregorianToWeek(dt.c);
}
return dt.weekData;
} // clone really means, "make a new object with these modifications". all "setters" really use this
// to create a new object while only changing some of the properties
function clone$1(inst, alts) {
const current = {
ts: inst.ts,
zone: inst.zone,
c: inst.c,
o: inst.o,
loc: inst.loc,
invalid: inst.invalid
};
return new DateTime(Object.assign({}, current, alts, {
old: current
}));
} // find the right offset a given local time. The o input is our guess, which determines which
// offset we'll pick in ambiguous cases (e.g. there are two 3 AMs b/c Fallback DST)
function fixOffset(localTS, o, tz) {
// Our UTC time is just a guess because our offset is just a guess
let utcGuess = localTS - o * 60 * 1000; // Test whether the zone matches the offset for this ts
const o2 = tz.offset(utcGuess); // If so, offset didn't change and we're done
if (o === o2) {
return [utcGuess, o];
} // If not, change the ts by the difference in the offset
utcGuess -= (o2 - o) * 60 * 1000; // If that gives us the local time we want, we're done
const o3 = tz.offset(utcGuess);
if (o2 === o3) {
return [utcGuess, o2];
} // If it's different, we're in a hole time. The offset has changed, but the we don't adjust the time
return [localTS - Math.min(o2, o3) * 60 * 1000, Math.max(o2, o3)];
} // convert an epoch timestamp into a calendar object with the given offset
function tsToObj(ts, offset) {
ts += offset * 60 * 1000;
const d = new Date(ts);
return {
year: d.getUTCFullYear(),
month: d.getUTCMonth() + 1,
day: d.getUTCDate(),
hour: d.getUTCHours(),
minute: d.getUTCMinutes(),
second: d.getUTCSeconds(),
millisecond: d.getUTCMilliseconds()
};
} // convert a calendar object to a epoch timestamp
function objToTS(obj, offset, zone) {
return fixOffset(objToLocalTS(obj), offset, zone);
} // create a new DT instance by adding a duration, adjusting for DSTs
function adjustTime(inst, dur) {
const oPre = inst.o,
year = inst.c.year + Math.trunc(dur.years),
month = inst.c.month + Math.trunc(dur.months) + Math.trunc(dur.quarters) * 3,
c = Object.assign({}, inst.c, {
year,
month,
day: Math.min(inst.c.day, daysInMonth(year, month)) + Math.trunc(dur.days) + Math.trunc(dur.weeks) * 7
}),
millisToAdd = Duration.fromObject({
years: dur.years - Math.trunc(dur.years),
quarters: dur.quarters - Math.trunc(dur.quarters),
months: dur.months - Math.trunc(dur.months),
weeks: dur.weeks - Math.trunc(dur.weeks),
days: dur.days - Math.trunc(dur.days),
hours: dur.hours,
minutes: dur.minutes,
seconds: dur.seconds,
milliseconds: dur.milliseconds
}).as("milliseconds"),
localTS = objToLocalTS(c);
let [ts, o] = fixOffset(localTS, oPre, inst.zone);
if (millisToAdd !== 0) {
ts += millisToAdd; // that could have changed the offset by going over a DST, but we want to keep the ts the same
o = inst.zone.offset(ts);
}
return {
ts,
o
};
} // helper useful in turning the results of parsing into real dates
// by handling the zone options
function parseDataToDateTime(parsed, parsedZone, opts, format, text) {
const {
setZone,
zone
} = opts;
if (parsed && Object.keys(parsed).length !== 0) {
const interpretationZone = parsedZone || zone,
inst = DateTime.fromObject(Object.assign(parsed, opts, {
zone: interpretationZone,
// setZone is a valid option in the calling methods, but not in fromObject
setZone: undefined
}));
return setZone ? inst : inst.setZone(zone);
} else {
return DateTime.invalid(new Invalid("unparsable", `the input "${text}" can't be parsed as ${format}`));
}
} // if you want to output a technical format (e.g. RFC 2822), this helper
// helps handle the details
function toTechFormat(dt, format, allowZ = true) {
return dt.isValid ? Formatter.create(Locale.create("en-US"), {
allowZ,
forceSimple: true
}).formatDateTimeFromString(dt, format) : null;
} // technical time formats (e.g. the time part of ISO 8601), take some options
// and this commonizes their handling
function toTechTimeFormat(dt, {
suppressSeconds = false,
suppressMilliseconds = false,
includeOffset,
includePrefix = false,
includeZone = false,
spaceZone = false,
format = "extended"
}) {
let fmt = format === "basic" ? "HHmm" : "HH:mm";
if (!suppressSeconds || dt.second !== 0 || dt.millisecond !== 0) {
fmt += format === "basic" ? "ss" : ":ss";
if (!suppressMilliseconds || dt.millisecond !== 0) {
fmt += ".SSS";
}
}
if ((includeZone || includeOffset) && spaceZone) {
fmt += " ";
}
if (includeZone) {
fmt += "z";
} else if (includeOffset) {
fmt += format === "basic" ? "ZZZ" : "ZZ";
}
let str = toTechFormat(dt, fmt);
if (includePrefix) {
str = "T" + str;
}
return str;
} // defaults for unspecified units in the supported calendars
const defaultUnitValues = {
month: 1,
day: 1,
hour: 0,
minute: 0,
second: 0,
millisecond: 0
},
defaultWeekUnitValues = {
weekNumber: 1,
weekday: 1,
hour: 0,
minute: 0,
second: 0,
millisecond: 0
},
defaultOrdinalUnitValues = {
ordinal: 1,
hour: 0,
minute: 0,
second: 0,
millisecond: 0
}; // Units in the supported calendars, sorted by bigness
const orderedUnits$1 = ["year", "month", "day", "hour", "minute", "second", "millisecond"],
orderedWeekUnits = ["weekYear", "weekNumber", "weekday", "hour", "minute", "second", "millisecond"],
orderedOrdinalUnits = ["year", "ordinal", "hour", "minute", "second", "millisecond"]; // standardize case and plurality in units
function normalizeUnit(unit) {
const normalized = {
year: "year",
years: "year",
month: "month",
months: "month",
day: "day",
days: "day",
hour: "hour",
hours: "hour",
minute: "minute",
minutes: "minute",
quarter: "quarter",
quarters: "quarter",
second: "second",
seconds: "second",
millisecond: "millisecond",
milliseconds: "millisecond",
weekday: "weekday",
weekdays: "weekday",
weeknumber: "weekNumber",
weeksnumber: "weekNumber",
weeknumbers: "weekNumber",
weekyear: "weekYear",
weekyears: "weekYear",
ordinal: "ordinal"
}[unit.toLowerCase()];
if (!normalized) throw new InvalidUnitError(unit);
return normalized;
} // this is a dumbed down version of fromObject() that runs about 60% faster
// but doesn't do any validation, makes a bunch of assumptions about what units
// are present, and so on.
function quickDT(obj, zone) {
// assume we have the higher-order units
for (const u of orderedUnits$1) {
if (isUndefined(obj[u])) {
obj[u] = defaultUnitValues[u];
}
}
const invalid = hasInvalidGregorianData(obj) || hasInvalidTimeData(obj);
if (invalid) {
return DateTime.invalid(invalid);
}
const tsNow = Settings$1.now(),
offsetProvis = zone.offset(tsNow),
[ts, o] = objToTS(obj, offsetProvis, zone);
return new DateTime({
ts,
zone,
o
});
}
function diffRelative(start, end, opts) {
const round = isUndefined(opts.round) ? true : opts.round,
format = (c, unit) => {
c = roundTo(c, round || opts.calendary ? 0 : 2, true);
const formatter = end.loc.clone(opts).relFormatter(opts);
return formatter.format(c, unit);
},
differ = unit => {
if (opts.calendary) {
if (!end.hasSame(start, unit)) {
return end.startOf(unit).diff(start.startOf(unit), unit).get(unit);
} else return 0;
} else {
return end.diff(start, unit).get(unit);
}
};
if (opts.unit) {
return format(differ(opts.unit), opts.unit);
}
for (const unit of opts.units) {
const count = differ(unit);
if (Math.abs(count) >= 1) {
return format(count, unit);
}
}
return format(start > end ? -0 : 0, opts.units[opts.units.length - 1]);
}
/**
* A DateTime is an immutable data structure representing a specific date and time and accompanying methods. It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them.
*
* A DateTime comprises of:
* * A timestamp. Each DateTime instance refers to a specific millisecond of the Unix epoch.
* * A time zone. Each instance is considered in the context of a specific zone (by default the local system's zone).
* * Configuration properties that effect how output strings are formatted, such as `locale`, `numberingSystem`, and `outputCalendar`.
*
* Here is a brief overview of the most commonly used functionality it provides:
*
* * **Creation**: To create a DateTime from its components, use one of its factory class methods: {@link local}, {@link utc}, and (most flexibly) {@link fromObject}. To create one from a standard string format, use {@link fromISO}, {@link fromHTTP}, and {@link fromRFC2822}. To create one from a custom string format, use {@link fromFormat}. To create one from a native JS date, use {@link fromJSDate}.
* * **Gregorian calendar and time**: To examine the Gregorian properties of a DateTime individually (i.e as opposed to collectively through {@link toObject}), use the {@link year}, {@link month},
* {@link day}, {@link hour}, {@link minute}, {@link second}, {@link millisecond} accessors.
* * **Week calendar**: For ISO week calendar attributes, see the {@link weekYear}, {@link weekNumber}, and {@link weekday} accessors.
* * **Configuration** See the {@link locale} and {@link numberingSystem} accessors.
* * **Transformation**: To transform the DateTime into other DateTimes, use {@link set}, {@link reconfigure}, {@link setZone}, {@link setLocale}, {@link plus}, {@link minus}, {@link endOf}, {@link startOf}, {@link toUTC}, and {@link toLocal}.
* * **Output**: To convert the DateTime to other representations, use the {@link toRelative}, {@link toRelativeCalendar}, {@link toJSON}, {@link toISO}, {@link toHTTP}, {@link toObject}, {@link toRFC2822}, {@link toString}, {@link toLocaleString}, {@link toFormat}, {@link toMillis} and {@link toJSDate}.
*
* There's plenty others documented below. In addition, for more information on subtler topics like internationalization, time zones, alternative calendars, validity, and so on, see the external documentation.
*/
class DateTime {
/**
* @access private
*/
constructor(config) {
const zone = config.zone || Settings$1.defaultZone;
let invalid = config.invalid || (Number.isNaN(config.ts) ? new Invalid("invalid input") : null) || (!zone.isValid ? unsupportedZone(zone) : null);
/**
* @access private
*/
this.ts = isUndefined(config.ts) ? Settings$1.now() : config.ts;
let c = null,
o = null;
if (!invalid) {
const unchanged = config.old && config.old.ts === this.ts && config.old.zone.equals(zone);
if (unchanged) {
[c, o] = [config.old.c, config.old.o];
} else {
const ot = zone.offset(this.ts);
c = tsToObj(this.ts, ot);
invalid = Number.isNaN(c.year) ? new Invalid("invalid input") : null;
c = invalid ? null : c;
o = invalid ? null : ot;
}
}
/**
* @access private
*/
this._zone = zone;
/**
* @access private
*/
this.loc = config.loc || Locale.create();
/**
* @access private
*/
this.invalid = invalid;
/**
* @access private
*/
this.weekData = null;
/**
* @access private
*/
this.c = c;
/**
* @access private
*/
this.o = o;
/**
* @access private
*/
this.isLuxonDateTime = true;
} // CONSTRUCT
/**
* Create a DateTime for the current instant, in the system's time zone.
*
* Use Settings to override these default values if needed.
* @example DateTime.now().toISO() //~> now in the ISO format
* @return {DateTime}
*/
static now() {
return new DateTime({});
}
/**
* Create a local DateTime
* @param {number} [year] - The calendar year. If omitted (as in, call `local()` with no arguments), the current time will be used
* @param {number} [month=1] - The month, 1-indexed
* @param {number} [day=1] - The day of the month, 1-indexed
* @param {number} [hour=0] - The hour of the day, in 24-hour time
* @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59
* @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59
* @param {number} [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999
* @example DateTime.local() //~> now
* @example DateTime.local(2017) //~> 2017-01-01T00:00:00
* @example DateTime.local(2017, 3) //~> 2017-03-01T00:00:00
* @example DateTime.local(2017, 3, 12) //~> 2017-03-12T00:00:00
* @example DateTime.local(2017, 3, 12, 5) //~> 2017-03-12T05:00:00
* @example DateTime.local(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00
* @example DateTime.local(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10
* @example DateTime.local(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765
* @return {DateTime}
*/
static local(year, month, day, hour, minute, second, millisecond) {
if (isUndefined(year)) {
return DateTime.now();
} else {
return quickDT({
year,
month,
day,
hour,
minute,
second,
millisecond
}, Settings$1.defaultZone);
}
}
/**
* Create a DateTime in UTC
* @param {number} [year] - The calendar year. If omitted (as in, call `utc()` with no arguments), the current time will be used
* @param {number} [month=1] - The month, 1-indexed
* @param {number} [day=1] - The day of the month
* @param {number} [hour=0] - The hour of the day, in 24-hour time
* @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59
* @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59
* @param {number} [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999
* @example DateTime.utc() //~> now
* @example DateTime.utc(2017) //~> 2017-01-01T00:00:00Z
* @example DateTime.utc(2017, 3) //~> 2017-03-01T00:00:00Z
* @example DateTime.utc(2017, 3, 12) //~> 2017-03-12T00:00:00Z
* @example DateTime.utc(2017, 3, 12, 5) //~> 2017-03-12T05:00:00Z
* @example DateTime.utc(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00Z
* @example DateTime.utc(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10Z
* @example DateTime.utc(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765Z
* @return {DateTime}
*/
static utc(year, month, day, hour, minute, second, millisecond) {
if (isUndefined(year)) {
return new DateTime({
ts: Settings$1.now(),
zone: FixedOffsetZone.utcInstance
});
} else {
return quickDT({
year,
month,
day,
hour,
minute,
second,
millisecond
}, FixedOffsetZone.utcInstance);
}
}
/**
* Create a DateTime from a JavaScript Date object. Uses the default zone.
* @param {Date} date - a JavaScript Date object
* @param {Object} options - configuration options for the DateTime
* @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
* @return {DateTime}
*/
static fromJSDate(date, options = {}) {
const ts = isDate(date) ? date.valueOf() : NaN;
if (Number.isNaN(ts)) {
return DateTime.invalid("invalid input");
}
const zoneToUse = normalizeZone(options.zone, Settings$1.defaultZone);
if (!zoneToUse.isValid) {
return DateTime.invalid(unsupportedZone(zoneToUse));
}
return new DateTime({
ts: ts,
zone: zoneToUse,
loc: Locale.fromObject(options)
});
}
/**
* Create a DateTime from a number of milliseconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
* @param {number} milliseconds - a number of milliseconds since 1970 UTC
* @param {Object} options - configuration options for the DateTime
* @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
* @param {string} [options.locale] - a locale to set on the resulting DateTime instance
* @param {string} options.outputCalendar - the output calendar to set on the resulting DateTime instance
* @param {string} options.numberingSystem - the numbering system to set on the resulting DateTime instance
* @return {DateTime}
*/
static fromMillis(milliseconds, options = {}) {
if (!isNumber(milliseconds)) {
throw new InvalidArgumentError(`fromMillis requires a numerical input, but received a ${typeof milliseconds} with value ${milliseconds}`);
} else if (milliseconds < -MAX_DATE || milliseconds > MAX_DATE) {
// this isn't perfect because because we can still end up out of range because of additional shifting, but it's a start
return DateTime.invalid("Timestamp out of range");
} else {
return new DateTime({
ts: milliseconds,
zone: normalizeZone(options.zone, Settings$1.defaultZone),
loc: Locale.fromObject(options)
});
}
}
/**
* Create a DateTime from a number of seconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
* @param {number} seconds - a number of seconds since 1970 UTC
* @param {Object} options - configuration options for the DateTime
* @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
* @param {string} [options.locale] - a locale to set on the resulting DateTime instance
* @param {string} options.outputCalendar - the output calendar to set on the resulting DateTime instance
* @param {string} options.numberingSystem - the numbering system to set on the resulting DateTime instance
* @return {DateTime}
*/
static fromSeconds(seconds, options = {}) {
if (!isNumber(seconds)) {
throw new InvalidArgumentError("fromSeconds requires a numerical input");
} else {
return new DateTime({
ts: seconds * 1000,
zone: normalizeZone(options.zone, Settings$1.defaultZone),
loc: Locale.fromObject(options)
});
}
}
/**
* Create a DateTime from a JavaScript object with keys like 'year' and 'hour' with reasonable defaults.
* @param {Object} obj - the object to create the DateTime from
* @param {number} obj.year - a year, such as 1987
* @param {number} obj.month - a month, 1-12
* @param {number} obj.day - a day of the month, 1-31, depending on the month
* @param {number} obj.ordinal - day of the year, 1-365 or 366
* @param {number} obj.weekYear - an ISO week year
* @param {number} obj.weekNumber - an ISO week number, between 1 and 52 or 53, depending on the year
* @param {number} obj.weekday - an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
* @param {number} obj.hour - hour of the day, 0-23
* @param {number} obj.minute - minute of the hour, 0-59
* @param {number} obj.second - second of the minute, 0-59
* @param {number} obj.millisecond - millisecond of the second, 0-999
* @param {string|Zone} [obj.zone='local'] - interpret the numbers in the context of a particular zone. Can take any value taken as the first argument to setZone()
* @param {string} [obj.locale='system's locale'] - a locale to set on the resulting DateTime instance
* @param {string} obj.outputCalendar - the output calendar to set on the resulting DateTime instance
* @param {string} obj.numberingSystem - the numbering system to set on the resulting DateTime instance
* @example DateTime.fromObject({ year: 1982, month: 5, day: 25}).toISODate() //=> '1982-05-25'
* @example DateTime.fromObject({ year: 1982 }).toISODate() //=> '1982-01-01'
* @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }) //~> today at 10:26:06
* @example DateTime.fromObject({ hour: 10, minute: 26, second: 6, zone: 'utc' }),
* @example DateTime.fromObject({ hour: 10, minute: 26, second: 6, zone: 'local' })
* @example DateTime.fromObject({ hour: 10, minute: 26, second: 6, zone: 'America/New_York' })
* @example DateTime.fromObject({ weekYear: 2016, weekNumber: 2, weekday: 3 }).toISODate() //=> '2016-01-13'
* @return {DateTime}
*/
static fromObject(obj) {
const zoneToUse = normalizeZone(obj.zone, Settings$1.defaultZone);
if (!zoneToUse.isValid) {
return DateTime.invalid(unsupportedZone(zoneToUse));
}
const tsNow = Settings$1.now(),
offsetProvis = zoneToUse.offset(tsNow),
normalized = normalizeObject(obj, normalizeUnit, ["zone", "locale", "outputCalendar", "numberingSystem"]),
containsOrdinal = !isUndefined(normalized.ordinal),
containsGregorYear = !isUndefined(normalized.year),
containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
containsGregor = containsGregorYear || containsGregorMD,
definiteWeekDef = normalized.weekYear || normalized.weekNumber,
loc = Locale.fromObject(obj); // cases:
// just a weekday -> this week's instance of that weekday, no worries
// (gregorian data or ordinal) + (weekYear or weekNumber) -> error
// (gregorian month or day) + ordinal -> error
// otherwise just use weeks or ordinals or gregorian, depending on what's specified
if ((containsGregor || containsOrdinal) && definiteWeekDef) {
throw new ConflictingSpecificationError("Can't mix weekYear/weekNumber units with year/month/day or ordinals");
}
if (containsGregorMD && containsOrdinal) {
throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day");
}
const useWeekData = definiteWeekDef || normalized.weekday && !containsGregor; // configure ourselves to deal with gregorian dates or week stuff
let units,
defaultValues,
objNow = tsToObj(tsNow, offsetProvis);
if (useWeekData) {
units = orderedWeekUnits;
defaultValues = defaultWeekUnitValues;
objNow = gregorianToWeek(objNow);
} else if (containsOrdinal) {
units = orderedOrdinalUnits;
defaultValues = defaultOrdinalUnitValues;
objNow = gregorianToOrdinal(objNow);
} else {
units = orderedUnits$1;
defaultValues = defaultUnitValues;
} // set default values for missing stuff
let foundFirst = false;
for (const u of units) {
const v = normalized[u];
if (!isUndefined(v)) {
foundFirst = true;
} else if (foundFirst) {
normalized[u] = defaultValues[u];
} else {
normalized[u] = objNow[u];
}
} // make sure the values we have are in range
const higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized),
invalid = higherOrderInvalid || hasInvalidTimeData(normalized);
if (invalid) {
return DateTime.invalid(invalid);
} // compute the actual time
const gregorian = useWeekData ? weekToGregorian(normalized) : containsOrdinal ? ordinalToGregorian(normalized) : normalized,
[tsFinal, offsetFinal] = objToTS(gregorian, offsetProvis, zoneToUse),
inst = new DateTime({
ts: tsFinal,
zone: zoneToUse,
o: offsetFinal,
loc
}); // gregorian data + weekday serves only to validate
if (normalized.weekday && containsGregor && obj.weekday !== inst.weekday) {
return DateTime.invalid("mismatched weekday", `you can't specify both a weekday of ${normalized.weekday} and a date of ${inst.toISO()}`);
}
return inst;
}
/**
* Create a DateTime from an ISO 8601 string
* @param {string} text - the ISO string
* @param {Object} opts - options to affect the creation
* @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the time to this zone
* @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one
* @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
* @param {string} [opts.outputCalendar] - the output calendar to set on the resulting DateTime instance
* @param {string} [opts.numberingSystem] - the numbering system to set on the resulting DateTime instance
* @example DateTime.fromISO('2016-05-25T09:08:34.123')
* @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00')
* @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true})
* @example DateTime.fromISO('2016-05-25T09:08:34.123', {zone: 'utc'})
* @example DateTime.fromISO('2016-W05-4')
* @return {DateTime}
*/
static fromISO(text, opts = {}) {
const [vals, parsedZone] = parseISODate(text);
return parseDataToDateTime(vals, parsedZone, opts, "ISO 8601", text);
}
/**
* Create a DateTime from an RFC 2822 string
* @param {string} text - the RFC 2822 string
* @param {Object} opts - options to affect the creation
* @param {string|Zone} [opts.zone='local'] - convert the time to this zone. Since the offset is always specified in the string itself, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in.
* @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one
* @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
* @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
* @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
* @example DateTime.fromRFC2822('25 Nov 2016 13:23:12 GMT')
* @example DateTime.fromRFC2822('Fri, 25 Nov 2016 13:23:12 +0600')
* @example DateTime.fromRFC2822('25 Nov 2016 13:23 Z')
* @return {DateTime}
*/
static fromRFC2822(text, opts = {}) {
const [vals, parsedZone] = parseRFC2822Date(text);
return parseDataToDateTime(vals, parsedZone, opts, "RFC 2822", text);
}
/**
* Create a DateTime from an HTTP header date
* @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
* @param {string} text - the HTTP header date
* @param {Object} opts - options to affect the creation
* @param {string|Zone} [opts.zone='local'] - convert the time to this zone. Since HTTP dates are always in UTC, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in.
* @param {boolean} [opts.setZone=false] - override the zone with the fixed-offset zone specified in the string. For HTTP dates, this is always UTC, so this option is equivalent to setting the `zone` option to 'utc', but this option is included for consistency with similar methods.
* @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
* @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
* @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
* @example DateTime.fromHTTP('Sun, 06 Nov 1994 08:49:37 GMT')
* @example DateTime.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT')
* @example DateTime.fromHTTP('Sun Nov 6 08:49:37 1994')
* @return {DateTime}
*/
static fromHTTP(text, opts = {}) {
const [vals, parsedZone] = parseHTTPDate(text);
return parseDataToDateTime(vals, parsedZone, opts, "HTTP", opts);
}
/**
* Create a DateTime from an input string and format string.
* Defaults to en-US if no locale has been specified, regardless of the system's locale.
* @see https://moment.github.io/luxon/docs/manual/parsing.html#table-of-tokens
* @param {string} text - the string to parse
* @param {string} fmt - the format the string is expected to be in (see the link below for the formats)
* @param {Object} opts - options to affect the creation
* @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone
* @param {boolean} [opts.setZone=false] - override the zone with a zone specified in the string itself, if it specifies one
* @param {string} [opts.locale='en-US'] - a locale string to use when parsing. Will also set the DateTime to this locale
* @param {string} opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
* @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
* @return {DateTime}
*/
static fromFormat(text, fmt, opts = {}) {
if (isUndefined(text) || isUndefined(fmt)) {
throw new InvalidArgumentError("fromFormat requires an input string and a format");
}
const {
locale = null,
numberingSystem = null
} = opts,
localeToUse = Locale.fromOpts({
locale,
numberingSystem,
defaultToEN: true
}),
[vals, parsedZone, invalid] = parseFromTokens(localeToUse, text, fmt);
if (invalid) {
return DateTime.invalid(invalid);
} else {
return parseDataToDateTime(vals, parsedZone, opts, `format ${fmt}`, text);
}
}
/**
* @deprecated use fromFormat instead
*/
static fromString(text, fmt, opts = {}) {
return DateTime.fromFormat(text, fmt, opts);
}
/**
* Create a DateTime from a SQL date, time, or datetime
* Defaults to en-US if no locale has been specified, regardless of the system's locale
* @param {string} text - the string to parse
* @param {Object} opts - options to affect the creation
* @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone
* @param {boolean} [opts.setZone=false] - override the zone with a zone specified in the string itself, if it specifies one
* @param {string} [opts.locale='en-US'] - a locale string to use when parsing. Will also set the DateTime to this locale
* @param {string} opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
* @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
* @example DateTime.fromSQL('2017-05-15')
* @example DateTime.fromSQL('2017-05-15 09:12:34')
* @example DateTime.fromSQL('2017-05-15 09:12:34.342')
* @example DateTime.fromSQL('2017-05-15 09:12:34.342+06:00')
* @example DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles')
* @example DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles', { setZone: true })
* @example DateTime.fromSQL('2017-05-15 09:12:34.342', { zone: 'America/Los_Angeles' })
* @example DateTime.fromSQL('09:12:34.342')
* @return {DateTime}
*/
static fromSQL(text, opts = {}) {
const [vals, parsedZone] = parseSQL(text);
return parseDataToDateTime(vals, parsedZone, opts, "SQL", text);
}
/**
* Create an invalid DateTime.
* @param {string} reason - simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent
* @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information
* @return {DateTime}
*/
static invalid(reason, explanation = null) {
if (!reason) {
throw new InvalidArgumentError("need to specify a reason the DateTime is invalid");
}
const invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
if (Settings$1.throwOnInvalid) {
throw new InvalidDateTimeError(invalid);
} else {
return new DateTime({
invalid
});
}
}
/**
* Check if an object is a DateTime. Works across context boundaries
* @param {object} o
* @return {boolean}
*/
static isDateTime(o) {
return o && o.isLuxonDateTime || false;
} // INFO
/**
* Get the value of unit.
* @param {string} unit - a unit such as 'minute' or 'day'
* @example DateTime.local(2017, 7, 4).get('month'); //=> 7
* @example DateTime.local(2017, 7, 4).get('day'); //=> 4
* @return {number}
*/
get(unit) {
return this[unit];
}
/**
* Returns whether the DateTime is valid. Invalid DateTimes occur when:
* * The DateTime was created from invalid calendar information, such as the 13th month or February 30
* * The DateTime was created by an operation on another invalid date
* @type {boolean}
*/
get isValid() {
return this.invalid === null;
}
/**
* Returns an error code if this DateTime is invalid, or null if the DateTime is valid
* @type {string}
*/
get invalidReason() {
return this.invalid ? this.invalid.reason : null;
}
/**
* Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid
* @type {string}
*/
get invalidExplanation() {
return this.invalid ? this.invalid.explanation : null;
}
/**
* Get the locale of a DateTime, such 'en-GB'. The locale is used when formatting the DateTime
*
* @type {string}
*/
get locale() {
return this.isValid ? this.loc.locale : null;
}
/**
* Get the numbering system of a DateTime, such 'beng'. The numbering system is used when formatting the DateTime
*
* @type {string}
*/
get numberingSystem() {
return this.isValid ? this.loc.numberingSystem : null;
}
/**
* Get the output calendar of a DateTime, such 'islamic'. The output calendar is used when formatting the DateTime
*
* @type {string}
*/
get outputCalendar() {
return this.isValid ? this.loc.outputCalendar : null;
}
/**
* Get the time zone associated with this DateTime.
* @type {Zone}
*/
get zone() {
return this._zone;
}
/**
* Get the name of the time zone.
* @type {string}
*/
get zoneName() {
return this.isValid ? this.zone.name : null;
}
/**
* Get the year
* @example DateTime.local(2017, 5, 25).year //=> 2017
* @type {number}
*/
get year() {
return this.isValid ? this.c.year : NaN;
}
/**
* Get the quarter
* @example DateTime.local(2017, 5, 25).quarter //=> 2
* @type {number}
*/
get quarter() {
return this.isValid ? Math.ceil(this.c.month / 3) : NaN;
}
/**
* Get the month (1-12).
* @example DateTime.local(2017, 5, 25).month //=> 5
* @type {number}
*/
get month() {
return this.isValid ? this.c.month : NaN;
}
/**
* Get the day of the month (1-30ish).
* @example DateTime.local(2017, 5, 25).day //=> 25
* @type {number}
*/
get day() {
return this.isValid ? this.c.day : NaN;
}
/**
* Get the hour of the day (0-23).
* @example DateTime.local(2017, 5, 25, 9).hour //=> 9
* @type {number}
*/
get hour() {
return this.isValid ? this.c.hour : NaN;
}
/**
* Get the minute of the hour (0-59).
* @example DateTime.local(2017, 5, 25, 9, 30).minute //=> 30
* @type {number}
*/
get minute() {
return this.isValid ? this.c.minute : NaN;
}
/**
* Get the second of the minute (0-59).
* @example DateTime.local(2017, 5, 25, 9, 30, 52).second //=> 52
* @type {number}
*/
get second() {
return this.isValid ? this.c.second : NaN;
}
/**
* Get the millisecond of the second (0-999).
* @example DateTime.local(2017, 5, 25, 9, 30, 52, 654).millisecond //=> 654
* @type {number}
*/
get millisecond() {
return this.isValid ? this.c.millisecond : NaN;
}
/**
* Get the week year
* @see https://en.wikipedia.org/wiki/ISO_week_date
* @example DateTime.local(2014, 12, 31).weekYear //=> 2015
* @type {number}
*/
get weekYear() {
return this.isValid ? possiblyCachedWeekData(this).weekYear : NaN;
}
/**
* Get the week number of the week year (1-52ish).
* @see https://en.wikipedia.org/wiki/ISO_week_date
* @example DateTime.local(2017, 5, 25).weekNumber //=> 21
* @type {number}
*/
get weekNumber() {
return this.isValid ? possiblyCachedWeekData(this).weekNumber : NaN;
}
/**
* Get the day of the week.
* 1 is Monday and 7 is Sunday
* @see https://en.wikipedia.org/wiki/ISO_week_date
* @example DateTime.local(2014, 11, 31).weekday //=> 4
* @type {number}
*/
get weekday() {
return this.isValid ? possiblyCachedWeekData(this).weekday : NaN;
}
/**
* Get the ordinal (meaning the day of the year)
* @example DateTime.local(2017, 5, 25).ordinal //=> 145
* @type {number|DateTime}
*/
get ordinal() {
return this.isValid ? gregorianToOrdinal(this.c).ordinal : NaN;
}
/**
* Get the human readable short month name, such as 'Oct'.
* Defaults to the system's locale if no locale has been specified
* @example DateTime.local(2017, 10, 30).monthShort //=> Oct
* @type {string}
*/
get monthShort() {
return this.isValid ? Info.months("short", {
locObj: this.loc
})[this.month - 1] : null;
}
/**
* Get the human readable long month name, such as 'October'.
* Defaults to the system's locale if no locale has been specified
* @example DateTime.local(2017, 10, 30).monthLong //=> October
* @type {string}
*/
get monthLong() {
return this.isValid ? Info.months("long", {
locObj: this.loc
})[this.month - 1] : null;
}
/**
* Get the human readable short weekday, such as 'Mon'.
* Defaults to the system's locale if no locale has been specified
* @example DateTime.local(2017, 10, 30).weekdayShort //=> Mon
* @type {string}
*/
get weekdayShort() {
return this.isValid ? Info.weekdays("short", {
locObj: this.loc
})[this.weekday - 1] : null;
}
/**
* Get the human readable long weekday, such as 'Monday'.
* Defaults to the system's locale if no locale has been specified
* @example DateTime.local(2017, 10, 30).weekdayLong //=> Monday
* @type {string}
*/
get weekdayLong() {
return this.isValid ? Info.weekdays("long", {
locObj: this.loc
})[this.weekday - 1] : null;
}
/**
* Get the UTC offset of this DateTime in minutes
* @example DateTime.now().offset //=> -240
* @example DateTime.utc().offset //=> 0
* @type {number}
*/
get offset() {
return this.isValid ? +this.o : NaN;
}
/**
* Get the short human name for the zone's current offset, for example "EST" or "EDT".
* Defaults to the system's locale if no locale has been specified
* @type {string}
*/
get offsetNameShort() {
if (this.isValid) {
return this.zone.offsetName(this.ts, {
format: "short",
locale: this.locale
});
} else {
return null;
}
}
/**
* Get the long human name for the zone's current offset, for example "Eastern Standard Time" or "Eastern Daylight Time".
* Defaults to the system's locale if no locale has been specified
* @type {string}
*/
get offsetNameLong() {
if (this.isValid) {
return this.zone.offsetName(this.ts, {
format: "long",
locale: this.locale
});
} else {
return null;
}
}
/**
* Get whether this zone's offset ever changes, as in a DST.
* @type {boolean}
*/
get isOffsetFixed() {
return this.isValid ? this.zone.universal : null;
}
/**
* Get whether the DateTime is in a DST.
* @type {boolean}
*/
get isInDST() {
if (this.isOffsetFixed) {
return false;
} else {
return this.offset > this.set({
month: 1
}).offset || this.offset > this.set({
month: 5
}).offset;
}
}
/**
* Returns true if this DateTime is in a leap year, false otherwise
* @example DateTime.local(2016).isInLeapYear //=> true
* @example DateTime.local(2013).isInLeapYear //=> false
* @type {boolean}
*/
get isInLeapYear() {
return isLeapYear(this.year);
}
/**
* Returns the number of days in this DateTime's month
* @example DateTime.local(2016, 2).daysInMonth //=> 29
* @example DateTime.local(2016, 3).daysInMonth //=> 31
* @type {number}
*/
get daysInMonth() {
return daysInMonth(this.year, this.month);
}
/**
* Returns the number of days in this DateTime's year
* @example DateTime.local(2016).daysInYear //=> 366
* @example DateTime.local(2013).daysInYear //=> 365
* @type {number}
*/
get daysInYear() {
return this.isValid ? daysInYear(this.year) : NaN;
}
/**
* Returns the number of weeks in this DateTime's year
* @see https://en.wikipedia.org/wiki/ISO_week_date
* @example DateTime.local(2004).weeksInWeekYear //=> 53
* @example DateTime.local(2013).weeksInWeekYear //=> 52
* @type {number}
*/
get weeksInWeekYear() {
return this.isValid ? weeksInWeekYear(this.weekYear) : NaN;
}
/**
* Returns the resolved Intl options for this DateTime.
* This is useful in understanding the behavior of formatting methods
* @param {Object} opts - the same options as toLocaleString
* @return {Object}
*/
resolvedLocaleOpts(opts = {}) {
const {
locale,
numberingSystem,
calendar
} = Formatter.create(this.loc.clone(opts), opts).resolvedOptions(this);
return {
locale,
numberingSystem,
outputCalendar: calendar
};
} // TRANSFORM
/**
* "Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime.
*
* Equivalent to {@link setZone}('utc')
* @param {number} [offset=0] - optionally, an offset from UTC in minutes
* @param {Object} [opts={}] - options to pass to `setZone()`
* @return {DateTime}
*/
toUTC(offset = 0, opts = {}) {
return this.setZone(FixedOffsetZone.instance(offset), opts);
}
/**
* "Set" the DateTime's zone to the host's local zone. Returns a newly-constructed DateTime.
*
* Equivalent to `setZone('local')`
* @return {DateTime}
*/
toLocal() {
return this.setZone(Settings$1.defaultZone);
}
/**
* "Set" the DateTime's zone to specified zone. Returns a newly-constructed DateTime.
*
* By default, the setter keeps the underlying time the same (as in, the same timestamp), but the new instance will report different local times and consider DSTs when making computations, as with {@link plus}. You may wish to use {@link toLocal} and {@link toUTC} which provide simple convenience wrappers for commonly used zones.
* @param {string|Zone} [zone='local'] - a zone identifier. As a string, that can be any IANA zone supported by the host environment, or a fixed-offset name of the form 'UTC+3', or the strings 'local' or 'utc'. You may also supply an instance of a {@link Zone} class.
* @param {Object} opts - options
* @param {boolean} [opts.keepLocalTime=false] - If true, adjust the underlying time so that the local time stays the same, but in the target zone. You should rarely need this.
* @return {DateTime}
*/
setZone(zone, {
keepLocalTime = false,
keepCalendarTime = false
} = {}) {
zone = normalizeZone(zone, Settings$1.defaultZone);
if (zone.equals(this.zone)) {
return this;
} else if (!zone.isValid) {
return DateTime.invalid(unsupportedZone(zone));
} else {
let newTS = this.ts;
if (keepLocalTime || keepCalendarTime) {
const offsetGuess = zone.offset(this.ts);
const asObj = this.toObject();
[newTS] = objToTS(asObj, offsetGuess, zone);
}
return clone$1(this, {
ts: newTS,
zone
});
}
}
/**
* "Set" the locale, numberingSystem, or outputCalendar. Returns a newly-constructed DateTime.
* @param {Object} properties - the properties to set
* @example DateTime.local(2017, 5, 25).reconfigure({ locale: 'en-GB' })
* @return {DateTime}
*/
reconfigure({
locale,
numberingSystem,
outputCalendar
} = {}) {
const loc = this.loc.clone({
locale,
numberingSystem,
outputCalendar
});
return clone$1(this, {
loc
});
}
/**
* "Set" the locale. Returns a newly-constructed DateTime.
* Just a convenient alias for reconfigure({ locale })
* @example DateTime.local(2017, 5, 25).setLocale('en-GB')
* @return {DateTime}
*/
setLocale(locale) {
return this.reconfigure({
locale
});
}
/**
* "Set" the values of specified units. Returns a newly-constructed DateTime.
* You can only set units with this method; for "setting" metadata, see {@link reconfigure} and {@link setZone}.
* @param {Object} values - a mapping of units to numbers
* @example dt.set({ year: 2017 })
* @example dt.set({ hour: 8, minute: 30 })
* @example dt.set({ weekday: 5 })
* @example dt.set({ year: 2005, ordinal: 234 })
* @return {DateTime}
*/
set(values) {
if (!this.isValid) return this;
const normalized = normalizeObject(values, normalizeUnit, []),
settingWeekStuff = !isUndefined(normalized.weekYear) || !isUndefined(normalized.weekNumber) || !isUndefined(normalized.weekday),
containsOrdinal = !isUndefined(normalized.ordinal),
containsGregorYear = !isUndefined(normalized.year),
containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
containsGregor = containsGregorYear || containsGregorMD,
definiteWeekDef = normalized.weekYear || normalized.weekNumber;
if ((containsGregor || containsOrdinal) && definiteWeekDef) {
throw new ConflictingSpecificationError("Can't mix weekYear/weekNumber units with year/month/day or ordinals");
}
if (containsGregorMD && containsOrdinal) {
throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day");
}
let mixed;
if (settingWeekStuff) {
mixed = weekToGregorian(Object.assign(gregorianToWeek(this.c), normalized));
} else if (!isUndefined(normalized.ordinal)) {
mixed = ordinalToGregorian(Object.assign(gregorianToOrdinal(this.c), normalized));
} else {
mixed = Object.assign(this.toObject(), normalized); // if we didn't set the day but we ended up on an overflow date,
// use the last day of the right month
if (isUndefined(normalized.day)) {
mixed.day = Math.min(daysInMonth(mixed.year, mixed.month), mixed.day);
}
}
const [ts, o] = objToTS(mixed, this.o, this.zone);
return clone$1(this, {
ts,
o
});
}
/**
* Add a period of time to this DateTime and return the resulting DateTime
*
* Adding hours, minutes, seconds, or milliseconds increases the timestamp by the right number of milliseconds. Adding days, months, or years shifts the calendar, accounting for DSTs and leap years along the way. Thus, `dt.plus({ hours: 24 })` may result in a different time than `dt.plus({ days: 1 })` if there's a DST shift in between.
* @param {Duration|Object|number} duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
* @example DateTime.now().plus(123) //~> in 123 milliseconds
* @example DateTime.now().plus({ minutes: 15 }) //~> in 15 minutes
* @example DateTime.now().plus({ days: 1 }) //~> this time tomorrow
* @example DateTime.now().plus({ days: -1 }) //~> this time yesterday
* @example DateTime.now().plus({ hours: 3, minutes: 13 }) //~> in 3 hr, 13 min
* @example DateTime.now().plus(Duration.fromObject({ hours: 3, minutes: 13 })) //~> in 3 hr, 13 min
* @return {DateTime}
*/
plus(duration) {
if (!this.isValid) return this;
const dur = friendlyDuration(duration);
return clone$1(this, adjustTime(this, dur));
}
/**
* Subtract a period of time to this DateTime and return the resulting DateTime
* See {@link plus}
* @param {Duration|Object|number} duration - The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
@return {DateTime}
*/
minus(duration) {
if (!this.isValid) return this;
const dur = friendlyDuration(duration).negate();
return clone$1(this, adjustTime(this, dur));
}
/**
* "Set" this DateTime to the beginning of a unit of time.
* @param {string} unit - The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
* @example DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
* @example DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01'
* @example DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays
* @example DateTime.local(2014, 3, 3, 5, 30).startOf('day').toISOTime(); //=> '00:00.000-05:00'
* @example DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
* @return {DateTime}
*/
startOf(unit) {
if (!this.isValid) return this;
const o = {},
normalizedUnit = Duration.normalizeUnit(unit);
switch (normalizedUnit) {
case "years":
o.month = 1;
// falls through
case "quarters":
case "months":
o.day = 1;
// falls through
case "weeks":
case "days":
o.hour = 0;
// falls through
case "hours":
o.minute = 0;
// falls through
case "minutes":
o.second = 0;
// falls through
case "seconds":
o.millisecond = 0;
break;
// no default, invalid units throw in normalizeUnit()
}
if (normalizedUnit === "weeks") {
o.weekday = 1;
}
if (normalizedUnit === "quarters") {
const q = Math.ceil(this.month / 3);
o.month = (q - 1) * 3 + 1;
}
return this.set(o);
}
/**
* "Set" this DateTime to the end (meaning the last millisecond) of a unit of time
* @param {string} unit - The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
* @example DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
* @example DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00'
* @example DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays
* @example DateTime.local(2014, 3, 3, 5, 30).endOf('day').toISO(); //=> '2014-03-03T23:59:59.999-05:00'
* @example DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
* @return {DateTime}
*/
endOf(unit) {
return this.isValid ? this.plus({
[unit]: 1
}).startOf(unit).minus(1) : this;
} // OUTPUT
/**
* Returns a string representation of this DateTime formatted according to the specified format string.
* **You may not want this.** See {@link toLocaleString} for a more flexible formatting tool. For a table of tokens and their interpretations, see [here](https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens).
* Defaults to en-US if no locale has been specified, regardless of the system's locale.
* @see https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens
* @param {string} fmt - the format string
* @param {Object} opts - opts to override the configuration options
* @example DateTime.now().toFormat('yyyy LLL dd') //=> '2017 Apr 22'
* @example DateTime.now().setLocale('fr').toFormat('yyyy LLL dd') //=> '2017 avr. 22'
* @example DateTime.now().toFormat('yyyy LLL dd', { locale: "fr" }) //=> '2017 avr. 22'
* @example DateTime.now().toFormat("HH 'hours and' mm 'minutes'") //=> '20 hours and 55 minutes'
* @return {string}
*/
toFormat(fmt, opts = {}) {
return this.isValid ? Formatter.create(this.loc.redefaultToEN(opts)).formatDateTimeFromString(this, fmt) : INVALID$2;
}
/**
* Returns a localized string representing this date. Accepts the same options as the Intl.DateTimeFormat constructor and any presets defined by Luxon, such as `DateTime.DATE_FULL` or `DateTime.TIME_SIMPLE`.
* The exact behavior of this method is browser-specific, but in general it will return an appropriate representation
* of the DateTime in the assigned locale.
* Defaults to the system's locale if no locale has been specified
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
* @param opts {Object} - Intl.DateTimeFormat constructor options and configuration options
* @example DateTime.now().toLocaleString(); //=> 4/20/2017
* @example DateTime.now().setLocale('en-gb').toLocaleString(); //=> '20/04/2017'
* @example DateTime.now().toLocaleString({ locale: 'en-gb' }); //=> '20/04/2017'
* @example DateTime.now().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017'
* @example DateTime.now().toLocaleString(DateTime.TIME_SIMPLE); //=> '11:32 AM'
* @example DateTime.now().toLocaleString(DateTime.DATETIME_SHORT); //=> '4/20/2017, 11:32 AM'
* @example DateTime.now().toLocaleString({ weekday: 'long', month: 'long', day: '2-digit' }); //=> 'Thursday, April 20'
* @example DateTime.now().toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> 'Thu, Apr 20, 11:27 AM'
* @example DateTime.now().toLocaleString({ hour: '2-digit', minute: '2-digit', hour12: false }); //=> '11:32'
* @return {string}
*/
toLocaleString(opts = DATE_SHORT) {
return this.isValid ? Formatter.create(this.loc.clone(opts), opts).formatDateTime(this) : INVALID$2;
}
/**
* Returns an array of format "parts", meaning individual tokens along with metadata. This is allows callers to post-process individual sections of the formatted output.
* Defaults to the system's locale if no locale has been specified
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts
* @param opts {Object} - Intl.DateTimeFormat constructor options, same as `toLocaleString`.
* @example DateTime.now().toLocaleParts(); //=> [
* //=> { type: 'day', value: '25' },
* //=> { type: 'literal', value: '/' },
* //=> { type: 'month', value: '05' },
* //=> { type: 'literal', value: '/' },
* //=> { type: 'year', value: '1982' }
* //=> ]
*/
toLocaleParts(opts = {}) {
return this.isValid ? Formatter.create(this.loc.clone(opts), opts).formatDateTimeParts(this) : [];
}
/**
* Returns an ISO 8601-compliant string representation of this DateTime
* @param {Object} opts - options
* @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0
* @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0
* @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
* @param {string} [opts.format='extended'] - choose between the basic and extended format
* @example DateTime.utc(1982, 5, 25).toISO() //=> '1982-05-25T00:00:00.000Z'
* @example DateTime.now().toISO() //=> '2017-04-22T20:47:05.335-04:00'
* @example DateTime.now().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335'
* @example DateTime.now().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400'
* @return {string}
*/
toISO(opts = {}) {
if (!this.isValid) {
return null;
}
return `${this.toISODate(opts)}T${this.toISOTime(opts)}`;
}
/**
* Returns an ISO 8601-compliant string representation of this DateTime's date component
* @param {Object} opts - options
* @param {string} [opts.format='extended'] - choose between the basic and extended format
* @example DateTime.utc(1982, 5, 25).toISODate() //=> '1982-05-25'
* @example DateTime.utc(1982, 5, 25).toISODate({ format: 'basic' }) //=> '19820525'
* @return {string}
*/
toISODate({
format = "extended"
} = {}) {
let fmt = format === "basic" ? "yyyyMMdd" : "yyyy-MM-dd";
if (this.year > 9999) {
fmt = "+" + fmt;
}
return toTechFormat(this, fmt);
}
/**
* Returns an ISO 8601-compliant string representation of this DateTime's week date
* @example DateTime.utc(1982, 5, 25).toISOWeekDate() //=> '1982-W21-2'
* @return {string}
*/
toISOWeekDate() {
return toTechFormat(this, "kkkk-'W'WW-c");
}
/**
* Returns an ISO 8601-compliant string representation of this DateTime's time component
* @param {Object} opts - options
* @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0
* @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0
* @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
* @param {boolean} [opts.includePrefix=false] - include the `T` prefix
* @param {string} [opts.format='extended'] - choose between the basic and extended format
* @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime() //=> '07:34:19.361Z'
* @example DateTime.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) //=> '07:34Z'
* @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) //=> '073419.361Z'
* @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ includePrefix: true }) //=> 'T07:34:19.361Z'
* @return {string}
*/
toISOTime({
suppressMilliseconds = false,
suppressSeconds = false,
includeOffset = true,
includePrefix = false,
format = "extended"
} = {}) {
return toTechTimeFormat(this, {
suppressSeconds,
suppressMilliseconds,
includeOffset,
includePrefix,
format
});
}
/**
* Returns an RFC 2822-compatible string representation of this DateTime, always in UTC
* @example DateTime.utc(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 +0000'
* @example DateTime.local(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 -0400'
* @return {string}
*/
toRFC2822() {
return toTechFormat(this, "EEE, dd LLL yyyy HH:mm:ss ZZZ", false);
}
/**
* Returns a string representation of this DateTime appropriate for use in HTTP headers.
* Specifically, the string conforms to RFC 1123.
* @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
* @example DateTime.utc(2014, 7, 13).toHTTP() //=> 'Sun, 13 Jul 2014 00:00:00 GMT'
* @example DateTime.utc(2014, 7, 13, 19).toHTTP() //=> 'Sun, 13 Jul 2014 19:00:00 GMT'
* @return {string}
*/
toHTTP() {
return toTechFormat(this.toUTC(), "EEE, dd LLL yyyy HH:mm:ss 'GMT'");
}
/**
* Returns a string representation of this DateTime appropriate for use in SQL Date
* @example DateTime.utc(2014, 7, 13).toSQLDate() //=> '2014-07-13'
* @return {string}
*/
toSQLDate() {
return toTechFormat(this, "yyyy-MM-dd");
}
/**
* Returns a string representation of this DateTime appropriate for use in SQL Time
* @param {Object} opts - options
* @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset.
* @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
* @example DateTime.utc().toSQL() //=> '05:15:16.345'
* @example DateTime.now().toSQL() //=> '05:15:16.345 -04:00'
* @example DateTime.now().toSQL({ includeOffset: false }) //=> '05:15:16.345'
* @example DateTime.now().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York'
* @return {string}
*/
toSQLTime({
includeOffset = true,
includeZone = false
} = {}) {
return toTechTimeFormat(this, {
includeOffset,
includeZone,
spaceZone: true
});
}
/**
* Returns a string representation of this DateTime appropriate for use in SQL DateTime
* @param {Object} opts - options
* @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset.
* @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
* @example DateTime.utc(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 Z'
* @example DateTime.local(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 -04:00'
* @example DateTime.local(2014, 7, 13).toSQL({ includeOffset: false }) //=> '2014-07-13 00:00:00.000'
* @example DateTime.local(2014, 7, 13).toSQL({ includeZone: true }) //=> '2014-07-13 00:00:00.000 America/New_York'
* @return {string}
*/
toSQL(opts = {}) {
if (!this.isValid) {
return null;
}
return `${this.toSQLDate()} ${this.toSQLTime(opts)}`;
}
/**
* Returns a string representation of this DateTime appropriate for debugging
* @return {string}
*/
toString() {
return this.isValid ? this.toISO() : INVALID$2;
}
/**
* Returns the epoch milliseconds of this DateTime. Alias of {@link toMillis}
* @return {number}
*/
valueOf() {
return this.toMillis();
}
/**
* Returns the epoch milliseconds of this DateTime.
* @return {number}
*/
toMillis() {
return this.isValid ? this.ts : NaN;
}
/**
* Returns the epoch seconds of this DateTime.
* @return {number}
*/
toSeconds() {
return this.isValid ? this.ts / 1000 : NaN;
}
/**
* Returns an ISO 8601 representation of this DateTime appropriate for use in JSON.
* @return {string}
*/
toJSON() {
return this.toISO();
}
/**
* Returns a BSON serializable equivalent to this DateTime.
* @return {Date}
*/
toBSON() {
return this.toJSDate();
}
/**
* Returns a JavaScript object with this DateTime's year, month, day, and so on.
* @param opts - options for generating the object
* @param {boolean} [opts.includeConfig=false] - include configuration attributes in the output
* @example DateTime.now().toObject() //=> { year: 2017, month: 4, day: 22, hour: 20, minute: 49, second: 42, millisecond: 268 }
* @return {Object}
*/
toObject(opts = {}) {
if (!this.isValid) return {};
const base = Object.assign({}, this.c);
if (opts.includeConfig) {
base.outputCalendar = this.outputCalendar;
base.numberingSystem = this.loc.numberingSystem;
base.locale = this.loc.locale;
}
return base;
}
/**
* Returns a JavaScript Date equivalent to this DateTime.
* @return {Date}
*/
toJSDate() {
return new Date(this.isValid ? this.ts : NaN);
} // COMPARE
/**
* Return the difference between two DateTimes as a Duration.
* @param {DateTime} otherDateTime - the DateTime to compare this one to
* @param {string|string[]} [unit=['milliseconds']] - the unit or array of units (such as 'hours' or 'days') to include in the duration.
* @param {Object} opts - options that affect the creation of the Duration
* @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
* @example
* var i1 = DateTime.fromISO('1982-05-25T09:45'),
* i2 = DateTime.fromISO('1983-10-14T10:30');
* i2.diff(i1).toObject() //=> { milliseconds: 43807500000 }
* i2.diff(i1, 'hours').toObject() //=> { hours: 12168.75 }
* i2.diff(i1, ['months', 'days']).toObject() //=> { months: 16, days: 19.03125 }
* i2.diff(i1, ['months', 'days', 'hours']).toObject() //=> { months: 16, days: 19, hours: 0.75 }
* @return {Duration}
*/
diff(otherDateTime, unit = "milliseconds", opts = {}) {
if (!this.isValid || !otherDateTime.isValid) {
return Duration.invalid(this.invalid || otherDateTime.invalid, "created by diffing an invalid DateTime");
}
const durOpts = Object.assign({
locale: this.locale,
numberingSystem: this.numberingSystem
}, opts);
const units = maybeArray(unit).map(Duration.normalizeUnit),
otherIsLater = otherDateTime.valueOf() > this.valueOf(),
earlier = otherIsLater ? this : otherDateTime,
later = otherIsLater ? otherDateTime : this,
diffed = diff(earlier, later, units, durOpts);
return otherIsLater ? diffed.negate() : diffed;
}
/**
* Return the difference between this DateTime and right now.
* See {@link diff}
* @param {string|string[]} [unit=['milliseconds']] - the unit or units units (such as 'hours' or 'days') to include in the duration
* @param {Object} opts - options that affect the creation of the Duration
* @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
* @return {Duration}
*/
diffNow(unit = "milliseconds", opts = {}) {
return this.diff(DateTime.now(), unit, opts);
}
/**
* Return an Interval spanning between this DateTime and another DateTime
* @param {DateTime} otherDateTime - the other end point of the Interval
* @return {Interval}
*/
until(otherDateTime) {
return this.isValid ? Interval.fromDateTimes(this, otherDateTime) : this;
}
/**
* Return whether this DateTime is in the same unit of time as another DateTime.
* Higher-order units must also be identical for this function to return `true`.
* Note that time zones are **ignored** in this comparison, which compares the **local** calendar time. Use {@link setZone} to convert one of the dates if needed.
* @param {DateTime} otherDateTime - the other DateTime
* @param {string} unit - the unit of time to check sameness on
* @example DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
* @return {boolean}
*/
hasSame(otherDateTime, unit) {
if (!this.isValid) return false;
const inputMs = otherDateTime.valueOf();
const otherZoneDateTime = this.setZone(otherDateTime.zone, {
keepLocalTime: true
});
return otherZoneDateTime.startOf(unit) <= inputMs && inputMs <= otherZoneDateTime.endOf(unit);
}
/**
* Equality check
* Two DateTimes are equal iff they represent the same millisecond, have the same zone and location, and are both valid.
* To compare just the millisecond values, use `+dt1 === +dt2`.
* @param {DateTime} other - the other DateTime
* @return {boolean}
*/
equals(other) {
return this.isValid && other.isValid && this.valueOf() === other.valueOf() && this.zone.equals(other.zone) && this.loc.equals(other.loc);
}
/**
* Returns a string representation of a this time relative to now, such as "in two days". Can only internationalize if your
* platform supports Intl.RelativeTimeFormat. Rounds down by default.
* @param {Object} options - options that affect the output
* @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
* @param {string} [options.style="long"] - the style of units, must be "long", "short", or "narrow"
* @param {string|string[]} options.unit - use a specific unit or array of units; if omitted, or an array, the method will pick the best unit. Use an array or one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", or "seconds"
* @param {boolean} [options.round=true] - whether to round the numbers in the output.
* @param {number} [options.padding=0] - padding in milliseconds. This allows you to round up the result if it fits inside the threshold. Don't use in combination with {round: false} because the decimal output will include the padding.
* @param {string} options.locale - override the locale of this DateTime
* @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this
* @example DateTime.now().plus({ days: 1 }).toRelative() //=> "in 1 day"
* @example DateTime.now().setLocale("es").toRelative({ days: 1 }) //=> "dentro de 1 día"
* @example DateTime.now().plus({ days: 1 }).toRelative({ locale: "fr" }) //=> "dans 23 heures"
* @example DateTime.now().minus({ days: 2 }).toRelative() //=> "2 days ago"
* @example DateTime.now().minus({ days: 2 }).toRelative({ unit: "hours" }) //=> "48 hours ago"
* @example DateTime.now().minus({ hours: 36 }).toRelative({ round: false }) //=> "1.5 days ago"
*/
toRelative(options = {}) {
if (!this.isValid) return null;
const base = options.base || DateTime.fromObject({
zone: this.zone
}),
padding = options.padding ? this < base ? -options.padding : options.padding : 0;
let units = ["years", "months", "days", "hours", "minutes", "seconds"];
let unit = options.unit;
if (Array.isArray(options.unit)) {
units = options.unit;
unit = undefined;
}
return diffRelative(base, this.plus(padding), Object.assign(options, {
numeric: "always",
units,
unit
}));
}
/**
* Returns a string representation of this date relative to today, such as "yesterday" or "next month".
* Only internationalizes on platforms that supports Intl.RelativeTimeFormat.
* @param {Object} options - options that affect the output
* @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
* @param {string} options.locale - override the locale of this DateTime
* @param {string} options.unit - use a specific unit; if omitted, the method will pick the unit. Use one of "years", "quarters", "months", "weeks", or "days"
* @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this
* @example DateTime.now().plus({ days: 1 }).toRelativeCalendar() //=> "tomorrow"
* @example DateTime.now().setLocale("es").plus({ days: 1 }).toRelative() //=> ""mañana"
* @example DateTime.now().plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) //=> "demain"
* @example DateTime.now().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago"
*/
toRelativeCalendar(options = {}) {
if (!this.isValid) return null;
return diffRelative(options.base || DateTime.fromObject({
zone: this.zone
}), this, Object.assign(options, {
numeric: "auto",
units: ["years", "months", "days"],
calendary: true
}));
}
/**
* Return the min of several date times
* @param {...DateTime} dateTimes - the DateTimes from which to choose the minimum
* @return {DateTime} the min DateTime, or undefined if called with no argument
*/
static min(...dateTimes) {
if (!dateTimes.every(DateTime.isDateTime)) {
throw new InvalidArgumentError("min requires all arguments be DateTimes");
}
return bestBy(dateTimes, i => i.valueOf(), Math.min);
}
/**
* Return the max of several date times
* @param {...DateTime} dateTimes - the DateTimes from which to choose the maximum
* @return {DateTime} the max DateTime, or undefined if called with no argument
*/
static max(...dateTimes) {
if (!dateTimes.every(DateTime.isDateTime)) {
throw new InvalidArgumentError("max requires all arguments be DateTimes");
}
return bestBy(dateTimes, i => i.valueOf(), Math.max);
} // MISC
/**
* Explain how a string would be parsed by fromFormat()
* @param {string} text - the string to parse
* @param {string} fmt - the format the string is expected to be in (see description)
* @param {Object} options - options taken by fromFormat()
* @return {Object}
*/
static fromFormatExplain(text, fmt, options = {}) {
const {
locale = null,
numberingSystem = null
} = options,
localeToUse = Locale.fromOpts({
locale,
numberingSystem,
defaultToEN: true
});
return explainFromTokens(localeToUse, text, fmt);
}
/**
* @deprecated use fromFormatExplain instead
*/
static fromStringExplain(text, fmt, options = {}) {
return DateTime.fromFormatExplain(text, fmt, options);
} // FORMAT PRESETS
/**
* {@link toLocaleString} format like 10/14/1983
* @type {Object}
*/
static get DATE_SHORT() {
return DATE_SHORT;
}
/**
* {@link toLocaleString} format like 'Oct 14, 1983'
* @type {Object}
*/
static get DATE_MED() {
return DATE_MED;
}
/**
* {@link toLocaleString} format like 'Fri, Oct 14, 1983'
* @type {Object}
*/
static get DATE_MED_WITH_WEEKDAY() {
return DATE_MED_WITH_WEEKDAY;
}
/**
* {@link toLocaleString} format like 'October 14, 1983'
* @type {Object}
*/
static get DATE_FULL() {
return DATE_FULL;
}
/**
* {@link toLocaleString} format like 'Tuesday, October 14, 1983'
* @type {Object}
*/
static get DATE_HUGE() {
return DATE_HUGE;
}
/**
* {@link toLocaleString} format like '09:30 AM'. Only 12-hour if the locale is.
* @type {Object}
*/
static get TIME_SIMPLE() {
return TIME_SIMPLE;
}
/**
* {@link toLocaleString} format like '09:30:23 AM'. Only 12-hour if the locale is.
* @type {Object}
*/
static get TIME_WITH_SECONDS() {
return TIME_WITH_SECONDS;
}
/**
* {@link toLocaleString} format like '09:30:23 AM EDT'. Only 12-hour if the locale is.
* @type {Object}
*/
static get TIME_WITH_SHORT_OFFSET() {
return TIME_WITH_SHORT_OFFSET;
}
/**
* {@link toLocaleString} format like '09:30:23 AM Eastern Daylight Time'. Only 12-hour if the locale is.
* @type {Object}
*/
static get TIME_WITH_LONG_OFFSET() {
return TIME_WITH_LONG_OFFSET;
}
/**
* {@link toLocaleString} format like '09:30', always 24-hour.
* @type {Object}
*/
static get TIME_24_SIMPLE() {
return TIME_24_SIMPLE;
}
/**
* {@link toLocaleString} format like '09:30:23', always 24-hour.
* @type {Object}
*/
static get TIME_24_WITH_SECONDS() {
return TIME_24_WITH_SECONDS;
}
/**
* {@link toLocaleString} format like '09:30:23 EDT', always 24-hour.
* @type {Object}
*/
static get TIME_24_WITH_SHORT_OFFSET() {
return TIME_24_WITH_SHORT_OFFSET;
}
/**
* {@link toLocaleString} format like '09:30:23 Eastern Daylight Time', always 24-hour.
* @type {Object}
*/
static get TIME_24_WITH_LONG_OFFSET() {
return TIME_24_WITH_LONG_OFFSET;
}
/**
* {@link toLocaleString} format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is.
* @type {Object}
*/
static get DATETIME_SHORT() {
return DATETIME_SHORT;
}
/**
* {@link toLocaleString} format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is.
* @type {Object}
*/
static get DATETIME_SHORT_WITH_SECONDS() {
return DATETIME_SHORT_WITH_SECONDS;
}
/**
* {@link toLocaleString} format like 'Oct 14, 1983, 9:30 AM'. Only 12-hour if the locale is.
* @type {Object}
*/
static get DATETIME_MED() {
return DATETIME_MED;
}
/**
* {@link toLocaleString} format like 'Oct 14, 1983, 9:30:33 AM'. Only 12-hour if the locale is.
* @type {Object}
*/
static get DATETIME_MED_WITH_SECONDS() {
return DATETIME_MED_WITH_SECONDS;
}
/**
* {@link toLocaleString} format like 'Fri, 14 Oct 1983, 9:30 AM'. Only 12-hour if the locale is.
* @type {Object}
*/
static get DATETIME_MED_WITH_WEEKDAY() {
return DATETIME_MED_WITH_WEEKDAY;
}
/**
* {@link toLocaleString} format like 'October 14, 1983, 9:30 AM EDT'. Only 12-hour if the locale is.
* @type {Object}
*/
static get DATETIME_FULL() {
return DATETIME_FULL;
}
/**
* {@link toLocaleString} format like 'October 14, 1983, 9:30:33 AM EDT'. Only 12-hour if the locale is.
* @type {Object}
*/
static get DATETIME_FULL_WITH_SECONDS() {
return DATETIME_FULL_WITH_SECONDS;
}
/**
* {@link toLocaleString} format like 'Friday, October 14, 1983, 9:30 AM Eastern Daylight Time'. Only 12-hour if the locale is.
* @type {Object}
*/
static get DATETIME_HUGE() {
return DATETIME_HUGE;
}
/**
* {@link toLocaleString} format like 'Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time'. Only 12-hour if the locale is.
* @type {Object}
*/
static get DATETIME_HUGE_WITH_SECONDS() {
return DATETIME_HUGE_WITH_SECONDS;
}
}
/**
* @private
*/
function friendlyDateTime(dateTimeish) {
if (DateTime.isDateTime(dateTimeish)) {
return dateTimeish;
} else if (dateTimeish && dateTimeish.valueOf && isNumber(dateTimeish.valueOf())) {
return DateTime.fromJSDate(dateTimeish);
} else if (dateTimeish && typeof dateTimeish === "object") {
return DateTime.fromObject(dateTimeish);
} else {
throw new InvalidArgumentError(`Unknown datetime argument: ${dateTimeish}, of type ${typeof dateTimeish}`);
}
}
var DateTime_1 = DateTime;
var DateWithZone = /** @class */ (function () {
function DateWithZone(date, tzid) {
this.date = date;
this.tzid = tzid;
}
Object.defineProperty(DateWithZone.prototype, "isUTC", {
get: function () {
return !this.tzid || this.tzid.toUpperCase() === 'UTC';
},
enumerable: true,
configurable: true
});
DateWithZone.prototype.toString = function () {
var datestr = dateutil$1.timeToUntilString(this.date.getTime(), this.isUTC);
if (!this.isUTC) {
return ";TZID=" + this.tzid + ":" + datestr;
}
return ":" + datestr;
};
DateWithZone.prototype.getTime = function () {
return this.date.getTime();
};
DateWithZone.prototype.rezonedDate = function () {
if (this.isUTC) {
return this.date;
}
try {
var datetime = DateTime_1
.fromJSDate(this.date);
var rezoned = datetime.setZone(this.tzid, { keepLocalTime: true });
return rezoned.toJSDate();
}
catch (e) {
if (e instanceof TypeError) {
console.error('Using TZID without Luxon available is unsupported. Returned times are in UTC, not the requested time zone');
}
return this.date;
}
};
return DateWithZone;
}());
function optionsToString(options) {
var rrule = [];
var dtstart = '';
var keys = Object.keys(options);
var defaultKeys = Object.keys(DEFAULT_OPTIONS$1);
for (var i = 0; i < keys.length; i++) {
if (keys[i] === 'tzid')
continue;
if (!includes(defaultKeys, keys[i]))
continue;
var key = keys[i].toUpperCase();
var value = options[keys[i]];
var outValue = '';
if (!isPresent(value) || (isArray(value) && !value.length))
continue;
switch (key) {
case 'FREQ':
outValue = RRule.FREQUENCIES[options.freq];
break;
case 'WKST':
if (isNumber$1(value)) {
outValue = new Weekday(value).toString();
}
else {
outValue = value.toString();
}
break;
case 'BYWEEKDAY':
/*
NOTE: BYWEEKDAY is a special case.
RRule() deconstructs the rule.options.byweekday array
into an array of Weekday arguments.
On the other hand, rule.origOptions is an array of Weekdays.
We need to handle both cases here.
It might be worth change RRule to keep the Weekdays.
Also, BYWEEKDAY (used by RRule) vs. BYDAY (RFC)
*/
key = 'BYDAY';
outValue = toArray(value).map(function (wday) {
if (wday instanceof Weekday) {
return wday;
}
if (isArray(wday)) {
return new Weekday(wday[0], wday[1]);
}
return new Weekday(wday);
}).toString();
break;
case 'DTSTART':
dtstart = buildDtstart(value, options.tzid);
break;
case 'UNTIL':
outValue = dateutil$1.timeToUntilString(value, !options.tzid);
break;
default:
if (isArray(value)) {
var strValues = [];
for (var j = 0; j < value.length; j++) {
strValues[j] = String(value[j]);
}
outValue = strValues.toString();
}
else {
outValue = String(value);
}
}
if (outValue) {
rrule.push([key, outValue]);
}
}
var rules = rrule.map(function (_a) {
var key = _a[0], value = _a[1];
return key + "=" + value.toString();
}).join(';');
var ruleString = '';
if (rules !== '') {
ruleString = "RRULE:" + rules;
}
return [dtstart, ruleString].filter(function (x) { return !!x; }).join('\n');
}
function buildDtstart(dtstart, tzid) {
if (!dtstart) {
return '';
}
return 'DTSTART' + new DateWithZone(new Date(dtstart), tzid).toString();
}
var Cache = /** @class */ (function () {
function Cache() {
this.all = false;
this.before = [];
this.after = [];
this.between = [];
}
/**
* @param {String} what - all/before/after/between
* @param {Array,Date} value - an array of dates, one date, or null
* @param {Object?} args - _iter arguments
*/
Cache.prototype._cacheAdd = function (what, value, args) {
if (value) {
value =
value instanceof Date
? dateutil$1.clone(value)
: dateutil$1.cloneDates(value);
}
if (what === 'all') {
this.all = value;
}
else {
args._value = value;
this[what].push(args);
}
};
/**
* @return false - not in the cache
* null - cached, but zero occurrences (before/after)
* Date - cached (before/after)
* [] - cached, but zero occurrences (all/between)
* [Date1, DateN] - cached (all/between)
*/
Cache.prototype._cacheGet = function (what, args) {
var cached = false;
var argsKeys = args ? Object.keys(args) : [];
var findCacheDiff = function (item) {
for (var i = 0; i < argsKeys.length; i++) {
var key = argsKeys[i];
if (String(args[key]) !== String(item[key])) {
return true;
}
}
return false;
};
var cachedObject = this[what];
if (what === 'all') {
cached = this.all;
}
else if (isArray(cachedObject)) {
// Let's see whether we've already called the
// 'what' method with the same 'args'
for (var i = 0; i < cachedObject.length; i++) {
var item = cachedObject[i];
if (argsKeys.length && findCacheDiff(item))
continue;
cached = item._value;
break;
}
}
if (!cached && this.all) {
// Not in the cache, but we already know all the occurrences,
// so we can find the correct dates from the cached ones.
var iterResult = new IterResult(what, args);
for (var i = 0; i < this.all.length; i++) {
if (!iterResult.accept(this.all[i]))
break;
}
cached = iterResult.getValue();
this._cacheAdd(what, cached, args);
}
return isArray(cached)
? dateutil$1.cloneDates(cached)
: cached instanceof Date
? dateutil$1.clone(cached)
: cached;
};
return Cache;
}());
// =============================================================================
// Date masks
// =============================================================================
// Every mask is 7 days longer to handle cross-year weekly periods.
var M365MASK = __spreadArrays(repeat(1, 31), repeat(2, 28), repeat(3, 31), repeat(4, 30), repeat(5, 31), repeat(6, 30), repeat(7, 31), repeat(8, 31), repeat(9, 30), repeat(10, 31), repeat(11, 30), repeat(12, 31), repeat(1, 7));
var M366MASK = __spreadArrays(repeat(1, 31), repeat(2, 29), repeat(3, 31), repeat(4, 30), repeat(5, 31), repeat(6, 30), repeat(7, 31), repeat(8, 31), repeat(9, 30), repeat(10, 31), repeat(11, 30), repeat(12, 31), repeat(1, 7));
var M28 = range(1, 29);
var M29 = range(1, 30);
var M30 = range(1, 31);
var M31 = range(1, 32);
var MDAY366MASK = __spreadArrays(M31, M29, M31, M30, M31, M30, M31, M31, M30, M31, M30, M31, M31.slice(0, 7));
var MDAY365MASK = __spreadArrays(M31, M28, M31, M30, M31, M30, M31, M31, M30, M31, M30, M31, M31.slice(0, 7));
var NM28 = range(-28, 0);
var NM29 = range(-29, 0);
var NM30 = range(-30, 0);
var NM31 = range(-31, 0);
var NMDAY366MASK = __spreadArrays(NM31, NM29, NM31, NM30, NM31, NM30, NM31, NM31, NM30, NM31, NM30, NM31, NM31.slice(0, 7));
var NMDAY365MASK = __spreadArrays(NM31, NM28, NM31, NM30, NM31, NM30, NM31, NM31, NM30, NM31, NM30, NM31, NM31.slice(0, 7));
var M366RANGE = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366];
var M365RANGE = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
var WDAYMASK = (function () {
var wdaymask = [];
for (var i = 0; i < 55; i++)
wdaymask = wdaymask.concat(range(7));
return wdaymask;
})();
function rebuildYear(year, options) {
var firstyday = new Date(Date.UTC(year, 0, 1));
var yearlen = dateutil$1.isLeapYear(year) ? 366 : 365;
var nextyearlen = dateutil$1.isLeapYear(year + 1) ? 366 : 365;
var yearordinal = dateutil$1.toOrdinal(firstyday);
var yearweekday = dateutil$1.getWeekday(firstyday);
var result = __assign(__assign({ yearlen: yearlen,
nextyearlen: nextyearlen,
yearordinal: yearordinal,
yearweekday: yearweekday }, baseYearMasks(year)), { wnomask: null });
if (empty(options.byweekno)) {
return result;
}
result.wnomask = repeat(0, yearlen + 7);
var firstwkst;
var wyearlen;
var no1wkst = firstwkst = pymod(7 - yearweekday + options.wkst, 7);
if (no1wkst >= 4) {
no1wkst = 0;
// Number of days in the year, plus the days we got
// from last year.
wyearlen =
result.yearlen + pymod(yearweekday - options.wkst, 7);
}
else {
// Number of days in the year, minus the days we
// left in last year.
wyearlen = yearlen - no1wkst;
}
var div = Math.floor(wyearlen / 7);
var mod = pymod(wyearlen, 7);
var numweeks = Math.floor(div + mod / 4);
for (var j = 0; j < options.byweekno.length; j++) {
var n = options.byweekno[j];
if (n < 0) {
n += numweeks + 1;
}
if (!(n > 0 && n <= numweeks)) {
continue;
}
var i = void 0;
if (n > 1) {
i = no1wkst + (n - 1) * 7;
if (no1wkst !== firstwkst) {
i -= 7 - firstwkst;
}
}
else {
i = no1wkst;
}
for (var k = 0; k < 7; k++) {
result.wnomask[i] = 1;
i++;
if (result.wdaymask[i] === options.wkst)
break;
}
}
if (includes(options.byweekno, 1)) {
// Check week number 1 of next year as well
// orig-TODO : Check -numweeks for next year.
var i = no1wkst + numweeks * 7;
if (no1wkst !== firstwkst)
i -= 7 - firstwkst;
if (i < yearlen) {
// If week starts in next year, we
// don't care about it.
for (var j = 0; j < 7; j++) {
result.wnomask[i] = 1;
i += 1;
if (result.wdaymask[i] === options.wkst)
break;
}
}
}
if (no1wkst) {
// Check last week number of last year as
// well. If no1wkst is 0, either the year
// started on week start, or week number 1
// got days from last year, so there are no
// days from last year's last week number in
// this year.
var lnumweeks = void 0;
if (!includes(options.byweekno, -1)) {
var lyearweekday = dateutil$1.getWeekday(new Date(Date.UTC(year - 1, 0, 1)));
var lno1wkst = pymod(7 - lyearweekday.valueOf() + options.wkst, 7);
var lyearlen = dateutil$1.isLeapYear(year - 1) ? 366 : 365;
var weekst = void 0;
if (lno1wkst >= 4) {
lno1wkst = 0;
weekst = lyearlen + pymod(lyearweekday - options.wkst, 7);
}
else {
weekst = yearlen - no1wkst;
}
lnumweeks = Math.floor(52 + pymod(weekst, 7) / 4);
}
else {
lnumweeks = -1;
}
if (includes(options.byweekno, lnumweeks)) {
for (var i = 0; i < no1wkst; i++)
result.wnomask[i] = 1;
}
}
return result;
}
function baseYearMasks(year) {
var yearlen = dateutil$1.isLeapYear(year) ? 366 : 365;
var firstyday = new Date(Date.UTC(year, 0, 1));
var wday = dateutil$1.getWeekday(firstyday);
if (yearlen === 365) {
return {
mmask: M365MASK,
mdaymask: MDAY365MASK,
nmdaymask: NMDAY365MASK,
wdaymask: WDAYMASK.slice(wday),
mrange: M365RANGE
};
}
return {
mmask: M366MASK,
mdaymask: MDAY366MASK,
nmdaymask: NMDAY366MASK,
wdaymask: WDAYMASK.slice(wday),
mrange: M366RANGE
};
}
function rebuildMonth(year, month, yearlen, mrange, wdaymask, options) {
var result = {
lastyear: year,
lastmonth: month,
nwdaymask: []
};
var ranges = [];
if (options.freq === RRule.YEARLY) {
if (empty(options.bymonth)) {
ranges = [[0, yearlen]];
}
else {
for (var j = 0; j < options.bymonth.length; j++) {
month = options.bymonth[j];
ranges.push(mrange.slice(month - 1, month + 1));
}
}
}
else if (options.freq === RRule.MONTHLY) {
ranges = [mrange.slice(month - 1, month + 1)];
}
if (empty(ranges)) {
return result;
}
// Weekly frequency won't get here, so we may not
// care about cross-year weekly periods.
result.nwdaymask = repeat(0, yearlen);
for (var j = 0; j < ranges.length; j++) {
var rang = ranges[j];
var first = rang[0];
var last = rang[1] - 1;
for (var k = 0; k < options.bynweekday.length; k++) {
var i = void 0;
var _a = options.bynweekday[k], wday = _a[0], n = _a[1];
if (n < 0) {
i = last + (n + 1) * 7;
i -= pymod(wdaymask[i] - wday, 7);
}
else {
i = first + (n - 1) * 7;
i += pymod(7 - wdaymask[i] + wday, 7);
}
if (first <= i && i <= last)
result.nwdaymask[i] = 1;
}
}
return result;
}
function easter(y, offset) {
if (offset === void 0) { offset = 0; }
var a = y % 19;
var b = Math.floor(y / 100);
var c = y % 100;
var d = Math.floor(b / 4);
var e = b % 4;
var f = Math.floor((b + 8) / 25);
var g = Math.floor((b - f + 1) / 3);
var h = Math.floor(19 * a + b - d - g + 15) % 30;
var i = Math.floor(c / 4);
var k = c % 4;
var l = Math.floor(32 + 2 * e + 2 * i - h - k) % 7;
var m = Math.floor((a + 11 * h + 22 * l) / 451);
var month = Math.floor((h + l - 7 * m + 114) / 31);
var day = ((h + l - 7 * m + 114) % 31) + 1;
var date = Date.UTC(y, month - 1, day + offset);
var yearStart = Date.UTC(y, 0, 1);
return [Math.ceil((date - yearStart) / (1000 * 60 * 60 * 24))];
}
// =============================================================================
// Iterinfo
// =============================================================================
var Iterinfo = /** @class */ (function () {
function Iterinfo(options) {
this.options = options;
}
Iterinfo.prototype.rebuild = function (year, month) {
var options = this.options;
if (year !== this.lastyear) {
this.yearinfo = rebuildYear(year, options);
}
if (notEmpty(options.bynweekday) &&
(month !== this.lastmonth || year !== this.lastyear)) {
var _a = this.yearinfo, yearlen = _a.yearlen, mrange = _a.mrange, wdaymask = _a.wdaymask;
this.monthinfo = rebuildMonth(year, month, yearlen, mrange, wdaymask, options);
}
if (isPresent(options.byeaster)) {
this.eastermask = easter(year, options.byeaster);
}
};
Object.defineProperty(Iterinfo.prototype, "lastyear", {
get: function () {
return this.monthinfo ? this.monthinfo.lastyear : null;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Iterinfo.prototype, "lastmonth", {
get: function () {
return this.monthinfo ? this.monthinfo.lastmonth : null;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Iterinfo.prototype, "yearlen", {
get: function () {
return this.yearinfo.yearlen;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Iterinfo.prototype, "yearordinal", {
get: function () {
return this.yearinfo.yearordinal;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Iterinfo.prototype, "mrange", {
get: function () {
return this.yearinfo.mrange;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Iterinfo.prototype, "wdaymask", {
get: function () {
return this.yearinfo.wdaymask;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Iterinfo.prototype, "mmask", {
get: function () {
return this.yearinfo.mmask;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Iterinfo.prototype, "wnomask", {
get: function () {
return this.yearinfo.wnomask;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Iterinfo.prototype, "nwdaymask", {
get: function () {
return this.monthinfo ? this.monthinfo.nwdaymask : [];
},
enumerable: true,
configurable: true
});
Object.defineProperty(Iterinfo.prototype, "nextyearlen", {
get: function () {
return this.yearinfo.nextyearlen;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Iterinfo.prototype, "mdaymask", {
get: function () {
return this.yearinfo.mdaymask;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Iterinfo.prototype, "nmdaymask", {
get: function () {
return this.yearinfo.nmdaymask;
},
enumerable: true,
configurable: true
});
Iterinfo.prototype.ydayset = function () {
return [range(this.yearlen), 0, this.yearlen];
};
Iterinfo.prototype.mdayset = function (_, month, __) {
var start = this.mrange[month - 1];
var end = this.mrange[month];
var set = repeat(null, this.yearlen);
for (var i = start; i < end; i++)
set[i] = i;
return [set, start, end];
};
Iterinfo.prototype.wdayset = function (year, month, day) {
// We need to handle cross-year weeks here.
var set = repeat(null, this.yearlen + 7);
var i = dateutil$1.toOrdinal(new Date(Date.UTC(year, month - 1, day))) -
this.yearordinal;
var start = i;
for (var j = 0; j < 7; j++) {
set[i] = i;
++i;
if (this.wdaymask[i] === this.options.wkst)
break;
}
return [set, start, i];
};
Iterinfo.prototype.ddayset = function (year, month, day) {
var set = repeat(null, this.yearlen);
var i = dateutil$1.toOrdinal(new Date(Date.UTC(year, month - 1, day))) -
this.yearordinal;
set[i] = i;
return [set, i, i + 1];
};
Iterinfo.prototype.htimeset = function (hour, _, second, millisecond) {
var _this = this;
var set = [];
this.options.byminute.forEach(function (minute) {
set = set.concat(_this.mtimeset(hour, minute, second, millisecond));
});
dateutil$1.sort(set);
return set;
};
Iterinfo.prototype.mtimeset = function (hour, minute, _, millisecond) {
var set = this.options.bysecond.map(function (second) {
return new Time(hour, minute, second, millisecond);
});
dateutil$1.sort(set);
return set;
};
Iterinfo.prototype.stimeset = function (hour, minute, second, millisecond) {
return [new Time(hour, minute, second, millisecond)];
};
Iterinfo.prototype.getdayset = function (freq) {
switch (freq) {
case Frequency.YEARLY: return this.ydayset.bind(this);
case Frequency.MONTHLY: return this.mdayset.bind(this);
case Frequency.WEEKLY: return this.wdayset.bind(this);
case Frequency.DAILY: return this.ddayset.bind(this);
default: return this.ddayset.bind(this);
}
};
Iterinfo.prototype.gettimeset = function (freq) {
switch (freq) {
case Frequency.HOURLY: return this.htimeset.bind(this);
case Frequency.MINUTELY: return this.mtimeset.bind(this);
case Frequency.SECONDLY: return this.stimeset.bind(this);
}
};
return Iterinfo;
}());
function buildPoslist(bysetpos, timeset, start, end, ii, dayset) {
var poslist = [];
for (var j = 0; j < bysetpos.length; j++) {
var daypos = void 0;
var timepos = void 0;
var pos = bysetpos[j];
if (pos < 0) {
daypos = Math.floor(pos / timeset.length);
timepos = pymod(pos, timeset.length);
}
else {
daypos = Math.floor((pos - 1) / timeset.length);
timepos = pymod(pos - 1, timeset.length);
}
var tmp = [];
for (var k = start; k < end; k++) {
var val = dayset[k];
if (!isPresent(val))
continue;
tmp.push(val);
}
var i = void 0;
if (daypos < 0) {
i = tmp.slice(daypos)[0];
}
else {
i = tmp[daypos];
}
var time = timeset[timepos];
var date = dateutil$1.fromOrdinal(ii.yearordinal + i);
var res = dateutil$1.combine(date, time);
// XXX: can this ever be in the array?
// - compare the actual date instead?
if (!includes(poslist, res))
poslist.push(res);
}
dateutil$1.sort(poslist);
return poslist;
}
function iter(iterResult, options) {
var dtstart = options.dtstart, freq = options.freq, interval = options.interval, until = options.until, bysetpos = options.bysetpos;
var count = options.count;
if (count === 0 || interval === 0) {
return emitResult(iterResult);
}
var counterDate = DateTime$1.fromDate(dtstart);
var ii = new Iterinfo(options);
ii.rebuild(counterDate.year, counterDate.month);
var timeset = makeTimeset(ii, counterDate, options);
while (true) {
var _a = ii.getdayset(freq)(counterDate.year, counterDate.month, counterDate.day), dayset = _a[0], start = _a[1], end = _a[2];
var filtered = removeFilteredDays(dayset, start, end, ii, options);
if (notEmpty(bysetpos)) {
var poslist = buildPoslist(bysetpos, timeset, start, end, ii, dayset);
for (var j = 0; j < poslist.length; j++) {
var res = poslist[j];
if (until && res > until) {
return emitResult(iterResult);
}
if (res >= dtstart) {
var rezonedDate = rezoneIfNeeded(res, options);
if (!iterResult.accept(rezonedDate)) {
return emitResult(iterResult);
}
if (count) {
--count;
if (!count) {
return emitResult(iterResult);
}
}
}
}
}
else {
for (var j = start; j < end; j++) {
var currentDay = dayset[j];
if (!isPresent(currentDay)) {
continue;
}
var date = dateutil$1.fromOrdinal(ii.yearordinal + currentDay);
for (var k = 0; k < timeset.length; k++) {
var time = timeset[k];
var res = dateutil$1.combine(date, time);
if (until && res > until) {
return emitResult(iterResult);
}
if (res >= dtstart) {
var rezonedDate = rezoneIfNeeded(res, options);
if (!iterResult.accept(rezonedDate)) {
return emitResult(iterResult);
}
if (count) {
--count;
if (!count) {
return emitResult(iterResult);
}
}
}
}
}
}
if (options.interval === 0) {
return emitResult(iterResult);
}
// Handle frequency and interval
counterDate.add(options, filtered);
if (counterDate.year > dateutil$1.MAXYEAR) {
return emitResult(iterResult);
}
if (!freqIsDailyOrGreater(freq)) {
timeset = ii.gettimeset(freq)(counterDate.hour, counterDate.minute, counterDate.second, 0);
}
ii.rebuild(counterDate.year, counterDate.month);
}
}
function isFiltered(ii, currentDay, options) {
var bymonth = options.bymonth, byweekno = options.byweekno, byweekday = options.byweekday, byeaster = options.byeaster, bymonthday = options.bymonthday, bynmonthday = options.bynmonthday, byyearday = options.byyearday;
return ((notEmpty(bymonth) && !includes(bymonth, ii.mmask[currentDay])) ||
(notEmpty(byweekno) && !ii.wnomask[currentDay]) ||
(notEmpty(byweekday) && !includes(byweekday, ii.wdaymask[currentDay])) ||
(notEmpty(ii.nwdaymask) && !ii.nwdaymask[currentDay]) ||
(byeaster !== null && !includes(ii.eastermask, currentDay)) ||
((notEmpty(bymonthday) || notEmpty(bynmonthday)) &&
!includes(bymonthday, ii.mdaymask[currentDay]) &&
!includes(bynmonthday, ii.nmdaymask[currentDay])) ||
(notEmpty(byyearday) &&
((currentDay < ii.yearlen &&
!includes(byyearday, currentDay + 1) &&
!includes(byyearday, -ii.yearlen + currentDay)) ||
(currentDay >= ii.yearlen &&
!includes(byyearday, currentDay + 1 - ii.yearlen) &&
!includes(byyearday, -ii.nextyearlen + currentDay - ii.yearlen)))));
}
function rezoneIfNeeded(date, options) {
return new DateWithZone(date, options.tzid).rezonedDate();
}
function emitResult(iterResult) {
return iterResult.getValue();
}
function removeFilteredDays(dayset, start, end, ii, options) {
var filtered = false;
for (var dayCounter = start; dayCounter < end; dayCounter++) {
var currentDay = dayset[dayCounter];
filtered = isFiltered(ii, currentDay, options);
if (filtered)
dayset[currentDay] = null;
}
return filtered;
}
function makeTimeset(ii, counterDate, options) {
var freq = options.freq, byhour = options.byhour, byminute = options.byminute, bysecond = options.bysecond;
if (freqIsDailyOrGreater(freq)) {
return buildTimeset(options);
}
if ((freq >= RRule.HOURLY &&
notEmpty(byhour) &&
!includes(byhour, counterDate.hour)) ||
(freq >= RRule.MINUTELY &&
notEmpty(byminute) &&
!includes(byminute, counterDate.minute)) ||
(freq >= RRule.SECONDLY &&
notEmpty(bysecond) &&
!includes(bysecond, counterDate.second))) {
return [];
}
return ii.gettimeset(freq)(counterDate.hour, counterDate.minute, counterDate.second, counterDate.millisecond);
}
// =============================================================================
// RRule
// =============================================================================
var Days = {
MO: new Weekday(0),
TU: new Weekday(1),
WE: new Weekday(2),
TH: new Weekday(3),
FR: new Weekday(4),
SA: new Weekday(5),
SU: new Weekday(6)
};
var DEFAULT_OPTIONS$1 = {
freq: Frequency.YEARLY,
dtstart: null,
interval: 1,
wkst: Days.MO,
count: null,
until: null,
tzid: null,
bysetpos: null,
bymonth: null,
bymonthday: null,
bynmonthday: null,
byyearday: null,
byweekno: null,
byweekday: null,
bynweekday: null,
byhour: null,
byminute: null,
bysecond: null,
byeaster: null
};
var defaultKeys = Object.keys(DEFAULT_OPTIONS$1);
/**
*
* @param {Options?} options - see <http://labix.org/python-dateutil/#head-cf004ee9a75592797e076752b2a889c10f445418>
* The only required option is `freq`, one of RRule.YEARLY, RRule.MONTHLY, ...
* @constructor
*/
var RRule = /** @class */ (function () {
function RRule(options, noCache) {
if (options === void 0) { options = {}; }
if (noCache === void 0) { noCache = false; }
// RFC string
this._cache = noCache ? null : new Cache();
// used by toString()
this.origOptions = initializeOptions$1(options);
var parsedOptions = parseOptions(options).parsedOptions;
this.options = parsedOptions;
}
RRule.parseText = function (text, language) {
return parseText(text, language);
};
RRule.fromText = function (text, language) {
return fromText(text, language);
};
RRule.fromString = function (str) {
return new RRule(RRule.parseString(str) || undefined);
};
RRule.prototype._iter = function (iterResult) {
return iter(iterResult, this.options);
};
RRule.prototype._cacheGet = function (what, args) {
if (!this._cache)
return false;
return this._cache._cacheGet(what, args);
};
RRule.prototype._cacheAdd = function (what, value, args) {
if (!this._cache)
return;
return this._cache._cacheAdd(what, value, args);
};
/**
* @param {Function} iterator - optional function that will be called
* on each date that is added. It can return false
* to stop the iteration.
* @return Array containing all recurrences.
*/
RRule.prototype.all = function (iterator) {
if (iterator) {
return this._iter(new CallbackIterResult('all', {}, iterator));
}
var result = this._cacheGet('all');
if (result === false) {
result = this._iter(new IterResult('all', {}));
this._cacheAdd('all', result);
}
return result;
};
/**
* Returns all the occurrences of the rrule between after and before.
* The inc keyword defines what happens if after and/or before are
* themselves occurrences. With inc == True, they will be included in the
* list, if they are found in the recurrence set.
* @return Array
*/
RRule.prototype.between = function (after, before, inc, iterator) {
if (inc === void 0) { inc = false; }
if (!dateutil$1.isValidDate(after) || !dateutil$1.isValidDate(before))
throw new Error('Invalid date passed in to RRule.between');
var args = {
before: before,
after: after,
inc: inc
};
if (iterator) {
return this._iter(new CallbackIterResult('between', args, iterator));
}
var result = this._cacheGet('between', args);
if (result === false) {
result = this._iter(new IterResult('between', args));
this._cacheAdd('between', result, args);
}
return result;
};
/**
* Returns the last recurrence before the given datetime instance.
* The inc keyword defines what happens if dt is an occurrence.
* With inc == True, if dt itself is an occurrence, it will be returned.
* @return Date or null
*/
RRule.prototype.before = function (dt, inc) {
if (inc === void 0) { inc = false; }
if (!dateutil$1.isValidDate(dt))
throw new Error('Invalid date passed in to RRule.before');
var args = { dt: dt, inc: inc };
var result = this._cacheGet('before', args);
if (result === false) {
result = this._iter(new IterResult('before', args));
this._cacheAdd('before', result, args);
}
return result;
};
/**
* Returns the first recurrence after the given datetime instance.
* The inc keyword defines what happens if dt is an occurrence.
* With inc == True, if dt itself is an occurrence, it will be returned.
* @return Date or null
*/
RRule.prototype.after = function (dt, inc) {
if (inc === void 0) { inc = false; }
if (!dateutil$1.isValidDate(dt))
throw new Error('Invalid date passed in to RRule.after');
var args = { dt: dt, inc: inc };
var result = this._cacheGet('after', args);
if (result === false) {
result = this._iter(new IterResult('after', args));
this._cacheAdd('after', result, args);
}
return result;
};
/**
* Returns the number of recurrences in this set. It will have go trough
* the whole recurrence, if this hasn't been done before.
*/
RRule.prototype.count = function () {
return this.all().length;
};
/**
* Converts the rrule into its string representation
* @see <http://www.ietf.org/rfc/rfc2445.txt>
* @return String
*/
RRule.prototype.toString = function () {
return optionsToString(this.origOptions);
};
/**
* Will convert all rules described in nlp:ToText
* to text.
*/
RRule.prototype.toText = function (gettext, language, dateFormatter) {
return toText(this, gettext, language, dateFormatter);
};
RRule.prototype.isFullyConvertibleToText = function () {
return isFullyConvertible(this);
};
/**
* @return a RRule instance with the same freq and options
* as this one (cache is not cloned)
*/
RRule.prototype.clone = function () {
return new RRule(this.origOptions);
};
// RRule class 'constants'
RRule.FREQUENCIES = [
'YEARLY',
'MONTHLY',
'WEEKLY',
'DAILY',
'HOURLY',
'MINUTELY',
'SECONDLY'
];
RRule.YEARLY = Frequency.YEARLY;
RRule.MONTHLY = Frequency.MONTHLY;
RRule.WEEKLY = Frequency.WEEKLY;
RRule.DAILY = Frequency.DAILY;
RRule.HOURLY = Frequency.HOURLY;
RRule.MINUTELY = Frequency.MINUTELY;
RRule.SECONDLY = Frequency.SECONDLY;
RRule.MO = Days.MO;
RRule.TU = Days.TU;
RRule.WE = Days.WE;
RRule.TH = Days.TH;
RRule.FR = Days.FR;
RRule.SA = Days.SA;
RRule.SU = Days.SU;
RRule.parseString = parseString;
RRule.optionsToString = optionsToString;
return RRule;
}());
function iterSet(iterResult, _rrule, _exrule, _rdate, _exdate, tzid) {
var _exdateHash = {};
var _accept = iterResult.accept;
function evalExdate(after, before) {
_exrule.forEach(function (rrule) {
rrule.between(after, before, true).forEach(function (date) {
_exdateHash[Number(date)] = true;
});
});
}
_exdate.forEach(function (date) {
var zonedDate = new DateWithZone(date, tzid).rezonedDate();
_exdateHash[Number(zonedDate)] = true;
});
iterResult.accept = function (date) {
var dt = Number(date);
if (isNaN(dt))
return _accept.call(this, date);
if (!_exdateHash[dt]) {
evalExdate(new Date(dt - 1), new Date(dt + 1));
if (!_exdateHash[dt]) {
_exdateHash[dt] = true;
return _accept.call(this, date);
}
}
return true;
};
if (iterResult.method === 'between') {
evalExdate(iterResult.args.after, iterResult.args.before);
iterResult.accept = function (date) {
var dt = Number(date);
if (!_exdateHash[dt]) {
_exdateHash[dt] = true;
return _accept.call(this, date);
}
return true;
};
}
for (var i = 0; i < _rdate.length; i++) {
var zonedDate = new DateWithZone(_rdate[i], tzid).rezonedDate();
if (!iterResult.accept(new Date(zonedDate.getTime())))
break;
}
_rrule.forEach(function (rrule) {
iter(iterResult, rrule.options);
});
var res = iterResult._result;
dateutil$1.sort(res);
switch (iterResult.method) {
case 'all':
case 'between':
return res;
case 'before':
return ((res.length && res[res.length - 1]) || null);
case 'after':
default:
return ((res.length && res[0]) || null);
}
}
/**
* RRuleStr
* To parse a set of rrule strings
*/
var DEFAULT_OPTIONS = {
dtstart: null,
cache: false,
unfold: false,
forceset: false,
compatible: false,
tzid: null
};
function parseInput(s, options) {
var rrulevals = [];
var rdatevals = [];
var exrulevals = [];
var exdatevals = [];
var _a = parseDtstart(s), dtstart = _a.dtstart, tzid = _a.tzid;
var lines = splitIntoLines(s, options.unfold);
lines.forEach(function (line) {
if (!line)
return;
var _a = breakDownLine(line), name = _a.name, parms = _a.parms, value = _a.value;
switch (name.toUpperCase()) {
case 'RRULE':
if (parms.length) {
throw new Error("unsupported RRULE parm: " + parms.join(','));
}
rrulevals.push(parseString(line));
break;
case 'RDATE':
var _b = /RDATE(?:;TZID=([^:=]+))?/i.exec(line); _b[0]; var rdateTzid = _b[1];
if (rdateTzid && !tzid) {
tzid = rdateTzid;
}
rdatevals = rdatevals.concat(parseRDate(value, parms));
break;
case 'EXRULE':
if (parms.length) {
throw new Error("unsupported EXRULE parm: " + parms.join(','));
}
exrulevals.push(parseString(value));
break;
case 'EXDATE':
exdatevals = exdatevals.concat(parseRDate(value, parms));
break;
case 'DTSTART':
break;
default:
throw new Error('unsupported property: ' + name);
}
});
return {
dtstart: dtstart,
tzid: tzid,
rrulevals: rrulevals,
rdatevals: rdatevals,
exrulevals: exrulevals,
exdatevals: exdatevals
};
}
function buildRule(s, options) {
var _a = parseInput(s, options), rrulevals = _a.rrulevals, rdatevals = _a.rdatevals, exrulevals = _a.exrulevals, exdatevals = _a.exdatevals, dtstart = _a.dtstart, tzid = _a.tzid;
var noCache = options.cache === false;
if (options.compatible) {
options.forceset = true;
options.unfold = true;
}
if (options.forceset ||
rrulevals.length > 1 ||
rdatevals.length ||
exrulevals.length ||
exdatevals.length) {
var rset_1 = new RRuleSet(noCache);
rset_1.dtstart(dtstart);
rset_1.tzid(tzid || undefined);
rrulevals.forEach(function (val) {
rset_1.rrule(new RRule(groomRruleOptions(val, dtstart, tzid), noCache));
});
rdatevals.forEach(function (date) {
rset_1.rdate(date);
});
exrulevals.forEach(function (val) {
rset_1.exrule(new RRule(groomRruleOptions(val, dtstart, tzid), noCache));
});
exdatevals.forEach(function (date) {
rset_1.exdate(date);
});
if (options.compatible && options.dtstart)
rset_1.rdate(dtstart);
return rset_1;
}
var val = rrulevals[0] || {};
return new RRule(groomRruleOptions(val, val.dtstart || options.dtstart || dtstart, val.tzid || options.tzid || tzid), noCache);
}
function rrulestr(s, options) {
if (options === void 0) { options = {}; }
return buildRule(s, initializeOptions(options));
}
function groomRruleOptions(val, dtstart, tzid) {
return __assign(__assign({}, val), { dtstart: dtstart,
tzid: tzid });
}
function initializeOptions(options) {
var invalid = [];
var keys = Object.keys(options);
var defaultKeys = Object.keys(DEFAULT_OPTIONS);
keys.forEach(function (key) {
if (!includes(defaultKeys, key))
invalid.push(key);
});
if (invalid.length) {
throw new Error('Invalid options: ' + invalid.join(', '));
}
return __assign(__assign({}, DEFAULT_OPTIONS), options);
}
function extractName(line) {
if (line.indexOf(':') === -1) {
return {
name: 'RRULE',
value: line
};
}
var _a = split(line, ':', 1), name = _a[0], value = _a[1];
return {
name: name,
value: value
};
}
function breakDownLine(line) {
var _a = extractName(line), name = _a.name, value = _a.value;
var parms = name.split(';');
if (!parms)
throw new Error('empty property name');
return {
name: parms[0].toUpperCase(),
parms: parms.slice(1),
value: value
};
}
function splitIntoLines(s, unfold) {
if (unfold === void 0) { unfold = false; }
s = s && s.trim();
if (!s)
throw new Error('Invalid empty string');
// More info about 'unfold' option
// Go head to http://www.ietf.org/rfc/rfc2445.txt
if (!unfold) {
return s.split(/\s/);
}
var lines = s.split('\n');
var i = 0;
while (i < lines.length) {
// TODO
var line = (lines[i] = lines[i].replace(/\s+$/g, ''));
if (!line) {
lines.splice(i, 1);
}
else if (i > 0 && line[0] === ' ') {
lines[i - 1] += line.slice(1);
lines.splice(i, 1);
}
else {
i += 1;
}
}
return lines;
}
function validateDateParm(parms) {
parms.forEach(function (parm) {
if (!/(VALUE=DATE(-TIME)?)|(TZID=)/.test(parm)) {
throw new Error('unsupported RDATE/EXDATE parm: ' + parm);
}
});
}
function parseRDate(rdateval, parms) {
validateDateParm(parms);
return rdateval
.split(',')
.map(function (datestr) { return dateutil$1.untilStringToDate(datestr); });
}
function createGetterSetter(fieldName) {
var _this = this;
return function (field) {
if (field !== undefined) {
_this["_" + fieldName] = field;
}
if (_this["_" + fieldName] !== undefined) {
return _this["_" + fieldName];
}
for (var i = 0; i < _this._rrule.length; i++) {
var field_1 = _this._rrule[i].origOptions[fieldName];
if (field_1) {
return field_1;
}
}
};
}
var RRuleSet = /** @class */ (function (_super) {
__extends(RRuleSet, _super);
/**
*
* @param {Boolean?} noCache
* The same stratagy as RRule on cache, default to false
* @constructor
*/
function RRuleSet(noCache) {
if (noCache === void 0) { noCache = false; }
var _this = _super.call(this, {}, noCache) || this;
_this.dtstart = createGetterSetter.apply(_this, ['dtstart']);
_this.tzid = createGetterSetter.apply(_this, ['tzid']);
_this._rrule = [];
_this._rdate = [];
_this._exrule = [];
_this._exdate = [];
return _this;
}
RRuleSet.prototype._iter = function (iterResult) {
return iterSet(iterResult, this._rrule, this._exrule, this._rdate, this._exdate, this.tzid());
};
/**
* Adds an RRule to the set
*
* @param {RRule}
*/
RRuleSet.prototype.rrule = function (rrule) {
_addRule(rrule, this._rrule);
};
/**
* Adds an EXRULE to the set
*
* @param {RRule}
*/
RRuleSet.prototype.exrule = function (rrule) {
_addRule(rrule, this._exrule);
};
/**
* Adds an RDate to the set
*
* @param {Date}
*/
RRuleSet.prototype.rdate = function (date) {
_addDate(date, this._rdate);
};
/**
* Adds an EXDATE to the set
*
* @param {Date}
*/
RRuleSet.prototype.exdate = function (date) {
_addDate(date, this._exdate);
};
/**
* Get list of included rrules in this recurrence set.
*
* @return List of rrules
*/
RRuleSet.prototype.rrules = function () {
return this._rrule.map(function (e) { return rrulestr(e.toString()); });
};
/**
* Get list of excluded rrules in this recurrence set.
*
* @return List of exrules
*/
RRuleSet.prototype.exrules = function () {
return this._exrule.map(function (e) { return rrulestr(e.toString()); });
};
/**
* Get list of included datetimes in this recurrence set.
*
* @return List of rdates
*/
RRuleSet.prototype.rdates = function () {
return this._rdate.map(function (e) { return new Date(e.getTime()); });
};
/**
* Get list of included datetimes in this recurrence set.
*
* @return List of exdates
*/
RRuleSet.prototype.exdates = function () {
return this._exdate.map(function (e) { return new Date(e.getTime()); });
};
RRuleSet.prototype.valueOf = function () {
var result = [];
if (!this._rrule.length && this._dtstart) {
result = result.concat(optionsToString({ dtstart: this._dtstart }));
}
this._rrule.forEach(function (rrule) {
result = result.concat(rrule.toString().split('\n'));
});
this._exrule.forEach(function (exrule) {
result = result.concat(exrule.toString().split('\n')
.map(function (line) { return line.replace(/^RRULE:/, 'EXRULE:'); })
.filter(function (line) { return !/^DTSTART/.test(line); }));
});
if (this._rdate.length) {
result.push(rdatesToString('RDATE', this._rdate, this.tzid()));
}
if (this._exdate.length) {
result.push(rdatesToString('EXDATE', this._exdate, this.tzid()));
}
return result;
};
/**
* to generate recurrence field such as:
* DTSTART:19970902T010000Z
* RRULE:FREQ=YEARLY;COUNT=2;BYDAY=TU
* RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TH
*/
RRuleSet.prototype.toString = function () {
return this.valueOf().join('\n');
};
/**
* Create a new RRuleSet Object completely base on current instance
*/
RRuleSet.prototype.clone = function () {
var rrs = new RRuleSet(!!this._cache);
this._rrule.forEach(function (rule) { return rrs.rrule(rule.clone()); });
this._exrule.forEach(function (rule) { return rrs.exrule(rule.clone()); });
this._rdate.forEach(function (date) { return rrs.rdate(new Date(date.getTime())); });
this._exdate.forEach(function (date) { return rrs.exdate(new Date(date.getTime())); });
return rrs;
};
return RRuleSet;
}(RRule));
function _addRule(rrule, collection) {
if (!(rrule instanceof RRule)) {
throw new TypeError(String(rrule) + ' is not RRule instance');
}
if (!includes(collection.map(String), String(rrule))) {
collection.push(rrule);
}
}
function _addDate(date, collection) {
if (!(date instanceof Date)) {
throw new TypeError(String(date) + ' is not Date instance');
}
if (!includes(collection.map(Number), Number(date))) {
collection.push(date);
dateutil$1.sort(collection);
}
}
function rdatesToString(param, rdates, tzid) {
var isUTC = !tzid || tzid.toUpperCase() === 'UTC';
var header = isUTC ? param + ":" : param + ";TZID=" + tzid + ":";
var dateString = rdates
.map(function (rdate) { return dateutil$1.timeToUntilString(rdate.valueOf(), isUTC); })
.join(',');
return "" + header + dateString;
}
class Symbol$1 {
constructor(primary, func) {
this.primary = primary;
this.func = func;
}
static ofChar(ch) {
return new Symbol$1(ch, text => {
return text === ch;
});
}
static ofChars(ch) {
if (ch.length === 0) {
throw "empty symbol";
}
if (ch[0] == null) {
throw "ch mustn't be null";
}
if (ch.length === 0) {
return this.ofChar(ch[0]);
}
return new Symbol$1(ch[0], text => {
return ch.filter(c => text === c).length > 0;
});
}
isSymbol(text) {
return this.func(text);
}
;
}
class Tokens {
constructor(tokens) {
this.tokens = tokens;
}
setTokenText(symbol, text, keepSpace = false, create = false, separateSymbolAndText = false) {
let token = this.getToken(symbol);
if (token === null) {
if (!create) {
return null;
}
// append new token
if (symbol instanceof Symbol$1) {
token = { symbol: symbol.primary, text };
}
else {
token = { symbol, text };
}
if (separateSymbolAndText && token.symbol !== '' && !token.text.startsWith(" ")) {
token.text = ' ' + token.text;
}
if (this.tokens.length > 0) {
const lastToken = this.tokens[this.tokens.length - 1];
if (!this.isTokenEndsWithSpace(lastToken)) {
// last token doesn't end with space. Append space to last token.
lastToken.text += ' ';
}
}
this.tokens.push(token);
return token;
}
this.replaceTokenText(token, text, keepSpace);
return token;
}
length() {
return this.tokens.length;
}
replaceTokenText(token, text, keepSpace = false) {
if (!keepSpace) {
token.text = text;
return;
}
token.text = token.text.replace(/^(\s*).*?(\s*)$/, `$1${text}$2`);
}
isTokenEndsWithSpace(token) {
return token.text.match(/^.*\s$/);
}
getToken(symbol) {
for (let token of this.tokens) {
if (symbol instanceof Symbol$1) {
if (symbol.isSymbol(token.symbol)) {
return token;
}
}
else {
if (symbol === token.symbol) {
return token;
}
}
}
return null;
}
getTokenText(symbol, removeSpace = false) {
const token = this.getToken(symbol);
if (token === null) {
return null;
}
if (!removeSpace) {
return token.text;
}
return token.text.replace(/^\s*(.*?)\s*$/, `$1`);
}
removeToken(symbol) {
this.tokens = this.tokens.filter(token => !symbol.isSymbol(token.symbol));
}
forEachTokens(consumer) {
this.tokens.forEach(consumer);
}
join() {
return this.tokens.map(t => t.symbol + t.text).join("");
}
}
function splitBySymbol(line, symbols) {
const chars = [...line];
let text = "";
let currentToken = null;
const splitted = [];
const fillPreviousToken = () => {
if (currentToken === null) {
// previous token
splitted.push({ symbol: '', text });
}
else {
// previous token
currentToken.text = text;
}
};
chars.forEach(c => {
let isSymbol = symbols.filter(s => s.isSymbol(c)).length > 0;
if (isSymbol) {
fillPreviousToken();
// new token
currentToken = { symbol: c, text: '' };
splitted.push(currentToken);
text = '';
}
else {
text += c;
}
});
if (text.length > 0) {
fillPreviousToken();
}
return splitted;
}
class TasksPluginReminderModel {
constructor(useCustomEmoji, strictDateFormat, tokens) {
this.useCustomEmoji = useCustomEmoji;
this.strictDateFormat = strictDateFormat;
this.tokens = tokens;
}
static parse(line, useCustomEmoji, strictDateFormat) {
return new TasksPluginReminderModel(useCustomEmoji !== null && useCustomEmoji !== void 0 ? useCustomEmoji : false, strictDateFormat !== null && strictDateFormat !== void 0 ? strictDateFormat : true, new Tokens(splitBySymbol(line, this.allSymbols)));
}
getTitle() {
return this.tokens.getTokenText("", true);
}
getTime() {
return this.getDate(this.getReminderSymbol());
}
setTime(time) {
this.setDate(this.getReminderSymbol(), time);
}
getDueDate() {
return this.getDate(TasksPluginReminderModel.symbolDueDate);
}
setDueDate(time) {
this.setDate(TasksPluginReminderModel.symbolDueDate, time);
}
setRawTime(rawTime) {
this.setDate(this.getReminderSymbol(), rawTime);
return true;
}
getReminderSymbol() {
if (this.useCustomEmoji) {
return TasksPluginReminderModel.symbolReminder;
}
else {
return TasksPluginReminderModel.symbolDueDate;
}
}
toMarkdown() {
return this.tokens.join();
}
setTitle(description) {
this.tokens.setTokenText("", description, true, true);
}
getDoneDate() {
return this.getDate(TasksPluginReminderModel.symbolDoneDate);
}
setDoneDate(time) {
this.setDate(TasksPluginReminderModel.symbolDoneDate, time);
}
getRecurrence() {
return this.tokens.getTokenText(TasksPluginReminderModel.symbolRecurrence, true);
}
clone() {
return TasksPluginReminderModel.parse(this.toMarkdown(), this.useCustomEmoji, this.strictDateFormat);
}
getDate(symbol) {
const dateText = this.tokens.getTokenText(symbol, true);
if (dateText === null) {
return null;
}
if (symbol === TasksPluginReminderModel.symbolReminder) {
return DATE_TIME_FORMATTER.parse(dateText);
}
else {
const date = moment(dateText, TasksPluginReminderModel.dateFormat, this.strictDateFormat);
if (!date.isValid()) {
return null;
}
return new DateTime$2(date, false);
}
}
setDate(symbol, time) {
if (time == null) {
this.tokens.removeToken(symbol);
return;
}
let timeStr;
if (time instanceof DateTime$2) {
if (symbol === TasksPluginReminderModel.symbolReminder) {
timeStr = DATE_TIME_FORMATTER.toString(time);
}
else {
timeStr = time.format(TasksPluginReminderModel.dateFormat);
}
}
else {
timeStr = time;
}
this.tokens.setTokenText(symbol, timeStr, true, true, this.shouldSplitBetweenSymbolAndText());
}
shouldSplitBetweenSymbolAndText() {
let withSpace = 0;
let noSpace = 0;
this.tokens.forEachTokens(token => {
if (token.symbol === '') {
return;
}
if (token.text.match(/^\s.*$/)) {
withSpace += 1;
}
else {
noSpace++;
}
});
if (withSpace > noSpace) {
return true;
}
else if (withSpace < noSpace) {
return false;
}
else {
return true;
}
}
}
TasksPluginReminderModel.dateFormat = "YYYY-MM-DD";
TasksPluginReminderModel.symbolDueDate = Symbol$1.ofChars([..."📅📆🗓"]);
TasksPluginReminderModel.symbolDoneDate = Symbol$1.ofChar("✅");
TasksPluginReminderModel.symbolRecurrence = Symbol$1.ofChar("🔁");
TasksPluginReminderModel.symbolReminder = Symbol$1.ofChar("⏰");
TasksPluginReminderModel.allSymbols = [
TasksPluginReminderModel.symbolDueDate,
TasksPluginReminderModel.symbolDoneDate,
TasksPluginReminderModel.symbolRecurrence,
TasksPluginReminderModel.symbolReminder,
];
class TasksPluginFormat extends TodoBasedReminderFormat {
parseReminder(todo) {
const parsed = TasksPluginReminderModel.parse(todo.body, this.useCustomEmoji(), this.isStrictDateFormat());
if (this.useCustomEmoji() && parsed.getDueDate() == null) {
return null;
}
return parsed;
}
useCustomEmoji() {
return this.config.getParameter(ReminderFormatParameterKey.useCustomEmojiForTasksPlugin);
}
modifyReminder(doc, todo, parsed, edit) {
if (!super.modifyReminder(doc, todo, parsed, edit)) {
return false;
}
if (edit.checked !== undefined) {
if (edit.checked) {
const recurrence = parsed.getRecurrence();
if (recurrence !== null) {
const nextReminderTodo = todo.clone();
const nextReminder = parsed.clone();
const dueDate = parsed.getDueDate();
if (dueDate == null) {
return false;
}
if (this.useCustomEmoji()) {
const time = parsed.getTime();
if (time == null) {
return false;
}
const nextTime = this.nextDate(recurrence, time.moment());
const nextDueDate = this.nextDate(recurrence, dueDate.moment());
if (nextTime == null || nextDueDate == null) {
return false;
}
nextReminder.setTime(new DateTime$2(moment(nextTime), true));
nextReminder.setDueDate(new DateTime$2(moment(nextDueDate), true));
}
else {
const next = this.nextDate(recurrence, dueDate.moment());
if (next == null) {
return false;
}
const nextDueDate = new DateTime$2(moment(next), true);
nextReminder.setTime(nextDueDate);
}
nextReminderTodo.body = nextReminder.toMarkdown();
nextReminderTodo.setChecked(false);
doc.insertTodo(todo.lineIndex, nextReminderTodo);
}
parsed.setDoneDate(this.config.getParameter(ReminderFormatParameterKey.now));
}
else {
parsed.setDoneDate(undefined);
}
}
return true;
}
nextDate(recurrence, dtStart) {
const rruleOptions = RRule.parseText(recurrence);
if (!rruleOptions) {
return undefined;
}
const today = this.config.getParameter(ReminderFormatParameterKey.now).moment();
today.set("hour", dtStart.get("hour"));
today.set("minute", dtStart.get("minute"));
today.set("second", dtStart.get("second"));
today.set("millisecond", dtStart.get("millisecond"));
if (today.isAfter(dtStart)) {
dtStart = today;
}
rruleOptions.dtstart = dtStart.toDate();
const rrule = new RRule(rruleOptions);
return rrule.after(dtStart.toDate(), false);
}
newReminder(title, time) {
const parsed = TasksPluginReminderModel.parse(title, this.useCustomEmoji(), this.isStrictDateFormat());
parsed.setTime(time);
if (this.useCustomEmoji() && parsed.getDueDate() == null) {
parsed.setDueDate(time);
}
parsed.setTitle(title);
return parsed;
}
}
TasksPluginFormat.instance = new TasksPluginFormat();
const REMINDER_FORMAT = new CompositeReminderFormat();
REMINDER_FORMAT.resetFormat([DefaultReminderFormat.instance]);
class ReminderFormatType {
constructor(name, description, example, format, defaultEnabled) {
this.name = name;
this.description = description;
this.example = example;
this.format = format;
this.defaultEnabled = defaultEnabled;
}
;
}
function parseReminder(doc) {
return REMINDER_FORMAT.parse(doc);
}
function modifyReminder(doc, reminder, edit) {
return __awaiter(this, void 0, void 0, function* () {
return REMINDER_FORMAT.modify(doc, reminder, edit);
});
}
function changeReminderFormat(formatTypes) {
if (formatTypes.length === 0) {
REMINDER_FORMAT.resetFormat([DefaultReminderFormat.instance]);
}
else {
REMINDER_FORMAT.resetFormat(formatTypes.map(f => f.format));
}
}
function setReminderFormatConfig(config) {
REMINDER_FORMAT.setConfig(config);
}
const reminderPluginReminderFormat = new ReminderFormatType("ReminderPluginReminderFormat", "Reminder plugin format", "(@2021-09-08)", DefaultReminderFormat.instance, true);
const tasksPluginReminderFormat = new ReminderFormatType("TasksPluginReminderFormat", "Tasks plugin format", "📅 2021-09-08", TasksPluginFormat.instance, false);
const kanbanPluginReminderFormat = new ReminderFormatType("KanbanPluginReminderFormat", "Kanban plugin format", "@{2021-09-08}", KanbanReminderFormat.instance, false);
const ReminderFormatTypes = [
reminderPluginReminderFormat,
tasksPluginReminderFormat,
kanbanPluginReminderFormat
];
class SettingRegistry {
constructor() {
this.settingContexts = [];
}
register(settingContext) {
this.settingContexts.push(settingContext);
}
findByKey(key) {
return this.settingContexts.find(c => c.key === key);
}
forEach(consumer) {
this.settingContexts.forEach(consumer);
}
}
class SettingContext {
constructor(_settingRegistry) {
this._settingRegistry = _settingRegistry;
this.tags = [];
}
init(settingModel, setting, containerEl) {
this.settingModel = settingModel;
this._setting = setting;
this.validationEl = containerEl.createDiv("validation", el => {
el.style.color = 'var(--text-error)';
el.style.marginBottom = '1rem';
el.style.fontSize = '14px';
el.style.display = 'none';
});
this.infoEl = containerEl.createDiv("info", el => {
el.style.color = 'var(--text-faint)';
el.style.marginBottom = '1rem';
el.style.fontSize = '14px';
el.style.display = 'none';
});
}
setValidationError(error) {
this.setText(this.validationEl, error);
}
setInfo(info) {
this.setText(this.infoEl, info);
}
setText(el, text) {
if (!el) {
console.error("element not created");
return;
}
if (text === null) {
el.style.display = "none";
}
else {
el.style.display = "block";
el.innerHTML = text;
}
}
get setting() {
return this._setting;
}
get registry() {
return this._settingRegistry;
}
hasTag(tag) {
return this.tags.filter(t => t === tag).length > 0;
}
update() {
if (!this.anyValueChanged) {
return;
}
this.anyValueChanged(this);
}
setEnabled(enable) {
this.setting.setDisabled(!enable);
}
findContextByKey(key) {
return this._settingRegistry.findByKey(key);
}
booleanValue() {
return this.settingModel.value;
}
isInitialized() {
return this.settingModel && this.validationEl && this.setting;
}
}
class SettingModelBuilder {
constructor(registry) {
this.registry = registry;
this.context = new SettingContext(this.registry);
this.registry.register(this.context);
}
key(key) {
this.context.key = key;
return this;
}
name(name) {
this.context.name = name;
return this;
}
desc(desc) {
this.context.desc = desc;
return this;
}
tag(tag) {
this.context.tags.push(tag);
return this;
}
enableWhen(enableWhen) {
this.context.anyValueChanged = enableWhen;
return this;
}
text(initValue) {
return new TextSettingModelBuilder(this.context, false, initValue);
}
textArea(initValue) {
return new TextSettingModelBuilder(this.context, true, initValue);
}
number(initValue) {
return new NumberSettingModelBuilder(this.context, initValue);
}
toggle(initValue) {
return new ToggleSettingModelBuilder(this.context, initValue);
}
dropdown(initValue) {
return new DropdownSettingModelBuilder(this.context, initValue);
}
}
class AbstractSettingModelBuilder {
constructor(context, initValue) {
this.context = context;
this.initValue = initValue;
}
;
onAnyValueChanged(anyValueChanged) {
this.context.anyValueChanged = anyValueChanged;
return this;
}
onValueChange() {
this.context.registry.forEach(c => {
c.update();
});
}
buildSettingModel(serde, initializer) {
return new SettingModelImpl(this.context, serde, this.initValue, initializer);
}
}
class TextSettingModelBuilder extends AbstractSettingModelBuilder {
constructor(context, longText, initValue) {
super(context, initValue);
this.longText = longText;
}
placeHolder(placeHolder) {
this._placeHolder = placeHolder;
return this;
}
build(serde) {
return this.buildSettingModel(serde, ({ setting, rawValue, context }) => {
const initText = (text) => {
var _a;
text
.setPlaceholder((_a = this._placeHolder) !== null && _a !== void 0 ? _a : "")
.setValue(rawValue.value)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
try {
serde.unmarshal(value);
rawValue.value = value;
context.setValidationError(null);
this.onValueChange();
}
catch (e) {
if (e instanceof Error) {
context.setValidationError(e.message);
}
else if (typeof e === "string") {
context.setValidationError(e);
}
}
}));
};
if (this.longText) {
setting.addTextArea((textarea) => {
initText(textarea);
});
}
else {
setting.addText((text) => {
initText(text);
});
}
});
}
}
class NumberSettingModelBuilder extends AbstractSettingModelBuilder {
constructor(context, initValue) {
super(context, initValue);
}
placeHolder(placeHolder) {
this._placeHolder = placeHolder;
return this;
}
build(serde) {
return this.buildSettingModel(serde, ({ setting, rawValue, context }) => {
const initText = (text) => {
var _a;
text
.setPlaceholder((_a = this._placeHolder) !== null && _a !== void 0 ? _a : "")
.setValue(rawValue.value.toString())
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
try {
const n = parseInt(value);
rawValue.value = n;
context.setValidationError(null);
this.onValueChange();
}
catch (e) {
if (e instanceof Error) {
context.setValidationError(e.message);
}
else if (typeof e === "string") {
context.setValidationError(e);
}
}
}));
};
setting.addText((textarea) => {
initText(textarea);
});
});
}
}
class ToggleSettingModelBuilder extends AbstractSettingModelBuilder {
build(serde) {
return new SettingModelImpl(this.context, serde, this.initValue, ({ setting, rawValue }) => {
setting.addToggle((toggle) => toggle
.setValue(rawValue.value)
.onChange((value) => __awaiter(this, void 0, void 0, function* () {
rawValue.value = value;
this.onValueChange();
})));
});
}
}
class DropdownOption {
constructor(label, value) {
this.label = label;
this.value = value;
}
}
class DropdownSettingModelBuilder extends AbstractSettingModelBuilder {
constructor() {
super(...arguments);
this.options = [];
}
addOption(label, value) {
this.options.push(new DropdownOption(label, value));
return this;
}
build(serde) {
return new SettingModelImpl(this.context, serde, this.initValue, ({ setting, rawValue }) => {
setting.addDropdown(d => {
this.options.forEach(option => {
d.addOption(option.value, option.label);
});
d.setValue(rawValue.value);
d.onChange((value) => __awaiter(this, void 0, void 0, function* () {
rawValue.value = value;
this.onValueChange();
}));
});
});
}
}
class SettingModelImpl {
constructor(context, serde, initRawValue, settingInitializer) {
this.context = context;
this.serde = serde;
this.settingInitializer = settingInitializer;
this.rawValue = new Reference(initRawValue);
if (context.key == null) {
throw new Error("key is required.");
}
}
createSetting(containerEl) {
var _a, _b;
const setting = new obsidian.Setting(containerEl)
.setName((_a = this.context.name) !== null && _a !== void 0 ? _a : "")
.setDesc((_b = this.context.desc) !== null && _b !== void 0 ? _b : "");
this.context.init(this, setting, containerEl);
this.settingInitializer({
setting,
rawValue: this.rawValue,
context: this.context
});
return setting;
}
get value() {
return this.serde.unmarshal(this.rawValue.value);
}
get key() {
return this.context.key;
}
load(settings) {
if (settings === undefined) {
return;
}
const newValue = settings[this.key];
if (newValue !== undefined) {
this.rawValue.value = newValue;
}
}
store(settings) {
settings[this.key] = this.rawValue.value;
}
hasTag(tag) {
return this.context.hasTag(tag);
}
}
class SettingGroup {
constructor(name) {
this.name = name;
this.settings = [];
}
addSettings(...settingModels) {
this.settings.push(...settingModels);
}
}
class SettingTabModel {
constructor() {
this.groups = [];
this.registry = new SettingRegistry();
}
newSettingBuilder() {
return new SettingModelBuilder(this.registry);
}
newGroup(name) {
const group = new SettingGroup(name);
this.groups.push(group);
return group;
}
displayOn(el) {
el.empty();
this.groups.forEach(group => {
el.createEl('h3', { text: group.name });
group.settings.forEach(settings => {
settings.createSetting(el);
});
});
this.registry.forEach(context => context.update());
}
forEach(consumer) {
this.groups.forEach(group => {
group.settings.forEach(setting => {
consumer(setting);
});
});
}
}
class TimeSerde {
unmarshal(rawValue) {
return Time$1.parse(rawValue);
}
marshal(value) {
return value.toString();
}
}
class RawSerde {
unmarshal(rawValue) {
return rawValue;
}
marshal(value) {
return value;
}
}
class LatersSerde {
unmarshal(rawValue) {
return parseLaters(rawValue);
}
marshal(value) {
return value.map(v => v.label).join("\n");
}
}
class ReminderFormatTypeSerde {
unmarshal(rawValue) {
const format = ReminderFormatTypes.find(format => format.name === rawValue);
// TODO return undefined when it is not found
return format;
}
marshal(value) {
return value.name;
}
}
const TAG_RESCAN = "re-scan";
class Settings {
constructor() {
this.settings = new SettingTabModel();
const reminderFormatSettings = new ReminderFormatSettings(this.settings);
this.reminderTime = this.settings.newSettingBuilder()
.key("reminderTime")
.name("Reminder Time")
.desc("Time when a reminder with no time part will show")
.tag(TAG_RESCAN)
.text("09:00")
.placeHolder("Time (hh:mm)")
.build(new TimeSerde());
this.useSystemNotification = this.settings.newSettingBuilder()
.key("useSystemNotification")
.name("Use system notification")
.desc("Use system notification for reminder notifications")
.toggle(false)
.build(new RawSerde());
this.laters = this.settings.newSettingBuilder()
.key("laters")
.name("Remind me later")
.desc("Line-separated list of remind me later items")
.textArea("In 30 minutes\nIn 1 hour\nIn 3 hours\nTomorrow\nNext week")
.placeHolder("In 30 minutes\nIn 1 hour\nIn 3 hours\nTomorrow\nNext week")
.build(new LatersSerde());
this.dateFormat = this.settings.newSettingBuilder()
.key("dateFormat")
.name("Date format")
.desc("moment style date format: https://momentjs.com/docs/#/displaying/format/")
.tag(TAG_RESCAN)
.text("YYYY-MM-DD")
.placeHolder("YYYY-MM-DD")
.onAnyValueChanged(context => {
context.setEnabled(reminderFormatSettings.enableReminderPluginReminderFormat.value);
})
.build(new RawSerde());
this.strictDateFormat = this.settings.newSettingBuilder()
.key("strictDateFormat")
.name("Strict Date format")
.desc("Strictly parse the date and time")
.tag(TAG_RESCAN)
.toggle(false)
.build(new RawSerde());
this.dateTimeFormat = this.settings.newSettingBuilder()
.key("dateTimeFormat")
.name("Date and time format")
.desc("moment() style date time format: https://momentjs.com/docs/#/displaying/format/")
.tag(TAG_RESCAN)
.text("YYYY-MM-DD HH:mm")
.placeHolder("YYYY-MM-DD HH:mm")
.onAnyValueChanged(context => {
context.setEnabled(reminderFormatSettings.enableReminderPluginReminderFormat.value);
})
.build(new RawSerde());
this.linkDatesToDailyNotes = this.settings.newSettingBuilder()
.key("linkDatesToDailyNotes")
.name("Link dates to daily notes")
.desc("When toggled, Dates link to daily notes.")
.tag(TAG_RESCAN)
.toggle(false)
.onAnyValueChanged(context => {
context.setEnabled(reminderFormatSettings.enableReminderPluginReminderFormat.value);
})
.build(new RawSerde());
this.autoCompleteTrigger = this.settings.newSettingBuilder()
.key("autoCompleteTrigger")
.name("Calendar popup trigger")
.desc("Trigger text to show calendar popup")
.text("(@")
.placeHolder("(@")
.onAnyValueChanged(context => {
const value = this.autoCompleteTrigger.value;
context.setInfo(`Popup is ${value.length === 0 ? "disabled" : "enabled"}`);
})
.build(new RawSerde());
const primaryFormatBuilder = this.settings.newSettingBuilder()
.key("primaryReminderFormat")
.name("Primary reminder format")
.desc("Reminder format for generated reminder by calendar popup")
.dropdown(ReminderFormatTypes[0].name);
ReminderFormatTypes.forEach(f => primaryFormatBuilder.addOption(`${f.description} - ${f.example}`, f.name));
this.primaryFormat = primaryFormatBuilder.build(new ReminderFormatTypeSerde());
this.useCustomEmojiForTasksPlugin = this.settings.newSettingBuilder()
.key("useCustomEmojiForTasksPlugin")
.name("Distinguish between reminder date and due date")
.desc("Use custom emoji ⏰ instead of 📅 and distinguish between reminder date/time and Tasks Plugin's due date.")
.tag(TAG_RESCAN)
.toggle(false)
.onAnyValueChanged(context => {
context.setEnabled(reminderFormatSettings.enableTasksPluginReminderFormat.value);
})
.build(new RawSerde());
this.editDetectionSec = this.settings.newSettingBuilder()
.key("editDetectionSec")
.name("Edit Detection Time")
.desc("The minimum amount of time (in seconds) after a key is typed that it will be identified as notifiable.")
.number(10)
.build(new RawSerde());
this.reminderCheckIntervalSec = this.settings.newSettingBuilder()
.key("reminderCheckIntervalSec")
.name("Reminder check interval")
.desc("Interval(in seconds) to periodically check whether or not you should be notified of reminders. You will need to restart Obsidian for this setting to take effect.")
.number(5)
.build(new RawSerde());
this.settings
.newGroup("Notification Settings")
.addSettings(this.reminderTime, this.laters, this.useSystemNotification);
this.settings
.newGroup("Editor")
.addSettings(this.autoCompleteTrigger, this.primaryFormat);
this.settings
.newGroup("Reminder Format - Reminder Plugin")
.addSettings(reminderFormatSettings.enableReminderPluginReminderFormat, this.dateFormat, this.dateTimeFormat, this.strictDateFormat, this.linkDatesToDailyNotes);
this.settings
.newGroup("Reminder Format - Tasks Plugin")
.addSettings(reminderFormatSettings.enableTasksPluginReminderFormat, this.useCustomEmojiForTasksPlugin);
this.settings
.newGroup("Reminder Format - Kanban Plugin")
.addSettings(reminderFormatSettings.enableKanbanPluginReminderFormat);
this.settings
.newGroup("Advanced")
.addSettings(this.editDetectionSec, this.reminderCheckIntervalSec);
const config = new ReminderFormatConfig();
config.setParameterFunc(ReminderFormatParameterKey.now, () => DateTime$2.now());
config.setParameter(ReminderFormatParameterKey.useCustomEmojiForTasksPlugin, this.useCustomEmojiForTasksPlugin);
config.setParameter(ReminderFormatParameterKey.linkDatesToDailyNotes, this.linkDatesToDailyNotes);
setReminderFormatConfig(config);
}
forEach(consumer) {
this.settings.forEach(consumer);
}
}
class ReminderFormatSettings {
constructor(settings) {
this.settings = settings;
this.settingKeyToFormatName = new Map();
this.reminderFormatSettings = [];
this.enableReminderPluginReminderFormat = this.createUseReminderFormatSetting(reminderPluginReminderFormat);
this.enableTasksPluginReminderFormat = this.createUseReminderFormatSetting(tasksPluginReminderFormat);
this.enableKanbanPluginReminderFormat = this.createUseReminderFormatSetting(kanbanPluginReminderFormat);
}
createUseReminderFormatSetting(format) {
const key = `enable${format.name}`;
const setting = this.settings.newSettingBuilder()
.key(key)
.name(`Enable ${format.description}`)
.desc(`Enable ${format.description}`)
.tag(TAG_RESCAN)
.toggle(format.defaultEnabled)
.onAnyValueChanged(context => {
context.setInfo(`Example: ${format.format.appendReminder("- [ ] Task 1", DateTime$2.now())}`);
})
.build(new RawSerde());
this.settingKeyToFormatName.set(key, format);
this.reminderFormatSettings.push(setting);
setting.rawValue.onChanged(() => {
this.updateReminderFormat(setting);
});
return setting;
}
updateReminderFormat(setting) {
const selectedFormats = this.reminderFormatSettings
.filter(s => s.value)
.map(s => this.settingKeyToFormatName.get(s.key))
.filter((s) => s !== undefined);
changeReminderFormat(selectedFormats);
}
}
const SETTINGS = new Settings();
class ReminderSettingTab extends obsidian.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
}
display() {
let { containerEl } = this;
SETTINGS.settings.displayOn(containerEl);
}
}
class Content {
constructor(file, content) {
this.doc = new MarkdownDocument(file, content);
}
getReminders(doneOnly = true) {
const reminders = parseReminder(this.doc);
if (!doneOnly) {
return reminders;
}
return reminders.filter(reminder => !reminder.done);
}
getTodos() {
return this.doc.getTodos();
}
modifyReminderLines(modifyFunc) {
return __awaiter(this, void 0, void 0, function* () {
for (const reminder of this.getReminders(false)) {
const edit = modifyFunc(reminder);
if (edit === null) {
return;
}
yield this.modifyReminderLine(reminder, edit);
}
});
}
updateReminder(reminder, edit) {
return __awaiter(this, void 0, void 0, function* () {
yield this.modifyReminderLine(reminder, edit);
});
}
modifyReminderLine(reminder, edit) {
return __awaiter(this, void 0, void 0, function* () {
const modified = yield modifyReminder(this.doc, reminder, edit);
if (modified) {
console.info("Reminder was updated: reminder=%o", reminder);
}
else {
console.warn("Cannot modify reminder because it's not a reminder todo: reminder=%o", reminder);
}
return modified;
});
}
getContent() {
return this.doc.toMarkdown();
}
}
class RemindersController {
constructor(vault, viewProxy, reminders) {
this.vault = vault;
this.viewProxy = viewProxy;
this.reminders = reminders;
}
openReminder(reminder, leaf) {
return __awaiter(this, void 0, void 0, function* () {
console.log("Open reminder: ", reminder);
const file = this.vault.getAbstractFileByPath(reminder.file);
if (!(file instanceof obsidian.TFile)) {
console.error("Cannot open file because it isn't a TFile: %o", file);
return;
}
// Open the reminder file and select the reminder
yield leaf.openFile(file);
if (!(leaf.view instanceof obsidian.MarkdownView)) {
return;
}
leaf.view.editor.setSelection({
line: reminder.rowNumber,
ch: 0,
}, {
line: reminder.rowNumber,
// End of the line
ch: 1000,
});
});
}
removeFile(path) {
return __awaiter(this, void 0, void 0, function* () {
console.debug("Remove file: path=%s", path);
this.reminders.removeFile(path);
this.reloadUI();
});
}
reloadFile(file, reloadUI = false) {
return __awaiter(this, void 0, void 0, function* () {
console.debug("Reload file and collect reminders: file=%s, forceReloadUI=%s", file.path, reloadUI);
if (!(file instanceof obsidian.TFile)) {
console.debug("Cannot read file other than TFile: file=%o", file);
return false;
}
if (!this.isMarkdownFile(file)) {
console.debug("Not a markdown file: file=%o", file);
return false;
}
const content = new Content(file.path, yield this.vault.cachedRead(file));
const reminders = content.getReminders();
if (reminders.length > 0) {
if (!this.reminders.replaceFile(file.path, reminders)) {
return false;
}
}
else {
if (!this.reminders.removeFile(file.path)) {
return false;
}
}
if (reloadUI) {
this.reloadUI();
}
return true;
});
}
convertDateTimeFormat(dateFormat, dateTimeFormat) {
return __awaiter(this, void 0, void 0, function* () {
let updated = 0;
for (const file of this.vault.getMarkdownFiles()) {
const content = new Content(file.path, yield this.vault.read(file));
let updatedInFile = 0;
yield content.modifyReminderLines(reminder => {
let converted;
if (reminder.time.hasTimePart) {
converted = reminder.time.format(dateTimeFormat);
}
else {
converted = reminder.time.format(dateFormat);
}
updated++;
updatedInFile++;
return {
rawTime: converted
};
});
if (updatedInFile > 0) {
yield this.vault.modify(file, content.getContent());
}
}
SETTINGS.dateFormat.rawValue.value = dateFormat;
SETTINGS.dateTimeFormat.rawValue.value = dateTimeFormat;
if (updated > 0) {
yield this.reloadAllFiles();
}
return updated;
});
}
isMarkdownFile(file) {
return file.extension.toLowerCase() === "md";
}
reloadAllFiles() {
return __awaiter(this, void 0, void 0, function* () {
console.debug("Reload all files and collect reminders");
this.reminders.clear();
for (const file of this.vault.getMarkdownFiles()) {
yield this.reloadFile(file, false);
}
this.reloadUI();
});
}
updateReminder(reminder, checked) {
return __awaiter(this, void 0, void 0, function* () {
const file = this.vault.getAbstractFileByPath(reminder.file);
if (!(file instanceof obsidian.TFile)) {
console.error("file is not instance of TFile: %o", file);
return;
}
const content = new Content(file.path, yield this.vault.read(file));
yield content.updateReminder(reminder, {
checked,
time: reminder.time
});
yield this.vault.modify(file, content.getContent());
});
}
toggleCheck(file, lineNumber) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.isMarkdownFile(file)) {
return;
}
const content = new Content(file.path, yield this.vault.read(file));
const reminder = content.getReminders(false).find(r => r.rowNumber === lineNumber);
if (reminder) {
yield content.updateReminder(reminder, {
checked: !reminder.done
});
}
else {
const todo = content.getTodos().find(t => t.lineIndex === lineNumber);
console.log(todo);
if (!todo) {
return;
}
todo.setChecked(!todo.isChecked());
}
yield this.vault.modify(file, content.getContent());
});
}
reloadUI() {
console.debug("Reload reminder list view");
if (this.viewProxy === null) {
console.debug("reminder list is null. Skipping UI reload.");
return;
}
this.viewProxy.reload(true);
}
}
class PluginDataIO {
constructor(plugin, reminders) {
this.plugin = plugin;
this.reminders = reminders;
this.restoring = true;
this.changed = false;
this.scanned = new Reference(false);
this.debug = new Reference(false);
SETTINGS.forEach(setting => {
setting.rawValue.onChanged(() => {
if (this.restoring) {
return;
}
if (setting.hasTag(TAG_RESCAN)) {
this.scanned.value = false;
}
this.changed = true;
});
});
}
load() {
return __awaiter(this, void 0, void 0, function* () {
console.debug("Load reminder plugin data");
const data = yield this.plugin.loadData();
if (!data) {
this.scanned.value = false;
return;
}
this.scanned.value = data.scanned;
if (data.debug != null) {
this.debug.value = data.debug;
}
const loadedSettings = data.settings;
SETTINGS.forEach(setting => {
setting.load(loadedSettings);
});
if (data.reminders) {
Object.keys(data.reminders).forEach((filePath) => {
const remindersInFile = data.reminders[filePath];
if (!remindersInFile) {
return;
}
this.reminders.replaceFile(filePath, remindersInFile.map((d) => new Reminder$1(filePath, d.title, DateTime$2.parse(d.time), d.rowNumber, false)));
});
}
this.changed = false;
if (this.restoring) {
this.restoring = false;
}
});
}
save(force = false) {
return __awaiter(this, void 0, void 0, function* () {
if (!force && !this.changed) {
return;
}
console.debug("Save reminder plugin data: force=%s, changed=%s", force, this.changed);
const remindersData = {};
this.reminders.fileToReminders.forEach((r, filePath) => {
remindersData[filePath] = r.map((rr) => ({
title: rr.title,
time: rr.time.toString(),
rowNumber: rr.rowNumber,
}));
});
const settings = {};
SETTINGS.forEach(setting => {
setting.store(settings);
});
yield this.plugin.saveData({
scanned: this.scanned.value,
reminders: remindersData,
debug: this.debug.value,
settings
});
this.changed = false;
});
}
}
// Copied from: https://gist.github.com/liamcain/3f21f1ee820cb30f18050d2f3ad85f3f
// Call this method inside your plugin's
// `onload` function like so:
// monkeyPatchConsole(this);
function monkeyPatchConsole(plugin) {
if (!obsidian.Platform.isMobile) {
return;
}
const logFile = `${plugin.manifest.dir}/logs.txt`;
const logs = [];
const logMessages = (prefix) => (...messages) => {
logs.push(`\n[${prefix}]`);
for (const message of messages) {
logs.push(String(message));
}
plugin.app.vault.adapter.write(logFile, logs.join(" "));
};
console.debug = logMessages("debug");
console.error = logMessages("error");
console.info = logMessages("info");
console.log = logMessages("log");
console.warn = logMessages("warn");
}
function noop() { }
function run(fn) {
return fn();
}
function blank_object() {
return Object.create(null);
}
function run_all(fns) {
fns.forEach(run);
}
function is_function(thing) {
return typeof thing === 'function';
}
function safe_not_equal(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function is_empty(obj) {
return Object.keys(obj).length === 0;
}
function append(target, node) {
target.appendChild(node);
}
function append_styles(target, style_sheet_id, styles) {
const append_styles_to = get_root_for_style(target);
if (!append_styles_to.getElementById(style_sheet_id)) {
const style = element('style');
style.id = style_sheet_id;
style.textContent = styles;
append_stylesheet(append_styles_to, style);
}
}
function get_root_for_style(node) {
if (!node)
return document;
const root = node.getRootNode ? node.getRootNode() : node.ownerDocument;
if (root.host) {
return root;
}
return document;
}
function append_stylesheet(node, style) {
append(node.head || node, style);
}
function insert(target, node, anchor) {
target.insertBefore(node, anchor || null);
}
function detach(node) {
node.parentNode.removeChild(node);
}
function destroy_each(iterations, detaching) {
for (let i = 0; i < iterations.length; i += 1) {
if (iterations[i])
iterations[i].d(detaching);
}
}
function element(name) {
return document.createElement(name);
}
function text(data) {
return document.createTextNode(data);
}
function space() {
return text(' ');
}
function listen(node, event, handler, options) {
node.addEventListener(event, handler, options);
return () => node.removeEventListener(event, handler, options);
}
function attr(node, attribute, value) {
if (value == null)
node.removeAttribute(attribute);
else if (node.getAttribute(attribute) !== value)
node.setAttribute(attribute, value);
}
function children(element) {
return Array.from(element.childNodes);
}
function set_data(text, data) {
data = '' + data;
if (text.wholeText !== data)
text.data = data;
}
function select_option(select, value) {
for (let i = 0; i < select.options.length; i += 1) {
const option = select.options[i];
if (option.__value === value) {
option.selected = true;
return;
}
}
select.selectedIndex = -1; // no option should be selected
}
function select_value(select) {
const selected_option = select.querySelector(':checked') || select.options[0];
return selected_option && selected_option.__value;
}
function toggle_class(element, name, toggle) {
element.classList[toggle ? 'add' : 'remove'](name);
}
let current_component;
function set_current_component(component) {
current_component = component;
}
function get_current_component() {
if (!current_component)
throw new Error('Function called outside component initialization');
return current_component;
}
function onMount(fn) {
get_current_component().$$.on_mount.push(fn);
}
function afterUpdate(fn) {
get_current_component().$$.after_update.push(fn);
}
const dirty_components = [];
const binding_callbacks = [];
const render_callbacks = [];
const flush_callbacks = [];
const resolved_promise = Promise.resolve();
let update_scheduled = false;
function schedule_update() {
if (!update_scheduled) {
update_scheduled = true;
resolved_promise.then(flush);
}
}
function add_render_callback(fn) {
render_callbacks.push(fn);
}
let flushing = false;
const seen_callbacks = new Set();
function flush() {
if (flushing)
return;
flushing = true;
do {
// first, call beforeUpdate functions
// and update components
for (let i = 0; i < dirty_components.length; i += 1) {
const component = dirty_components[i];
set_current_component(component);
update(component.$$);
}
set_current_component(null);
dirty_components.length = 0;
while (binding_callbacks.length)
binding_callbacks.pop()();
// then, once components are updated, call
// afterUpdate functions. This may cause
// subsequent updates...
for (let i = 0; i < render_callbacks.length; i += 1) {
const callback = render_callbacks[i];
if (!seen_callbacks.has(callback)) {
// ...so guard against infinite loops
seen_callbacks.add(callback);
callback();
}
}
render_callbacks.length = 0;
} while (dirty_components.length);
while (flush_callbacks.length) {
flush_callbacks.pop()();
}
update_scheduled = false;
flushing = false;
seen_callbacks.clear();
}
function update($$) {
if ($$.fragment !== null) {
$$.update();
run_all($$.before_update);
const dirty = $$.dirty;
$$.dirty = [-1];
$$.fragment && $$.fragment.p($$.ctx, dirty);
$$.after_update.forEach(add_render_callback);
}
}
const outroing = new Set();
let outros;
function group_outros() {
outros = {
r: 0,
c: [],
p: outros // parent group
};
}
function check_outros() {
if (!outros.r) {
run_all(outros.c);
}
outros = outros.p;
}
function transition_in(block, local) {
if (block && block.i) {
outroing.delete(block);
block.i(local);
}
}
function transition_out(block, local, detach, callback) {
if (block && block.o) {
if (outroing.has(block))
return;
outroing.add(block);
outros.c.push(() => {
outroing.delete(block);
if (callback) {
if (detach)
block.d(1);
callback();
}
});
block.o(local);
}
}
function create_component(block) {
block && block.c();
}
function mount_component(component, target, anchor, customElement) {
const { fragment, on_mount, on_destroy, after_update } = component.$$;
fragment && fragment.m(target, anchor);
if (!customElement) {
// onMount happens before the initial afterUpdate
add_render_callback(() => {
const new_on_destroy = on_mount.map(run).filter(is_function);
if (on_destroy) {
on_destroy.push(...new_on_destroy);
}
else {
// Edge case - component was destroyed immediately,
// most likely as a result of a binding initialising
run_all(new_on_destroy);
}
component.$$.on_mount = [];
});
}
after_update.forEach(add_render_callback);
}
function destroy_component(component, detaching) {
const $$ = component.$$;
if ($$.fragment !== null) {
run_all($$.on_destroy);
$$.fragment && $$.fragment.d(detaching);
// TODO null out other refs, including component.$$ (but need to
// preserve final state?)
$$.on_destroy = $$.fragment = null;
$$.ctx = [];
}
}
function make_dirty(component, i) {
if (component.$$.dirty[0] === -1) {
dirty_components.push(component);
schedule_update();
component.$$.dirty.fill(0);
}
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
}
function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) {
const parent_component = current_component;
set_current_component(component);
const $$ = component.$$ = {
fragment: null,
ctx: null,
// state
props,
update: noop,
not_equal,
bound: blank_object(),
// lifecycle
on_mount: [],
on_destroy: [],
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(parent_component ? parent_component.$$.context : options.context || []),
// everything else
callbacks: blank_object(),
dirty,
skip_bound: false,
root: options.target || parent_component.$$.root
};
append_styles && append_styles($$.root);
let ready = false;
$$.ctx = instance
? instance(component, options.props || {}, (i, ret, ...rest) => {
const value = rest.length ? rest[0] : ret;
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
if (!$$.skip_bound && $$.bound[i])
$$.bound[i](value);
if (ready)
make_dirty(component, i);
}
return ret;
})
: [];
$$.update();
ready = true;
run_all($$.before_update);
// `false` as a special case of no DOM component
$$.fragment = create_fragment ? create_fragment($$.ctx) : false;
if (options.target) {
if (options.hydrate) {
const nodes = children(options.target);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment.l(nodes);
nodes.forEach(detach);
}
else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment.c();
}
if (options.intro)
transition_in(component.$$.fragment);
mount_component(component, options.target, options.anchor, options.customElement);
flush();
}
set_current_component(parent_component);
}
/**
* Base class for Svelte components. Used when dev=false.
*/
class SvelteComponent {
$destroy() {
destroy_component(this, 1);
this.$destroy = noop;
}
$on(type, callback) {
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
callbacks.push(callback);
return () => {
const index = callbacks.indexOf(callback);
if (index !== -1)
callbacks.splice(index, 1);
};
}
$set($$props) {
if (this.$$set && !is_empty($$props)) {
this.$$.skip_bound = true;
this.$$set($$props);
this.$$.skip_bound = false;
}
}
}
class Day {
constructor(date) {
this.date = date;
}
isToday(date) {
if (this.date === undefined) {
return false;
}
return this.date.date() === date.date() && this.date.month() === date.month() && this.date.year() === date.year();
}
isHoliday() {
return this.date.weekday() === 0 || this.date.weekday() === 6;
}
}
class Week {
constructor(weekStart) {
this.weekStart = weekStart;
this.days = [];
const current = weekStart.clone();
for (let i = 0; i < 7; i++) {
this.days.push(new Day(current.clone()));
current.add(1, "day");
}
}
}
class Month {
constructor(monthStart) {
this.monthStart = monthStart;
this.weeks = [];
let current = monthStart.clone().add(-monthStart.weekday(), "day");
for (let i = 0; i < 6; i++) {
if (i > 0 && !this.isThisMonth(current)) {
break;
}
this.weeks.push(new Week(current.clone()));
current.add(1, "week");
}
}
isThisMonth(date) {
return this.monthStart.month() === date.month() && this.monthStart.year() === date.year();
}
}
class Calendar {
constructor(today, monthStart) {
if (today) {
this.today = today;
}
else {
this.today = moment();
}
if (monthStart) {
this._current = new Month(monthStart.clone().set("date", 1));
}
else {
this._current = new Month(this.today.clone().set("date", 1));
}
}
nextMonth() {
return new Calendar(this.today, this._current.monthStart.clone().add(1, "month"));
}
previousMonth() {
return new Calendar(this.today, this._current.monthStart.clone().add(-1, "month"));
}
calendarString() {
let str = `${this._current.monthStart.format("YYYY, MMM")}\nSun Mon Tue Wed Thu Fri Sat\n`;
this._current.weeks.forEach((week, weekIndex) => {
let line = " ";
week.days.forEach((slot, slotIndex) => {
let s;
if (slot.date) {
if (this._current.isThisMonth(slot.date)) {
s = slot.date.format("DD");
}
else {
s = " ";
}
}
else {
s = " ";
}
line = line + s + " ";
});
str = str + line + "\n";
});
return str;
}
get current() {
return this._current;
}
}
/* src/ui/components/Calendar.svelte generated by Svelte v3.42.2 */
function add_css$5(target) {
append_styles(target, "svelte-18sic8s", ".reminder-calendar.svelte-18sic8s.svelte-18sic8s{padding:0.5rem}.reminder-calendar.svelte-18sic8s .year-month.svelte-18sic8s{font-size:1rem;font-weight:bold;text-align:center}.reminder-calendar.svelte-18sic8s .month-nav.svelte-18sic8s{color:var(--text-muted);margin-left:1rem;margin-right:1rem;cursor:pointer}.reminder-calendar.svelte-18sic8s .month.svelte-18sic8s{color:var(--text-muted)}.reminder-calendar.svelte-18sic8s .year.svelte-18sic8s{color:var(--text-accent)}.reminder-calendar.svelte-18sic8s th.svelte-18sic8s{font-size:0.7rem;color:var(--text-muted)}.reminder-calendar.svelte-18sic8s .calendar-date.svelte-18sic8s{text-align:center;min-width:2rem;max-width:2rem}.reminder-calendar.svelte-18sic8s .calendar-date.svelte-18sic8s:hover{background-color:var(--background-secondary-alt)}.reminder-calendar.svelte-18sic8s .is-selected.svelte-18sic8s{background-color:var(--text-accent) !important;color:var(--text-normal) !important}.reminder-calendar.svelte-18sic8s .other-month.svelte-18sic8s,.reminder-calendar.svelte-18sic8s .is-past.svelte-18sic8s,.reminder-calendar.svelte-18sic8s .is-holiday.svelte-18sic8s{color:var(--text-faint)}");
}
function get_each_context$3(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[8] = list[i];
child_ctx[10] = i;
return child_ctx;
}
function get_each_context_1(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[11] = list[i];
child_ctx[10] = i;
return child_ctx;
}
// (41:20) {#each week.days as day, i}
function create_each_block_1(ctx) {
let td;
let t_value = /*day*/ ctx[11].date.format("D") + "";
let t;
let mounted;
let dispose;
function click_handler_2() {
return /*click_handler_2*/ ctx[7](/*day*/ ctx[11]);
}
return {
c() {
td = element("td");
t = text(t_value);
attr(td, "class", "calendar-date svelte-18sic8s");
toggle_class(td, "is-selected", /*day*/ ctx[11].isToday(/*selectedDate*/ ctx[1]));
toggle_class(td, "other-month", !/*calendar*/ ctx[0].current.isThisMonth(/*day*/ ctx[11].date));
toggle_class(td, "is-holiday", /*day*/ ctx[11].isHoliday());
toggle_class(td, "is-past", /*day*/ ctx[11].date.isBefore(/*calendar*/ ctx[0].today));
},
m(target, anchor) {
insert(target, td, anchor);
append(td, t);
if (!mounted) {
dispose = listen(td, "click", click_handler_2);
mounted = true;
}
},
p(new_ctx, dirty) {
ctx = new_ctx;
if (dirty & /*calendar*/ 1 && t_value !== (t_value = /*day*/ ctx[11].date.format("D") + "")) set_data(t, t_value);
if (dirty & /*calendar, selectedDate*/ 3) {
toggle_class(td, "is-selected", /*day*/ ctx[11].isToday(/*selectedDate*/ ctx[1]));
}
if (dirty & /*calendar*/ 1) {
toggle_class(td, "other-month", !/*calendar*/ ctx[0].current.isThisMonth(/*day*/ ctx[11].date));
}
if (dirty & /*calendar*/ 1) {
toggle_class(td, "is-holiday", /*day*/ ctx[11].isHoliday());
}
if (dirty & /*calendar*/ 1) {
toggle_class(td, "is-past", /*day*/ ctx[11].date.isBefore(/*calendar*/ ctx[0].today));
}
},
d(detaching) {
if (detaching) detach(td);
mounted = false;
dispose();
}
};
}
// (39:12) {#each calendar.current.weeks as week, i}
function create_each_block$3(ctx) {
let tr;
let t;
let each_value_1 = /*week*/ ctx[8].days;
let each_blocks = [];
for (let i = 0; i < each_value_1.length; i += 1) {
each_blocks[i] = create_each_block_1(get_each_context_1(ctx, each_value_1, i));
}
return {
c() {
tr = element("tr");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
t = space();
},
m(target, anchor) {
insert(target, tr, anchor);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(tr, null);
}
append(tr, t);
},
p(ctx, dirty) {
if (dirty & /*calendar, selectedDate, onClick, DateTime*/ 7) {
each_value_1 = /*week*/ ctx[8].days;
let i;
for (i = 0; i < each_value_1.length; i += 1) {
const child_ctx = get_each_context_1(ctx, each_value_1, i);
if (each_blocks[i]) {
each_blocks[i].p(child_ctx, dirty);
} else {
each_blocks[i] = create_each_block_1(child_ctx);
each_blocks[i].c();
each_blocks[i].m(tr, t);
}
}
for (; i < each_blocks.length; i += 1) {
each_blocks[i].d(1);
}
each_blocks.length = each_value_1.length;
}
},
d(detaching) {
if (detaching) detach(tr);
destroy_each(each_blocks, detaching);
}
};
}
function create_fragment$6(ctx) {
let div1;
let div0;
let span0;
let t1;
let span1;
let t2_value = /*calendar*/ ctx[0].current.monthStart.format("MMM") + "";
let t2;
let t3;
let span2;
let t4_value = /*calendar*/ ctx[0].current.monthStart.format("YYYY") + "";
let t4;
let t5;
let span3;
let t7;
let table;
let thead;
let t21;
let tbody;
let mounted;
let dispose;
let each_value = /*calendar*/ ctx[0].current.weeks;
let each_blocks = [];
for (let i = 0; i < each_value.length; i += 1) {
each_blocks[i] = create_each_block$3(get_each_context$3(ctx, each_value, i));
}
return {
c() {
div1 = element("div");
div0 = element("div");
span0 = element("span");
span0.textContent = "<";
t1 = space();
span1 = element("span");
t2 = text(t2_value);
t3 = space();
span2 = element("span");
t4 = text(t4_value);
t5 = space();
span3 = element("span");
span3.textContent = ">";
t7 = space();
table = element("table");
thead = element("thead");
thead.innerHTML = `<tr><th class="svelte-18sic8s">SUN</th>
<th class="svelte-18sic8s">MON</th>
<th class="svelte-18sic8s">TUE</th>
<th class="svelte-18sic8s">WED</th>
<th class="svelte-18sic8s">THU</th>
<th class="svelte-18sic8s">FRI</th>
<th class="svelte-18sic8s">SAT</th></tr>`;
t21 = space();
tbody = element("tbody");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
attr(span0, "class", "month-nav svelte-18sic8s");
attr(span1, "class", "month svelte-18sic8s");
attr(span2, "class", "year svelte-18sic8s");
attr(span3, "class", "month-nav svelte-18sic8s");
attr(div0, "class", "year-month svelte-18sic8s");
attr(div1, "class", "reminder-calendar svelte-18sic8s");
},
m(target, anchor) {
insert(target, div1, anchor);
append(div1, div0);
append(div0, span0);
append(div0, t1);
append(div0, span1);
append(span1, t2);
append(div0, t3);
append(div0, span2);
append(span2, t4);
append(div0, t5);
append(div0, span3);
append(div1, t7);
append(div1, table);
append(table, thead);
append(table, t21);
append(table, tbody);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(tbody, null);
}
if (!mounted) {
dispose = [
listen(span0, "click", /*click_handler*/ ctx[5]),
listen(span3, "click", /*click_handler_1*/ ctx[6])
];
mounted = true;
}
},
p(ctx, [dirty]) {
if (dirty & /*calendar*/ 1 && t2_value !== (t2_value = /*calendar*/ ctx[0].current.monthStart.format("MMM") + "")) set_data(t2, t2_value);
if (dirty & /*calendar*/ 1 && t4_value !== (t4_value = /*calendar*/ ctx[0].current.monthStart.format("YYYY") + "")) set_data(t4, t4_value);
if (dirty & /*calendar, selectedDate, onClick, DateTime*/ 7) {
each_value = /*calendar*/ ctx[0].current.weeks;
let i;
for (i = 0; i < each_value.length; i += 1) {
const child_ctx = get_each_context$3(ctx, each_value, i);
if (each_blocks[i]) {
each_blocks[i].p(child_ctx, dirty);
} else {
each_blocks[i] = create_each_block$3(child_ctx);
each_blocks[i].c();
each_blocks[i].m(tbody, null);
}
}
for (; i < each_blocks.length; i += 1) {
each_blocks[i].d(1);
}
each_blocks.length = each_value.length;
}
},
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(div1);
destroy_each(each_blocks, detaching);
mounted = false;
run_all(dispose);
}
};
}
function instance$6($$self, $$props, $$invalidate) {
let { calendar = new Calendar() } = $$props;
let { selectedDate = moment() } = $$props;
let { onClick = date => {
console.log(date);
} } = $$props;
function previousMonth() {
selectedDate.add(-1, "month");
$$invalidate(0, calendar = calendar.previousMonth());
}
function nextMonth() {
selectedDate.add(1, "month");
$$invalidate(0, calendar = calendar.nextMonth());
}
const click_handler = () => previousMonth();
const click_handler_1 = () => nextMonth();
const click_handler_2 = day => onClick(new DateTime$2(day.date, false));
$$self.$$set = $$props => {
if ('calendar' in $$props) $$invalidate(0, calendar = $$props.calendar);
if ('selectedDate' in $$props) $$invalidate(1, selectedDate = $$props.selectedDate);
if ('onClick' in $$props) $$invalidate(2, onClick = $$props.onClick);
};
return [
calendar,
selectedDate,
onClick,
previousMonth,
nextMonth,
click_handler,
click_handler_1,
click_handler_2
];
}
class Calendar_1 extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance$6, create_fragment$6, safe_not_equal, { calendar: 0, selectedDate: 1, onClick: 2 }, add_css$5);
}
}
/* src/ui/components/Markdown.svelte generated by Svelte v3.42.2 */
function create_fragment$5(ctx) {
let span1;
let span0;
return {
c() {
span1 = element("span");
span0 = element("span");
attr(span0, "class", "reminder-markdown");
},
m(target, anchor) {
insert(target, span1, anchor);
append(span1, span0);
/*span0_binding*/ ctx[4](span0);
},
p: noop,
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(span1);
/*span0_binding*/ ctx[4](null);
}
};
}
function instance$5($$self, $$props, $$invalidate) {
let { component } = $$props;
let { sourcePath } = $$props;
let { markdown } = $$props;
let span;
afterUpdate(() => {
span.empty();
obsidian.MarkdownRenderer.renderMarkdown(markdown, span, sourcePath, component);
span.childNodes.forEach(n => {
if (n instanceof HTMLElement) {
n.style.display = "inline";
}
});
});
function span0_binding($$value) {
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
span = $$value;
$$invalidate(0, span);
});
}
$$self.$$set = $$props => {
if ('component' in $$props) $$invalidate(1, component = $$props.component);
if ('sourcePath' in $$props) $$invalidate(2, sourcePath = $$props.sourcePath);
if ('markdown' in $$props) $$invalidate(3, markdown = $$props.markdown);
};
return [span, component, sourcePath, markdown, span0_binding];
}
class Markdown extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance$5, create_fragment$5, safe_not_equal, { component: 1, sourcePath: 2, markdown: 3 });
}
}
/* src/ui/components/ReminderListByDate.svelte generated by Svelte v3.42.2 */
function add_css$4(target) {
append_styles(target, "svelte-gzdxib", ".reminder-group.svelte-gzdxib{margin-bottom:1rem;font-size:13px;color:var(--text-muted)}.reminder-list-item.svelte-gzdxib{list-style:none;line-height:14px;padding:3px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;word-break:break-all;width:100%}.reminder-list-item.svelte-gzdxib:hover{color:var(--text-normal);background-color:var(--background-secondary-alt)}.reminder-time.svelte-gzdxib{font-size:14px;font-family:monospace, serif}.reminder-file.svelte-gzdxib{color:var(--text-faint)}.no-reminders.svelte-gzdxib{font-style:italic}");
}
function get_each_context$2(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[5] = list[i];
return child_ctx;
}
// (14:2) {:else}
function create_else_block(ctx) {
let div;
let current;
let each_value = /*reminders*/ ctx[0];
let each_blocks = [];
for (let i = 0; i < each_value.length; i += 1) {
each_blocks[i] = create_each_block$2(get_each_context$2(ctx, each_value, i));
}
const out = i => transition_out(each_blocks[i], 1, 1, () => {
each_blocks[i] = null;
});
return {
c() {
div = element("div");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
},
m(target, anchor) {
insert(target, div, anchor);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(div, null);
}
current = true;
},
p(ctx, dirty) {
if (dirty & /*reminders, onOpenReminder, component, timeToString*/ 15) {
each_value = /*reminders*/ ctx[0];
let i;
for (i = 0; i < each_value.length; i += 1) {
const child_ctx = get_each_context$2(ctx, each_value, i);
if (each_blocks[i]) {
each_blocks[i].p(child_ctx, dirty);
transition_in(each_blocks[i], 1);
} else {
each_blocks[i] = create_each_block$2(child_ctx);
each_blocks[i].c();
transition_in(each_blocks[i], 1);
each_blocks[i].m(div, null);
}
}
group_outros();
for (i = each_value.length; i < each_blocks.length; i += 1) {
out(i);
}
check_outros();
}
},
i(local) {
if (current) return;
for (let i = 0; i < each_value.length; i += 1) {
transition_in(each_blocks[i]);
}
current = true;
},
o(local) {
each_blocks = each_blocks.filter(Boolean);
for (let i = 0; i < each_blocks.length; i += 1) {
transition_out(each_blocks[i]);
}
current = false;
},
d(detaching) {
if (detaching) detach(div);
destroy_each(each_blocks, detaching);
}
};
}
// (12:2) {#if reminders.length === 0}
function create_if_block(ctx) {
let div;
return {
c() {
div = element("div");
div.textContent = "No reminders";
attr(div, "class", "reminder-list-item no-reminders svelte-gzdxib");
},
m(target, anchor) {
insert(target, div, anchor);
},
p: noop,
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(div);
}
};
}
// (16:6) {#each reminders as reminder}
function create_each_block$2(ctx) {
let div;
let span0;
let t0_value = /*timeToString*/ ctx[3](/*reminder*/ ctx[5].time) + "";
let t0;
let t1;
let span1;
let markdown;
let t2;
let span2;
let t3;
let t4_value = /*reminder*/ ctx[5].getFileName() + "";
let t4;
let t5;
let div_aria_label_value;
let current;
let mounted;
let dispose;
markdown = new Markdown({
props: {
markdown: /*reminder*/ ctx[5].title,
sourcePath: /*reminder*/ ctx[5].file,
component: /*component*/ ctx[1]
}
});
function click_handler() {
return /*click_handler*/ ctx[4](/*reminder*/ ctx[5]);
}
return {
c() {
div = element("div");
span0 = element("span");
t0 = text(t0_value);
t1 = space();
span1 = element("span");
create_component(markdown.$$.fragment);
t2 = space();
span2 = element("span");
t3 = text("- ");
t4 = text(t4_value);
t5 = space();
attr(span0, "class", "reminder-time svelte-gzdxib");
attr(span1, "class", "reminder-title");
attr(span2, "class", "reminder-file svelte-gzdxib");
attr(div, "class", "reminder-list-item svelte-gzdxib");
attr(div, "aria-label", div_aria_label_value = `[${/*reminder*/ ctx[5].time.toString()}] ${/*reminder*/ ctx[5].title} - ${/*reminder*/ ctx[5].getFileName()}`);
},
m(target, anchor) {
insert(target, div, anchor);
append(div, span0);
append(span0, t0);
append(div, t1);
append(div, span1);
mount_component(markdown, span1, null);
append(div, t2);
append(div, span2);
append(span2, t3);
append(span2, t4);
append(div, t5);
current = true;
if (!mounted) {
dispose = listen(div, "click", click_handler);
mounted = true;
}
},
p(new_ctx, dirty) {
ctx = new_ctx;
if ((!current || dirty & /*timeToString, reminders*/ 9) && t0_value !== (t0_value = /*timeToString*/ ctx[3](/*reminder*/ ctx[5].time) + "")) set_data(t0, t0_value);
const markdown_changes = {};
if (dirty & /*reminders*/ 1) markdown_changes.markdown = /*reminder*/ ctx[5].title;
if (dirty & /*reminders*/ 1) markdown_changes.sourcePath = /*reminder*/ ctx[5].file;
if (dirty & /*component*/ 2) markdown_changes.component = /*component*/ ctx[1];
markdown.$set(markdown_changes);
if ((!current || dirty & /*reminders*/ 1) && t4_value !== (t4_value = /*reminder*/ ctx[5].getFileName() + "")) set_data(t4, t4_value);
if (!current || dirty & /*reminders*/ 1 && div_aria_label_value !== (div_aria_label_value = `[${/*reminder*/ ctx[5].time.toString()}] ${/*reminder*/ ctx[5].title} - ${/*reminder*/ ctx[5].getFileName()}`)) {
attr(div, "aria-label", div_aria_label_value);
}
},
i(local) {
if (current) return;
transition_in(markdown.$$.fragment, local);
current = true;
},
o(local) {
transition_out(markdown.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) detach(div);
destroy_component(markdown);
mounted = false;
dispose();
}
};
}
function create_fragment$4(ctx) {
let div;
let current_block_type_index;
let if_block;
let current;
const if_block_creators = [create_if_block, create_else_block];
const if_blocks = [];
function select_block_type(ctx, dirty) {
if (/*reminders*/ ctx[0].length === 0) return 0;
return 1;
}
current_block_type_index = select_block_type(ctx);
if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
return {
c() {
div = element("div");
if_block.c();
attr(div, "class", "reminder-group svelte-gzdxib");
},
m(target, anchor) {
insert(target, div, anchor);
if_blocks[current_block_type_index].m(div, null);
current = true;
},
p(ctx, [dirty]) {
let previous_block_index = current_block_type_index;
current_block_type_index = select_block_type(ctx);
if (current_block_type_index === previous_block_index) {
if_blocks[current_block_type_index].p(ctx, dirty);
} else {
group_outros();
transition_out(if_blocks[previous_block_index], 1, 1, () => {
if_blocks[previous_block_index] = null;
});
check_outros();
if_block = if_blocks[current_block_type_index];
if (!if_block) {
if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
if_block.c();
} else {
if_block.p(ctx, dirty);
}
transition_in(if_block, 1);
if_block.m(div, null);
}
},
i(local) {
if (current) return;
transition_in(if_block);
current = true;
},
o(local) {
transition_out(if_block);
current = false;
},
d(detaching) {
if (detaching) detach(div);
if_blocks[current_block_type_index].d();
}
};
}
function instance$4($$self, $$props, $$invalidate) {
let { reminders } = $$props;
let { component } = $$props;
let { onOpenReminder = () => {
} } = $$props;
let { timeToString = time => time.format("HH:MM") } = $$props;
const click_handler = reminder => {
onOpenReminder(reminder);
};
$$self.$$set = $$props => {
if ('reminders' in $$props) $$invalidate(0, reminders = $$props.reminders);
if ('component' in $$props) $$invalidate(1, component = $$props.component);
if ('onOpenReminder' in $$props) $$invalidate(2, onOpenReminder = $$props.onOpenReminder);
if ('timeToString' in $$props) $$invalidate(3, timeToString = $$props.timeToString);
};
return [reminders, component, onOpenReminder, timeToString, click_handler];
}
class ReminderListByDate extends SvelteComponent {
constructor(options) {
super();
init(
this,
options,
instance$4,
create_fragment$4,
safe_not_equal,
{
reminders: 0,
component: 1,
onOpenReminder: 2,
timeToString: 3
},
add_css$4
);
}
}
/* src/ui/components/DateTimeChooser.svelte generated by Svelte v3.42.2 */
function add_css$3(target) {
append_styles(target, "svelte-j0lpwh", ".dtchooser.svelte-j0lpwh{background-color:var(--background-primary-alt);position:absolute;z-index:2147483647}.dtchooser-divider.svelte-j0lpwh{margin:0.5rem}.reminder-list-container.svelte-j0lpwh{padding:0.5rem;max-width:16rem}");
}
function create_fragment$3(ctx) {
let div1;
let calendarview;
let t0;
let hr;
let t1;
let div0;
let reminderlistbydate;
let current;
calendarview = new Calendar_1({
props: {
onClick: /*onClick*/ ctx[4],
selectedDate: /*selectedDate*/ ctx[1],
calendar: /*calendar*/ ctx[0]
}
});
reminderlistbydate = new ReminderListByDate({
props: {
reminders: /*reminders*/ ctx[3].byDate(new DateTime$2(/*selectedDate*/ ctx[1], false)),
component: /*component*/ ctx[2]
}
});
return {
c() {
div1 = element("div");
create_component(calendarview.$$.fragment);
t0 = space();
hr = element("hr");
t1 = space();
div0 = element("div");
create_component(reminderlistbydate.$$.fragment);
attr(hr, "class", "dtchooser-divider svelte-j0lpwh");
attr(div0, "class", "reminder-list-container svelte-j0lpwh");
attr(div1, "class", "dtchooser svelte-j0lpwh");
},
m(target, anchor) {
insert(target, div1, anchor);
mount_component(calendarview, div1, null);
append(div1, t0);
append(div1, hr);
append(div1, t1);
append(div1, div0);
mount_component(reminderlistbydate, div0, null);
current = true;
},
p(ctx, [dirty]) {
const calendarview_changes = {};
if (dirty & /*onClick*/ 16) calendarview_changes.onClick = /*onClick*/ ctx[4];
if (dirty & /*selectedDate*/ 2) calendarview_changes.selectedDate = /*selectedDate*/ ctx[1];
if (dirty & /*calendar*/ 1) calendarview_changes.calendar = /*calendar*/ ctx[0];
calendarview.$set(calendarview_changes);
const reminderlistbydate_changes = {};
if (dirty & /*reminders, selectedDate*/ 10) reminderlistbydate_changes.reminders = /*reminders*/ ctx[3].byDate(new DateTime$2(/*selectedDate*/ ctx[1], false));
if (dirty & /*component*/ 4) reminderlistbydate_changes.component = /*component*/ ctx[2];
reminderlistbydate.$set(reminderlistbydate_changes);
},
i(local) {
if (current) return;
transition_in(calendarview.$$.fragment, local);
transition_in(reminderlistbydate.$$.fragment, local);
current = true;
},
o(local) {
transition_out(calendarview.$$.fragment, local);
transition_out(reminderlistbydate.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) detach(div1);
destroy_component(calendarview);
destroy_component(reminderlistbydate);
}
};
}
function instance$3($$self, $$props, $$invalidate) {
let { calendar = new Calendar() } = $$props;
let { component } = $$props;
let { selectedDate = moment() } = $$props;
let { reminders } = $$props;
function selectDate(date) {
// clone() for re-render forcibly
$$invalidate(1, selectedDate = date.clone());
$$invalidate(0, calendar = new Calendar(moment(), date));
}
function moveUp() {
selectDate(selectedDate.add(-7, "day"));
}
function moveDown() {
selectDate(selectedDate.add(7, "day"));
}
function moveLeft() {
selectDate(selectedDate.add(-1, "day"));
}
function moveRight() {
selectDate(selectedDate.add(1, "day"));
}
function selection() {
return new DateTime$2(selectedDate, false);
}
let { onClick } = $$props;
$$self.$$set = $$props => {
if ('calendar' in $$props) $$invalidate(0, calendar = $$props.calendar);
if ('component' in $$props) $$invalidate(2, component = $$props.component);
if ('selectedDate' in $$props) $$invalidate(1, selectedDate = $$props.selectedDate);
if ('reminders' in $$props) $$invalidate(3, reminders = $$props.reminders);
if ('onClick' in $$props) $$invalidate(4, onClick = $$props.onClick);
};
return [
calendar,
selectedDate,
component,
reminders,
onClick,
moveUp,
moveDown,
moveLeft,
moveRight,
selection
];
}
class DateTimeChooser extends SvelteComponent {
constructor(options) {
super();
init(
this,
options,
instance$3,
create_fragment$3,
safe_not_equal,
{
calendar: 0,
component: 2,
selectedDate: 1,
reminders: 3,
moveUp: 5,
moveDown: 6,
moveLeft: 7,
moveRight: 8,
selection: 9,
onClick: 4
},
add_css$3
);
}
get moveUp() {
return this.$$.ctx[5];
}
get moveDown() {
return this.$$.ctx[6];
}
get moveLeft() {
return this.$$.ctx[7];
}
get moveRight() {
return this.$$.ctx[8];
}
get selection() {
return this.$$.ctx[9];
}
}
class DateTimeChooserModal extends obsidian.Modal {
constructor(app, reminders, onSelect, onCancel) {
super(app);
this.reminders = reminders;
this.onSelect = onSelect;
this.onCancel = onCancel;
}
onOpen() {
new DateTimeChooser({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
target: this.containerEl,
props: {
onClick: (time) => {
this.selected = time;
this.close();
},
reminders: this.reminders,
undefined
},
});
}
onClose() {
if (this.selected != null) {
this.onSelect(this.selected);
}
else {
this.onCancel();
}
}
}
function showDateTimeChooserModal(app, reminders) {
return new Promise((resolve, reject) => {
const modal = new DateTimeChooserModal(app, reminders, resolve, reject);
modal.open();
});
}
class DateTimeChooserView {
constructor(editor, reminders) {
this.editor = editor;
this.keyMaps = {
'Ctrl-P': () => this.dateTimeChooser["moveUp"](),
'Ctrl-N': () => this.dateTimeChooser["moveDown"](),
'Ctrl-B': () => this.dateTimeChooser["moveLeft"](),
'Ctrl-F': () => this.dateTimeChooser["moveRight"](),
'Enter': () => this.select(),
Up: () => this.dateTimeChooser["moveUp"](),
Down: () => this.dateTimeChooser["moveDown"](),
Right: () => this.dateTimeChooser["moveRight"](),
Left: () => this.dateTimeChooser["moveLeft"](),
Esc: () => this.cancel(),
};
this.view = document.createElement("div");
this.view.addClass("date-time-chooser-popup");
this.view.style.position = "fixed";
this.dateTimeChooser = new DateTimeChooser({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
target: this.view,
props: {
onClick: (time) => {
this.setResult(time);
this.hide();
},
reminders,
undefined
},
});
}
show() {
this.setResult(null);
this.hide();
this.dateTimeChooser.$set({
selectedDate: moment(),
calendar: new Calendar()
});
const cursor = this.editor.getCursor();
const coords = this.editor.charCoords(cursor);
const parent = document.body;
const parentRect = parent.getBoundingClientRect();
this.view.style.top = `${coords.top - parentRect.top + this.editor.defaultTextHeight()}px`;
this.view.style.left = `${coords.left - parentRect.left}px`;
parent.appendChild(this.view);
this.editor.addKeyMap(this.keyMaps);
return new Promise((resolve, reject) => {
this.resultResolve = resolve;
this.resultReject = reject;
});
}
select() {
this.setResult(this.dateTimeChooser["selection"]());
this.hide();
}
cancel() {
this.setResult(null);
this.hide();
}
setResult(result) {
if (this.resultReject == null || this.resultResolve == null) {
return;
}
if (result === null) {
this.resultReject();
}
else {
this.resultResolve(result);
}
this.resultReject = undefined;
this.resultResolve = undefined;
}
hide() {
if (this.view.parentNode) {
this.editor.removeKeyMap(this.keyMaps);
this.view.parentNode.removeChild(this.view);
}
}
}
class AutoComplete {
constructor(trigger) {
this.trigger = trigger;
}
;
isTrigger(cmEditor, changeObj) {
const trigger = this.trigger.value;
if (trigger.length === 0) {
return false;
}
if (changeObj.text.contains(trigger.charAt(trigger.length - 1))) {
const line = cmEditor.getLine(changeObj.from.line).substring(0, changeObj.to.ch) + changeObj.text;
if (!line.match(/^\s*\- \[.\]\s.*/)) {
// is not a TODO line
return false;
}
if (line.endsWith(trigger)) {
return true;
}
}
return false;
}
show(app, editor, reminders) {
let result;
if (obsidian.Platform.isDesktopApp) {
const cm = editor.cm;
if (cm == null) {
console.error("Cannot get codemirror editor.");
return;
}
const v = new DateTimeChooserView(cm, reminders);
result = v.show();
}
else {
result = showDateTimeChooserModal(app, reminders);
}
result
.then(value => {
this.insert(editor, value, true);
})
.catch(() => { });
}
insert(editor, value, triggerFromCommand = false) {
const pos = editor.getCursor();
let line = editor.getLine(pos.line);
const endPos = {
line: pos.line,
ch: line.length
};
// remove trigger string
if (!triggerFromCommand) {
line = line.substring(0, pos.ch - this.trigger.value.length);
}
// append reminder to the line
const format = SETTINGS.primaryFormat.value.format;
try {
const appended = format.appendReminder(line, value);
if (appended == null) {
console.error("Cannot append reminder time to the line: line=%s, date=%s", line, value);
return;
}
editor.replaceRange(appended, { line: pos.line, ch: 0 }, endPos);
}
catch (ex) {
console.error(ex);
}
}
}
class DateTimeFormatModal extends obsidian.FuzzySuggestModal {
constructor(app, suggestions, onChooseSuggestionFunc) {
super(app);
this.suggestions = suggestions;
this.onChooseSuggestionFunc = onChooseSuggestionFunc;
}
getItems() {
return this.suggestions;
}
getItemText(item) {
return item;
}
onChooseItem(item, evt) {
this.onChooseSuggestionFunc(item);
}
}
function openDateTimeFormatChooser(app, onSelectFormat) {
new DateTimeFormatModal(app, ["YYYY-MM-DD", "YYYY/MM/DD", "DD-MM-YYYY", "DD/MM/YYYY"], (dateFormat) => {
new DateTimeFormatModal(app, ["YYYY-MM-DD HH:mm", "YYYY/MM/DD HH:mm", "DD-MM-YYYY HH:mm", "DD/MM/YYYY HH:mm", "YYYY-MM-DDTHH:mm:ss:SSS"], (dateTimeFormat) => {
onSelectFormat(dateFormat, dateTimeFormat);
}).open();
}).open();
}
/* src/ui/components/Icon.svelte generated by Svelte v3.42.2 */
function add_css$2(target) {
append_styles(target, "svelte-1gcidq0", ".icon.svelte-1gcidq0{vertical-align:middle}");
}
function create_fragment$2(ctx) {
let span_1;
return {
c() {
span_1 = element("span");
attr(span_1, "class", "icon svelte-1gcidq0");
},
m(target, anchor) {
insert(target, span_1, anchor);
/*span_1_binding*/ ctx[3](span_1);
},
p: noop,
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(span_1);
/*span_1_binding*/ ctx[3](null);
}
};
}
function instance$2($$self, $$props, $$invalidate) {
let { icon = "" } = $$props;
let { size = 16 } = $$props;
let span;
onMount(() => {
obsidian.setIcon(span, icon, size);
});
function span_1_binding($$value) {
binding_callbacks[$$value ? 'unshift' : 'push'](() => {
span = $$value;
$$invalidate(0, span);
});
}
$$self.$$set = $$props => {
if ('icon' in $$props) $$invalidate(1, icon = $$props.icon);
if ('size' in $$props) $$invalidate(2, size = $$props.size);
};
return [span, icon, size, span_1_binding];
}
class Icon extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance$2, create_fragment$2, safe_not_equal, { icon: 1, size: 2 }, add_css$2);
}
}
/* src/ui/components/Reminder.svelte generated by Svelte v3.42.2 */
function add_css$1(target) {
append_styles(target, "svelte-1most86", "main.svelte-1most86{padding:1em;margin:0 auto}.reminder-actions.svelte-1most86{margin-top:1rem}.reminder-file.svelte-1most86{color:var(--text-muted);cursor:pointer}.reminder-file.svelte-1most86:hover{color:var(--text-normal);text-decoration:underline}.later-select.svelte-1most86{font-size:14px}");
}
function get_each_context$1(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[10] = list[i];
child_ctx[12] = i;
return child_ctx;
}
// (51:6) {#each laters as later, i}
function create_each_block$1(ctx) {
let option;
let t_value = /*later*/ ctx[10].label + "";
let t;
let option_value_value;
let option_selected_value;
return {
c() {
option = element("option");
t = text(t_value);
option.__value = option_value_value = /*i*/ ctx[12];
option.value = option.__value;
option.selected = option_selected_value = /*selectedIndex*/ ctx[6] === /*i*/ ctx[12];
},
m(target, anchor) {
insert(target, option, anchor);
append(option, t);
},
p(ctx, dirty) {
if (dirty & /*laters*/ 32 && t_value !== (t_value = /*later*/ ctx[10].label + "")) set_data(t, t_value);
if (dirty & /*selectedIndex*/ 64 && option_selected_value !== (option_selected_value = /*selectedIndex*/ ctx[6] === /*i*/ ctx[12])) {
option.selected = option_selected_value;
}
},
d(detaching) {
if (detaching) detach(option);
}
};
}
function create_fragment$1(ctx) {
let main;
let h1;
let markdown;
let t0;
let span;
let icon0;
let t1;
let t2_value = /*reminder*/ ctx[0].file + "";
let t2;
let t3;
let div;
let button0;
let icon1;
let t4;
let t5;
let button1;
let icon2;
let t6;
let t7;
let select;
let option;
let current;
let mounted;
let dispose;
markdown = new Markdown({
props: {
markdown: /*reminder*/ ctx[0].title,
sourcePath: /*reminder*/ ctx[0].file,
component: /*component*/ ctx[1]
}
});
icon0 = new Icon({ props: { icon: "link" } });
icon1 = new Icon({ props: { icon: "check-small" } });
icon2 = new Icon({ props: { icon: "minus-with-circle" } });
let each_value = /*laters*/ ctx[5];
let each_blocks = [];
for (let i = 0; i < each_value.length; i += 1) {
each_blocks[i] = create_each_block$1(get_each_context$1(ctx, each_value, i));
}
return {
c() {
main = element("main");
h1 = element("h1");
create_component(markdown.$$.fragment);
t0 = space();
span = element("span");
create_component(icon0.$$.fragment);
t1 = space();
t2 = text(t2_value);
t3 = space();
div = element("div");
button0 = element("button");
create_component(icon1.$$.fragment);
t4 = text(" Mark as Done");
t5 = space();
button1 = element("button");
create_component(icon2.$$.fragment);
t6 = text(" Mute");
t7 = space();
select = element("select");
option = element("option");
option.textContent = "Remind Me Later";
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
attr(span, "class", "reminder-file svelte-1most86");
attr(button0, "class", "mod-cta");
option.selected = true;
option.disabled = true;
option.hidden = true;
option.__value = "Remind Me Later";
option.value = option.__value;
attr(select, "class", "dropdown later-select svelte-1most86");
if (/*selectedIndex*/ ctx[6] === void 0) add_render_callback(() => /*select_change_handler*/ ctx[9].call(select));
attr(div, "class", "reminder-actions svelte-1most86");
attr(main, "class", "svelte-1most86");
},
m(target, anchor) {
insert(target, main, anchor);
append(main, h1);
mount_component(markdown, h1, null);
append(main, t0);
append(main, span);
mount_component(icon0, span, null);
append(span, t1);
append(span, t2);
append(main, t3);
append(main, div);
append(div, button0);
mount_component(icon1, button0, null);
append(button0, t4);
append(div, t5);
append(div, button1);
mount_component(icon2, button1, null);
append(button1, t6);
append(div, t7);
append(div, select);
append(select, option);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(select, null);
}
select_option(select, /*selectedIndex*/ ctx[6]);
current = true;
if (!mounted) {
dispose = [
listen(span, "click", function () {
if (is_function(/*onOpenFile*/ ctx[3])) /*onOpenFile*/ ctx[3].apply(this, arguments);
}),
listen(button0, "click", function () {
if (is_function(/*onDone*/ ctx[2])) /*onDone*/ ctx[2].apply(this, arguments);
}),
listen(button1, "click", function () {
if (is_function(/*onMute*/ ctx[4])) /*onMute*/ ctx[4].apply(this, arguments);
}),
listen(select, "change", /*select_change_handler*/ ctx[9]),
listen(select, "change", /*remindMeLater*/ ctx[7])
];
mounted = true;
}
},
p(new_ctx, [dirty]) {
ctx = new_ctx;
const markdown_changes = {};
if (dirty & /*reminder*/ 1) markdown_changes.markdown = /*reminder*/ ctx[0].title;
if (dirty & /*reminder*/ 1) markdown_changes.sourcePath = /*reminder*/ ctx[0].file;
if (dirty & /*component*/ 2) markdown_changes.component = /*component*/ ctx[1];
markdown.$set(markdown_changes);
if ((!current || dirty & /*reminder*/ 1) && t2_value !== (t2_value = /*reminder*/ ctx[0].file + "")) set_data(t2, t2_value);
if (dirty & /*selectedIndex, laters*/ 96) {
each_value = /*laters*/ ctx[5];
let i;
for (i = 0; i < each_value.length; i += 1) {
const child_ctx = get_each_context$1(ctx, each_value, i);
if (each_blocks[i]) {
each_blocks[i].p(child_ctx, dirty);
} else {
each_blocks[i] = create_each_block$1(child_ctx);
each_blocks[i].c();
each_blocks[i].m(select, null);
}
}
for (; i < each_blocks.length; i += 1) {
each_blocks[i].d(1);
}
each_blocks.length = each_value.length;
}
if (dirty & /*selectedIndex*/ 64) {
select_option(select, /*selectedIndex*/ ctx[6]);
}
},
i(local) {
if (current) return;
transition_in(markdown.$$.fragment, local);
transition_in(icon0.$$.fragment, local);
transition_in(icon1.$$.fragment, local);
transition_in(icon2.$$.fragment, local);
current = true;
},
o(local) {
transition_out(markdown.$$.fragment, local);
transition_out(icon0.$$.fragment, local);
transition_out(icon1.$$.fragment, local);
transition_out(icon2.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) detach(main);
destroy_component(markdown);
destroy_component(icon0);
destroy_component(icon1);
destroy_component(icon2);
destroy_each(each_blocks, detaching);
mounted = false;
run_all(dispose);
}
};
}
function instance$1($$self, $$props, $$invalidate) {
let { reminder } = $$props;
let { component } = $$props;
let { onRemindMeLater } = $$props;
let { onDone } = $$props;
let { onOpenFile } = $$props;
let { onMute } = $$props;
// Do not set initial value so that svelte can render the placeholder `Remind Me Later`.
let selectedIndex;
let { laters = [] } = $$props;
function remindMeLater() {
const selected = laters[selectedIndex];
if (selected == null) {
return;
}
onRemindMeLater(selected.later());
}
function select_change_handler() {
selectedIndex = select_value(this);
$$invalidate(6, selectedIndex);
}
$$self.$$set = $$props => {
if ('reminder' in $$props) $$invalidate(0, reminder = $$props.reminder);
if ('component' in $$props) $$invalidate(1, component = $$props.component);
if ('onRemindMeLater' in $$props) $$invalidate(8, onRemindMeLater = $$props.onRemindMeLater);
if ('onDone' in $$props) $$invalidate(2, onDone = $$props.onDone);
if ('onOpenFile' in $$props) $$invalidate(3, onOpenFile = $$props.onOpenFile);
if ('onMute' in $$props) $$invalidate(4, onMute = $$props.onMute);
if ('laters' in $$props) $$invalidate(5, laters = $$props.laters);
};
return [
reminder,
component,
onDone,
onOpenFile,
onMute,
laters,
selectedIndex,
remindMeLater,
onRemindMeLater,
select_change_handler
];
}
class Reminder extends SvelteComponent {
constructor(options) {
super();
init(
this,
options,
instance$1,
create_fragment$1,
safe_not_equal,
{
reminder: 0,
component: 1,
onRemindMeLater: 8,
onDone: 2,
onOpenFile: 3,
onMute: 4,
laters: 5
},
add_css$1
);
}
}
const electron$1 = require("electron");
class ReminderModal {
constructor(app, useSystemNotification, laters) {
this.app = app;
this.useSystemNotification = useSystemNotification;
this.laters = laters;
}
show(reminder, onRemindMeLater, onDone, onMute, onOpenFile) {
if (!this.isSystemNotification()) {
this.showBuiltinReminder(reminder, onRemindMeLater, onDone, onMute, onOpenFile);
}
else {
// Show system notification
const Notification = electron$1.remote.Notification;
const n = new Notification({
title: "Obsidian Reminder",
body: reminder.title,
});
n.on("click", () => {
n.close();
this.showBuiltinReminder(reminder, onRemindMeLater, onDone, onMute, onOpenFile);
});
n.on("close", () => {
onMute();
});
// Only for macOS
{
const laters = SETTINGS.laters.value;
n.on("action", (_, index) => {
if (index === 0) {
onDone();
return;
}
const later = laters[index - 1];
onRemindMeLater(later.later());
});
const actions = [{ type: "button", text: "Mark as Done" }];
laters.forEach(later => {
actions.push({ type: "button", text: later.label });
});
n.actions = actions;
}
n.show();
}
}
showBuiltinReminder(reminder, onRemindMeLater, onDone, onCancel, onOpenFile) {
new NotificationModal(this.app, this.laters.value, reminder, onRemindMeLater, onDone, onCancel, onOpenFile).open();
}
isSystemNotification() {
if (this.isMobile()) {
return false;
}
return this.useSystemNotification.value;
}
isMobile() {
return electron$1 === undefined;
}
}
class NotificationModal extends obsidian.Modal {
constructor(app, laters, reminder, onRemindMeLater, onDone, onCancel, onOpenFile) {
super(app);
this.laters = laters;
this.reminder = reminder;
this.onRemindMeLater = onRemindMeLater;
this.onDone = onDone;
this.onCancel = onCancel;
this.onOpenFile = onOpenFile;
this.canceled = true;
}
onOpen() {
let { contentEl } = this;
new Reminder({
target: contentEl,
props: {
reminder: this.reminder,
laters: this.laters,
component: this,
onRemindMeLater: (time) => {
this.onRemindMeLater(time);
this.canceled = false;
this.close();
},
onDone: () => {
this.canceled = false;
this.onDone();
this.close();
},
onOpenFile: () => {
this.canceled = true;
this.onOpenFile();
this.close();
},
onMute: () => {
this.canceled = true;
this.close();
},
},
});
}
onClose() {
let { contentEl } = this;
contentEl.empty();
if (this.canceled) {
this.onCancel();
}
}
}
const VIEW_TYPE_REMINDER_LIST = "reminder-list";
/* src/ui/components/ReminderList.svelte generated by Svelte v3.42.2 */
function add_css(target) {
append_styles(target, "svelte-2zqui4", ".group-name.svelte-2zqui4{font-size:14px;color:var(--text-muted);border-bottom:1px solid var(--text-muted);margin-bottom:0.5rem}.group-name-overdue.svelte-2zqui4{color:var(--text-accent)}");
}
function get_each_context(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[4] = list[i];
return child_ctx;
}
// (11:4) {#each groups as group}
function create_each_block(ctx) {
let div;
let t0_value = /*group*/ ctx[4].name + "";
let t0;
let t1;
let reminderlistbydate;
let current;
function func(...args) {
return /*func*/ ctx[3](/*group*/ ctx[4], ...args);
}
reminderlistbydate = new ReminderListByDate({
props: {
reminders: /*group*/ ctx[4].reminders,
component: /*component*/ ctx[1],
onOpenReminder: /*onOpenReminder*/ ctx[2],
timeToString: func
}
});
return {
c() {
div = element("div");
t0 = text(t0_value);
t1 = space();
create_component(reminderlistbydate.$$.fragment);
attr(div, "class", "group-name svelte-2zqui4");
toggle_class(div, "group-name-overdue", /*group*/ ctx[4].isOverdue);
},
m(target, anchor) {
insert(target, div, anchor);
append(div, t0);
insert(target, t1, anchor);
mount_component(reminderlistbydate, target, anchor);
current = true;
},
p(new_ctx, dirty) {
ctx = new_ctx;
if ((!current || dirty & /*groups*/ 1) && t0_value !== (t0_value = /*group*/ ctx[4].name + "")) set_data(t0, t0_value);
if (dirty & /*groups*/ 1) {
toggle_class(div, "group-name-overdue", /*group*/ ctx[4].isOverdue);
}
const reminderlistbydate_changes = {};
if (dirty & /*groups*/ 1) reminderlistbydate_changes.reminders = /*group*/ ctx[4].reminders;
if (dirty & /*component*/ 2) reminderlistbydate_changes.component = /*component*/ ctx[1];
if (dirty & /*onOpenReminder*/ 4) reminderlistbydate_changes.onOpenReminder = /*onOpenReminder*/ ctx[2];
if (dirty & /*groups*/ 1) reminderlistbydate_changes.timeToString = func;
reminderlistbydate.$set(reminderlistbydate_changes);
},
i(local) {
if (current) return;
transition_in(reminderlistbydate.$$.fragment, local);
current = true;
},
o(local) {
transition_out(reminderlistbydate.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) detach(div);
if (detaching) detach(t1);
destroy_component(reminderlistbydate, detaching);
}
};
}
function create_fragment(ctx) {
let main;
let div;
let current;
let each_value = /*groups*/ ctx[0];
let each_blocks = [];
for (let i = 0; i < each_value.length; i += 1) {
each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i));
}
const out = i => transition_out(each_blocks[i], 1, 1, () => {
each_blocks[i] = null;
});
return {
c() {
main = element("main");
div = element("div");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
},
m(target, anchor) {
insert(target, main, anchor);
append(main, div);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(div, null);
}
current = true;
},
p(ctx, [dirty]) {
if (dirty & /*groups, component, onOpenReminder*/ 7) {
each_value = /*groups*/ ctx[0];
let i;
for (i = 0; i < each_value.length; i += 1) {
const child_ctx = get_each_context(ctx, each_value, i);
if (each_blocks[i]) {
each_blocks[i].p(child_ctx, dirty);
transition_in(each_blocks[i], 1);
} else {
each_blocks[i] = create_each_block(child_ctx);
each_blocks[i].c();
transition_in(each_blocks[i], 1);
each_blocks[i].m(div, null);
}
}
group_outros();
for (i = each_value.length; i < each_blocks.length; i += 1) {
out(i);
}
check_outros();
}
},
i(local) {
if (current) return;
for (let i = 0; i < each_value.length; i += 1) {
transition_in(each_blocks[i]);
}
current = true;
},
o(local) {
each_blocks = each_blocks.filter(Boolean);
for (let i = 0; i < each_blocks.length; i += 1) {
transition_out(each_blocks[i]);
}
current = false;
},
d(detaching) {
if (detaching) detach(main);
destroy_each(each_blocks, detaching);
}
};
}
function instance($$self, $$props, $$invalidate) {
let { groups } = $$props;
let { component } = $$props;
let { onOpenReminder } = $$props;
const func = (group, time) => group.timeToString(time);
$$self.$$set = $$props => {
if ('groups' in $$props) $$invalidate(0, groups = $$props.groups);
if ('component' in $$props) $$invalidate(1, component = $$props.component);
if ('onOpenReminder' in $$props) $$invalidate(2, onOpenReminder = $$props.onOpenReminder);
};
return [groups, component, onOpenReminder, func];
}
class ReminderList extends SvelteComponent {
constructor(options) {
super();
init(
this,
options,
instance,
create_fragment,
safe_not_equal,
{
groups: 0,
component: 1,
onOpenReminder: 2
},
add_css
);
}
}
class ReminderListItemView extends obsidian.ItemView {
constructor(leaf, reminders, reminderTime, onOpenReminder) {
super(leaf);
this.reminders = reminders;
this.reminderTime = reminderTime;
this.onOpenReminder = onOpenReminder;
}
getViewType() {
return VIEW_TYPE_REMINDER_LIST;
}
getDisplayText() {
return "Reminders";
}
getIcon() {
return "clock";
}
onOpen() {
return __awaiter(this, void 0, void 0, function* () {
this.view = new ReminderList({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
target: this.contentEl,
props: {
groups: this.remindersForView(),
onOpenReminder: this.onOpenReminder,
component: this,
},
});
});
}
reload() {
if (this.view == null) {
return;
}
this.view.$set({
groups: this.remindersForView(),
onOpenReminder: this.onOpenReminder,
});
}
remindersForView() {
return groupReminders(this.reminders.reminders, this.reminderTime.value);
}
onClose() {
if (this.view) {
this.view.$destroy();
}
return Promise.resolve();
}
}
class ReminderListItemViewProxy {
constructor(workspace, reminders, reminderTime, onOpenReminder) {
this.workspace = workspace;
this.reminders = reminders;
this.reminderTime = reminderTime;
this.onOpenReminder = onOpenReminder;
// valid is a flag which means that this view should be re-rendered if true;
this.valid = false;
}
createView(leaf) {
return new ReminderListItemView(leaf, this.reminders, this.reminderTime, this.onOpenReminder);
}
openView() {
if (this.workspace.getLeavesOfType(VIEW_TYPE_REMINDER_LIST).length) {
// reminder list view is already in workspace
return;
}
// Create new view
this.workspace.getRightLeaf(false).setViewState({
type: VIEW_TYPE_REMINDER_LIST,
});
}
reload(force = false) {
if (force || !this.valid) {
const views = this.getViews();
if (views.length > 0) {
views.forEach(view => view.reload());
this.valid = true;
}
else {
this.valid = false;
console.debug("view is null. Skipping reminder list view reload");
}
}
}
getViews() {
return this.workspace
.getLeavesOfType(VIEW_TYPE_REMINDER_LIST)
.map(leaf => leaf.view);
}
invalidate() {
this.valid = false;
}
}
const electron = require("electron");
var OkCancel;
(function (OkCancel) {
OkCancel[OkCancel["OK"] = 0] = "OK";
OkCancel[OkCancel["CANCEL"] = 1] = "CANCEL";
})(OkCancel || (OkCancel = {}));
function showOkCancelDialog(title, message) {
return __awaiter(this, void 0, void 0, function* () {
if (!electron) {
return OkCancel.CANCEL;
}
const selected = yield electron.remote.dialog.showMessageBox({
"type": "question",
"title": "Obsidian Reminder",
"message": title,
"detail": message,
buttons: ['OK', 'Cancel'],
cancelId: 1
});
if (selected.response === 0) {
return OkCancel.OK;
}
return OkCancel.CANCEL;
});
}
class ReminderPlugin extends obsidian.Plugin {
constructor(app, manifest) {
super(app, manifest);
this.reminders = new Reminders(() => {
// on changed
if (this.viewProxy) {
this.viewProxy.invalidate();
}
this.pluginDataIO.changed = true;
});
this.pluginDataIO = new PluginDataIO(this, this.reminders);
this.reminders.reminderTime = SETTINGS.reminderTime;
DATE_TIME_FORMATTER.setTimeFormat(SETTINGS.dateFormat, SETTINGS.dateTimeFormat, SETTINGS.strictDateFormat);
this.editDetector = new EditDetector(SETTINGS.editDetectionSec);
this.viewProxy = new ReminderListItemViewProxy(app.workspace, this.reminders, SETTINGS.reminderTime,
// On select a reminder in the list
(reminder) => {
if (reminder.muteNotification) {
this.showReminder(reminder);
return;
}
this.openReminderFile(reminder);
});
this.remindersController = new RemindersController(app.vault, this.viewProxy, this.reminders);
this.reminderModal = new ReminderModal(this.app, SETTINGS.useSystemNotification, SETTINGS.laters);
this.autoComplete = new AutoComplete(SETTINGS.autoCompleteTrigger);
}
onload() {
return __awaiter(this, void 0, void 0, function* () {
yield this.pluginDataIO.load();
if (this.pluginDataIO.debug.value) {
monkeyPatchConsole(this);
}
this.setupUI();
this.setupCommands();
this.watchVault();
this.startPeriodicTask();
});
}
setupUI() {
// Reminder List
this.registerView(VIEW_TYPE_REMINDER_LIST, (leaf) => {
return this.viewProxy.createView(leaf);
});
this.addSettingTab(new ReminderSettingTab(this.app, this));
this.registerDomEvent(document, "keydown", (evt) => {
this.editDetector.fileChanged();
});
if (obsidian.Platform.isDesktopApp) {
this.registerCodeMirror((cm) => {
const dateTimeChooser = new DateTimeChooserView(cm, this.reminders);
cm.on("change", (cmEditor, changeObj) => {
if (!this.autoComplete.isTrigger(cmEditor, changeObj)) {
dateTimeChooser.cancel();
return;
}
dateTimeChooser.show()
.then(value => {
this.autoComplete.insert(cmEditor, value);
})
.catch(() => { });
return;
});
});
}
// Open reminder list view
if (this.app.workspace.layoutReady) {
this.viewProxy.openView();
}
else {
this.app.workspace.on("layout-ready", () => {
this.viewProxy.openView();
});
}
}
setupCommands() {
this.addCommand({
id: "scan-reminders",
name: "Scan reminders",
checkCallback: (checking) => {
if (checking) {
return true;
}
this.remindersController.reloadAllFiles();
return true;
},
});
this.addCommand({
id: "show-reminders",
name: "Show reminders",
checkCallback: (checking) => {
if (!checking) {
this.showReminderList();
}
return true;
},
});
this.addCommand({
id: "convert-reminder-time-format",
name: "Convert reminder time format",
checkCallback: (checking) => {
if (!checking) {
showOkCancelDialog("Convert reminder time format", "This command rewrite reminder dates in all markdown files. You should make a backup of your vault before you execute this. May I continue to convert?").then((res) => {
if (res !== OkCancel.OK) {
return;
}
openDateTimeFormatChooser(this.app, (dateFormat, dateTimeFormat) => {
this.remindersController.convertDateTimeFormat(dateFormat, dateTimeFormat)
.catch(() => { });
});
});
}
return true;
},
});
this.addCommand({
id: "show-date-chooser",
name: "Show calendar popup",
icon: "calendar-with-checkmark",
hotkeys: [
{
modifiers: ["Meta", "Shift"],
key: "2" // Shift + 2 = `@`
}
],
editorCheckCallback: (checking, editor) => {
if (checking) {
return true;
}
this.autoComplete.show(this.app, editor, this.reminders);
},
});
this.addCommand({
id: "toggle-checklist-status",
name: "Toggle checklist status",
hotkeys: [
{
modifiers: ["Meta", "Shift"],
key: "Enter"
}
],
editorCheckCallback: (checking, editor, view) => {
if (checking) {
return true;
}
this.remindersController.toggleCheck(view.file, editor.getCursor().line);
},
});
}
watchVault() {
[
this.app.vault.on("modify", (file) => __awaiter(this, void 0, void 0, function* () {
this.remindersController.reloadFile(file, true);
})),
this.app.vault.on("delete", (file) => {
this.remindersController.removeFile(file.path);
}),
this.app.vault.on("rename", (file, oldPath) => {
this.remindersController.removeFile(oldPath);
this.remindersController.reloadFile(file);
}),
].forEach(eventRef => {
this.registerEvent(eventRef);
});
}
startPeriodicTask() {
let intervalTaskRunning = false;
this.registerInterval(window.setInterval(() => {
if (intervalTaskRunning) {
console.log("Skip reminder interval task because task is already running.");
return;
}
intervalTaskRunning = true;
this.periodicTask().finally(() => {
intervalTaskRunning = false;
});
}, SETTINGS.reminderCheckIntervalSec.value * 1000));
}
periodicTask() {
return __awaiter(this, void 0, void 0, function* () {
this.viewProxy.reload(false);
if (!this.pluginDataIO.scanned.value) {
this.remindersController.reloadAllFiles().then(() => {
this.pluginDataIO.scanned.value = true;
this.pluginDataIO.save();
});
}
this.pluginDataIO.save(false);
if (this.editDetector.isEditing()) {
return;
}
const expired = this.reminders.getExpiredReminders(SETTINGS.reminderTime.value);
expired.forEach((reminder) => {
if (reminder.muteNotification) {
return;
}
this.showReminder(reminder);
});
});
}
showReminder(reminder) {
reminder.muteNotification = true;
this.reminderModal.show(reminder, (time) => {
console.info("Remind me later: time=%o", time);
reminder.time = time;
reminder.muteNotification = false;
this.remindersController.updateReminder(reminder, false);
this.pluginDataIO.save(true);
}, () => {
console.info("done");
reminder.muteNotification = false;
this.remindersController.updateReminder(reminder, true);
this.reminders.removeReminder(reminder);
this.pluginDataIO.save(true);
}, () => {
console.info("Mute");
reminder.muteNotification = true;
this.viewProxy.reload(true);
}, () => {
console.info("Open");
this.openReminderFile(reminder);
});
}
openReminderFile(reminder) {
return __awaiter(this, void 0, void 0, function* () {
const leaf = this.app.workspace.getUnpinnedLeaf();
yield this.remindersController.openReminder(reminder, leaf);
});
}
onunload() {
this.app.workspace
.getLeavesOfType(VIEW_TYPE_REMINDER_LIST)
.forEach((leaf) => leaf.detach());
}
showReminderList() {
if (this.app.workspace.getLeavesOfType(VIEW_TYPE_REMINDER_LIST).length) {
return;
}
this.app.workspace.getRightLeaf(false).setViewState({
type: VIEW_TYPE_REMINDER_LIST,
});
}
}
class EditDetector {
constructor(editDetectionSec) {
this.editDetectionSec = editDetectionSec;
}
fileChanged() {
this.lastModified = new Date();
}
isEditing() {
if (this.editDetectionSec.value <= 0) {
return false;
}
if (this.lastModified == null) {
return false;
}
const elapsedSec = (new Date().getTime() - this.lastModified.getTime()) / 1000;
return elapsedSec < this.editDetectionSec.value;
}
}
module.exports = ReminderPlugin;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWFpbi5qcyIsInNvdXJjZXMiOlsibm9kZV9tb2R1bGVzL3RzbGliL3RzbGliLmVzNi5qcyIsInNyYy9tb2RlbC9mb3JtYXQvbWFya2Rvd24udHMiLCJzcmMvbW9kZWwvcmVmLnRzIiwibm9kZV9tb2R1bGVzL21vbWVudC9tb21lbnQuanMiLCJzcmMvbW9kZWwvdGltZS50cyIsInNyYy9tb2RlbC9yZW1pbmRlci50cyIsInNyYy9tb2RlbC9mb3JtYXQvcmVtaW5kZXItYmFzZS50cyIsInNyYy9tb2RlbC9mb3JtYXQvcmVtaW5kZXItZGVmYXVsdC50cyIsInNyYy9tb2RlbC9mb3JtYXQvdXRpbC50cyIsInNyYy9tb2RlbC9mb3JtYXQvcmVtaW5kZXIta2FuYmFuLXBsdWdpbi50cyIsIm5vZGVfbW9kdWxlcy9ycnVsZS9kaXN0L2VzbS9zcmMvd2Vla2RheS5qcyIsIm5vZGVfbW9kdWxlcy9ycnVsZS9kaXN0L2VzbS9zcmMvaGVscGVycy5qcyIsIm5vZGVfbW9kdWxlcy9ycnVsZS9kaXN0L2VzbS9zcmMvZGF0ZXV0aWwuanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL2l0ZXJyZXN1bHQuanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL2NhbGxiYWNraXRlcnJlc3VsdC5qcyIsIm5vZGVfbW9kdWxlcy9ycnVsZS9kaXN0L2VzbS9zcmMvbmxwL2kxOG4uanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL25scC90b3RleHQuanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL25scC9wYXJzZXRleHQuanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL3R5cGVzLmpzIiwibm9kZV9tb2R1bGVzL3JydWxlL2Rpc3QvZXNtL3NyYy9ubHAvaW5kZXguanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL2RhdGV0aW1lLmpzIiwibm9kZV9tb2R1bGVzL3JydWxlL2Rpc3QvZXNtL3NyYy9wYXJzZW9wdGlvbnMuanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL3BhcnNlc3RyaW5nLmpzIiwibm9kZV9tb2R1bGVzL2x1eG9uL2J1aWxkL25vZGUvbHV4b24uanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL2RhdGV3aXRoem9uZS5qcyIsIm5vZGVfbW9kdWxlcy9ycnVsZS9kaXN0L2VzbS9zcmMvb3B0aW9uc3Rvc3RyaW5nLmpzIiwibm9kZV9tb2R1bGVzL3JydWxlL2Rpc3QvZXNtL3NyYy9jYWNoZS5qcyIsIm5vZGVfbW9kdWxlcy9ycnVsZS9kaXN0L2VzbS9zcmMvbWFza3MuanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL2l0ZXJpbmZvL3llYXJpbmZvLmpzIiwibm9kZV9tb2R1bGVzL3JydWxlL2Rpc3QvZXNtL3NyYy9pdGVyaW5mby9tb250aGluZm8uanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL2l0ZXJpbmZvL2Vhc3Rlci5qcyIsIm5vZGVfbW9kdWxlcy9ycnVsZS9kaXN0L2VzbS9zcmMvaXRlcmluZm8vaW5kZXguanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL2l0ZXIvcG9zbGlzdC5qcyIsIm5vZGVfbW9kdWxlcy9ycnVsZS9kaXN0L2VzbS9zcmMvaXRlci9pbmRleC5qcyIsIm5vZGVfbW9kdWxlcy9ycnVsZS9kaXN0L2VzbS9zcmMvcnJ1bGUuanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL2l0ZXJzZXQuanMiLCJub2RlX21vZHVsZXMvcnJ1bGUvZGlzdC9lc20vc3JjL3JydWxlc3RyLmpzIiwibm9kZV9tb2R1bGVzL3JydWxlL2Rpc3QvZXNtL3NyYy9ycnVsZXNldC5qcyIsInNyYy9tb2RlbC9mb3JtYXQvc3BsaXR0ZXIudHMiLCJzcmMvbW9kZWwvZm9ybWF0L3JlbWluZGVyLXRhc2tzLXBsdWdpbi50cyIsInNyYy9tb2RlbC9mb3JtYXQvaW5kZXgudHMiLCJzcmMvbW9kZWwvc2V0dGluZ3MudHMiLCJzcmMvc2V0dGluZ3MudHMiLCJzcmMvbW9kZWwvY29udGVudC50cyIsInNyYy9jb250cm9sbGVyLnRzIiwic3JjL2RhdGEudHMiLCJzcmMvb2JzaWRpYW4taGFjay9vYnNpZGlhbi1kZWJ1Zy1tb2JpbGUudHMiLCJub2RlX21vZHVsZXMvc3ZlbHRlL2ludGVybmFsL2luZGV4Lm1qcyIsInNyYy9tb2RlbC9jYWxlbmRhci50cyIsInNyYy91aS9jb21wb25lbnRzL0NhbGVuZGFyLnN2ZWx0ZSIsInNyYy91aS9jb21wb25lbnRzL01hcmtkb3duLnN2ZWx0ZSIsInNyYy91aS9jb21wb25lbnRzL1JlbWluZGVyTGlzdEJ5RGF0ZS5zdmVsdGUiLCJzcmMvdWkvY29tcG9uZW50cy9EYXRlVGltZUNob29zZXIuc3ZlbHRlIiwic3JjL3VpL2RhdGUtY2hvb3Nlci1tb2JpbGUudHMiLCJzcmMvdWkvZGF0ZXRpbWUtY2hvb3Nlci50cyIsInNyYy91aS9hdXRvY29tcGxldGUudHMiLCJzcmMvdWkvZGF0ZXRpbWUtZm9ybWF0LW1vZGFsLnRzIiwic3JjL3VpL2NvbXBvbmVudHMvSWNvbi5zdmVsdGUiLCJzcmMvdWkvY29tcG9uZW50cy9SZW1pbmRlci5zdmVsdGUiLCJzcmMvdWkvcmVtaW5kZXIudHMiLCJzcmMvY29uc3RhbnRzLnRzIiwic3JjL3VpL2NvbXBvbmVudHMvUmVtaW5kZXJMaXN0LnN2ZWx0ZSIsInNyYy91aS9yZW1pbmRlci1saXN0LnRzIiwic3JjL3VpL3V0aWwudHMiLCJzcmMvbWFpbi50cyJdLCJzb3VyY2VzQ29udGVudCI6bnVsbCwibmFtZXMiOlsidGhpcyIsInJlcXVpcmUiLCJEYXRlVGltZSIsIlRpbWUiLCJSZW1pbmRlciIsImlzTnVtYmVyIiwicGFkU3RhcnQiLCJpbml0aWFsaXplT3B0aW9ucyIsImRhdGV1dGlsIiwiREVGQVVMVF9PUFRJT05TIiwiU2V0dGluZ3MiLCJTeW1ib2wiLCJTZXR0aW5nIiwiUGx1Z2luU2V0dGluZ1RhYiIsIlRGaWxlIiwiTWFya2Rvd25WaWV3IiwiUGxhdGZvcm0iLCJNYXJrZG93blJlbmRlcmVyIiwiTW9kYWwiLCJGdXp6eVN1Z2dlc3RNb2RhbCIsInNldEljb24iLCJlbGVjdHJvbiIsIlJlbWluZGVyVmlldyIsIkl0ZW1WaWV3IiwiUmVtaW5kZXJMaXN0VmlldyIsIlBsdWdpbiJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSxJQUFJLGFBQWEsR0FBRyxTQUFTLENBQUMsRUFBRSxDQUFDLEVBQUU7QUFDbkMsSUFBSSxhQUFhLEdBQUcsTUFBTSxDQUFDLGN