11534 lines
439 KiB
JavaScript
11534 lines
439 KiB
JavaScript
import { __unplugin_components_0 as __unplugin_components_0$3 } from "./HelpText.js";
|
|
import { defineComponent, h, resolveWrappedSlot, createTheme, buttonLight, scrollbarLight, derived, composite, createInjectionKey, cB, cM, cE, c, cNotM, NBaseIcon, inject, Button, NBaseClose, useMemo, Scrollbar, ref, useMergedState, toRef, computed, useConfig, useTheme, useFormItem, createKey, depx, provide, isMounted, call, axios, getDefaultExportFromCjs, _export_sfc, useConfigStore, storeToRefs, watch, onMounted, createBlock, openBlock, withCtx, createVNode, createCommentVNode, createElementBlock, unref, createBaseVNode, createTextVNode, Fragment, toDisplayString, isRef, __unplugin_components_0 as __unplugin_components_0$5, usePlanStore, renderList, normalizeStyle, normalizeClass, createSlots, withModifiers, nextTick } from "./index.js";
|
|
import { requireVue } from "./index2.js";
|
|
import { useMessage } from "./use-message.js";
|
|
import { __unplugin_components_14, __unplugin_components_17, __unplugin_components_16, __unplugin_components_7 as __unplugin_components_7$1 } from "./SlickOperatorSelect.js";
|
|
import { emptyLight, getTitleAttribute, NEmpty, VVirtualList, __unplugin_components_5 } from "./Select.js";
|
|
import { inputLight, checkboxLight, __unplugin_components_0 as __unplugin_components_0$2, __unplugin_components_1 } from "./Checkbox.js";
|
|
import { __unplugin_components_15, __unplugin_components_12, pinyin_match, render_op_label, __unplugin_components_6 as __unplugin_components_6$1 } from "./common.js";
|
|
import { __unplugin_components_3, __unplugin_components_0 as __unplugin_components_0$4 } from "./text.js";
|
|
import { setup, radioBaseProps, __unplugin_components_13, __unplugin_components_11 } from "./RadioGroup.js";
|
|
import { __unplugin_components_4 as __unplugin_components_4$1 } from "./Image.js";
|
|
import { __unplugin_components_1 as __unplugin_components_1$1 } from "./Alert.js";
|
|
import { __unplugin_components_2 as __unplugin_components_2$1 } from "./Flex.js";
|
|
import { NIcon } from "./Icon.js";
|
|
import { useLocale } from "./use-locale.js";
|
|
import { __unplugin_components_6 } from "./Slider.js";
|
|
import { NH4 } from "./headers.js";
|
|
import { __unplugin_components_5 as __unplugin_components_5$1 } from "./Table.js";
|
|
import { __unplugin_components_7 } from "./Avatar.js";
|
|
import { __unplugin_components_4 as __unplugin_components_4$2 } from "./Tag.js";
|
|
import { __unplugin_components_6 as __unplugin_components_6$2 } from "./Tooltip.js";
|
|
const SearchIcon = defineComponent({
|
|
name: "Search",
|
|
render() {
|
|
return h("svg", {
|
|
version: "1.1",
|
|
xmlns: "http://www.w3.org/2000/svg",
|
|
viewBox: "0 0 512 512",
|
|
style: "enable-background: new 0 0 512 512"
|
|
}, h("path", {
|
|
d: "M443.5,420.2L336.7,312.4c20.9-26.2,33.5-59.4,33.5-95.5c0-84.5-68.5-153-153.1-153S64,132.5,64,217s68.5,153,153.1,153\n c36.6,0,70.1-12.8,96.5-34.2l106.1,107.1c3.2,3.4,7.6,5.1,11.9,5.1c4.1,0,8.2-1.5,11.3-4.5C449.5,437.2,449.7,426.8,443.5,420.2z\n M217.1,337.1c-32.1,0-62.3-12.5-85-35.2c-22.7-22.7-35.2-52.9-35.2-84.9c0-32.1,12.5-62.3,35.2-84.9c22.7-22.7,52.9-35.2,85-35.2\n c32.1,0,62.3,12.5,85,35.2c22.7,22.7,35.2,52.9,35.2,84.9c0,32.1-12.5,62.3-35.2,84.9C279.4,324.6,249.2,337.1,217.1,337.1z"
|
|
}));
|
|
}
|
|
});
|
|
const __unplugin_components_2 = defineComponent({
|
|
name: "RadioButton",
|
|
props: radioBaseProps,
|
|
setup,
|
|
render() {
|
|
const {
|
|
mergedClsPrefix
|
|
} = this;
|
|
return h("label", {
|
|
class: [`${mergedClsPrefix}-radio-button`, this.mergedDisabled && `${mergedClsPrefix}-radio-button--disabled`, this.renderSafeChecked && `${mergedClsPrefix}-radio-button--checked`, this.focus && [`${mergedClsPrefix}-radio-button--focus`]]
|
|
}, h("input", {
|
|
ref: "inputRef",
|
|
type: "radio",
|
|
class: `${mergedClsPrefix}-radio-input`,
|
|
value: this.value,
|
|
name: this.mergedName,
|
|
checked: this.renderSafeChecked,
|
|
disabled: this.mergedDisabled,
|
|
onChange: this.handleRadioInputChange,
|
|
onFocus: this.handleRadioInputFocus,
|
|
onBlur: this.handleRadioInputBlur
|
|
}), h("div", {
|
|
class: `${mergedClsPrefix}-radio-button__state-border`
|
|
}), resolveWrappedSlot(this.$slots.default, (children) => {
|
|
if (!children && !this.label) return null;
|
|
return h("div", {
|
|
ref: "labelRef",
|
|
class: `${mergedClsPrefix}-radio__label`
|
|
}, children || this.label);
|
|
}));
|
|
}
|
|
});
|
|
const commonVariables = {
|
|
extraFontSizeSmall: "12px",
|
|
extraFontSizeMedium: "12px",
|
|
extraFontSizeLarge: "14px",
|
|
titleFontSizeSmall: "14px",
|
|
titleFontSizeMedium: "16px",
|
|
titleFontSizeLarge: "16px",
|
|
closeSize: "20px",
|
|
closeIconSize: "16px",
|
|
headerHeightSmall: "44px",
|
|
headerHeightMedium: "44px",
|
|
headerHeightLarge: "50px"
|
|
};
|
|
function self(vars) {
|
|
const {
|
|
fontWeight,
|
|
fontSizeLarge,
|
|
fontSizeMedium,
|
|
fontSizeSmall,
|
|
heightLarge,
|
|
heightMedium,
|
|
borderRadius,
|
|
cardColor,
|
|
tableHeaderColor,
|
|
textColor1,
|
|
textColorDisabled,
|
|
textColor2,
|
|
textColor3,
|
|
borderColor,
|
|
hoverColor,
|
|
closeColorHover,
|
|
closeColorPressed,
|
|
closeIconColor,
|
|
closeIconColorHover,
|
|
closeIconColorPressed
|
|
} = vars;
|
|
return Object.assign(Object.assign({}, commonVariables), {
|
|
itemHeightSmall: heightMedium,
|
|
itemHeightMedium: heightMedium,
|
|
itemHeightLarge: heightLarge,
|
|
fontSizeSmall,
|
|
fontSizeMedium,
|
|
fontSizeLarge,
|
|
borderRadius,
|
|
dividerColor: borderColor,
|
|
borderColor,
|
|
listColor: cardColor,
|
|
headerColor: composite(cardColor, tableHeaderColor),
|
|
titleTextColor: textColor1,
|
|
titleTextColorDisabled: textColorDisabled,
|
|
extraTextColor: textColor3,
|
|
extraTextColorDisabled: textColorDisabled,
|
|
itemTextColor: textColor2,
|
|
itemTextColorDisabled: textColorDisabled,
|
|
itemColorPending: hoverColor,
|
|
titleFontWeight: fontWeight,
|
|
closeColorHover,
|
|
closeColorPressed,
|
|
closeIconColor,
|
|
closeIconColorHover,
|
|
closeIconColorPressed
|
|
});
|
|
}
|
|
const transferLight = createTheme({
|
|
name: "Transfer",
|
|
common: derived,
|
|
peers: {
|
|
Checkbox: checkboxLight,
|
|
Scrollbar: scrollbarLight,
|
|
Input: inputLight,
|
|
Empty: emptyLight,
|
|
Button: buttonLight
|
|
},
|
|
self
|
|
});
|
|
const transferInjectionKey = createInjectionKey("n-transfer");
|
|
const style = cB("transfer", `
|
|
width: 100%;
|
|
font-size: var(--n-font-size);
|
|
height: 300px;
|
|
display: flex;
|
|
flex-wrap: nowrap;
|
|
word-break: break-word;
|
|
`, [cM("disabled", [cB("transfer-list", [cB("transfer-list-header", [cE("title", `
|
|
color: var(--n-header-text-color-disabled);
|
|
`), cE("extra", `
|
|
color: var(--n-header-extra-text-color-disabled);
|
|
`)])])]), cB("transfer-list", `
|
|
flex: 1;
|
|
min-width: 0;
|
|
height: inherit;
|
|
display: flex;
|
|
flex-direction: column;
|
|
background-clip: padding-box;
|
|
position: relative;
|
|
transition: background-color .3s var(--n-bezier);
|
|
background-color: var(--n-list-color);
|
|
`, [cM("source", `
|
|
border-top-left-radius: var(--n-border-radius);
|
|
border-bottom-left-radius: var(--n-border-radius);
|
|
`, [cE("border", "border-right: 1px solid var(--n-divider-color);")]), cM("target", `
|
|
border-top-right-radius: var(--n-border-radius);
|
|
border-bottom-right-radius: var(--n-border-radius);
|
|
`, [cE("border", "border-left: none;")]), cE("border", `
|
|
padding: 0 12px;
|
|
border: 1px solid var(--n-border-color);
|
|
transition: border-color .3s var(--n-bezier);
|
|
pointer-events: none;
|
|
border-radius: inherit;
|
|
position: absolute;
|
|
left: 0;
|
|
right: 0;
|
|
top: 0;
|
|
bottom: 0;
|
|
`), cB("transfer-list-header", `
|
|
min-height: var(--n-header-height);
|
|
box-sizing: border-box;
|
|
display: flex;
|
|
padding: 12px 12px 10px 12px;
|
|
align-items: center;
|
|
background-clip: padding-box;
|
|
border-radius: inherit;
|
|
border-bottom-left-radius: 0;
|
|
border-bottom-right-radius: 0;
|
|
line-height: 1.5;
|
|
transition:
|
|
border-color .3s var(--n-bezier),
|
|
background-color .3s var(--n-bezier);
|
|
`, [c("> *:not(:first-child)", `
|
|
margin-left: 8px;
|
|
`), cE("title", `
|
|
flex: 1;
|
|
min-width: 0;
|
|
line-height: 1.5;
|
|
font-size: var(--n-header-font-size);
|
|
font-weight: var(--n-header-font-weight);
|
|
transition: color .3s var(--n-bezier);
|
|
color: var(--n-header-text-color);
|
|
`), cE("button", `
|
|
position: relative;
|
|
`), cE("extra", `
|
|
transition: color .3s var(--n-bezier);
|
|
font-size: var(--n-extra-font-size);
|
|
margin-right: 0;
|
|
white-space: nowrap;
|
|
color: var(--n-header-extra-text-color);
|
|
`)]), cB("transfer-list-body", `
|
|
flex-basis: 0;
|
|
flex-grow: 1;
|
|
box-sizing: border-box;
|
|
position: relative;
|
|
display: flex;
|
|
flex-direction: column;
|
|
border-radius: inherit;
|
|
border-top-left-radius: 0;
|
|
border-top-right-radius: 0;
|
|
`, [cB("transfer-filter", `
|
|
padding: 4px 12px 8px 12px;
|
|
box-sizing: border-box;
|
|
transition:
|
|
border-color .3s var(--n-bezier),
|
|
background-color .3s var(--n-bezier);
|
|
`), cB("transfer-list-flex-container", `
|
|
flex: 1;
|
|
position: relative;
|
|
`, [cB("scrollbar", `
|
|
position: absolute;
|
|
left: 0;
|
|
right: 0;
|
|
top: 0;
|
|
bottom: 0;
|
|
height: unset;
|
|
`), cB("empty", `
|
|
position: absolute;
|
|
left: 50%;
|
|
top: 50%;
|
|
transform: translateY(-50%) translateX(-50%);
|
|
`), cB("transfer-list-content", `
|
|
padding: 0;
|
|
margin: 0;
|
|
position: relative;
|
|
`, [cB("transfer-list-item", `
|
|
padding: 0 12px;
|
|
min-height: var(--n-item-height);
|
|
display: flex;
|
|
align-items: center;
|
|
color: var(--n-item-text-color);
|
|
position: relative;
|
|
transition: color .3s var(--n-bezier);
|
|
`, [cE("background", `
|
|
position: absolute;
|
|
left: 4px;
|
|
right: 4px;
|
|
top: 0;
|
|
bottom: 0;
|
|
border-radius: var(--n-border-radius);
|
|
transition: background-color .3s var(--n-bezier);
|
|
`), cE("checkbox", `
|
|
position: relative;
|
|
margin-right: 8px;
|
|
`), cE("close", `
|
|
opacity: 0;
|
|
pointer-events: none;
|
|
position: relative;
|
|
transition:
|
|
opacity .3s var(--n-bezier),
|
|
background-color .3s var(--n-bezier),
|
|
color .3s var(--n-bezier);
|
|
`), cE("label", `
|
|
position: relative;
|
|
min-width: 0;
|
|
flex-grow: 1;
|
|
`), cM("source", "cursor: pointer;"), cM("disabled", `
|
|
cursor: not-allowed;
|
|
color: var(--n-item-text-color-disabled);
|
|
`), cNotM("disabled", [c("&:hover", [cE("background", "background-color: var(--n-item-color-pending);"), cE("close", `
|
|
opacity: 1;
|
|
pointer-events: all;
|
|
`)])])])])])])])]);
|
|
const NTransferFilter = defineComponent({
|
|
name: "TransferFilter",
|
|
props: {
|
|
value: String,
|
|
placeholder: String,
|
|
disabled: Boolean,
|
|
onUpdateValue: {
|
|
type: Function,
|
|
required: true
|
|
}
|
|
},
|
|
setup() {
|
|
const {
|
|
mergedThemeRef,
|
|
mergedClsPrefixRef
|
|
} = inject(transferInjectionKey);
|
|
return {
|
|
mergedClsPrefix: mergedClsPrefixRef,
|
|
mergedTheme: mergedThemeRef
|
|
};
|
|
},
|
|
render() {
|
|
const {
|
|
mergedTheme,
|
|
mergedClsPrefix
|
|
} = this;
|
|
return h("div", {
|
|
class: `${mergedClsPrefix}-transfer-filter`
|
|
}, h(__unplugin_components_0$2, {
|
|
value: this.value,
|
|
onUpdateValue: this.onUpdateValue,
|
|
disabled: this.disabled,
|
|
placeholder: this.placeholder,
|
|
theme: mergedTheme.peers.Input,
|
|
themeOverrides: mergedTheme.peerOverrides.Input,
|
|
clearable: true,
|
|
size: "small"
|
|
}, {
|
|
"clear-icon-placeholder": () => h(NBaseIcon, {
|
|
clsPrefix: mergedClsPrefix
|
|
}, {
|
|
default: () => h(SearchIcon, null)
|
|
})
|
|
}));
|
|
}
|
|
});
|
|
const NTransferHeader = defineComponent({
|
|
name: "TransferHeader",
|
|
props: {
|
|
size: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
selectAllText: String,
|
|
clearText: String,
|
|
source: Boolean,
|
|
onCheckedAll: Function,
|
|
onClearAll: Function,
|
|
title: [String, Function]
|
|
},
|
|
setup(props) {
|
|
const {
|
|
targetOptionsRef,
|
|
canNotSelectAnythingRef,
|
|
canBeClearedRef,
|
|
allCheckedRef,
|
|
mergedThemeRef,
|
|
disabledRef,
|
|
mergedClsPrefixRef,
|
|
srcOptionsLengthRef
|
|
} = inject(transferInjectionKey);
|
|
const {
|
|
localeRef
|
|
} = useLocale("Transfer");
|
|
return () => {
|
|
const {
|
|
source,
|
|
onClearAll,
|
|
onCheckedAll,
|
|
selectAllText,
|
|
clearText
|
|
} = props;
|
|
const {
|
|
value: mergedTheme
|
|
} = mergedThemeRef;
|
|
const {
|
|
value: mergedClsPrefix
|
|
} = mergedClsPrefixRef;
|
|
const {
|
|
value: locale
|
|
} = localeRef;
|
|
const buttonSize = props.size === "large" ? "small" : "tiny";
|
|
const {
|
|
title
|
|
} = props;
|
|
return h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list-header`
|
|
}, title && h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list-header__title`
|
|
}, typeof title === "function" ? title() : title), source && h(Button, {
|
|
class: `${mergedClsPrefix}-transfer-list-header__button`,
|
|
theme: mergedTheme.peers.Button,
|
|
themeOverrides: mergedTheme.peerOverrides.Button,
|
|
size: buttonSize,
|
|
tertiary: true,
|
|
onClick: allCheckedRef.value ? onClearAll : onCheckedAll,
|
|
disabled: canNotSelectAnythingRef.value || disabledRef.value
|
|
}, {
|
|
default: () => allCheckedRef.value ? clearText || locale.unselectAll : selectAllText || locale.selectAll
|
|
}), !source && canBeClearedRef.value && h(Button, {
|
|
class: `${mergedClsPrefix}-transfer-list-header__button`,
|
|
theme: mergedTheme.peers.Button,
|
|
themeOverrides: mergedTheme.peerOverrides.Button,
|
|
size: buttonSize,
|
|
tertiary: true,
|
|
onClick: onClearAll,
|
|
disabled: disabledRef.value
|
|
}, {
|
|
default: () => locale.clearAll
|
|
}), h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list-header__extra`
|
|
}, source ? locale.total(srcOptionsLengthRef.value) : locale.selected(targetOptionsRef.value.length)));
|
|
};
|
|
}
|
|
});
|
|
const NTransferListItem = defineComponent({
|
|
name: "NTransferListItem",
|
|
props: {
|
|
source: Boolean,
|
|
label: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
value: {
|
|
type: [String, Number],
|
|
required: true
|
|
},
|
|
disabled: Boolean,
|
|
option: {
|
|
type: Object,
|
|
required: true
|
|
}
|
|
},
|
|
setup(props) {
|
|
const {
|
|
targetValueSetRef,
|
|
mergedClsPrefixRef,
|
|
mergedThemeRef,
|
|
handleItemCheck,
|
|
renderSourceLabelRef,
|
|
renderTargetLabelRef,
|
|
showSelectedRef
|
|
} = inject(transferInjectionKey);
|
|
const checkedRef = useMemo(() => targetValueSetRef.value.has(props.value));
|
|
function handleClick() {
|
|
if (!props.disabled) {
|
|
handleItemCheck(!checkedRef.value, props.value);
|
|
}
|
|
}
|
|
return {
|
|
mergedClsPrefix: mergedClsPrefixRef,
|
|
mergedTheme: mergedThemeRef,
|
|
checked: checkedRef,
|
|
showSelected: showSelectedRef,
|
|
renderSourceLabel: renderSourceLabelRef,
|
|
renderTargetLabel: renderTargetLabelRef,
|
|
handleClick
|
|
};
|
|
},
|
|
render() {
|
|
const {
|
|
disabled,
|
|
mergedTheme,
|
|
mergedClsPrefix,
|
|
label,
|
|
checked,
|
|
source,
|
|
renderSourceLabel,
|
|
renderTargetLabel
|
|
} = this;
|
|
return h("div", {
|
|
class: [`${mergedClsPrefix}-transfer-list-item`, disabled && `${mergedClsPrefix}-transfer-list-item--disabled`, source ? `${mergedClsPrefix}-transfer-list-item--source` : `${mergedClsPrefix}-transfer-list-item--target`],
|
|
onClick: source ? this.handleClick : void 0
|
|
}, h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list-item__background`
|
|
}), source && this.showSelected && h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list-item__checkbox`
|
|
}, h(__unplugin_components_1, {
|
|
theme: mergedTheme.peers.Checkbox,
|
|
themeOverrides: mergedTheme.peerOverrides.Checkbox,
|
|
disabled,
|
|
checked
|
|
})), h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list-item__label`,
|
|
title: getTitleAttribute(label)
|
|
}, source ? renderSourceLabel ? renderSourceLabel({
|
|
option: this.option
|
|
}) : label : renderTargetLabel ? renderTargetLabel({
|
|
option: this.option
|
|
}) : label), !source && !disabled && h(NBaseClose, {
|
|
focusable: false,
|
|
class: `${mergedClsPrefix}-transfer-list-item__close`,
|
|
clsPrefix: mergedClsPrefix,
|
|
onClick: this.handleClick
|
|
}));
|
|
}
|
|
});
|
|
const NTransferList = defineComponent({
|
|
name: "TransferList",
|
|
props: {
|
|
virtualScroll: {
|
|
type: Boolean,
|
|
required: true
|
|
},
|
|
itemSize: {
|
|
type: Number,
|
|
required: true
|
|
},
|
|
options: {
|
|
type: Array,
|
|
required: true
|
|
},
|
|
disabled: {
|
|
type: Boolean,
|
|
required: true
|
|
},
|
|
source: Boolean
|
|
},
|
|
setup() {
|
|
const {
|
|
mergedThemeRef,
|
|
mergedClsPrefixRef
|
|
} = inject(transferInjectionKey);
|
|
const scrollerInstRef = ref(null);
|
|
const vlInstRef = ref(null);
|
|
function syncVLScroller() {
|
|
var _a;
|
|
(_a = scrollerInstRef.value) === null || _a === void 0 ? void 0 : _a.sync();
|
|
}
|
|
function scrollContainer() {
|
|
const {
|
|
value
|
|
} = vlInstRef;
|
|
if (!value) return null;
|
|
const {
|
|
listElRef
|
|
} = value;
|
|
return listElRef;
|
|
}
|
|
function scrollContent() {
|
|
const {
|
|
value
|
|
} = vlInstRef;
|
|
if (!value) return null;
|
|
const {
|
|
itemsElRef
|
|
} = value;
|
|
return itemsElRef;
|
|
}
|
|
return {
|
|
mergedTheme: mergedThemeRef,
|
|
mergedClsPrefix: mergedClsPrefixRef,
|
|
scrollerInstRef,
|
|
vlInstRef,
|
|
syncVLScroller,
|
|
scrollContainer,
|
|
scrollContent
|
|
};
|
|
},
|
|
render() {
|
|
const {
|
|
mergedTheme,
|
|
options
|
|
} = this;
|
|
if (options.length === 0) {
|
|
return h(NEmpty, {
|
|
theme: mergedTheme.peers.Empty,
|
|
themeOverrides: mergedTheme.peerOverrides.Empty
|
|
});
|
|
}
|
|
const {
|
|
mergedClsPrefix,
|
|
virtualScroll,
|
|
source,
|
|
disabled,
|
|
syncVLScroller
|
|
} = this;
|
|
return h(Scrollbar, {
|
|
ref: "scrollerInstRef",
|
|
theme: mergedTheme.peers.Scrollbar,
|
|
themeOverrides: mergedTheme.peerOverrides.Scrollbar,
|
|
container: virtualScroll ? this.scrollContainer : void 0,
|
|
content: virtualScroll ? this.scrollContent : void 0
|
|
}, {
|
|
default: () => virtualScroll ? h(VVirtualList, {
|
|
ref: "vlInstRef",
|
|
style: {
|
|
height: "100%"
|
|
},
|
|
class: `${mergedClsPrefix}-transfer-list-content`,
|
|
items: this.options,
|
|
itemSize: this.itemSize,
|
|
showScrollbar: false,
|
|
onResize: syncVLScroller,
|
|
onScroll: syncVLScroller,
|
|
keyField: "value"
|
|
}, {
|
|
default: ({
|
|
item
|
|
}) => {
|
|
const {
|
|
source: source2,
|
|
disabled: disabled2
|
|
} = this;
|
|
return h(NTransferListItem, {
|
|
source: source2,
|
|
key: item.value,
|
|
value: item.value,
|
|
disabled: item.disabled || disabled2,
|
|
label: item.label,
|
|
option: item
|
|
});
|
|
}
|
|
}) : h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list-content`
|
|
}, options.map((option) => h(NTransferListItem, {
|
|
source,
|
|
key: option.value,
|
|
value: option.value,
|
|
disabled: option.disabled || disabled,
|
|
label: option.label,
|
|
option
|
|
})))
|
|
});
|
|
}
|
|
});
|
|
function useTransferData(props) {
|
|
const uncontrolledValueRef = ref(props.defaultValue);
|
|
const mergedValueRef = useMergedState(toRef(props, "value"), uncontrolledValueRef);
|
|
const optionsMapRef = computed(() => {
|
|
const map = /* @__PURE__ */ new Map();
|
|
(props.options || []).forEach((opt) => map.set(opt.value, opt));
|
|
return map;
|
|
});
|
|
const targetValueSetRef = computed(() => new Set(mergedValueRef.value || []));
|
|
const targetOptionsRef = computed(() => {
|
|
const optionMap = optionsMapRef.value;
|
|
const targetOptions = [];
|
|
(mergedValueRef.value || []).forEach((v) => {
|
|
const option = optionMap.get(v);
|
|
if (option) {
|
|
targetOptions.push(option);
|
|
}
|
|
});
|
|
return targetOptions;
|
|
});
|
|
const srcPatternRef = ref("");
|
|
const tgtPatternRef = ref("");
|
|
const mergedSrcFilterableRef = computed(() => {
|
|
return props.sourceFilterable || !!props.filterable;
|
|
});
|
|
const filteredSrcOptionsRef = computed(() => {
|
|
const {
|
|
showSelected,
|
|
options,
|
|
filter
|
|
} = props;
|
|
if (!mergedSrcFilterableRef.value) {
|
|
if (showSelected) {
|
|
return options;
|
|
} else {
|
|
return options.filter((option) => !targetValueSetRef.value.has(option.value));
|
|
}
|
|
}
|
|
return options.filter((option) => {
|
|
return filter(srcPatternRef.value, option, "source") && (showSelected || !targetValueSetRef.value.has(option.value));
|
|
});
|
|
});
|
|
const filteredTgtOptionsRef = computed(() => {
|
|
if (!props.targetFilterable) return targetOptionsRef.value;
|
|
const {
|
|
filter
|
|
} = props;
|
|
return targetOptionsRef.value.filter((opt) => filter(tgtPatternRef.value, opt, "target"));
|
|
});
|
|
const mergedValueSetRef = computed(() => {
|
|
const {
|
|
value
|
|
} = mergedValueRef;
|
|
if (value === null) return /* @__PURE__ */ new Set();
|
|
return new Set(value);
|
|
});
|
|
const valueSetForCheckAllRef = computed(() => {
|
|
const values = new Set(mergedValueSetRef.value);
|
|
filteredSrcOptionsRef.value.forEach((option) => {
|
|
if (!option.disabled && !values.has(option.value)) {
|
|
values.add(option.value);
|
|
}
|
|
});
|
|
return values;
|
|
});
|
|
const valueSetForUncheckAllRef = computed(() => {
|
|
const values = new Set(mergedValueSetRef.value);
|
|
filteredSrcOptionsRef.value.forEach((option) => {
|
|
if (!option.disabled && values.has(option.value)) {
|
|
values.delete(option.value);
|
|
}
|
|
});
|
|
return values;
|
|
});
|
|
const valueSetForClearRef = computed(() => {
|
|
const values = new Set(mergedValueSetRef.value);
|
|
filteredTgtOptionsRef.value.forEach((option) => {
|
|
if (!option.disabled) {
|
|
values.delete(option.value);
|
|
}
|
|
});
|
|
return values;
|
|
});
|
|
const canNotSelectAnythingRef = computed(() => {
|
|
return filteredSrcOptionsRef.value.every((option) => option.disabled);
|
|
});
|
|
const allCheckedRef = computed(() => {
|
|
if (!filteredSrcOptionsRef.value.length) {
|
|
return false;
|
|
}
|
|
const mergedValueSet = mergedValueSetRef.value;
|
|
return filteredSrcOptionsRef.value.every((option) => option.disabled || mergedValueSet.has(option.value));
|
|
});
|
|
const canBeClearedRef = computed(() => {
|
|
return filteredTgtOptionsRef.value.some((option) => !option.disabled);
|
|
});
|
|
function handleSrcFilterUpdateValue(value) {
|
|
srcPatternRef.value = value !== null && value !== void 0 ? value : "";
|
|
}
|
|
function handleTgtFilterUpdateValue(value) {
|
|
tgtPatternRef.value = value !== null && value !== void 0 ? value : "";
|
|
}
|
|
return {
|
|
uncontrolledValueRef,
|
|
mergedValueRef,
|
|
targetValueSetRef,
|
|
valueSetForCheckAllRef,
|
|
valueSetForUncheckAllRef,
|
|
valueSetForClearRef,
|
|
filteredTgtOptionsRef,
|
|
filteredSrcOptionsRef,
|
|
targetOptionsRef,
|
|
canNotSelectAnythingRef,
|
|
canBeClearedRef,
|
|
allCheckedRef,
|
|
srcPatternRef,
|
|
tgtPatternRef,
|
|
mergedSrcFilterableRef,
|
|
handleSrcFilterUpdateValue,
|
|
handleTgtFilterUpdateValue
|
|
};
|
|
}
|
|
const transferProps = Object.assign(Object.assign({}, useTheme.props), {
|
|
value: Array,
|
|
defaultValue: {
|
|
type: Array,
|
|
default: null
|
|
},
|
|
options: {
|
|
type: Array,
|
|
default: () => []
|
|
},
|
|
disabled: {
|
|
type: Boolean,
|
|
default: void 0
|
|
},
|
|
virtualScroll: Boolean,
|
|
sourceTitle: [String, Function],
|
|
selectAllText: String,
|
|
clearText: String,
|
|
targetTitle: [String, Function],
|
|
filterable: {
|
|
type: Boolean,
|
|
default: void 0
|
|
},
|
|
sourceFilterable: Boolean,
|
|
targetFilterable: Boolean,
|
|
showSelected: {
|
|
type: Boolean,
|
|
default: true
|
|
},
|
|
sourceFilterPlaceholder: String,
|
|
targetFilterPlaceholder: String,
|
|
filter: {
|
|
type: Function,
|
|
default: (pattern, option) => {
|
|
if (!pattern) return true;
|
|
return ~`${option.label}`.toLowerCase().indexOf(`${pattern}`.toLowerCase());
|
|
}
|
|
},
|
|
size: String,
|
|
renderSourceLabel: Function,
|
|
renderTargetLabel: Function,
|
|
renderSourceList: Function,
|
|
renderTargetList: Function,
|
|
"onUpdate:value": [Function, Array],
|
|
onUpdateValue: [Function, Array],
|
|
onChange: [Function, Array]
|
|
});
|
|
const __unplugin_components_0$1 = defineComponent({
|
|
name: "Transfer",
|
|
props: transferProps,
|
|
setup(props) {
|
|
const {
|
|
mergedClsPrefixRef
|
|
} = useConfig(props);
|
|
const themeRef = useTheme("Transfer", "-transfer", style, transferLight, props, mergedClsPrefixRef);
|
|
const formItem = useFormItem(props);
|
|
const {
|
|
mergedSizeRef,
|
|
mergedDisabledRef
|
|
} = formItem;
|
|
const itemSizeRef = computed(() => {
|
|
const {
|
|
value: size
|
|
} = mergedSizeRef;
|
|
const {
|
|
self: {
|
|
[createKey("itemHeight", size)]: itemSize
|
|
}
|
|
} = themeRef.value;
|
|
return depx(itemSize);
|
|
});
|
|
const {
|
|
uncontrolledValueRef,
|
|
mergedValueRef,
|
|
targetValueSetRef,
|
|
valueSetForCheckAllRef,
|
|
valueSetForUncheckAllRef,
|
|
valueSetForClearRef,
|
|
filteredTgtOptionsRef,
|
|
filteredSrcOptionsRef,
|
|
targetOptionsRef,
|
|
canNotSelectAnythingRef,
|
|
canBeClearedRef,
|
|
allCheckedRef,
|
|
srcPatternRef,
|
|
tgtPatternRef,
|
|
mergedSrcFilterableRef,
|
|
handleSrcFilterUpdateValue,
|
|
handleTgtFilterUpdateValue
|
|
} = useTransferData(props);
|
|
function doUpdateValue(value) {
|
|
const {
|
|
onUpdateValue,
|
|
"onUpdate:value": _onUpdateValue,
|
|
onChange
|
|
} = props;
|
|
const {
|
|
nTriggerFormInput,
|
|
nTriggerFormChange
|
|
} = formItem;
|
|
if (onUpdateValue) call(onUpdateValue, value);
|
|
if (_onUpdateValue) call(_onUpdateValue, value);
|
|
if (onChange) call(onChange, value);
|
|
uncontrolledValueRef.value = value;
|
|
nTriggerFormInput();
|
|
nTriggerFormChange();
|
|
}
|
|
function handleSourceCheckAll() {
|
|
doUpdateValue([...valueSetForCheckAllRef.value]);
|
|
}
|
|
function handleSourceUncheckAll() {
|
|
doUpdateValue([...valueSetForUncheckAllRef.value]);
|
|
}
|
|
function handleTargetClearAll() {
|
|
doUpdateValue([...valueSetForClearRef.value]);
|
|
}
|
|
function handleItemCheck(checked, optionValue) {
|
|
if (checked) {
|
|
doUpdateValue((mergedValueRef.value || []).concat(optionValue));
|
|
} else {
|
|
doUpdateValue((mergedValueRef.value || []).filter((v) => v !== optionValue));
|
|
}
|
|
}
|
|
function handleChecked(optionValueList) {
|
|
doUpdateValue(optionValueList);
|
|
}
|
|
provide(transferInjectionKey, {
|
|
targetValueSetRef,
|
|
mergedClsPrefixRef,
|
|
disabledRef: mergedDisabledRef,
|
|
mergedThemeRef: themeRef,
|
|
targetOptionsRef,
|
|
canNotSelectAnythingRef,
|
|
canBeClearedRef,
|
|
allCheckedRef,
|
|
srcOptionsLengthRef: computed(() => props.options.length),
|
|
handleItemCheck,
|
|
renderSourceLabelRef: toRef(props, "renderSourceLabel"),
|
|
renderTargetLabelRef: toRef(props, "renderTargetLabel"),
|
|
showSelectedRef: toRef(props, "showSelected")
|
|
});
|
|
return {
|
|
mergedClsPrefix: mergedClsPrefixRef,
|
|
mergedDisabled: mergedDisabledRef,
|
|
itemSize: itemSizeRef,
|
|
isMounted: isMounted(),
|
|
mergedTheme: themeRef,
|
|
filteredSrcOpts: filteredSrcOptionsRef,
|
|
filteredTgtOpts: filteredTgtOptionsRef,
|
|
srcPattern: srcPatternRef,
|
|
tgtPattern: tgtPatternRef,
|
|
mergedSize: mergedSizeRef,
|
|
mergedSrcFilterable: mergedSrcFilterableRef,
|
|
handleSrcFilterUpdateValue,
|
|
handleTgtFilterUpdateValue,
|
|
handleSourceCheckAll,
|
|
handleSourceUncheckAll,
|
|
handleTargetClearAll,
|
|
handleItemCheck,
|
|
handleChecked,
|
|
cssVars: computed(() => {
|
|
const {
|
|
value: size
|
|
} = mergedSizeRef;
|
|
const {
|
|
common: {
|
|
cubicBezierEaseInOut
|
|
},
|
|
self: {
|
|
borderRadius,
|
|
borderColor,
|
|
listColor,
|
|
titleTextColor,
|
|
titleTextColorDisabled,
|
|
extraTextColor,
|
|
itemTextColor,
|
|
itemColorPending,
|
|
itemTextColorDisabled,
|
|
titleFontWeight,
|
|
closeColorHover,
|
|
closeColorPressed,
|
|
closeIconColor,
|
|
closeIconColorHover,
|
|
closeIconColorPressed,
|
|
closeIconSize,
|
|
closeSize,
|
|
dividerColor,
|
|
extraTextColorDisabled,
|
|
[createKey("extraFontSize", size)]: extraFontSize,
|
|
[createKey("fontSize", size)]: fontSize,
|
|
[createKey("titleFontSize", size)]: titleFontSize,
|
|
[createKey("itemHeight", size)]: itemHeight,
|
|
[createKey("headerHeight", size)]: headerHeight
|
|
}
|
|
} = themeRef.value;
|
|
return {
|
|
"--n-bezier": cubicBezierEaseInOut,
|
|
"--n-border-color": borderColor,
|
|
"--n-border-radius": borderRadius,
|
|
"--n-extra-font-size": extraFontSize,
|
|
"--n-font-size": fontSize,
|
|
"--n-header-font-size": titleFontSize,
|
|
"--n-header-extra-text-color": extraTextColor,
|
|
"--n-header-extra-text-color-disabled": extraTextColorDisabled,
|
|
"--n-header-font-weight": titleFontWeight,
|
|
"--n-header-text-color": titleTextColor,
|
|
"--n-header-text-color-disabled": titleTextColorDisabled,
|
|
"--n-item-color-pending": itemColorPending,
|
|
"--n-item-height": itemHeight,
|
|
"--n-item-text-color": itemTextColor,
|
|
"--n-item-text-color-disabled": itemTextColorDisabled,
|
|
"--n-list-color": listColor,
|
|
"--n-header-height": headerHeight,
|
|
"--n-close-size": closeSize,
|
|
"--n-close-icon-size": closeIconSize,
|
|
"--n-close-color-hover": closeColorHover,
|
|
"--n-close-color-pressed": closeColorPressed,
|
|
"--n-close-icon-color": closeIconColor,
|
|
"--n-close-icon-color-hover": closeIconColorHover,
|
|
"--n-close-icon-color-pressed": closeIconColorPressed,
|
|
"--n-divider-color": dividerColor
|
|
};
|
|
})
|
|
};
|
|
},
|
|
render() {
|
|
const {
|
|
mergedClsPrefix,
|
|
renderSourceList,
|
|
renderTargetList,
|
|
mergedTheme,
|
|
mergedSrcFilterable,
|
|
targetFilterable
|
|
} = this;
|
|
return h("div", {
|
|
class: [`${mergedClsPrefix}-transfer`, this.mergedDisabled && `${mergedClsPrefix}-transfer--disabled`],
|
|
style: this.cssVars
|
|
}, h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list ${mergedClsPrefix}-transfer-list--source`
|
|
}, h(NTransferHeader, {
|
|
source: true,
|
|
selectAllText: this.selectAllText,
|
|
clearText: this.clearText,
|
|
title: this.sourceTitle,
|
|
onCheckedAll: this.handleSourceCheckAll,
|
|
onClearAll: this.handleSourceUncheckAll,
|
|
size: this.mergedSize
|
|
}), h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list-body`
|
|
}, mergedSrcFilterable ? h(NTransferFilter, {
|
|
onUpdateValue: this.handleSrcFilterUpdateValue,
|
|
value: this.srcPattern,
|
|
disabled: this.mergedDisabled,
|
|
placeholder: this.sourceFilterPlaceholder
|
|
}) : null, h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list-flex-container`
|
|
}, renderSourceList ? h(Scrollbar, {
|
|
theme: mergedTheme.peers.Scrollbar,
|
|
themeOverrides: mergedTheme.peerOverrides.Scrollbar
|
|
}, {
|
|
default: () => renderSourceList({
|
|
onCheck: this.handleChecked,
|
|
checkedOptions: this.filteredTgtOpts,
|
|
pattern: this.srcPattern
|
|
})
|
|
}) : h(NTransferList, {
|
|
source: true,
|
|
options: this.filteredSrcOpts,
|
|
disabled: this.mergedDisabled,
|
|
virtualScroll: this.virtualScroll,
|
|
itemSize: this.itemSize
|
|
}))), h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list__border`
|
|
})), h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list ${mergedClsPrefix}-transfer-list--target`
|
|
}, h(NTransferHeader, {
|
|
onClearAll: this.handleTargetClearAll,
|
|
size: this.mergedSize,
|
|
title: this.targetTitle
|
|
}), h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list-body`
|
|
}, targetFilterable ? h(NTransferFilter, {
|
|
onUpdateValue: this.handleTgtFilterUpdateValue,
|
|
value: this.tgtPattern,
|
|
disabled: this.mergedDisabled,
|
|
placeholder: this.sourceFilterPlaceholder
|
|
}) : null, h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list-flex-container`
|
|
}, renderTargetList ? h(Scrollbar, {
|
|
theme: mergedTheme.peers.Scrollbar,
|
|
themeOverrides: mergedTheme.peerOverrides.Scrollbar
|
|
}, {
|
|
default: () => renderTargetList({
|
|
onCheck: this.handleChecked,
|
|
checkedOptions: this.filteredTgtOpts,
|
|
pattern: this.tgtPattern
|
|
})
|
|
}) : h(NTransferList, {
|
|
options: this.filteredTgtOpts,
|
|
disabled: this.mergedDisabled,
|
|
virtualScroll: this.virtualScroll,
|
|
itemSize: this.itemSize
|
|
}))), h("div", {
|
|
class: `${mergedClsPrefix}-transfer-list__border`
|
|
})));
|
|
}
|
|
});
|
|
async function file_dialog() {
|
|
const response = await axios.get(`${""}/dialog/file`);
|
|
return response.data;
|
|
}
|
|
async function folder_dialog() {
|
|
const response = await axios.get(`${""}/dialog/folder`);
|
|
return response.data;
|
|
}
|
|
var SettingsAutomation$1 = {};
|
|
var hasRequiredSettingsAutomation;
|
|
function requireSettingsAutomation() {
|
|
if (hasRequiredSettingsAutomation) return SettingsAutomation$1;
|
|
hasRequiredSettingsAutomation = 1;
|
|
Object.defineProperty(SettingsAutomation$1, "__esModule", { value: true });
|
|
const vue_1 = requireVue();
|
|
const _hoisted_13 = {
|
|
xmlns: "http://www.w3.org/2000/svg",
|
|
"xmlns:xlink": "http://www.w3.org/1999/xlink",
|
|
viewBox: "0 0 24 24"
|
|
};
|
|
SettingsAutomation$1.default = (0, vue_1.defineComponent)({
|
|
name: "SettingsAutomation",
|
|
render: function render(_ctx, _cache) {
|
|
return (0, vue_1.openBlock)(), (0, vue_1.createElementBlock)(
|
|
"svg",
|
|
_hoisted_13,
|
|
_cache[0] || (_cache[0] = [
|
|
(0, vue_1.createElementVNode)(
|
|
"g",
|
|
{
|
|
fill: "none",
|
|
stroke: "currentColor",
|
|
"stroke-width": "2",
|
|
"stroke-linecap": "round",
|
|
"stroke-linejoin": "round"
|
|
},
|
|
[
|
|
(0, vue_1.createElementVNode)("path", {
|
|
d: "M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 0 0-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 0 0-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 0 0-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 0 0-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 0 0 1.066-2.573c-.94-1.543.826-3.31 2.37-2.37c1 .608 2.296.07 2.572-1.065z"
|
|
}),
|
|
(0, vue_1.createElementVNode)("path", {
|
|
d: "M10 9v6l5-3z"
|
|
})
|
|
],
|
|
-1
|
|
/* HOISTED */
|
|
)
|
|
])
|
|
);
|
|
}
|
|
});
|
|
return SettingsAutomation$1;
|
|
}
|
|
var SettingsAutomationExports = /* @__PURE__ */ requireSettingsAutomation();
|
|
const SettingsAutomation = /* @__PURE__ */ getDefaultExportFromCjs(SettingsAutomationExports);
|
|
const _hoisted_1$8 = { key: 0 };
|
|
const _sfc_main$i = {
|
|
__name: "Device",
|
|
setup(__props) {
|
|
const config_store = useConfigStore();
|
|
const { conf } = storeToRefs(config_store);
|
|
const mobile = inject("mobile");
|
|
const emulator_types = [
|
|
{ label: "夜神", value: "夜神" },
|
|
{ label: "MuMu模拟器12", value: "MuMu12" },
|
|
{ label: "Waydroid", value: "Waydroid" },
|
|
{ label: "雷电模拟器9", value: "雷电9" },
|
|
{ label: "ReDroid", value: "ReDroid" },
|
|
{ label: "MuMu模拟器Pro", value: "MuMuPro" },
|
|
{ label: "Genymotion", value: "Genymotion" },
|
|
{ label: "其它", value: "" }
|
|
];
|
|
const launch_options = [
|
|
{ label: "运行命令", value: "command" },
|
|
{ label: "点击屏幕", value: "tap" }
|
|
];
|
|
const stop_options = computed(() => {
|
|
const result = [
|
|
{ label: "什么都不做", value: "do_nothing" },
|
|
{ label: "退出游戏", value: "exit_game" }
|
|
];
|
|
if (!["adb_multiuser", "scrcpy"].includes(conf.value.app_control_strategy)) {
|
|
result.push({ label: "返回桌面", value: "switch_to_home" });
|
|
}
|
|
if (conf.value.app_control_strategy != "adb_multiuser" && conf.value.emulator.name != "") {
|
|
result.push({ label: "退出模拟器", value: "close_emulator" });
|
|
}
|
|
return result;
|
|
});
|
|
async function select_emulator_folder() {
|
|
const folder_path = await folder_dialog();
|
|
if (folder_path) {
|
|
conf.value.emulator.emulator_folder = folder_path;
|
|
}
|
|
}
|
|
async function select_maa_adb_path() {
|
|
const file_path = await file_dialog();
|
|
if (file_path) {
|
|
conf.value.maa_adb_path = file_path;
|
|
}
|
|
}
|
|
const screencap_options = computed(() => {
|
|
const result = [
|
|
{ label: "DroidCast(主动,有损,较快)", value: "droidcast" },
|
|
{ label: "DroidCast_raw(主动,无损,较快)", value: "droidcast_raw" },
|
|
{ label: "ADB+Gzip(主动,无损,很慢)", value: "adb" },
|
|
{ label: "scrcpy(被动,有损,特殊)", value: "scrcpy" },
|
|
{ label: "自定义(以下命令需要向STDOUT打印截图文件)", value: "diy" }
|
|
];
|
|
if (conf.value.emulator.name == "MuMu12") {
|
|
result.push({ label: "MuMu模拟器12截图API(主动,无损,超快)", value: "mumuipc" });
|
|
} else if (conf.value.emulator.name == "雷电9") {
|
|
result.push({ label: "雷电模拟器9截图API(主动,无损,超快)", value: "ldopengl" });
|
|
}
|
|
return result;
|
|
});
|
|
const touch_options = computed(() => {
|
|
const result = [{ label: "scrcpy", value: "scrcpy" }];
|
|
if (conf.value.emulator.name == "MuMu12") {
|
|
result.push({ label: "MuMu模拟器12触控API", value: "mumuipc" });
|
|
}
|
|
return result;
|
|
});
|
|
const app_control_options = computed(() => {
|
|
const result = [{ label: "ADB", value: "adb" }];
|
|
if (conf.value.emulator.name == "MuMu12") {
|
|
result.push({ label: "MuMu模拟器12应用管理器", value: "mumumanager" });
|
|
if (conf.value.screencap_strategy == "mumuipc" && conf.value.control_strategy == "mumuipc") {
|
|
result.push({ label: "MuMu模拟器12应用分身", value: "adb_multiuser" });
|
|
}
|
|
}
|
|
if (conf.value.screencap_strategy == "scrcpy" && conf.value.control_strategy == "scrcpy") {
|
|
result.push({ label: "scrcpy virtual display", value: "scrcpy" });
|
|
}
|
|
return result;
|
|
});
|
|
const tested = ref(false);
|
|
const image = ref("");
|
|
const elapsed = ref(0);
|
|
const screenshot_success = ref(true);
|
|
const reason = ref("");
|
|
const loading = ref(false);
|
|
const axios2 = inject("axios");
|
|
async function test_screenshot() {
|
|
loading.value = true;
|
|
tested.value = false;
|
|
try {
|
|
const { data } = await axios2.get(`${""}/test-screenshot`);
|
|
screenshot_success.value = data.success;
|
|
if (screenshot_success.value) {
|
|
image.value = data.screenshot;
|
|
elapsed.value = data.elapsed;
|
|
} else {
|
|
reason.value = data.reason;
|
|
}
|
|
} finally {
|
|
loading.value = false;
|
|
tested.value = true;
|
|
}
|
|
}
|
|
const screenshot_type = computed(() => {
|
|
if (elapsed.value <= 50) {
|
|
return "success";
|
|
} else if (elapsed.value <= 200) {
|
|
return "default";
|
|
} else if (elapsed.value <= 500) {
|
|
return "warning";
|
|
} else {
|
|
return "error";
|
|
}
|
|
});
|
|
const auto_fill_enable = computed(() => {
|
|
return ["夜神", "MuMu12", "雷电9", "ReDroid", "Waydroid"].includes(conf.value.emulator.name);
|
|
});
|
|
const auto_fill_animation = ref(false);
|
|
async function auto_fill() {
|
|
auto_fill_animation.value = true;
|
|
const [r1, r2] = await Promise.all([
|
|
axios2.get(`${""}/auto-get-path`),
|
|
axios2.get(`${""}/get-adb-serial`)
|
|
]);
|
|
auto_fill_animation.value = false;
|
|
if (r2.data != "OK") {
|
|
message.error("请填写正确的多开编号!");
|
|
} else {
|
|
message.success("自动填写成功!");
|
|
}
|
|
}
|
|
const message = useMessage();
|
|
const preset = ref("custom");
|
|
watch(preset, () => {
|
|
if (preset.value == "mumu") {
|
|
conf.value.emulator.name = "MuMu12";
|
|
conf.value.screencap_strategy = "mumuipc";
|
|
conf.value.control_strategy = "mumuipc";
|
|
conf.value.app_control_strategy = "mumumanager";
|
|
conf.value.kill_server_when_idle = true;
|
|
} else if (preset.value == "leidian9") {
|
|
conf.value.emulator.name = "雷电9";
|
|
conf.value.screencap_strategy = "ldopengl";
|
|
conf.value.control_strategy = "scrcpy";
|
|
conf.value.app_control_strategy = "adb";
|
|
conf.value.kill_server_when_idle = true;
|
|
} else if (preset.value == "mumultiuser") {
|
|
conf.value.emulator.name = "MuMu12";
|
|
conf.value.screencap_strategy = "mumuipc";
|
|
conf.value.control_strategy = "mumuipc";
|
|
conf.value.app_control_strategy = "adb_multiuser";
|
|
conf.value.kill_server_when_idle = true;
|
|
} else if (preset.value == "scrcpy") {
|
|
conf.value.screencap_strategy = "scrcpy";
|
|
conf.value.control_strategy = "scrcpy";
|
|
conf.value.app_control_strategy = "scrcpy";
|
|
conf.value.kill_server_when_idle = true;
|
|
conf.value.strategy_when_idle = "exit_game";
|
|
}
|
|
});
|
|
const presets = [
|
|
{ label: "MuMu全家桶", value: "mumu" },
|
|
{ label: "雷电9", value: "leidian9" },
|
|
{ label: "MuMu应用分身", value: "mumultiuser" },
|
|
{ label: "virtual display", value: "scrcpy" },
|
|
{ label: "自定义", value: "custom" }
|
|
];
|
|
onMounted(() => {
|
|
if (conf.value.emulator.name == "MuMu12" && conf.value.screencap_strategy == "mumuipc" && conf.value.control_strategy == "mumuipc" && conf.value.app_control_strategy == "mumumanager" && conf.value.kill_server_when_idle == true) {
|
|
preset.value = "mumu";
|
|
} else if (conf.value.emulator.name == "雷电9" && conf.value.screencap_strategy == "ldopengl" && conf.value.control_strategy == "scrcpy" && conf.value.app_control_strategy == "adb" && conf.value.kill_server_when_idle == true) {
|
|
preset.value = "leidian9";
|
|
} else if (conf.value.emulator.name == "MuMu12" && conf.value.screencap_strategy == "mumuipc" && conf.value.control_strategy == "mumuipc" && conf.value.app_control_strategy == "adb_multiuser" && conf.value.kill_server_when_idle == true) {
|
|
preset.value = "mumultiuser";
|
|
} else if (conf.value.screencap_strategy == "scrcpy" && conf.value.control_strategy == "scrcpy" && conf.value.app_control_strategy == "scrcpy" && conf.value.kill_server_when_idle == true && conf.value.strategy_when_idle == "exit_game") {
|
|
preset.value = "scrcpy";
|
|
}
|
|
});
|
|
return (_ctx, _cache) => {
|
|
const _component_n_select = __unplugin_components_5;
|
|
const _component_n_icon = NIcon;
|
|
const _component_n_button = Button;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_input = __unplugin_components_0$2;
|
|
const _component_n_input_number = __unplugin_components_15;
|
|
const _component_n_divider = __unplugin_components_3;
|
|
const _component_n_alert = __unplugin_components_1$1;
|
|
const _component_n_radio = __unplugin_components_11;
|
|
const _component_n_flex = __unplugin_components_2$1;
|
|
const _component_n_radio_group = __unplugin_components_13;
|
|
const _component_n_space = __unplugin_components_12;
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_n_text = __unplugin_components_0$4;
|
|
const _component_n_image = __unplugin_components_4$1;
|
|
const _component_n_form = __unplugin_components_17;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, null, {
|
|
header: withCtx(() => [
|
|
_cache[21] || (_cache[21] = createBaseVNode("div", { class: "card-title" }, "设备与游戏", -1)),
|
|
createVNode(_component_n_select, {
|
|
value: unref(preset),
|
|
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => isRef(preset) ? preset.value = $event : null),
|
|
options: presets
|
|
}, null, 8, ["value"]),
|
|
unref(auto_fill_enable) ? (openBlock(), createBlock(_component_n_button, {
|
|
key: 0,
|
|
class: "dialog-btn",
|
|
onClick: auto_fill,
|
|
loading: unref(auto_fill_animation)
|
|
}, {
|
|
icon: withCtx(() => [
|
|
createVNode(_component_n_icon, null, {
|
|
default: withCtx(() => [
|
|
createVNode(unref(SettingsAutomation))
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
!unref(mobile) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
createTextVNode("自动填写设置")
|
|
], 64)) : createCommentVNode("", true)
|
|
]),
|
|
_: 1
|
|
}, 8, ["loading"])) : createCommentVNode("", true)
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "130",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
!unref(preset).startsWith("mumu") ? (openBlock(), createBlock(_component_n_form_item, {
|
|
key: 0,
|
|
label: "模拟器"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).emulator.name,
|
|
"onUpdate:value": _cache[1] || (_cache[1] = ($event) => unref(conf).emulator.name = $event),
|
|
options: emulator_types
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
unref(conf).emulator.name ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[23] || (_cache[23] = createBaseVNode("span", null, "多开编号", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[22] || (_cache[22] = [
|
|
createBaseVNode("div", null, "MuMu模拟器12的多开器中,第一个实例(锁形图标)的序号为0", -1),
|
|
createBaseVNode("div", null, "夜神模拟器单开请填写-1", -1),
|
|
createBaseVNode("div", null, "其它模拟器请填写多开器中的序号", -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input, {
|
|
value: unref(conf).emulator.index,
|
|
"onUpdate:value": _cache[2] || (_cache[2] = ($event) => unref(conf).emulator.index = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[25] || (_cache[25] = createBaseVNode("span", null, "模拟器文件夹", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[24] || (_cache[24] = [
|
|
createBaseVNode("div", null, "夜神:写到bin文件夹", -1),
|
|
createBaseVNode("div", null, "MuMu12: 写到shell文件夹", -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input, {
|
|
value: unref(conf).emulator.emulator_folder,
|
|
"onUpdate:value": _cache[3] || (_cache[3] = ($event) => unref(conf).emulator.emulator_folder = $event),
|
|
type: "textarea",
|
|
autosize: true
|
|
}, null, 8, ["value"]),
|
|
createVNode(_component_n_button, {
|
|
onClick: select_emulator_folder,
|
|
class: "dialog-btn"
|
|
}, {
|
|
default: withCtx(() => _cache[26] || (_cache[26] = [
|
|
createTextVNode("...")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "模拟器启动时间" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).emulator.wait_time,
|
|
"onUpdate:value": _cache[4] || (_cache[4] = ($event) => unref(conf).emulator.wait_time = $event)
|
|
}, {
|
|
suffix: withCtx(() => _cache[27] || (_cache[27] = [
|
|
createTextVNode("秒")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[33] || (_cache[33] = createBaseVNode("span", null, "模拟器老板键", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => [
|
|
_cache[30] || (_cache[30] = createBaseVNode("div", null, "启动模拟器后按此快捷键", -1)),
|
|
_cache[31] || (_cache[31] = createBaseVNode("div", null, "若不需要此功能,请留空", -1)),
|
|
_cache[32] || (_cache[32] = createBaseVNode("div", null, "加号分隔按键,不要空格", -1)),
|
|
createBaseVNode("div", null, [
|
|
_cache[29] || (_cache[29] = createTextVNode(" 按键名参考 ")),
|
|
createVNode(_component_n_button, {
|
|
text: "",
|
|
tag: "a",
|
|
href: "https://pyautogui.readthedocs.io/en/latest/keyboard.html#keyboard-keys",
|
|
target: "_blank",
|
|
type: "primary"
|
|
}, {
|
|
default: withCtx(() => _cache[28] || (_cache[28] = [
|
|
createTextVNode(" KEYBOARD_KEYS ")
|
|
])),
|
|
_: 1
|
|
})
|
|
])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input, {
|
|
value: unref(conf).emulator.hotkey,
|
|
"onUpdate:value": _cache[5] || (_cache[5] = ($event) => unref(conf).emulator.hotkey = $event),
|
|
placeholder: "留空停用;组合键用加号分隔"
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})
|
|
], 64)) : createCommentVNode("", true),
|
|
unref(preset) != "mumu" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_form_item, { label: "ADB路径" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input, {
|
|
type: "textarea",
|
|
autosize: true,
|
|
value: unref(conf).maa_adb_path,
|
|
"onUpdate:value": _cache[6] || (_cache[6] = ($event) => unref(conf).maa_adb_path = $event)
|
|
}, null, 8, ["value"]),
|
|
createVNode(_component_n_button, {
|
|
onClick: select_maa_adb_path,
|
|
class: "dialog-btn"
|
|
}, {
|
|
default: withCtx(() => _cache[34] || (_cache[34] = [
|
|
createTextVNode("...")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[36] || (_cache[36] = createBaseVNode("span", null, "ADB连接地址", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[35] || (_cache[35] = [
|
|
createBaseVNode("div", null, "不同模拟器adb地址不同。如不填,系统会自动去寻找adb device中的第一个。", -1),
|
|
createBaseVNode("div", null, [
|
|
createTextVNode("夜神:"),
|
|
createBaseVNode("code", null, "127.0.0.1:62001")
|
|
], -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input, {
|
|
value: unref(conf).adb,
|
|
"onUpdate:value": _cache[7] || (_cache[7] = ($event) => unref(conf).adb = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})
|
|
], 64)) : createCommentVNode("", true),
|
|
unref(preset) == "custom" ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_form_item, { label: "截图方案" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).screencap_strategy,
|
|
"onUpdate:value": _cache[8] || (_cache[8] = ($event) => unref(conf).screencap_strategy = $event),
|
|
options: unref(screencap_options)
|
|
}, null, 8, ["value", "options"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
unref(conf).emulator.name == "MuMu12" && unref(conf).screencap_strategy != "mumuipc" ? (openBlock(), createBlock(_component_n_alert, {
|
|
key: 0,
|
|
title: "推荐使用MuMu模拟器12专属截图",
|
|
style: { "margin": "8px 0" },
|
|
type: "success"
|
|
}, {
|
|
default: withCtx(() => _cache[37] || (_cache[37] = [
|
|
createTextVNode(" 通过共享内存的方式直接获取无损截图,避免了编码、解码、跨进程传输等环节的开销,截图速度远高于通用截图方案。 ")
|
|
])),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
unref(conf).screencap_strategy.startsWith("droidcast") ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
createVNode(_component_n_form_item, { label: "屏幕朝向" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio_group, {
|
|
value: unref(conf).droidcast.orientation,
|
|
"onUpdate:value": _cache[9] || (_cache[9] = ($event) => unref(conf).droidcast.orientation = $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio, { value: "portrait" }, {
|
|
default: withCtx(() => _cache[38] || (_cache[38] = [
|
|
createTextVNode("竖屏")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_radio, { value: "landscape" }, {
|
|
default: withCtx(() => _cache[39] || (_cache[39] = [
|
|
createTextVNode("横屏")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "旋转截图" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio_group, {
|
|
value: unref(conf).droidcast.rotate,
|
|
"onUpdate:value": _cache[10] || (_cache[10] = ($event) => unref(conf).droidcast.rotate = $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio, { value: 0 }, {
|
|
default: withCtx(() => _cache[40] || (_cache[40] = [
|
|
createTextVNode("不旋转")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_radio, { value: 90 }, {
|
|
default: withCtx(() => _cache[41] || (_cache[41] = [
|
|
createTextVNode("旋转90度")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_radio, { value: 180 }, {
|
|
default: withCtx(() => _cache[42] || (_cache[42] = [
|
|
createTextVNode("旋转180度")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_radio, { value: 270 }, {
|
|
default: withCtx(() => _cache[43] || (_cache[43] = [
|
|
createTextVNode("旋转270度")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})
|
|
], 64)) : createCommentVNode("", true),
|
|
unref(conf).screencap_strategy == "diy" ? (openBlock(), createBlock(_component_n_form_item, {
|
|
key: 2,
|
|
label: "截图命令"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input, {
|
|
value: unref(conf).custom_screenshot.command,
|
|
"onUpdate:value": _cache[11] || (_cache[11] = ($event) => unref(conf).custom_screenshot.command = $event),
|
|
type: "textarea",
|
|
autosize: true
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
createVNode(_component_n_form_item, { label: "触控方案" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).control_strategy,
|
|
"onUpdate:value": _cache[12] || (_cache[12] = ($event) => unref(conf).control_strategy = $event),
|
|
options: unref(touch_options)
|
|
}, null, 8, ["value", "options"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "应用控制方案" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).app_control_strategy,
|
|
"onUpdate:value": _cache[13] || (_cache[13] = ($event) => unref(conf).app_control_strategy = $event),
|
|
options: unref(app_control_options)
|
|
}, null, 8, ["value", "options"])
|
|
]),
|
|
_: 1
|
|
})
|
|
], 64)) : createCommentVNode("", true),
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_form_item, { label: "游戏服务器" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio_group, {
|
|
value: unref(conf).package_type,
|
|
"onUpdate:value": _cache[14] || (_cache[14] = ($event) => unref(conf).package_type = $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_space, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio, { value: "official" }, {
|
|
default: withCtx(() => _cache[44] || (_cache[44] = [
|
|
createTextVNode("官服")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_radio, { value: "bilibili" }, {
|
|
default: withCtx(() => _cache[45] || (_cache[45] = [
|
|
createTextVNode("BiliBili服")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
unref(conf).app_control_strategy == "adb_multiuser" ? (openBlock(), createBlock(_component_n_form_item, { key: 4 }, {
|
|
label: withCtx(() => [
|
|
_cache[47] || (_cache[47] = createTextVNode(" 分身编号 ")),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[46] || (_cache[46] = [
|
|
createBaseVNode("div", null, "主应用的编号是0", -1),
|
|
createBaseVNode("div", null, "第一个分身的编号是1", -1),
|
|
createBaseVNode("div", null, "第二个分身的编号是2", -1),
|
|
createBaseVNode("div", null, "其余分身同理", -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).mumu_multi_app.app_index,
|
|
"onUpdate:value": _cache[15] || (_cache[15] = ($event) => unref(conf).mumu_multi_app.app_index = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
unref(conf).app_control_strategy == "adb_multiuser" ? (openBlock(), createBlock(_component_n_alert, {
|
|
key: 5,
|
|
title: "请开启MuMu模拟器12的后台保活!",
|
|
style: { "margin": "8px 0" },
|
|
type: "warning"
|
|
})) : createCommentVNode("", true),
|
|
unref(preset) == "custom" ? (openBlock(), createBlock(_component_n_form_item, {
|
|
key: 6,
|
|
label: "启动游戏"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).tap_to_launch_game.enable,
|
|
"onUpdate:value": _cache[16] || (_cache[16] = ($event) => unref(conf).tap_to_launch_game.enable = $event),
|
|
options: launch_options
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
unref(conf).tap_to_launch_game.enable == "tap" ? (openBlock(), createBlock(_component_n_form_item, {
|
|
key: 7,
|
|
label: "点击坐标"
|
|
}, {
|
|
default: withCtx(() => [
|
|
_cache[48] || (_cache[48] = createBaseVNode("span", { class: "coord-label" }, "X:", -1)),
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).tap_to_launch_game.x,
|
|
"onUpdate:value": _cache[17] || (_cache[17] = ($event) => unref(conf).tap_to_launch_game.x = $event)
|
|
}, null, 8, ["value"]),
|
|
_cache[49] || (_cache[49] = createBaseVNode("span", { class: "coord-label" }, "Y:", -1)),
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).tap_to_launch_game.y,
|
|
"onUpdate:value": _cache[18] || (_cache[18] = ($event) => unref(conf).tap_to_launch_game.y = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
createVNode(_component_n_form_item, { label: "任务结束" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).strategy_when_idle,
|
|
"onUpdate:value": _cache[19] || (_cache[19] = ($event) => unref(conf).strategy_when_idle = $event),
|
|
options: unref(stop_options)
|
|
}, null, 8, ["value", "options"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
unref(preset) == "custom" ? (openBlock(), createBlock(_component_n_form_item, {
|
|
key: 8,
|
|
"show-label": false
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).kill_server_when_idle,
|
|
"onUpdate:checked": _cache[20] || (_cache[20] = ($event) => unref(conf).kill_server_when_idle = $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
_cache[51] || (_cache[51] = createBaseVNode("span", null, "任务结束时关闭ADB Server", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[50] || (_cache[50] = [
|
|
createTextVNode("建议开启,多开不受影响")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, {
|
|
vertical: "",
|
|
style: { "gap": "12px" }
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, {
|
|
align: "center",
|
|
style: { "gap": "12px" }
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_button, {
|
|
onClick: test_screenshot,
|
|
loading: unref(loading)
|
|
}, {
|
|
default: withCtx(() => _cache[52] || (_cache[52] = [
|
|
createTextVNode("测试截图设置")
|
|
])),
|
|
_: 1
|
|
}, 8, ["loading"]),
|
|
unref(tested) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
unref(screenshot_success) ? (openBlock(), createElementBlock("div", _hoisted_1$8, [
|
|
_cache[53] || (_cache[53] = createTextVNode(" 截图用时:")),
|
|
createVNode(_component_n_text, {
|
|
strong: "",
|
|
type: unref(screenshot_type)
|
|
}, {
|
|
default: withCtx(() => [
|
|
createTextVNode(toDisplayString(unref(elapsed)) + "ms", 1)
|
|
]),
|
|
_: 1
|
|
}, 8, ["type"])
|
|
])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
createVNode(_component_n_text, { type: "error" }, {
|
|
default: withCtx(() => _cache[54] || (_cache[54] = [
|
|
createTextVNode("截图失败!")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createBaseVNode("div", null, toDisplayString(unref(reason)), 1)
|
|
], 64))
|
|
], 64)) : createCommentVNode("", true)
|
|
]),
|
|
_: 1
|
|
}),
|
|
unref(tested) && unref(screenshot_success) ? (openBlock(), createBlock(_component_n_image, {
|
|
key: 0,
|
|
src: "data:image/jpeg;base64," + unref(image),
|
|
width: "100%"
|
|
}, null, 8, ["src"])) : createCommentVNode("", true)
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"])
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const Device = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["__scopeId", "data-v-f4ed7511"]]);
|
|
const _hoisted_1$7 = { class: "threshold" };
|
|
const _sfc_main$h = {
|
|
__name: "RIIC",
|
|
setup(__props) {
|
|
const config_store = useConfigStore();
|
|
const { conf } = storeToRefs(config_store);
|
|
const plan_store = usePlanStore();
|
|
const { operators } = storeToRefs(plan_store);
|
|
const { left_side_facility } = plan_store;
|
|
const mobile = inject("mobile");
|
|
const facility_with_empty = computed(() => {
|
|
return [{ label: "(加速任意贸易站)", value: "" }].concat(left_side_facility);
|
|
});
|
|
return (_ctx, _cache) => {
|
|
const _component_n_transfer = __unplugin_components_0$1;
|
|
const _component_slick_operator_select = __unplugin_components_16;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_input_number = __unplugin_components_15;
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_n_select = __unplugin_components_5;
|
|
const _component_n_slider = __unplugin_components_6;
|
|
const _component_n_form = __unplugin_components_17;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, { title: "基建设置" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "160",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, { label: "宿舍黑名单(非主力)" }, {
|
|
default: withCtx(() => [
|
|
unref(mobile) ? (openBlock(), createBlock(_component_n_transfer, {
|
|
key: 0,
|
|
"virtual-scroll": "",
|
|
"source-filterable": "",
|
|
"target-filterable": "",
|
|
options: unref(operators),
|
|
value: unref(conf).free_blacklist,
|
|
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => unref(conf).free_blacklist = $event),
|
|
"render-source-label": (o) => unref(render_op_label)(o.option),
|
|
"render-target-label": (o) => unref(render_op_label)(o.option),
|
|
filter: (p, o) => p ? unref(pinyin_match)(o.label, p) : true
|
|
}, null, 8, ["options", "value", "render-source-label", "render-target-label", "filter"])) : (openBlock(), createBlock(_component_slick_operator_select, {
|
|
key: 1,
|
|
modelValue: unref(conf).free_blacklist,
|
|
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => unref(conf).free_blacklist = $event)
|
|
}, null, 8, ["modelValue"]))
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[15] || (_cache[15] = createBaseVNode("span", null, "跑单前置延时", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[14] || (_cache[14] = [
|
|
createBaseVNode("div", null, "推荐范围5-10", -1),
|
|
createBaseVNode("div", null, "可填小数", -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).run_order_delay,
|
|
"onUpdate:value": _cache[2] || (_cache[2] = ($event) => unref(conf).run_order_delay = $event)
|
|
}, {
|
|
suffix: withCtx(() => _cache[16] || (_cache[16] = [
|
|
createTextVNode("分钟")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).run_order_grandet_mode.enable,
|
|
"onUpdate:checked": _cache[3] || (_cache[3] = ($event) => unref(conf).run_order_grandet_mode.enable = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[17] || (_cache[17] = [
|
|
createTextVNode("葛朗台跑单")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
unref(conf).run_order_grandet_mode.enable ? (openBlock(), createBlock(_component_n_form_item, { key: 0 }, {
|
|
label: withCtx(() => [
|
|
_cache[19] || (_cache[19] = createBaseVNode("span", null, "葛朗台缓冲时间", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[18] || (_cache[18] = [
|
|
createTextVNode("推荐范围:15-30")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).run_order_grandet_mode.buffer_time,
|
|
"onUpdate:value": _cache[4] || (_cache[4] = ($event) => unref(conf).run_order_grandet_mode.buffer_time = $event)
|
|
}, {
|
|
suffix: withCtx(() => _cache[20] || (_cache[20] = [
|
|
createTextVNode("秒")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
unref(conf).run_order_grandet_mode.enable ? (openBlock(), createBlock(_component_n_form_item, {
|
|
key: 1,
|
|
"show-label": false
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).run_order_grandet_mode.back_to_index,
|
|
"onUpdate:checked": _cache[5] || (_cache[5] = ($event) => unref(conf).run_order_grandet_mode.back_to_index = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[21] || (_cache[21] = [
|
|
createTextVNode(" 跑单前返回主界面以保持登录状态 ")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[23] || (_cache[23] = createBaseVNode("span", null, "无人机使用房间", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[22] || (_cache[22] = [
|
|
createBaseVNode("div", null, "加速制造站为指定制造站加速", -1),
|
|
createBaseVNode("div", null, "(加速任意贸易站)只会加速有跑单人员作备班的站", -1),
|
|
createBaseVNode("div", null, "例:没填龙舌兰但书的卖玉站 (加速任意贸易站) 不会被加速", -1),
|
|
createBaseVNode("div", null, "如需要加速特定某个贸易站请指定对应房间", -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
options: unref(facility_with_empty),
|
|
value: unref(conf).drone_room,
|
|
"onUpdate:value": _cache[6] || (_cache[6] = ($event) => unref(conf).drone_room = $event)
|
|
}, null, 8, ["options", "value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[25] || (_cache[25] = createBaseVNode("span", null, "无人机使用阈值", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[24] || (_cache[24] = [
|
|
createBaseVNode("div", null, "如加速贸易,推荐大于 贸易站数*x + 92", -1),
|
|
createBaseVNode("div", null, "如加速制造,推荐大于 贸易站数*x", -1),
|
|
createBaseVNode("div", null, "葛朗台跑单模式下x=0,非葛朗台推荐x=10", -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).drone_count_limit,
|
|
"onUpdate:value": _cache[7] || (_cache[7] = ($event) => unref(conf).drone_count_limit = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[27] || (_cache[27] = createBaseVNode("span", null, "无人机加速间隔", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[26] || (_cache[26] = [
|
|
createBaseVNode("div", null, "可填小数", -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).drone_interval,
|
|
"onUpdate:value": _cache[8] || (_cache[8] = ($event) => unref(conf).drone_interval = $event)
|
|
}, {
|
|
suffix: withCtx(() => _cache[28] || (_cache[28] = [
|
|
createTextVNode("小时")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "搓玉补货房间" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
multiple: "",
|
|
filterable: "",
|
|
tag: "",
|
|
options: unref(left_side_facility),
|
|
value: unref(conf).reload_room,
|
|
"onUpdate:value": _cache[9] || (_cache[9] = ($event) => unref(conf).reload_room = $event)
|
|
}, null, 8, ["options", "value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[30] || (_cache[30] = createBaseVNode("span", null, "心情阈值", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[29] || (_cache[29] = [
|
|
createBaseVNode("div", null, "2电站推荐不低于65%", -1),
|
|
createBaseVNode("div", null, "3电站推荐不低于50%", -1),
|
|
createBaseVNode("div", null, "即将大更新推荐设置成80%", -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createBaseVNode("div", _hoisted_1$7, [
|
|
createVNode(_component_n_slider, {
|
|
value: unref(conf).resting_threshold,
|
|
"onUpdate:value": _cache[10] || (_cache[10] = ($event) => unref(conf).resting_threshold = $event),
|
|
step: 5,
|
|
min: 50,
|
|
max: 80,
|
|
"format-tooltip": (v) => `${v}%`
|
|
}, null, 8, ["value", "format-tooltip"]),
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).resting_threshold,
|
|
"onUpdate:value": _cache[11] || (_cache[11] = ($event) => unref(conf).resting_threshold = $event),
|
|
step: 5,
|
|
min: 50,
|
|
max: 80
|
|
}, {
|
|
suffix: withCtx(() => _cache[31] || (_cache[31] = [
|
|
createTextVNode("%")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).free_room,
|
|
"onUpdate:checked": _cache[12] || (_cache[12] = ($event) => unref(conf).free_room = $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
_cache[33] || (_cache[33] = createTextVNode(" 宿舍不养闲人 ")),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[32] || (_cache[32] = [
|
|
createTextVNode("干员心情回满后,立即释放宿舍空位")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "信赖阈值" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).trust_limit,
|
|
"onUpdate:value": _cache[13] || (_cache[13] = ($event) => unref(conf).trust_limit = $event),
|
|
min: 100,
|
|
max: 200,
|
|
precision: 0
|
|
}, {
|
|
suffix: withCtx(() => _cache[34] || (_cache[34] = [
|
|
createTextVNode("%")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"])
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const RIIC = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["__scopeId", "data-v-17303244"]]);
|
|
const _hoisted_1$6 = { key: 0 };
|
|
const _hoisted_2$5 = { key: 1 };
|
|
const _hoisted_3$2 = { key: 0 };
|
|
const _hoisted_4$2 = { class: "email-test mt-16" };
|
|
const _sfc_main$g = {
|
|
__name: "Email",
|
|
setup(__props) {
|
|
const store = useConfigStore();
|
|
const axios2 = inject("axios");
|
|
const mobile = inject("mobile");
|
|
const test_result = ref("");
|
|
const { conf } = storeToRefs(store);
|
|
async function test_email() {
|
|
test_result.value = "正在发送……";
|
|
const response = await axios2.get(`${""}/test-email`);
|
|
test_result.value = response.data;
|
|
}
|
|
const levels = [
|
|
{ label: "INFO - 基建任务、刷理智、公招汇总、基报、活动签到等", value: "INFO" },
|
|
{ label: "WARNING - 版本过旧、组内心情差过大、漏单、公招稀有标签等", value: "WARNING" },
|
|
{
|
|
label: "ERROR - 无法排班、专精失败、Maa调用出错、森空岛签到失败、活动签到超时、OF-1失败等",
|
|
value: "ERROR"
|
|
}
|
|
];
|
|
return (_ctx, _cache) => {
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_n_button = Button;
|
|
const _component_n_radio_button = __unplugin_components_2;
|
|
const _component_n_radio_group = __unplugin_components_13;
|
|
const _component_n_input = __unplugin_components_0$2;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_n_radio = __unplugin_components_11;
|
|
const _component_n_flex = __unplugin_components_2$1;
|
|
const _component_n_input_number = __unplugin_components_15;
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_select = __unplugin_components_5;
|
|
const _component_n_dynamic_input = __unplugin_components_6$1;
|
|
const _component_n_form = __unplugin_components_17;
|
|
const _component_n_divider = __unplugin_components_3;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, null, {
|
|
header: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).mail_enable,
|
|
"onUpdate:checked": _cache[0] || (_cache[0] = ($event) => unref(conf).mail_enable = $event),
|
|
class: "email-title"
|
|
}, {
|
|
default: withCtx(() => _cache[11] || (_cache[11] = [
|
|
createBaseVNode("div", { class: "card-title" }, "邮件提醒", -1),
|
|
createBaseVNode("div", { class: "expand" }, null, -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"]),
|
|
unref(mobile) ? (openBlock(), createBlock(_component_n_button, {
|
|
key: 0,
|
|
onClick: _cache[1] || (_cache[1] = ($event) => unref(conf).custom_smtp_server.enable = !unref(conf).custom_smtp_server.enable),
|
|
type: "primary",
|
|
ghost: ""
|
|
}, {
|
|
default: withCtx(() => [
|
|
createTextVNode(toDisplayString(unref(conf).custom_smtp_server.enable ? "自定义邮箱" : "QQ邮箱"), 1)
|
|
]),
|
|
_: 1
|
|
})) : (openBlock(), createBlock(_component_n_radio_group, {
|
|
key: 1,
|
|
class: "email-mode",
|
|
value: unref(conf).custom_smtp_server.enable,
|
|
"onUpdate:value": _cache[2] || (_cache[2] = ($event) => unref(conf).custom_smtp_server.enable = $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio_button, {
|
|
value: false,
|
|
label: "QQ邮箱"
|
|
}),
|
|
createVNode(_component_n_radio_button, {
|
|
value: true,
|
|
label: "自定义邮箱"
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["value"]))
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "96",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
unref(conf).custom_smtp_server.enable ? (openBlock(), createBlock(_component_n_form_item, {
|
|
key: 0,
|
|
label: "SMTP服务器"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input, {
|
|
value: unref(conf).custom_smtp_server.server,
|
|
"onUpdate:value": _cache[3] || (_cache[3] = ($event) => unref(conf).custom_smtp_server.server = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
unref(conf).custom_smtp_server.enable ? (openBlock(), createBlock(_component_n_form_item, {
|
|
key: 1,
|
|
label: "加密方式"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio_group, {
|
|
value: unref(conf).custom_smtp_server.encryption,
|
|
"onUpdate:value": _cache[4] || (_cache[4] = ($event) => unref(conf).custom_smtp_server.encryption = $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio, {
|
|
value: "tls",
|
|
label: "SSL/TLS"
|
|
}),
|
|
createVNode(_component_n_radio, {
|
|
value: "starttls",
|
|
label: "STARTTLS"
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
unref(conf).custom_smtp_server.enable ? (openBlock(), createBlock(_component_n_form_item, {
|
|
key: 2,
|
|
label: "端口号"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).custom_smtp_server.ssl_port,
|
|
"onUpdate:value": _cache[5] || (_cache[5] = ($event) => unref(conf).custom_smtp_server.ssl_port = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
unref(conf).custom_smtp_server.enable ? (openBlock(), createElementBlock("span", _hoisted_1$6, "账号")) : (openBlock(), createElementBlock("span", _hoisted_2$5, "QQ邮箱"))
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input, {
|
|
value: unref(conf).account,
|
|
"onUpdate:value": _cache[6] || (_cache[6] = ($event) => unref(conf).account = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
unref(conf).custom_smtp_server.enable ? (openBlock(), createElementBlock("span", _hoisted_3$2, "密码")) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
_cache[13] || (_cache[13] = createBaseVNode("span", null, "授权码", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_button, {
|
|
text: "",
|
|
tag: "a",
|
|
href: "https://service.mail.qq.com/detail/0/75",
|
|
target: "_blank",
|
|
type: "primary"
|
|
}, {
|
|
default: withCtx(() => _cache[12] || (_cache[12] = [
|
|
createTextVNode(" https://service.mail.qq.com/detail/0/75 ")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
], 64))
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input, {
|
|
value: unref(conf).pass_code,
|
|
"onUpdate:value": _cache[7] || (_cache[7] = ($event) => unref(conf).pass_code = $event),
|
|
type: "password",
|
|
"show-password-on": "click"
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "通知等级" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).notification_level,
|
|
"onUpdate:value": _cache[8] || (_cache[8] = ($event) => unref(conf).notification_level = $event),
|
|
options: levels
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[15] || (_cache[15] = createBaseVNode("span", null, "标题前缀", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[14] || (_cache[14] = [
|
|
createTextVNode("可用于区分来自多个Mower的邮件")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input, {
|
|
value: unref(conf).mail_subject,
|
|
"onUpdate:value": _cache[9] || (_cache[9] = ($event) => unref(conf).mail_subject = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[17] || (_cache[17] = createBaseVNode("span", null, "收件人", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[16] || (_cache[16] = [
|
|
createTextVNode("不填时将邮件发给自己")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_dynamic_input, {
|
|
value: unref(conf).recipient,
|
|
"onUpdate:value": _cache[10] || (_cache[10] = ($event) => unref(conf).recipient = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"]),
|
|
createVNode(_component_n_divider),
|
|
createBaseVNode("div", _hoisted_4$2, [
|
|
createVNode(_component_n_button, { onClick: test_email }, {
|
|
default: withCtx(() => _cache[18] || (_cache[18] = [
|
|
createTextVNode("发送测试邮件")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createBaseVNode("div", null, toDisplayString(unref(test_result)), 1)
|
|
])
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const Email = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["__scopeId", "data-v-3b2776a3"]]);
|
|
const _hoisted_1$5 = { style: { "display": "flex", "align-items": "center", "width": "100%" } };
|
|
const _hoisted_2$4 = { class: "misc-container" };
|
|
const _sfc_main$f = {
|
|
__name: "SKLand",
|
|
setup(__props) {
|
|
const axios2 = inject("axios");
|
|
const config = useConfigStore();
|
|
const { conf } = storeToRefs(config);
|
|
function add_account() {
|
|
return {
|
|
isCheck: true,
|
|
account: "",
|
|
password: "",
|
|
sign_in_official: true,
|
|
sign_in_bilibili: true,
|
|
cultivate_select: true
|
|
};
|
|
}
|
|
const maa_msg = ref("");
|
|
async function test_maa() {
|
|
maa_msg.value = "正在测试……";
|
|
const response = await axios2.get(`${""}/check-skland`);
|
|
maa_msg.value = response.data;
|
|
}
|
|
return (_ctx, _cache) => {
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_input = __unplugin_components_0$2;
|
|
const _component_n_dynamic_input = __unplugin_components_6$1;
|
|
const _component_n_divider = __unplugin_components_3;
|
|
const _component_n_button = Button;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, null, {
|
|
header: withCtx(() => [
|
|
_cache[2] || (_cache[2] = createBaseVNode("div", { class: "card-title" }, "森空岛账号", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[1] || (_cache[1] = [
|
|
createBaseVNode("div", null, "连接失败时,请尝试:", -1),
|
|
createBaseVNode("ol", { style: { "margin": "0" } }, [
|
|
createBaseVNode("li", null, "同步系统时间后再试;"),
|
|
createBaseVNode("li", null, "检查账号密码是否正确;"),
|
|
createBaseVNode("li", null, "关闭代理软件或设置分流规则;"),
|
|
createBaseVNode("li", null, "登录森空岛App,查看是否需要人机验证。")
|
|
], -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_dynamic_input, {
|
|
value: unref(conf).skland_info,
|
|
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => unref(conf).skland_info = $event),
|
|
"on-create": add_account,
|
|
"show-sort-button": ""
|
|
}, {
|
|
default: withCtx(({ value }) => [
|
|
createBaseVNode("div", _hoisted_1$5, [
|
|
createVNode(_component_n_input, {
|
|
style: { "margin-right": "10px" },
|
|
value: value.account,
|
|
"onUpdate:value": ($event) => value.account = $event,
|
|
type: "text",
|
|
placeholder: "账号"
|
|
}, null, 8, ["value", "onUpdate:value"]),
|
|
createVNode(_component_n_input, {
|
|
value: value.password,
|
|
"onUpdate:value": ($event) => value.password = $event,
|
|
type: "password",
|
|
"show-password-on": "click",
|
|
placeholder: "密码"
|
|
}, null, 8, ["value", "onUpdate:value"])
|
|
])
|
|
]),
|
|
_: 1
|
|
}, 8, ["value"]),
|
|
createVNode(_component_n_divider),
|
|
createBaseVNode("div", _hoisted_2$4, [
|
|
createVNode(_component_n_button, { onClick: test_maa }, {
|
|
default: withCtx(() => _cache[3] || (_cache[3] = [
|
|
createTextVNode("测试设置")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createBaseVNode("div", null, toDisplayString(unref(maa_msg)), 1)
|
|
])
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const _sfc_main$e = {
|
|
__name: "AutoFight",
|
|
setup(__props) {
|
|
const mobile = inject("mobile");
|
|
const config = useConfigStore();
|
|
const { conf } = storeToRefs(config);
|
|
const elite_options = [
|
|
{ label: "精零", value: 0 },
|
|
{ label: "精一", value: 1 },
|
|
{ label: "精二", value: 2 }
|
|
];
|
|
return (_ctx, _cache) => {
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_input_number = __unplugin_components_15;
|
|
const _component_n_divider = __unplugin_components_3;
|
|
const _component_n_h4 = NH4;
|
|
const _component_n_select = __unplugin_components_5;
|
|
const _component_n_form = __unplugin_components_17;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, { title: "自动战斗设置" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "110",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).avatar_recog_pause,
|
|
"onUpdate:checked": _cache[0] || (_cache[0] = ($event) => unref(conf).avatar_recog_pause = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[6] || (_cache[6] = [
|
|
createTextVNode("识别干员时暂停")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[8] || (_cache[8] = createBaseVNode("span", null, "第一段滑动", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[7] || (_cache[7] = [
|
|
createBaseVNode("div", null, "把干员从待部署区域拖到地图上的对应位置", -1),
|
|
createBaseVNode("div", null, "默认值:400毫秒", -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).first_swipe_duration,
|
|
"onUpdate:value": _cache[1] || (_cache[1] = ($event) => unref(conf).first_swipe_duration = $event),
|
|
precision: 0
|
|
}, {
|
|
suffix: withCtx(() => _cache[9] || (_cache[9] = [
|
|
createTextVNode("毫秒")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[11] || (_cache[11] = createBaseVNode("span", null, "第二段滑动", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[10] || (_cache[10] = [
|
|
createBaseVNode("div", null, "确认部署方向", -1),
|
|
createBaseVNode("div", null, "默认值:200毫秒", -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).second_swipe_duration,
|
|
"onUpdate:value": _cache[2] || (_cache[2] = ($event) => unref(conf).second_swipe_duration = $event),
|
|
precision: 0
|
|
}, {
|
|
suffix: withCtx(() => _cache[12] || (_cache[12] = [
|
|
createTextVNode("毫秒")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_h4, { class: "subtitle" }, {
|
|
default: withCtx(() => _cache[13] || (_cache[13] = [
|
|
createTextVNode("借助战")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "精英化限制" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).support.elite,
|
|
"onUpdate:value": _cache[3] || (_cache[3] = ($event) => unref(conf).support.elite = $event),
|
|
options: elite_options
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "等级限制" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).support.level,
|
|
"onUpdate:value": _cache[4] || (_cache[4] = ($event) => unref(conf).support.level = $event),
|
|
min: 1,
|
|
max: 90
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "最大刷新次数" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).support.refresh,
|
|
"onUpdate:value": _cache[5] || (_cache[5] = ($event) => unref(conf).support.refresh = $event),
|
|
min: 1
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"])
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const AutoFight = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["__scopeId", "data-v-4f64e716"]]);
|
|
const _sfc_main$d = {
|
|
__name: "Appearance",
|
|
setup(__props) {
|
|
const config_store = useConfigStore();
|
|
const { conf, scene_comment } = storeToRefs(config_store);
|
|
const mobile = inject("mobile");
|
|
return (_ctx, _cache) => {
|
|
const _component_n_input_number = __unplugin_components_15;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_table = __unplugin_components_5$1;
|
|
const _component_n_form = __unplugin_components_17;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, { title: "性能设置" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "120",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, { label: "截图最短间隔" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).screenshot_interval,
|
|
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => unref(conf).screenshot_interval = $event),
|
|
precision: 0
|
|
}, {
|
|
suffix: withCtx(() => _cache[2] || (_cache[2] = [
|
|
createTextVNode("毫秒")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[4] || (_cache[4] = createBaseVNode("span", null, "截图保存时间", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[3] || (_cache[3] = [
|
|
createTextVNode("可填小数;填0时不保存截图")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).screenshot,
|
|
"onUpdate:value": _cache[1] || (_cache[1] = ($event) => unref(conf).screenshot = $event)
|
|
}, {
|
|
suffix: withCtx(() => _cache[5] || (_cache[5] = [
|
|
createTextVNode("小时")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "等待时间" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_table, {
|
|
size: "small",
|
|
class: "waiting-table"
|
|
}, {
|
|
default: withCtx(() => [
|
|
_cache[8] || (_cache[8] = createBaseVNode("thead", null, [
|
|
createBaseVNode("tr", null, [
|
|
createBaseVNode("th", null, "场景"),
|
|
createBaseVNode("th", null, "截图间隔"),
|
|
createBaseVNode("th", null, "超时时长")
|
|
])
|
|
], -1)),
|
|
createBaseVNode("tbody", null, [
|
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(conf).waiting_scene, (value, key) => {
|
|
return openBlock(), createElementBlock("tr", null, [
|
|
createBaseVNode("td", null, toDisplayString(unref(scene_comment)[key]), 1),
|
|
createBaseVNode("td", null, [
|
|
createVNode(_component_n_input_number, {
|
|
value: value[0],
|
|
"onUpdate:value": ($event) => value[0] = $event,
|
|
"show-button": false,
|
|
precision: 0
|
|
}, {
|
|
suffix: withCtx(() => _cache[6] || (_cache[6] = [
|
|
createTextVNode("毫秒")
|
|
])),
|
|
_: 2
|
|
}, 1032, ["value", "onUpdate:value"])
|
|
]),
|
|
createBaseVNode("td", null, [
|
|
createVNode(_component_n_input_number, {
|
|
value: value[1],
|
|
"onUpdate:value": ($event) => value[1] = $event,
|
|
"show-button": false,
|
|
precision: 0
|
|
}, {
|
|
suffix: withCtx(() => _cache[7] || (_cache[7] = [
|
|
createTextVNode("秒")
|
|
])),
|
|
_: 2
|
|
}, 1032, ["value", "onUpdate:value"])
|
|
])
|
|
]);
|
|
}), 256))
|
|
])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"])
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const Appearance = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["__scopeId", "data-v-26ad4730"]]);
|
|
const _sfc_main$c = {
|
|
__name: "DailyMission",
|
|
setup(__props) {
|
|
const store = useConfigStore();
|
|
const { conf } = storeToRefs(store);
|
|
return (_ctx, _cache) => {
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_n_flex = __unplugin_components_2$1;
|
|
const _component_n_divider = __unplugin_components_3;
|
|
const _component_n_button = Button;
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_select = __unplugin_components_5;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, { title: "每日任务" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, { vertical: "" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.skland.SKLand"],
|
|
"onUpdate:checked": _cache[0] || (_cache[0] = ($event) => unref(conf).task["mower.solvers.skland.SKLand"] = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[11] || (_cache[11] = [
|
|
createBaseVNode("div", { class: "item" }, "森空岛签到", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"]),
|
|
unref(conf).task["mower.solvers.skland.SKLand"] ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(unref(conf).skland_info, (account_info) => {
|
|
return openBlock(), createElementBlock("div", {
|
|
key: account_info.account
|
|
}, [
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: account_info.isCheck,
|
|
"onUpdate:checked": ($event) => account_info.isCheck = $event,
|
|
style: { "margin-right": "12px" }
|
|
}, {
|
|
default: withCtx(() => [
|
|
createTextVNode(" 森空岛账号:" + toDisplayString(account_info.account), 1)
|
|
]),
|
|
_: 2
|
|
}, 1032, ["checked", "onUpdate:checked"]),
|
|
createVNode(_component_n_checkbox, {
|
|
checked: account_info.sign_in_official,
|
|
"onUpdate:checked": ($event) => account_info.sign_in_official = $event,
|
|
style: { "margin-right": "12px" }
|
|
}, {
|
|
default: withCtx(() => _cache[12] || (_cache[12] = [
|
|
createTextVNode(" 官服签到 ")
|
|
])),
|
|
_: 2
|
|
}, 1032, ["checked", "onUpdate:checked"]),
|
|
createVNode(_component_n_checkbox, {
|
|
checked: account_info.sign_in_bilibili,
|
|
"onUpdate:checked": ($event) => account_info.sign_in_bilibili = $event,
|
|
style: { "margin-right": "12px" }
|
|
}, {
|
|
default: withCtx(() => _cache[13] || (_cache[13] = [
|
|
createTextVNode(" B服签到 ")
|
|
])),
|
|
_: 2
|
|
}, 1032, ["checked", "onUpdate:checked"])
|
|
]),
|
|
_: 2
|
|
}, 1024)
|
|
]);
|
|
}), 128)) : createCommentVNode("", true),
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.mail.MailSolver"],
|
|
"onUpdate:checked": _cache[1] || (_cache[1] = ($event) => unref(conf).task["mower.solvers.mail.MailSolver"] = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[14] || (_cache[14] = [
|
|
createBaseVNode("div", { class: "item" }, "领取邮件", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"]),
|
|
createVNode(_component_n_checkbox, {
|
|
disabled: !unref(conf).task["mower.solvers.mail.MailSolver"],
|
|
checked: unref(conf).delete_read_mail,
|
|
"onUpdate:checked": _cache[2] || (_cache[2] = ($event) => unref(conf).delete_read_mail = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[15] || (_cache[15] = [
|
|
createTextVNode(" 删除已读邮件 ")
|
|
])),
|
|
_: 1
|
|
}, 8, ["disabled", "checked"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.credit.CreditSolver"],
|
|
"onUpdate:checked": _cache[3] || (_cache[3] = ($event) => unref(conf).task["mower.solvers.credit.CreditSolver"] = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[16] || (_cache[16] = [
|
|
createBaseVNode("div", { class: "item" }, "访问好友", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"]),
|
|
createVNode(_component_n_checkbox, {
|
|
disabled: !unref(conf).task["mower.solvers.credit.CreditSolver"],
|
|
checked: unref(conf).telemetry,
|
|
"onUpdate:checked": _cache[4] || (_cache[4] = ($event) => unref(conf).telemetry = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[17] || (_cache[17] = [
|
|
createTextVNode(" 上报数据 ")
|
|
])),
|
|
_: 1
|
|
}, 8, ["disabled", "checked"]),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => [
|
|
_cache[22] || (_cache[22] = createBaseVNode("table", { class: "telemetry" }, [
|
|
createBaseVNode("thead", null, [
|
|
createBaseVNode("tr", null, [
|
|
createBaseVNode("th", { style: { "width": "140px" } }, "数据"),
|
|
createBaseVNode("th", { style: { "width": "200px" } }, "获取方式"),
|
|
createBaseVNode("th", { style: { "width": "100px" } }, "用途")
|
|
])
|
|
]),
|
|
createBaseVNode("tbody", null, [
|
|
createBaseVNode("tr", null, [
|
|
createBaseVNode("td", null, "游戏内昵称"),
|
|
createBaseVNode("td", null, "OCR"),
|
|
createBaseVNode("td", null, "用户数量统计")
|
|
]),
|
|
createBaseVNode("tr", null, [
|
|
createBaseVNode("td", null, "CPU型号"),
|
|
createBaseVNode("td", null, [
|
|
createBaseVNode("code", null, "platform.processor()")
|
|
]),
|
|
createBaseVNode("td", { rowspan: "5" }, "性能分析")
|
|
]),
|
|
createBaseVNode("tr", null, [
|
|
createBaseVNode("td", null, "CPU线程数"),
|
|
createBaseVNode("td", null, [
|
|
createBaseVNode("code", null, "os.cpu_count()")
|
|
])
|
|
]),
|
|
createBaseVNode("tr", null, [
|
|
createBaseVNode("td", null, "模拟器类型"),
|
|
createBaseVNode("td", { rowspan: "2" }, "用户填写")
|
|
]),
|
|
createBaseVNode("tr", null, [
|
|
createBaseVNode("td", null, "截图方式")
|
|
]),
|
|
createBaseVNode("tr", null, [
|
|
createBaseVNode("td", null, "平均截图时间"),
|
|
createBaseVNode("td", null, "截图时自动计算")
|
|
]),
|
|
createBaseVNode("tr", null, [
|
|
createBaseVNode("td", null, "mower-ng代码分支"),
|
|
createBaseVNode("td", { rowspan: "2" }, "Git"),
|
|
createBaseVNode("td", { rowspan: "2" }, "更新行为分析")
|
|
]),
|
|
createBaseVNode("tr", null, [
|
|
createBaseVNode("td", null, "mower-ng版本")
|
|
])
|
|
])
|
|
], -1)),
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createBaseVNode("div", null, [
|
|
_cache[19] || (_cache[19] = createTextVNode(" 客户端代码: ")),
|
|
createVNode(_component_n_button, {
|
|
text: "",
|
|
tag: "a",
|
|
href: "https://git.zhaozuohong.vip/mower-ng/mower-ng/src/branch/main/mower/solvers/credit.py",
|
|
target: "_blank",
|
|
type: "primary"
|
|
}, {
|
|
default: withCtx(() => _cache[18] || (_cache[18] = [
|
|
createTextVNode(" credit.py ")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
createBaseVNode("div", null, [
|
|
_cache[21] || (_cache[21] = createTextVNode(" 服务端代码: ")),
|
|
createVNode(_component_n_button, {
|
|
text: "",
|
|
tag: "a",
|
|
href: "https://git.zhaozuohong.vip/mower-ng/stats/src/branch/main/main.py",
|
|
target: "_blank",
|
|
type: "primary"
|
|
}, {
|
|
default: withCtx(() => _cache[20] || (_cache[20] = [
|
|
createTextVNode(" main.py ")
|
|
])),
|
|
_: 1
|
|
})
|
|
])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.infra.report.ReportSolver"],
|
|
"onUpdate:checked": _cache[5] || (_cache[5] = ($event) => unref(conf).task["mower.solvers.infra.report.ReportSolver"] = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[23] || (_cache[23] = [
|
|
createBaseVNode("div", { class: "item" }, "读取基报", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_flex, { vertical: "" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.sign_in.SignInManager"],
|
|
"onUpdate:checked": _cache[6] || (_cache[6] = ($event) => unref(conf).task["mower.solvers.sign_in.SignInManager"] = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[24] || (_cache[24] = [
|
|
createBaseVNode("div", { class: "item" }, "签到活动", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"]),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[25] || (_cache[25] = [
|
|
createTextVNode("游戏内签到、矿区、限定池每日单抽、活动商店等")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_flex, { align: "center" }, {
|
|
default: withCtx(() => [
|
|
_cache[26] || (_cache[26] = createTextVNode(" 活动商店黑名单 ")),
|
|
createVNode(_component_n_select, {
|
|
style: { "flex": "1" },
|
|
value: unref(conf).activity_shop_blacklist,
|
|
"onUpdate:value": _cache[7] || (_cache[7] = ($event) => unref(conf).activity_shop_blacklist = $event),
|
|
filterable: "",
|
|
multiple: "",
|
|
tag: "",
|
|
"show-arrow": false,
|
|
show: false
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.infra.switch_assistants.SwitchAssistantsSolver"],
|
|
"onUpdate:checked": _cache[8] || (_cache[8] = ($event) => unref(conf).task["mower.solvers.infra.switch_assistants.SwitchAssistantsSolver"] = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[27] || (_cache[27] = [
|
|
createBaseVNode("div", { class: "item" }, "切换基建副手", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.infra.switch_activity_users.SwitchActivityUsersSolver"],
|
|
"onUpdate:checked": _cache[9] || (_cache[9] = ($event) => unref(conf).task["mower.solvers.infra.switch_activity_users.SwitchActivityUsersSolver"] = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[28] || (_cache[28] = [
|
|
createBaseVNode("div", { class: "item" }, "切换活动室入驻干员", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.trade_token.TradeTokenSolver"],
|
|
"onUpdate:checked": _cache[10] || (_cache[10] = ($event) => unref(conf).task["mower.solvers.trade_token.TradeTokenSolver"] = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[29] || (_cache[29] = [
|
|
createBaseVNode("div", { class: "item" }, "信物兑换", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const DailyMission = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["__scopeId", "data-v-9889efe8"]]);
|
|
const _sfc_main$b = {
|
|
__name: "Recruit",
|
|
setup(__props) {
|
|
const store = useConfigStore();
|
|
const { conf } = storeToRefs(store);
|
|
const mobile = inject("mobile");
|
|
return (_ctx, _cache) => {
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_input_number = __unplugin_components_15;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_n_radio = __unplugin_components_11;
|
|
const _component_n_space = __unplugin_components_12;
|
|
const _component_n_radio_group = __unplugin_components_13;
|
|
const _component_n_form = __unplugin_components_17;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, null, {
|
|
header: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.recruit.RecruitSolver"],
|
|
"onUpdate:checked": _cache[0] || (_cache[0] = ($event) => unref(conf).task["mower.solvers.recruit.RecruitSolver"] = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[6] || (_cache[6] = [
|
|
createBaseVNode("div", { class: "card-title" }, "公开招募", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "140",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[8] || (_cache[8] = createBaseVNode("span", null, "启动间隔", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[7] || (_cache[7] = [
|
|
createTextVNode("可填小数")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).recruit_gap,
|
|
"onUpdate:value": _cache[1] || (_cache[1] = ($event) => unref(conf).recruit_gap = $event)
|
|
}, {
|
|
suffix: withCtx(() => _cache[9] || (_cache[9] = [
|
|
createTextVNode("小时")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[11] || (_cache[11] = createBaseVNode("span", null, "三星招募阈值", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[10] || (_cache[10] = [
|
|
createTextVNode("剩余公招券大于此阈值时招募三星干员")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).recruitment_permit,
|
|
"onUpdate:value": _cache[2] || (_cache[2] = ($event) => unref(conf).recruitment_permit = $event)
|
|
}, {
|
|
suffix: withCtx(() => _cache[12] || (_cache[12] = [
|
|
createTextVNode("张")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "五星招募策略" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio_group, {
|
|
value: unref(conf).recruit_auto_5,
|
|
"onUpdate:value": _cache[3] || (_cache[3] = ($event) => unref(conf).recruit_auto_5 = $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_space, { justify: "start" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio, { value: 1 }, {
|
|
default: withCtx(() => _cache[13] || (_cache[13] = [
|
|
createTextVNode("自动选择")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_radio, { value: 2 }, {
|
|
default: withCtx(() => _cache[14] || (_cache[14] = [
|
|
createTextVNode("手动选择")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
unref(conf).recruit_auto_5 === 2 ? (openBlock(), createBlock(_component_n_form_item, {
|
|
key: 0,
|
|
"show-label": false
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).recruit_auto_only5,
|
|
"onUpdate:checked": _cache[4] || (_cache[4] = ($event) => unref(conf).recruit_auto_only5 = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[15] || (_cache[15] = [
|
|
createTextVNode("五星词条组合唯一时自动选择")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).recruit_robot,
|
|
"onUpdate:checked": _cache[5] || (_cache[5] = ($event) => unref(conf).recruit_robot = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[16] || (_cache[16] = [
|
|
createTextVNode("保留支援机械标签")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"])
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const Recruit = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["__scopeId", "data-v-46384f04"]]);
|
|
const _hoisted_1$4 = { style: { "display": "flex", "align-items": "center", "width": "100%" } };
|
|
const _hoisted_2$3 = { style: { "margin-right": "24px" } };
|
|
const _sfc_main$a = {
|
|
__name: "Depotswitch",
|
|
setup(__props) {
|
|
const store = useConfigStore();
|
|
const { conf } = storeToRefs(store);
|
|
return (_ctx, _cache) => {
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_radio = __unplugin_components_11;
|
|
const _component_n_flex = __unplugin_components_2$1;
|
|
const _component_n_radio_group = __unplugin_components_13;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, null, {
|
|
header: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.depotREC.depotREC"],
|
|
"onUpdate:checked": _cache[0] || (_cache[0] = ($event) => unref(conf).task["mower.solvers.depotREC.depotREC"] = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[1] || (_cache[1] = [
|
|
createBaseVNode("div", { class: "card-title" }, "仓库物品混合读取", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"]),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[2] || (_cache[2] = [
|
|
createTextVNode("请调整森空岛账号顺序,仅读取"),
|
|
createBaseVNode("strong", null, "第一个", -1),
|
|
createTextVNode("账户"),
|
|
createBaseVNode("strong", null, "指定服务器", -1),
|
|
createTextVNode("的材料")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(conf).skland_info, (account_info) => {
|
|
return openBlock(), createElementBlock("div", {
|
|
key: account_info.account
|
|
}, [
|
|
createBaseVNode("div", _hoisted_1$4, [
|
|
createBaseVNode("div", _hoisted_2$3, "森空岛账号:" + toDisplayString(account_info.account), 1),
|
|
createVNode(_component_n_radio_group, {
|
|
value: account_info.cultivate_select,
|
|
"onUpdate:value": ($event) => account_info.cultivate_select = $event
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio, { value: true }, {
|
|
default: withCtx(() => _cache[3] || (_cache[3] = [
|
|
createTextVNode("官服")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_radio, { value: false }, {
|
|
default: withCtx(() => _cache[4] || (_cache[4] = [
|
|
createTextVNode("B服")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 2
|
|
}, 1032, ["value", "onUpdate:value"])
|
|
])
|
|
]);
|
|
}), 128))
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const _sfc_main$9 = {
|
|
__name: "Regular",
|
|
setup(__props) {
|
|
const config_store = useConfigStore();
|
|
const { conf } = storeToRefs(config_store);
|
|
const mobile = inject("mobile");
|
|
return (_ctx, _cache) => {
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_input_number = __unplugin_components_15;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_n_form = __unplugin_components_17;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, null, {
|
|
header: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.operation.OperationManager"],
|
|
"onUpdate:checked": _cache[0] || (_cache[0] = ($event) => unref(conf).task["mower.solvers.operation.OperationManager"] = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[2] || (_cache[2] = [
|
|
createBaseVNode("div", { class: "card-title" }, "日常任务", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"]),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[3] || (_cache[3] = [
|
|
createBaseVNode("div", null, "刷理智周计划、每日/每周任务、信用作战", -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "100",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, null, {
|
|
label: withCtx(() => [
|
|
_cache[5] || (_cache[5] = createBaseVNode("span", null, "任务间隔", -1)),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => _cache[4] || (_cache[4] = [
|
|
createBaseVNode("div", null, "可填小数", -1),
|
|
createBaseVNode("div", null, "清理智、日常/周常任务领取、借助战打OF-1", -1)
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).maa_gap,
|
|
"onUpdate:value": _cache[1] || (_cache[1] = ($event) => unref(conf).maa_gap = $event)
|
|
}, {
|
|
suffix: withCtx(() => _cache[6] || (_cache[6] = [
|
|
createTextVNode("小时")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"])
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const _hoisted_1$3 = { key: 0 };
|
|
const _hoisted_2$2 = { key: 1 };
|
|
const _sfc_main$8 = {
|
|
__name: "Clue",
|
|
setup(__props) {
|
|
const config_store = useConfigStore();
|
|
const { conf, shop_list } = storeToRefs(config_store);
|
|
const plan_store = usePlanStore();
|
|
const { operators } = storeToRefs(plan_store);
|
|
const mobile = inject("mobile");
|
|
function render_tag({ option, handleClose }) {
|
|
return h(
|
|
__unplugin_components_4$2,
|
|
{
|
|
type: option.type,
|
|
closable: true,
|
|
onMousedown: (e) => {
|
|
e.preventDefault();
|
|
},
|
|
onClose: (e) => {
|
|
e.stopPropagation();
|
|
handleClose();
|
|
}
|
|
},
|
|
{ default: () => option.label, avatar: () => h(__unplugin_components_7, { src: `/shop/${option.label}.png` }) }
|
|
);
|
|
}
|
|
function render_label(option) {
|
|
return h(
|
|
"div",
|
|
{ style: { display: "flex", "align-items": "center", gap: "6px", padding: "2px 0" } },
|
|
[h(__unplugin_components_7, { src: `/shop/${option.label}.png` }), option.label]
|
|
);
|
|
}
|
|
const deploy_directions = [
|
|
{ label: "向上", value: "Up" },
|
|
{ label: "向下", value: "Down" },
|
|
{ label: "向左", value: "Left" },
|
|
{ label: "向右", value: "Right" }
|
|
];
|
|
const squads = [
|
|
{ label: "第一编队", value: 1 },
|
|
{ label: "第二编队", value: 2 },
|
|
{ label: "第三编队", value: 3 },
|
|
{ label: "第四编队", value: 4 }
|
|
];
|
|
const skills = [
|
|
{ label: "一技能", value: 1 },
|
|
{ label: "二技能", value: 2 },
|
|
{ label: "三技能", value: 3 }
|
|
];
|
|
const show_map = ref(false);
|
|
return (_ctx, _cache) => {
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_n_divider = __unplugin_components_3;
|
|
const _component_n_button = Button;
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_h4 = NH4;
|
|
const _component_n_radio = __unplugin_components_11;
|
|
const _component_n_space = __unplugin_components_12;
|
|
const _component_n_radio_group = __unplugin_components_13;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_n_select = __unplugin_components_5;
|
|
const _component_n_input_number = __unplugin_components_15;
|
|
const _component_n_image = __unplugin_components_4$1;
|
|
const _component_n_flex = __unplugin_components_2$1;
|
|
const _component_n_form = __unplugin_components_17;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, null, {
|
|
header: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.infra.clue.ClueManager"],
|
|
"onUpdate:checked": _cache[0] || (_cache[0] = ($event) => unref(conf).task["mower.solvers.infra.clue.ClueManager"] = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[15] || (_cache[15] = [
|
|
createBaseVNode("div", { class: "card-title" }, "线索收集与信用", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).leifeng_mode,
|
|
"onUpdate:checked": _cache[1] || (_cache[1] = ($event) => unref(conf).leifeng_mode = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[16] || (_cache[16] = [
|
|
createTextVNode("赠送多余的线索")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"]),
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_h4, null, {
|
|
default: withCtx(() => [
|
|
_cache[20] || (_cache[20] = createTextVNode(" 信用商店购物 ")),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => [
|
|
_cache[18] || (_cache[18] = createBaseVNode("span", null, "性价比参考:", -1)),
|
|
createVNode(_component_n_button, {
|
|
text: "",
|
|
tag: "a",
|
|
href: "https://github.com/Bidgecfah/Rhodes-Island-Bureau-of-Price",
|
|
target: "_blank",
|
|
type: "primary"
|
|
}, {
|
|
default: withCtx(() => _cache[17] || (_cache[17] = [
|
|
createTextVNode(" 罗德岛物价局 ")
|
|
])),
|
|
_: 1
|
|
}),
|
|
_cache[19] || (_cache[19] = createBaseVNode("p", null, "注意:跑单时赤金与作战记录均大幅升值", -1))
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "72",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, { label: "信用溢出" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio_group, {
|
|
value: unref(conf).maa_mall_ignore_blacklist_when_full,
|
|
"onUpdate:value": _cache[2] || (_cache[2] = ($event) => unref(conf).maa_mall_ignore_blacklist_when_full = $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_space, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio, { value: false }, {
|
|
default: withCtx(() => _cache[21] || (_cache[21] = [
|
|
createTextVNode("停止购买")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_radio, { value: true }, {
|
|
default: withCtx(() => _cache[22] || (_cache[22] = [
|
|
createTextVNode("无视黑名单继续购买,直至不再溢出")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "优先购买" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio_group, {
|
|
value: unref(conf).maa_mall_ignore_blacklist_when_full,
|
|
"onUpdate:value": _cache[4] || (_cache[4] = ($event) => unref(conf).maa_mall_ignore_blacklist_when_full = $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
multiple: "",
|
|
filterable: "",
|
|
tag: "",
|
|
options: unref(shop_list),
|
|
value: unref(conf).maa_mall_buy,
|
|
"onUpdate:value": _cache[3] || (_cache[3] = ($event) => unref(conf).maa_mall_buy = $event),
|
|
"render-tag": render_tag,
|
|
"render-label": render_label
|
|
}, null, 8, ["options", "value"])
|
|
]),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "黑名单" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
multiple: "",
|
|
filterable: "",
|
|
tag: "",
|
|
options: unref(shop_list),
|
|
value: unref(conf).maa_mall_blacklist,
|
|
"onUpdate:value": _cache[5] || (_cache[5] = ($event) => unref(conf).maa_mall_blacklist = $event),
|
|
"render-tag": render_tag,
|
|
"render-label": render_label
|
|
}, null, 8, ["options", "value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.fight.credit_fight.CreditFight"],
|
|
"onUpdate:checked": _cache[6] || (_cache[6] = ($event) => unref(conf).task["mower.solvers.fight.credit_fight.CreditFight"] = $event),
|
|
disabled: !unref(conf).task["mower.solvers.operation.OperationManager"]
|
|
}, {
|
|
default: withCtx(() => _cache[23] || (_cache[23] = [
|
|
createBaseVNode("div", { class: "item" }, "信用作战", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked", "disabled"]),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => [
|
|
!unref(conf).task["mower.solvers.operation.OperationManager"] ? (openBlock(), createElementBlock("div", _hoisted_1$3, "需开启日常任务")) : (openBlock(), createElementBlock("div", _hoisted_2$2, "借助战打OF-1"))
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "编队" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
options: squads,
|
|
value: unref(conf).credit_fight.squad,
|
|
"onUpdate:value": _cache[7] || (_cache[7] = ($event) => unref(conf).credit_fight.squad = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "干员" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
style: { "flex": "3", "margin-right": "8px" },
|
|
filterable: "",
|
|
options: unref(operators),
|
|
value: unref(conf).credit_fight.operator,
|
|
"onUpdate:value": _cache[8] || (_cache[8] = ($event) => unref(conf).credit_fight.operator = $event),
|
|
filter: (p, o) => unref(pinyin_match)(o.label, p),
|
|
"render-label": unref(render_op_label)
|
|
}, null, 8, ["options", "value", "filter", "render-label"]),
|
|
createVNode(_component_n_select, {
|
|
style: { "flex": "2" },
|
|
options: skills,
|
|
value: unref(conf).credit_fight.skill,
|
|
"onUpdate:value": _cache[9] || (_cache[9] = ($event) => unref(conf).credit_fight.skill = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "部署" }, {
|
|
default: withCtx(() => [
|
|
_cache[24] || (_cache[24] = createBaseVNode("div", { style: { "width": "40px", "text-align": "right" } }, "X", -1)),
|
|
createVNode(_component_n_input_number, {
|
|
style: { "margin": "0 8px" },
|
|
value: unref(conf).credit_fight.x,
|
|
"onUpdate:value": _cache[10] || (_cache[10] = ($event) => unref(conf).credit_fight.x = $event),
|
|
"show-button": false
|
|
}, null, 8, ["value"]),
|
|
_cache[25] || (_cache[25] = createBaseVNode("div", { style: { "width": "40px", "text-align": "right" } }, "Y", -1)),
|
|
createVNode(_component_n_input_number, {
|
|
style: { "margin": "0 8px" },
|
|
value: unref(conf).credit_fight.y,
|
|
"onUpdate:value": _cache[11] || (_cache[11] = ($event) => unref(conf).credit_fight.y = $event),
|
|
"show-button": false
|
|
}, null, 8, ["value"]),
|
|
createVNode(_component_n_select, {
|
|
style: { "width": "250px", "margin-right": "8px" },
|
|
options: deploy_directions,
|
|
value: unref(conf).credit_fight.direction,
|
|
"onUpdate:value": _cache[12] || (_cache[12] = ($event) => unref(conf).credit_fight.direction = $event)
|
|
}, null, 8, ["value"]),
|
|
createVNode(_component_n_button, {
|
|
onClick: _cache[13] || (_cache[13] = ($event) => show_map.value = !unref(show_map))
|
|
}, {
|
|
default: withCtx(() => [
|
|
createTextVNode(toDisplayString(unref(show_map) ? "隐藏" : "显示") + "OF-1地图", 1)
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}),
|
|
unref(show_map) ? (openBlock(), createBlock(_component_n_form_item, {
|
|
key: 0,
|
|
"show-label": false
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_image, {
|
|
src: "/map-OF-1.webp",
|
|
width: "100%"
|
|
})
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
createVNode(_component_n_form_item, { label: "策略" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio_group, {
|
|
value: unref(conf).credit_fight.apply_friend,
|
|
"onUpdate:value": _cache[14] || (_cache[14] = ($event) => unref(conf).credit_fight.apply_friend = $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio, { value: false }, {
|
|
default: withCtx(() => _cache[26] || (_cache[26] = [
|
|
createTextVNode("优先借好友的助战")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_radio, { value: true }, {
|
|
default: withCtx(() => _cache[27] || (_cache[27] = [
|
|
createTextVNode("优先借陌生人的助战并申请好友")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"])
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"])
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const Clue = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["__scopeId", "data-v-83ca4317"]]);
|
|
class LuxonError extends Error {
|
|
}
|
|
class InvalidDateTimeError extends LuxonError {
|
|
constructor(reason) {
|
|
super(`Invalid DateTime: ${reason.toMessage()}`);
|
|
}
|
|
}
|
|
class InvalidIntervalError extends LuxonError {
|
|
constructor(reason) {
|
|
super(`Invalid Interval: ${reason.toMessage()}`);
|
|
}
|
|
}
|
|
class InvalidDurationError extends LuxonError {
|
|
constructor(reason) {
|
|
super(`Invalid Duration: ${reason.toMessage()}`);
|
|
}
|
|
}
|
|
class ConflictingSpecificationError extends LuxonError {
|
|
}
|
|
class InvalidUnitError extends LuxonError {
|
|
constructor(unit) {
|
|
super(`Invalid unit ${unit}`);
|
|
}
|
|
}
|
|
class InvalidArgumentError extends LuxonError {
|
|
}
|
|
class ZoneIsAbstractError extends LuxonError {
|
|
constructor() {
|
|
super("Zone is an abstract class");
|
|
}
|
|
}
|
|
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,
|
|
hourCycle: "h23"
|
|
};
|
|
const TIME_24_WITH_SECONDS = {
|
|
hour: n,
|
|
minute: n,
|
|
second: n,
|
|
hourCycle: "h23"
|
|
};
|
|
const TIME_24_WITH_SHORT_OFFSET = {
|
|
hour: n,
|
|
minute: n,
|
|
second: n,
|
|
hourCycle: "h23",
|
|
timeZoneName: s
|
|
};
|
|
const TIME_24_WITH_LONG_OFFSET = {
|
|
hour: n,
|
|
minute: n,
|
|
second: n,
|
|
hourCycle: "h23",
|
|
timeZoneName: l
|
|
};
|
|
const DATETIME_SHORT = {
|
|
year: n,
|
|
month: n,
|
|
day: n,
|
|
hour: n,
|
|
minute: n
|
|
};
|
|
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
|
|
};
|
|
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();
|
|
}
|
|
/**
|
|
* The IANA name of this zone.
|
|
* Defaults to `name` if not overwritten by a subclass.
|
|
* @abstract
|
|
* @type {string}
|
|
*/
|
|
get ianaName() {
|
|
return this.name;
|
|
}
|
|
/**
|
|
* Returns whether the offset is known to be fixed for the whole year.
|
|
* @abstract
|
|
* @type {boolean}
|
|
*/
|
|
get isUniversal() {
|
|
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$1 = null;
|
|
class SystemZone extends Zone {
|
|
/**
|
|
* Get a singleton instance of the local zone
|
|
* @return {SystemZone}
|
|
*/
|
|
static get instance() {
|
|
if (singleton$1 === null) {
|
|
singleton$1 = new SystemZone();
|
|
}
|
|
return singleton$1;
|
|
}
|
|
/** @override **/
|
|
get type() {
|
|
return "system";
|
|
}
|
|
/** @override **/
|
|
get name() {
|
|
return new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
}
|
|
/** @override **/
|
|
get isUniversal() {
|
|
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 === "system";
|
|
}
|
|
/** @override **/
|
|
get isValid() {
|
|
return true;
|
|
}
|
|
}
|
|
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",
|
|
era: "short"
|
|
});
|
|
}
|
|
return dtfCache[zone];
|
|
}
|
|
const typeToPos = {
|
|
year: 0,
|
|
month: 1,
|
|
day: 2,
|
|
era: 3,
|
|
hour: 4,
|
|
minute: 5,
|
|
second: 6
|
|
};
|
|
function hackyOffset(dtf, date) {
|
|
const formatted = dtf.format(date).replace(/\u200E/g, ""), parsed = /(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(formatted), [, fMonth, fDay, fYear, fadOrBc, fHour, fMinute, fSecond] = parsed;
|
|
return [fYear, fMonth, fDay, fadOrBc, fHour, fMinute, fSecond];
|
|
}
|
|
function partsOffset(dtf, date) {
|
|
const formatted = dtf.formatToParts(date);
|
|
const filled = [];
|
|
for (let i = 0; i < formatted.length; i++) {
|
|
const { type, value } = formatted[i];
|
|
const pos = typeToPos[type];
|
|
if (type === "era") {
|
|
filled[pos] = value;
|
|
} else if (!isUndefined(pos)) {
|
|
filled[pos] = parseInt(value, 10);
|
|
}
|
|
}
|
|
return filled;
|
|
}
|
|
let ianaZoneCache = {};
|
|
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("Sport~~blorp") //=> false
|
|
* @deprecated For backward compatibility, this forwards to isValidZone, better use `isValidZone()` directly instead.
|
|
* @return {boolean}
|
|
*/
|
|
static isValidSpecifier(s2) {
|
|
return this.isValidZone(s2);
|
|
}
|
|
/**
|
|
* 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) {
|
|
if (!zone) {
|
|
return false;
|
|
}
|
|
try {
|
|
new Intl.DateTimeFormat("en-US", { timeZone: zone }).format();
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
constructor(name) {
|
|
super();
|
|
this.zoneName = name;
|
|
this.valid = IANAZone.isValidZone(name);
|
|
}
|
|
/**
|
|
* The type of zone. `iana` for all instances of `IANAZone`.
|
|
* @override
|
|
* @type {string}
|
|
*/
|
|
get type() {
|
|
return "iana";
|
|
}
|
|
/**
|
|
* The name of this zone (i.e. the IANA zone name).
|
|
* @override
|
|
* @type {string}
|
|
*/
|
|
get name() {
|
|
return this.zoneName;
|
|
}
|
|
/**
|
|
* Returns whether the offset is known to be fixed for the whole year:
|
|
* Always returns false for all IANA zones.
|
|
* @override
|
|
* @type {boolean}
|
|
*/
|
|
get isUniversal() {
|
|
return false;
|
|
}
|
|
/**
|
|
* Returns the offset's common name (such as EST) at the specified timestamp
|
|
* @override
|
|
* @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, { format, locale }) {
|
|
return parseZoneInfo(ts, format, locale, this.name);
|
|
}
|
|
/**
|
|
* Returns the offset's value as a string
|
|
* @override
|
|
* @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) {
|
|
return formatOffset(this.offset(ts), format);
|
|
}
|
|
/**
|
|
* Return the offset in minutes for this zone at the specified timestamp.
|
|
* @override
|
|
* @param {number} ts - Epoch milliseconds for which to compute the offset
|
|
* @return {number}
|
|
*/
|
|
offset(ts) {
|
|
const date = new Date(ts);
|
|
if (isNaN(date)) return NaN;
|
|
const dtf = makeDTF(this.name);
|
|
let [year, month, day, adOrBc, hour, minute, second] = dtf.formatToParts ? partsOffset(dtf, date) : hackyOffset(dtf, date);
|
|
if (adOrBc === "BC") {
|
|
year = -Math.abs(year) + 1;
|
|
}
|
|
const adjustedHour = hour === 24 ? 0 : hour;
|
|
const asUTC = objToLocalTS({
|
|
year,
|
|
month,
|
|
day,
|
|
hour: adjustedHour,
|
|
minute,
|
|
second,
|
|
millisecond: 0
|
|
});
|
|
let asTS = +date;
|
|
const over = asTS % 1e3;
|
|
asTS -= over >= 0 ? over : 1e3 + over;
|
|
return (asUTC - asTS) / (60 * 1e3);
|
|
}
|
|
/**
|
|
* Return whether this Zone is equal to another zone
|
|
* @override
|
|
* @param {Zone} otherZone - the zone to compare
|
|
* @return {boolean}
|
|
*/
|
|
equals(otherZone) {
|
|
return otherZone.type === "iana" && otherZone.name === this.name;
|
|
}
|
|
/**
|
|
* Return whether this Zone is valid.
|
|
* @override
|
|
* @type {boolean}
|
|
*/
|
|
get isValid() {
|
|
return this.valid;
|
|
}
|
|
}
|
|
let intlLFCache = {};
|
|
function getCachedLF(locString, opts = {}) {
|
|
const key = JSON.stringify([locString, opts]);
|
|
let dtf = intlLFCache[key];
|
|
if (!dtf) {
|
|
dtf = new Intl.ListFormat(locString, opts);
|
|
intlLFCache[key] = dtf;
|
|
}
|
|
return dtf;
|
|
}
|
|
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 { base, ...cacheKeyOpts } = opts;
|
|
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 {
|
|
sysLocaleCache = new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
return sysLocaleCache;
|
|
}
|
|
}
|
|
let weekInfoCache = {};
|
|
function getCachedWeekInfo(locString) {
|
|
let data = weekInfoCache[locString];
|
|
if (!data) {
|
|
const locale = new Intl.Locale(locString);
|
|
data = "getWeekInfo" in locale ? locale.getWeekInfo() : locale.weekInfo;
|
|
weekInfoCache[locString] = data;
|
|
}
|
|
return data;
|
|
}
|
|
function parseLocaleString(localeStr) {
|
|
const xIndex = localeStr.indexOf("-x-");
|
|
if (xIndex !== -1) {
|
|
localeStr = localeStr.substring(0, xIndex);
|
|
}
|
|
const uIndex = localeStr.indexOf("-u-");
|
|
if (uIndex === -1) {
|
|
return [localeStr];
|
|
} else {
|
|
let options;
|
|
let selectedStr;
|
|
try {
|
|
options = getCachedDTF(localeStr).resolvedOptions();
|
|
selectedStr = localeStr;
|
|
} catch (e) {
|
|
const smaller = localeStr.substring(0, uIndex);
|
|
options = getCachedDTF(smaller).resolvedOptions();
|
|
selectedStr = smaller;
|
|
}
|
|
const { numberingSystem, calendar } = options;
|
|
return [selectedStr, numberingSystem, calendar];
|
|
}
|
|
}
|
|
function intlConfigString(localeStr, numberingSystem, outputCalendar) {
|
|
if (outputCalendar || numberingSystem) {
|
|
if (!localeStr.includes("-u-")) {
|
|
localeStr += "-u";
|
|
}
|
|
if (outputCalendar) {
|
|
localeStr += `-ca-${outputCalendar}`;
|
|
}
|
|
if (numberingSystem) {
|
|
localeStr += `-nu-${numberingSystem}`;
|
|
}
|
|
return localeStr;
|
|
} else {
|
|
return localeStr;
|
|
}
|
|
}
|
|
function mapMonths(f) {
|
|
const ms = [];
|
|
for (let i = 1; i <= 12; i++) {
|
|
const dt = DateTime.utc(2009, 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, englishFn, intlFn) {
|
|
const mode = loc.listingMode();
|
|
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") || new Intl.DateTimeFormat(loc.intl).resolvedOptions().numberingSystem === "latn";
|
|
}
|
|
}
|
|
class PolyNumberFormatter {
|
|
constructor(intl, forceSimple, opts) {
|
|
this.padTo = opts.padTo || 0;
|
|
this.floor = opts.floor || false;
|
|
const { padTo, floor, ...otherOpts } = opts;
|
|
if (!forceSimple || Object.keys(otherOpts).length > 0) {
|
|
const intlOpts = { useGrouping: false, ...opts };
|
|
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 {
|
|
const fixed = this.floor ? Math.floor(i) : roundTo(i, 3);
|
|
return padStart(fixed, this.padTo);
|
|
}
|
|
}
|
|
}
|
|
class PolyDateFormatter {
|
|
constructor(dt, intl, opts) {
|
|
this.opts = opts;
|
|
this.originalZone = void 0;
|
|
let z = void 0;
|
|
if (this.opts.timeZone) {
|
|
this.dt = dt;
|
|
} else if (dt.zone.type === "fixed") {
|
|
const gmtOffset = -1 * (dt.offset / 60);
|
|
const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`;
|
|
if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) {
|
|
z = offsetZ;
|
|
this.dt = dt;
|
|
} else {
|
|
z = "UTC";
|
|
this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({ minutes: dt.offset });
|
|
this.originalZone = dt.zone;
|
|
}
|
|
} else if (dt.zone.type === "system") {
|
|
this.dt = dt;
|
|
} else if (dt.zone.type === "iana") {
|
|
this.dt = dt;
|
|
z = dt.zone.name;
|
|
} else {
|
|
z = "UTC";
|
|
this.dt = dt.setZone("UTC").plus({ minutes: dt.offset });
|
|
this.originalZone = dt.zone;
|
|
}
|
|
const intlOpts = { ...this.opts };
|
|
intlOpts.timeZone = intlOpts.timeZone || z;
|
|
this.dtf = getCachedDTF(intl, intlOpts);
|
|
}
|
|
format() {
|
|
if (this.originalZone) {
|
|
return this.formatToParts().map(({ value }) => value).join("");
|
|
}
|
|
return this.dtf.format(this.dt.toJSDate());
|
|
}
|
|
formatToParts() {
|
|
const parts = this.dtf.formatToParts(this.dt.toJSDate());
|
|
if (this.originalZone) {
|
|
return parts.map((part) => {
|
|
if (part.type === "timeZoneName") {
|
|
const offsetName = this.originalZone.offsetName(this.dt.ts, {
|
|
locale: this.dt.locale,
|
|
format: this.opts.timeZoneName
|
|
});
|
|
return {
|
|
...part,
|
|
value: offsetName
|
|
};
|
|
} else {
|
|
return part;
|
|
}
|
|
});
|
|
}
|
|
return parts;
|
|
}
|
|
resolvedOptions() {
|
|
return this.dtf.resolvedOptions();
|
|
}
|
|
}
|
|
class PolyRelFormatter {
|
|
constructor(intl, isEnglish, opts) {
|
|
this.opts = { 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 [];
|
|
}
|
|
}
|
|
}
|
|
const fallbackWeekSettings = {
|
|
firstDay: 1,
|
|
minimalDays: 4,
|
|
weekend: [6, 7]
|
|
};
|
|
class Locale {
|
|
static fromOpts(opts) {
|
|
return Locale.create(
|
|
opts.locale,
|
|
opts.numberingSystem,
|
|
opts.outputCalendar,
|
|
opts.weekSettings,
|
|
opts.defaultToEN
|
|
);
|
|
}
|
|
static create(locale, numberingSystem, outputCalendar, weekSettings, defaultToEN = false) {
|
|
const specifiedLocale = locale || Settings.defaultLocale;
|
|
const localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale());
|
|
const numberingSystemR = numberingSystem || Settings.defaultNumberingSystem;
|
|
const outputCalendarR = outputCalendar || Settings.defaultOutputCalendar;
|
|
const weekSettingsR = validateWeekSettings(weekSettings) || Settings.defaultWeekSettings;
|
|
return new Locale(localeR, numberingSystemR, outputCalendarR, weekSettingsR, specifiedLocale);
|
|
}
|
|
static resetCache() {
|
|
sysLocaleCache = null;
|
|
intlDTCache = {};
|
|
intlNumCache = {};
|
|
intlRelCache = {};
|
|
}
|
|
static fromObject({ locale, numberingSystem, outputCalendar, weekSettings } = {}) {
|
|
return Locale.create(locale, numberingSystem, outputCalendar, weekSettings);
|
|
}
|
|
constructor(locale, numbering, outputCalendar, weekSettings, specifiedLocale) {
|
|
const [parsedLocale, parsedNumberingSystem, parsedOutputCalendar] = parseLocaleString(locale);
|
|
this.locale = parsedLocale;
|
|
this.numberingSystem = numbering || parsedNumberingSystem || null;
|
|
this.outputCalendar = outputCalendar || parsedOutputCalendar || null;
|
|
this.weekSettings = weekSettings;
|
|
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() {
|
|
const isActuallyEn = this.isEnglish();
|
|
const hasNoWeirdness = (this.numberingSystem === null || this.numberingSystem === "latn") && (this.outputCalendar === null || this.outputCalendar === "gregory");
|
|
return isActuallyEn && hasNoWeirdness ? "en" : "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,
|
|
validateWeekSettings(alts.weekSettings) || this.weekSettings,
|
|
alts.defaultToEN || false
|
|
);
|
|
}
|
|
}
|
|
redefaultToEN(alts = {}) {
|
|
return this.clone({ ...alts, defaultToEN: true });
|
|
}
|
|
redefaultToSystem(alts = {}) {
|
|
return this.clone({ ...alts, defaultToEN: false });
|
|
}
|
|
months(length, format = false) {
|
|
return listStuff(this, length, 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) {
|
|
return listStuff(this, length, 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() {
|
|
return listStuff(
|
|
this,
|
|
void 0,
|
|
() => meridiems,
|
|
() => {
|
|
if (!this.meridiemCache) {
|
|
const intl = { hour: "numeric", hourCycle: "h12" };
|
|
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) {
|
|
return listStuff(this, length, eras, () => {
|
|
const intl = { era: length };
|
|
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 = {}) {
|
|
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);
|
|
}
|
|
listFormatter(opts = {}) {
|
|
return getCachedLF(this.intl, opts);
|
|
}
|
|
isEnglish() {
|
|
return this.locale === "en" || this.locale.toLowerCase() === "en-us" || new Intl.DateTimeFormat(this.intl).resolvedOptions().locale.startsWith("en-us");
|
|
}
|
|
getWeekSettings() {
|
|
if (this.weekSettings) {
|
|
return this.weekSettings;
|
|
} else if (!hasLocaleWeekInfo()) {
|
|
return fallbackWeekSettings;
|
|
} else {
|
|
return getCachedWeekInfo(this.locale);
|
|
}
|
|
}
|
|
getStartOfWeek() {
|
|
return this.getWeekSettings().firstDay;
|
|
}
|
|
getMinDaysInFirstWeek() {
|
|
return this.getWeekSettings().minimalDays;
|
|
}
|
|
getWeekendDays() {
|
|
return this.getWeekSettings().weekend;
|
|
}
|
|
equals(other) {
|
|
return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar;
|
|
}
|
|
toString() {
|
|
return `Locale(${this.locale}, ${this.numberingSystem}, ${this.outputCalendar})`;
|
|
}
|
|
}
|
|
let singleton = null;
|
|
class FixedOffsetZone extends Zone {
|
|
/**
|
|
* Get a singleton instance of UTC
|
|
* @return {FixedOffsetZone}
|
|
*/
|
|
static get utcInstance() {
|
|
if (singleton === null) {
|
|
singleton = new FixedOffsetZone(0);
|
|
}
|
|
return singleton;
|
|
}
|
|
/**
|
|
* Get an instance with a specified offset
|
|
* @param {number} offset - The offset in minutes
|
|
* @return {FixedOffsetZone}
|
|
*/
|
|
static instance(offset2) {
|
|
return offset2 === 0 ? FixedOffsetZone.utcInstance : new FixedOffsetZone(offset2);
|
|
}
|
|
/**
|
|
* 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(s2) {
|
|
if (s2) {
|
|
const r = s2.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);
|
|
if (r) {
|
|
return new FixedOffsetZone(signedOffset(r[1], r[2]));
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
constructor(offset2) {
|
|
super();
|
|
this.fixed = offset2;
|
|
}
|
|
/**
|
|
* The type of zone. `fixed` for all instances of `FixedOffsetZone`.
|
|
* @override
|
|
* @type {string}
|
|
*/
|
|
get type() {
|
|
return "fixed";
|
|
}
|
|
/**
|
|
* The name of this zone.
|
|
* All fixed zones' names always start with "UTC" (plus optional offset)
|
|
* @override
|
|
* @type {string}
|
|
*/
|
|
get name() {
|
|
return this.fixed === 0 ? "UTC" : `UTC${formatOffset(this.fixed, "narrow")}`;
|
|
}
|
|
/**
|
|
* The IANA name of this zone, i.e. `Etc/UTC` or `Etc/GMT+/-nn`
|
|
*
|
|
* @override
|
|
* @type {string}
|
|
*/
|
|
get ianaName() {
|
|
if (this.fixed === 0) {
|
|
return "Etc/UTC";
|
|
} else {
|
|
return `Etc/GMT${formatOffset(-this.fixed, "narrow")}`;
|
|
}
|
|
}
|
|
/**
|
|
* Returns the offset's common name at the specified timestamp.
|
|
*
|
|
* For fixed offset zones this equals to the zone name.
|
|
* @override
|
|
*/
|
|
offsetName() {
|
|
return this.name;
|
|
}
|
|
/**
|
|
* Returns the offset's value as a string
|
|
* @override
|
|
* @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) {
|
|
return formatOffset(this.fixed, format);
|
|
}
|
|
/**
|
|
* Returns whether the offset is known to be fixed for the whole year:
|
|
* Always returns true for all fixed offset zones.
|
|
* @override
|
|
* @type {boolean}
|
|
*/
|
|
get isUniversal() {
|
|
return true;
|
|
}
|
|
/**
|
|
* Return the offset in minutes for this zone at the specified timestamp.
|
|
*
|
|
* For fixed offset zones, this is constant and does not depend on a timestamp.
|
|
* @override
|
|
* @return {number}
|
|
*/
|
|
offset() {
|
|
return this.fixed;
|
|
}
|
|
/**
|
|
* Return whether this Zone is equal to another zone (i.e. also fixed and same offset)
|
|
* @override
|
|
* @param {Zone} otherZone - the zone to compare
|
|
* @return {boolean}
|
|
*/
|
|
equals(otherZone) {
|
|
return otherZone.type === "fixed" && otherZone.fixed === this.fixed;
|
|
}
|
|
/**
|
|
* Return whether this Zone is valid:
|
|
* All fixed offset zones are valid.
|
|
* @override
|
|
* @type {boolean}
|
|
*/
|
|
get isValid() {
|
|
return true;
|
|
}
|
|
}
|
|
class InvalidZone extends Zone {
|
|
constructor(zoneName) {
|
|
super();
|
|
this.zoneName = zoneName;
|
|
}
|
|
/** @override **/
|
|
get type() {
|
|
return "invalid";
|
|
}
|
|
/** @override **/
|
|
get name() {
|
|
return this.zoneName;
|
|
}
|
|
/** @override **/
|
|
get isUniversal() {
|
|
return false;
|
|
}
|
|
/** @override **/
|
|
offsetName() {
|
|
return null;
|
|
}
|
|
/** @override **/
|
|
formatOffset() {
|
|
return "";
|
|
}
|
|
/** @override **/
|
|
offset() {
|
|
return NaN;
|
|
}
|
|
/** @override **/
|
|
equals() {
|
|
return false;
|
|
}
|
|
/** @override **/
|
|
get isValid() {
|
|
return false;
|
|
}
|
|
}
|
|
function normalizeZone(input, defaultZone2) {
|
|
if (isUndefined(input) || input === null) {
|
|
return defaultZone2;
|
|
} else if (input instanceof Zone) {
|
|
return input;
|
|
} else if (isString(input)) {
|
|
const lowered = input.toLowerCase();
|
|
if (lowered === "default") return defaultZone2;
|
|
else if (lowered === "local" || lowered === "system") return SystemZone.instance;
|
|
else if (lowered === "utc" || lowered === "gmt") return FixedOffsetZone.utcInstance;
|
|
else return FixedOffsetZone.parseSpecifier(lowered) || IANAZone.create(input);
|
|
} else if (isNumber(input)) {
|
|
return FixedOffsetZone.instance(input);
|
|
} else if (typeof input === "object" && "offset" in input && typeof input.offset === "function") {
|
|
return input;
|
|
} else {
|
|
return new InvalidZone(input);
|
|
}
|
|
}
|
|
const numberingSystems = {
|
|
arab: "[٠-٩]",
|
|
arabext: "[۰-۹]",
|
|
bali: "[᭐-᭙]",
|
|
beng: "[০-৯]",
|
|
deva: "[०-९]",
|
|
fullwide: "[0-9]",
|
|
gujr: "[૦-૯]",
|
|
hanidec: "[〇|一|二|三|四|五|六|七|八|九]",
|
|
khmr: "[០-៩]",
|
|
knda: "[೦-೯]",
|
|
laoo: "[໐-໙]",
|
|
limb: "[᥆-᥏]",
|
|
mlym: "[൦-൯]",
|
|
mong: "[᠐-᠙]",
|
|
mymr: "[၀-၉]",
|
|
orya: "[୦-୯]",
|
|
tamldec: "[௦-௯]",
|
|
telu: "[౦-౯]",
|
|
thai: "[๐-๙]",
|
|
tibt: "[༠-༩]",
|
|
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]
|
|
};
|
|
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;
|
|
}
|
|
}
|
|
let digitRegexCache = {};
|
|
function resetDigitRegexCache() {
|
|
digitRegexCache = {};
|
|
}
|
|
function digitRegex({ numberingSystem }, append = "") {
|
|
const ns = numberingSystem || "latn";
|
|
if (!digitRegexCache[ns]) {
|
|
digitRegexCache[ns] = {};
|
|
}
|
|
if (!digitRegexCache[ns][append]) {
|
|
digitRegexCache[ns][append] = new RegExp(`${numberingSystems[ns]}${append}`);
|
|
}
|
|
return digitRegexCache[ns][append];
|
|
}
|
|
let now = () => Date.now(), defaultZone = "system", defaultLocale = null, defaultNumberingSystem = null, defaultOutputCalendar = null, twoDigitCutoffYear = 60, throwOnInvalid, defaultWeekSettings = null;
|
|
class Settings {
|
|
/**
|
|
* 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(n2) {
|
|
now = n2;
|
|
}
|
|
/**
|
|
* Set the default time zone to create DateTimes in. Does not affect existing instances.
|
|
* Use the value "system" to reset this value to the system's time zone.
|
|
* @type {string}
|
|
*/
|
|
static set defaultZone(zone) {
|
|
defaultZone = zone;
|
|
}
|
|
/**
|
|
* Get the default time zone object currently used to create DateTimes. Does not affect existing instances.
|
|
* The default value is the system's time zone (the one set on the machine that runs this code).
|
|
* @type {Zone}
|
|
*/
|
|
static get defaultZone() {
|
|
return normalizeZone(defaultZone, SystemZone.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;
|
|
}
|
|
/**
|
|
* @typedef {Object} WeekSettings
|
|
* @property {number} firstDay
|
|
* @property {number} minimalDays
|
|
* @property {number[]} weekend
|
|
*/
|
|
/**
|
|
* @return {WeekSettings|null}
|
|
*/
|
|
static get defaultWeekSettings() {
|
|
return defaultWeekSettings;
|
|
}
|
|
/**
|
|
* Allows overriding the default locale week settings, i.e. the start of the week, the weekend and
|
|
* how many days are required in the first week of a year.
|
|
* Does not affect existing instances.
|
|
*
|
|
* @param {WeekSettings|null} weekSettings
|
|
*/
|
|
static set defaultWeekSettings(weekSettings) {
|
|
defaultWeekSettings = validateWeekSettings(weekSettings);
|
|
}
|
|
/**
|
|
* Get the cutoff year for whether a 2-digit year string is interpreted in the current or previous century. Numbers higher than the cutoff will be considered to mean 19xx and numbers lower or equal to the cutoff will be considered 20xx.
|
|
* @type {number}
|
|
*/
|
|
static get twoDigitCutoffYear() {
|
|
return twoDigitCutoffYear;
|
|
}
|
|
/**
|
|
* Set the cutoff year for whether a 2-digit year string is interpreted in the current or previous century. Numbers higher than the cutoff will be considered to mean 19xx and numbers lower or equal to the cutoff will be considered 20xx.
|
|
* @type {number}
|
|
* @example Settings.twoDigitCutoffYear = 0 // all 'yy' are interpreted as 20th century
|
|
* @example Settings.twoDigitCutoffYear = 99 // all 'yy' are interpreted as 21st century
|
|
* @example Settings.twoDigitCutoffYear = 50 // '49' -> 2049; '50' -> 1950
|
|
* @example Settings.twoDigitCutoffYear = 1950 // interpreted as 50
|
|
* @example Settings.twoDigitCutoffYear = 2050 // ALSO interpreted as 50
|
|
*/
|
|
static set twoDigitCutoffYear(cutoffYear) {
|
|
twoDigitCutoffYear = cutoffYear % 100;
|
|
}
|
|
/**
|
|
* 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();
|
|
DateTime.resetCache();
|
|
resetDigitRegexCache();
|
|
}
|
|
}
|
|
class Invalid {
|
|
constructor(reason, explanation) {
|
|
this.reason = reason;
|
|
this.explanation = explanation;
|
|
}
|
|
toMessage() {
|
|
if (this.explanation) {
|
|
return `${this.reason}: ${this.explanation}`;
|
|
} else {
|
|
return this.reason;
|
|
}
|
|
}
|
|
}
|
|
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 d = new Date(Date.UTC(year, month - 1, day));
|
|
if (year < 100 && year >= 0) {
|
|
d.setUTCFullYear(d.getUTCFullYear() - 1900);
|
|
}
|
|
const js = d.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 };
|
|
}
|
|
function isoWeekdayToLocal(isoWeekday, startOfWeek) {
|
|
return (isoWeekday - startOfWeek + 7) % 7 + 1;
|
|
}
|
|
function gregorianToWeek(gregObj, minDaysInFirstWeek = 4, startOfWeek = 1) {
|
|
const { year, month, day } = gregObj, ordinal = computeOrdinal(year, month, day), weekday = isoWeekdayToLocal(dayOfWeek(year, month, day), startOfWeek);
|
|
let weekNumber = Math.floor((ordinal - weekday + 14 - minDaysInFirstWeek) / 7), weekYear;
|
|
if (weekNumber < 1) {
|
|
weekYear = year - 1;
|
|
weekNumber = weeksInWeekYear(weekYear, minDaysInFirstWeek, startOfWeek);
|
|
} else if (weekNumber > weeksInWeekYear(year, minDaysInFirstWeek, startOfWeek)) {
|
|
weekYear = year + 1;
|
|
weekNumber = 1;
|
|
} else {
|
|
weekYear = year;
|
|
}
|
|
return { weekYear, weekNumber, weekday, ...timeObject(gregObj) };
|
|
}
|
|
function weekToGregorian(weekData, minDaysInFirstWeek = 4, startOfWeek = 1) {
|
|
const { weekYear, weekNumber, weekday } = weekData, weekdayOfJan4 = isoWeekdayToLocal(dayOfWeek(weekYear, 1, minDaysInFirstWeek), startOfWeek), yearInDays = daysInYear(weekYear);
|
|
let ordinal = weekNumber * 7 + weekday - weekdayOfJan4 - 7 + minDaysInFirstWeek, 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 { year, month, day, ...timeObject(weekData) };
|
|
}
|
|
function gregorianToOrdinal(gregData) {
|
|
const { year, month, day } = gregData;
|
|
const ordinal = computeOrdinal(year, month, day);
|
|
return { year, ordinal, ...timeObject(gregData) };
|
|
}
|
|
function ordinalToGregorian(ordinalData) {
|
|
const { year, ordinal } = ordinalData;
|
|
const { month, day } = uncomputeOrdinal(year, ordinal);
|
|
return { year, month, day, ...timeObject(ordinalData) };
|
|
}
|
|
function usesLocalWeekValues(obj, loc) {
|
|
const hasLocaleWeekData = !isUndefined(obj.localWeekday) || !isUndefined(obj.localWeekNumber) || !isUndefined(obj.localWeekYear);
|
|
if (hasLocaleWeekData) {
|
|
const hasIsoWeekData = !isUndefined(obj.weekday) || !isUndefined(obj.weekNumber) || !isUndefined(obj.weekYear);
|
|
if (hasIsoWeekData) {
|
|
throw new ConflictingSpecificationError(
|
|
"Cannot mix locale-based week fields with ISO-based week fields"
|
|
);
|
|
}
|
|
if (!isUndefined(obj.localWeekday)) obj.weekday = obj.localWeekday;
|
|
if (!isUndefined(obj.localWeekNumber)) obj.weekNumber = obj.localWeekNumber;
|
|
if (!isUndefined(obj.localWeekYear)) obj.weekYear = obj.localWeekYear;
|
|
delete obj.localWeekday;
|
|
delete obj.localWeekNumber;
|
|
delete obj.localWeekYear;
|
|
return {
|
|
minDaysInFirstWeek: loc.getMinDaysInFirstWeek(),
|
|
startOfWeek: loc.getStartOfWeek()
|
|
};
|
|
} else {
|
|
return { minDaysInFirstWeek: 4, startOfWeek: 1 };
|
|
}
|
|
}
|
|
function hasInvalidWeekData(obj, minDaysInFirstWeek = 4, startOfWeek = 1) {
|
|
const validYear = isInteger(obj.weekYear), validWeek = integerBetween(
|
|
obj.weekNumber,
|
|
1,
|
|
weeksInWeekYear(obj.weekYear, minDaysInFirstWeek, startOfWeek)
|
|
), validWeekday = integerBetween(obj.weekday, 1, 7);
|
|
if (!validYear) {
|
|
return unitOutOfRange("weekYear", obj.weekYear);
|
|
} else if (!validWeek) {
|
|
return unitOutOfRange("week", obj.weekNumber);
|
|
} 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;
|
|
}
|
|
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]";
|
|
}
|
|
function hasRelative() {
|
|
try {
|
|
return typeof Intl !== "undefined" && !!Intl.RelativeTimeFormat;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
function hasLocaleWeekInfo() {
|
|
try {
|
|
return typeof Intl !== "undefined" && !!Intl.Locale && ("weekInfo" in Intl.Locale.prototype || "getWeekInfo" in Intl.Locale.prototype);
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
function maybeArray(thing) {
|
|
return Array.isArray(thing) ? thing : [thing];
|
|
}
|
|
function bestBy(arr, by, compare) {
|
|
if (arr.length === 0) {
|
|
return void 0;
|
|
}
|
|
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);
|
|
}
|
|
function validateWeekSettings(settings) {
|
|
if (settings == null) {
|
|
return null;
|
|
} else if (typeof settings !== "object") {
|
|
throw new InvalidArgumentError("Week settings must be an object");
|
|
} else {
|
|
if (!integerBetween(settings.firstDay, 1, 7) || !integerBetween(settings.minimalDays, 1, 7) || !Array.isArray(settings.weekend) || settings.weekend.some((v) => !integerBetween(v, 1, 7))) {
|
|
throw new InvalidArgumentError("Invalid week settings");
|
|
}
|
|
return {
|
|
firstDay: settings.firstDay,
|
|
minimalDays: settings.minimalDays,
|
|
weekend: Array.from(settings.weekend)
|
|
};
|
|
}
|
|
}
|
|
function integerBetween(thing, bottom, top) {
|
|
return isInteger(thing) && thing >= bottom && thing <= top;
|
|
}
|
|
function floorMod(x, n2) {
|
|
return x - n2 * Math.floor(x / n2);
|
|
}
|
|
function padStart(input, n2 = 2) {
|
|
const isNeg = input < 0;
|
|
let padded;
|
|
if (isNeg) {
|
|
padded = "-" + ("" + -input).padStart(n2, "0");
|
|
} else {
|
|
padded = ("" + input).padStart(n2, "0");
|
|
}
|
|
return padded;
|
|
}
|
|
function parseInteger(string) {
|
|
if (isUndefined(string) || string === null || string === "") {
|
|
return void 0;
|
|
} else {
|
|
return parseInt(string, 10);
|
|
}
|
|
}
|
|
function parseFloating(string) {
|
|
if (isUndefined(string) || string === null || string === "") {
|
|
return void 0;
|
|
} else {
|
|
return parseFloat(string);
|
|
}
|
|
}
|
|
function parseMillis(fraction) {
|
|
if (isUndefined(fraction) || fraction === null || fraction === "") {
|
|
return void 0;
|
|
} else {
|
|
const f = parseFloat("0." + fraction) * 1e3;
|
|
return Math.floor(f);
|
|
}
|
|
}
|
|
function roundTo(number, digits, towardZero = false) {
|
|
const factor = 10 ** digits, rounder = towardZero ? Math.trunc : Math.round;
|
|
return rounder(number * factor) / factor;
|
|
}
|
|
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];
|
|
}
|
|
}
|
|
function objToLocalTS(obj) {
|
|
let d = Date.UTC(
|
|
obj.year,
|
|
obj.month - 1,
|
|
obj.day,
|
|
obj.hour,
|
|
obj.minute,
|
|
obj.second,
|
|
obj.millisecond
|
|
);
|
|
if (obj.year < 100 && obj.year >= 0) {
|
|
d = new Date(d);
|
|
d.setUTCFullYear(obj.year, obj.month - 1, obj.day);
|
|
}
|
|
return +d;
|
|
}
|
|
function firstWeekOffset(year, minDaysInFirstWeek, startOfWeek) {
|
|
const fwdlw = isoWeekdayToLocal(dayOfWeek(year, 1, minDaysInFirstWeek), startOfWeek);
|
|
return -fwdlw + minDaysInFirstWeek - 1;
|
|
}
|
|
function weeksInWeekYear(weekYear, minDaysInFirstWeek = 4, startOfWeek = 1) {
|
|
const weekOffset = firstWeekOffset(weekYear, minDaysInFirstWeek, startOfWeek);
|
|
const weekOffsetNext = firstWeekOffset(weekYear + 1, minDaysInFirstWeek, startOfWeek);
|
|
return (daysInYear(weekYear) - weekOffset + weekOffsetNext) / 7;
|
|
}
|
|
function untruncateYear(year) {
|
|
if (year > 99) {
|
|
return year;
|
|
} else return year > Settings.twoDigitCutoffYear ? 1900 + year : 2e3 + year;
|
|
}
|
|
function parseZoneInfo(ts, offsetFormat, locale, timeZone = null) {
|
|
const date = new Date(ts), intlOpts = {
|
|
hourCycle: "h23",
|
|
year: "numeric",
|
|
month: "2-digit",
|
|
day: "2-digit",
|
|
hour: "2-digit",
|
|
minute: "2-digit"
|
|
};
|
|
if (timeZone) {
|
|
intlOpts.timeZone = timeZone;
|
|
}
|
|
const modified = { timeZoneName: offsetFormat, ...intlOpts };
|
|
const parsed = new Intl.DateTimeFormat(locale, modified).formatToParts(date).find((m) => m.type.toLowerCase() === "timezonename");
|
|
return parsed ? parsed.value : null;
|
|
}
|
|
function signedOffset(offHourStr, offMinuteStr) {
|
|
let offHour = parseInt(offHourStr, 10);
|
|
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;
|
|
}
|
|
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) {
|
|
const normalized = {};
|
|
for (const u in obj) {
|
|
if (hasOwnProperty(obj, u)) {
|
|
const v = obj[u];
|
|
if (v === void 0 || v === null) continue;
|
|
normalized[normalizer(u)] = asNumber(v);
|
|
}
|
|
}
|
|
return normalized;
|
|
}
|
|
function formatOffset(offset2, format) {
|
|
const hours = Math.trunc(Math.abs(offset2 / 60)), minutes = Math.trunc(Math.abs(offset2 % 60)), sign = offset2 >= 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 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 stringifyTokens(splits, tokenToString) {
|
|
let s2 = "";
|
|
for (const token of splits) {
|
|
if (token.literal) {
|
|
s2 += token.val;
|
|
} else {
|
|
s2 += tokenToString(token.val);
|
|
}
|
|
}
|
|
return s2;
|
|
}
|
|
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
|
|
};
|
|
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 c2 = fmt.charAt(i);
|
|
if (c2 === "'") {
|
|
if (currentFull.length > 0) {
|
|
splits.push({ literal: bracketed || /^\s+$/.test(currentFull), val: currentFull });
|
|
}
|
|
current = null;
|
|
currentFull = "";
|
|
bracketed = !bracketed;
|
|
} else if (bracketed) {
|
|
currentFull += c2;
|
|
} else if (c2 === current) {
|
|
currentFull += c2;
|
|
} else {
|
|
if (currentFull.length > 0) {
|
|
splits.push({ literal: /^\s+$/.test(currentFull), val: currentFull });
|
|
}
|
|
currentFull = c2;
|
|
current = c2;
|
|
}
|
|
}
|
|
if (currentFull.length > 0) {
|
|
splits.push({ literal: bracketed || /^\s+$/.test(currentFull), 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, { ...this.opts, ...opts });
|
|
return df.format();
|
|
}
|
|
dtFormatter(dt, opts = {}) {
|
|
return this.loc.dtFormatter(dt, { ...this.opts, ...opts });
|
|
}
|
|
formatDateTime(dt, opts) {
|
|
return this.dtFormatter(dt, opts).format();
|
|
}
|
|
formatDateTimeParts(dt, opts) {
|
|
return this.dtFormatter(dt, opts).formatToParts();
|
|
}
|
|
formatInterval(interval, opts) {
|
|
const df = this.dtFormatter(interval.start, opts);
|
|
return df.dtf.formatRange(interval.start.toJSDate(), interval.end.toJSDate());
|
|
}
|
|
resolvedOptions(dt, opts) {
|
|
return this.dtFormatter(dt, opts).resolvedOptions();
|
|
}
|
|
num(n2, p = 0) {
|
|
if (this.opts.forceSimple) {
|
|
return padStart(n2, p);
|
|
}
|
|
const opts = { ...this.opts };
|
|
if (p > 0) {
|
|
opts.padTo = p;
|
|
}
|
|
return this.loc.numberFormatter(opts).format(n2);
|
|
}
|
|
formatDateTimeFromString(dt, fmt) {
|
|
const knownEnglish = this.loc.listingMode() === "en", useDateTimeFormatter = this.loc.outputCalendar && this.loc.outputCalendar !== "gregory", string = (opts, extract) => this.loc.extract(dt, opts, extract), formatOffset2 = (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", hourCycle: "h12" }, "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) => {
|
|
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);
|
|
// fractional seconds
|
|
case "uu":
|
|
return this.num(Math.floor(dt.millisecond / 10), 2);
|
|
case "uuu":
|
|
return this.num(Math.floor(dt.millisecond / 100));
|
|
// 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":
|
|
return formatOffset2({ format: "narrow", allowZ: this.opts.allowZ });
|
|
case "ZZ":
|
|
return formatOffset2({ format: "short", allowZ: this.opts.allowZ });
|
|
case "ZZZ":
|
|
return formatOffset2({ format: "techie", allowZ: this.opts.allowZ });
|
|
case "ZZZZ":
|
|
return dt.zone.offsetName(dt.ts, { format: "short", locale: this.loc.locale });
|
|
case "ZZZZZ":
|
|
return dt.zone.offsetName(dt.ts, { format: "long", locale: this.loc.locale });
|
|
// zone
|
|
case "z":
|
|
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":
|
|
return this.num(dt.weekday);
|
|
case "ccc":
|
|
return weekday("short", true);
|
|
case "cccc":
|
|
return weekday("long", true);
|
|
case "ccccc":
|
|
return weekday("narrow", true);
|
|
// weekdays - format
|
|
case "E":
|
|
return this.num(dt.weekday);
|
|
case "EEE":
|
|
return weekday("short", false);
|
|
case "EEEE":
|
|
return weekday("long", false);
|
|
case "EEEEE":
|
|
return weekday("narrow", false);
|
|
// months - standalone
|
|
case "L":
|
|
return useDateTimeFormatter ? string({ month: "numeric", day: "numeric" }, "month") : this.num(dt.month);
|
|
case "LL":
|
|
return useDateTimeFormatter ? string({ month: "2-digit", day: "numeric" }, "month") : this.num(dt.month, 2);
|
|
case "LLL":
|
|
return month("short", true);
|
|
case "LLLL":
|
|
return month("long", true);
|
|
case "LLLLL":
|
|
return month("narrow", true);
|
|
// months - format
|
|
case "M":
|
|
return useDateTimeFormatter ? string({ month: "numeric" }, "month") : this.num(dt.month);
|
|
case "MM":
|
|
return useDateTimeFormatter ? string({ month: "2-digit" }, "month") : this.num(dt.month, 2);
|
|
case "MMM":
|
|
return month("short", false);
|
|
case "MMMM":
|
|
return month("long", false);
|
|
case "MMMMM":
|
|
return month("narrow", false);
|
|
// years
|
|
case "y":
|
|
return useDateTimeFormatter ? string({ year: "numeric" }, "year") : this.num(dt.year);
|
|
case "yy":
|
|
return useDateTimeFormatter ? string({ year: "2-digit" }, "year") : this.num(dt.year.toString().slice(-2), 2);
|
|
case "yyyy":
|
|
return useDateTimeFormatter ? string({ year: "numeric" }, "year") : this.num(dt.year, 4);
|
|
case "yyyyyy":
|
|
return useDateTimeFormatter ? string({ year: "numeric" }, "year") : this.num(dt.year, 6);
|
|
// eras
|
|
case "G":
|
|
return era("short");
|
|
case "GG":
|
|
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 "n":
|
|
return this.num(dt.localWeekNumber);
|
|
case "nn":
|
|
return this.num(dt.localWeekNumber, 2);
|
|
case "ii":
|
|
return this.num(dt.localWeekYear.toString().slice(-2), 2);
|
|
case "iiii":
|
|
return this.num(dt.localWeekYear, 4);
|
|
case "o":
|
|
return this.num(dt.ordinal);
|
|
case "ooo":
|
|
return this.num(dt.ordinal, 3);
|
|
case "q":
|
|
return this.num(dt.quarter);
|
|
case "qq":
|
|
return this.num(dt.quarter, 2);
|
|
case "X":
|
|
return this.num(Math.floor(dt.ts / 1e3));
|
|
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 "w":
|
|
return "week";
|
|
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));
|
|
}
|
|
}
|
|
const ianaRegex = /[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;
|
|
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 [{ ...mergedVals, ...val }, zone || mergedZone, next];
|
|
},
|
|
[{}, null, 1]
|
|
).slice(0, 2);
|
|
}
|
|
function parse(s2, ...patterns) {
|
|
if (s2 == null) {
|
|
return [null, null];
|
|
}
|
|
for (const [regex, extractor] of patterns) {
|
|
const m = regex.exec(s2);
|
|
if (m) {
|
|
return extractor(m);
|
|
}
|
|
}
|
|
return [null, null];
|
|
}
|
|
function simpleParse(...keys) {
|
|
return (match2, cursor) => {
|
|
const ret = {};
|
|
let i;
|
|
for (i = 0; i < keys.length; i++) {
|
|
ret[keys[i]] = parseInteger(match2[cursor + i]);
|
|
}
|
|
return [ret, null, cursor + i];
|
|
};
|
|
}
|
|
const offsetRegex = /(?:(Z)|([+-]\d\d)(?::?(\d\d))?)/;
|
|
const isoExtendedZone = `(?:${offsetRegex.source}?(?:\\[(${ianaRegex.source})\\])?)?`;
|
|
const isoTimeBaseRegex = /(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/;
|
|
const isoTimeRegex = RegExp(`${isoTimeBaseRegex.source}${isoExtendedZone}`);
|
|
const isoTimeExtensionRegex = RegExp(`(?:T${isoTimeRegex.source})?`);
|
|
const isoYmdRegex = /([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/;
|
|
const isoWeekRegex = /(\d{4})-?W(\d\d)(?:-?(\d))?/;
|
|
const isoOrdinalRegex = /(\d{4})-?(\d{3})/;
|
|
const extractISOWeekData = simpleParse("weekYear", "weekNumber", "weekDay");
|
|
const extractISOOrdinalData = simpleParse("year", "ordinal");
|
|
const sqlYmdRegex = /(\d{4})-(\d\d)-(\d\d)/;
|
|
const sqlTimeRegex = RegExp(
|
|
`${isoTimeBaseRegex.source} ?(?:${offsetRegex.source}|(${ianaRegex.source}))?`
|
|
);
|
|
const sqlTimeExtensionRegex = RegExp(`(?: ${sqlTimeRegex.source})?`);
|
|
function int(match2, pos, fallback) {
|
|
const m = match2[pos];
|
|
return isUndefined(m) ? fallback : parseInteger(m);
|
|
}
|
|
function extractISOYmd(match2, cursor) {
|
|
const item = {
|
|
year: int(match2, cursor),
|
|
month: int(match2, cursor + 1, 1),
|
|
day: int(match2, cursor + 2, 1)
|
|
};
|
|
return [item, null, cursor + 3];
|
|
}
|
|
function extractISOTime(match2, cursor) {
|
|
const item = {
|
|
hours: int(match2, cursor, 0),
|
|
minutes: int(match2, cursor + 1, 0),
|
|
seconds: int(match2, cursor + 2, 0),
|
|
milliseconds: parseMillis(match2[cursor + 3])
|
|
};
|
|
return [item, null, cursor + 4];
|
|
}
|
|
function extractISOOffset(match2, cursor) {
|
|
const local = !match2[cursor] && !match2[cursor + 1], fullOffset = signedOffset(match2[cursor + 1], match2[cursor + 2]), zone = local ? null : FixedOffsetZone.instance(fullOffset);
|
|
return [{}, zone, cursor + 3];
|
|
}
|
|
function extractIANAZone(match2, cursor) {
|
|
const zone = match2[cursor] ? IANAZone.create(match2[cursor]) : null;
|
|
return [{}, zone, cursor + 1];
|
|
}
|
|
const isoTimeOnly = RegExp(`^T?${isoTimeBaseRegex.source}$`);
|
|
const isoDuration = /^-?P(?:(?:(-?\d{1,20}(?:\.\d{1,20})?)Y)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20}(?:\.\d{1,20})?)W)?(?:(-?\d{1,20}(?:\.\d{1,20})?)D)?(?:T(?:(-?\d{1,20}(?:\.\d{1,20})?)H)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,20}))?S)?)?)$/;
|
|
function extractISODuration(match2) {
|
|
const [s2, yearStr, monthStr, weekStr, dayStr, hourStr, minuteStr, secondStr, millisecondsStr] = match2;
|
|
const hasNegativePrefix = s2[0] === "-";
|
|
const negativeSeconds = secondStr && secondStr[0] === "-";
|
|
const maybeNegate = (num, force = false) => num !== void 0 && (force || num && hasNegativePrefix) ? -num : num;
|
|
return [
|
|
{
|
|
years: maybeNegate(parseFloating(yearStr)),
|
|
months: maybeNegate(parseFloating(monthStr)),
|
|
weeks: maybeNegate(parseFloating(weekStr)),
|
|
days: maybeNegate(parseFloating(dayStr)),
|
|
hours: maybeNegate(parseFloating(hourStr)),
|
|
minutes: maybeNegate(parseFloating(minuteStr)),
|
|
seconds: maybeNegate(parseFloating(secondStr), secondStr === "-0"),
|
|
milliseconds: maybeNegate(parseMillis(millisecondsStr), negativeSeconds)
|
|
}
|
|
];
|
|
}
|
|
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;
|
|
}
|
|
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(match2) {
|
|
const [
|
|
,
|
|
weekdayStr,
|
|
dayStr,
|
|
monthStr,
|
|
yearStr,
|
|
hourStr,
|
|
minuteStr,
|
|
secondStr,
|
|
obsOffset,
|
|
milOffset,
|
|
offHourStr,
|
|
offMinuteStr
|
|
] = match2, result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr);
|
|
let offset2;
|
|
if (obsOffset) {
|
|
offset2 = obsOffsets[obsOffset];
|
|
} else if (milOffset) {
|
|
offset2 = 0;
|
|
} else {
|
|
offset2 = signedOffset(offHourStr, offMinuteStr);
|
|
}
|
|
return [result, new FixedOffsetZone(offset2)];
|
|
}
|
|
function preprocessRFC2822(s2) {
|
|
return s2.replace(/\([^()]*\)|[\n\t]/g, " ").replace(/(\s\s+)/g, " ").trim();
|
|
}
|
|
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|Wednesday|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(match2) {
|
|
const [, weekdayStr, dayStr, monthStr, yearStr, hourStr, minuteStr, secondStr] = match2, result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr);
|
|
return [result, FixedOffsetZone.utcInstance];
|
|
}
|
|
function extractASCII(match2) {
|
|
const [, weekdayStr, monthStr, dayStr, hourStr, minuteStr, secondStr, yearStr] = match2, 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,
|
|
extractIANAZone
|
|
);
|
|
const extractISOWeekTimeAndOffset = combineExtractors(
|
|
extractISOWeekData,
|
|
extractISOTime,
|
|
extractISOOffset,
|
|
extractIANAZone
|
|
);
|
|
const extractISOOrdinalDateAndTime = combineExtractors(
|
|
extractISOOrdinalData,
|
|
extractISOTime,
|
|
extractISOOffset,
|
|
extractIANAZone
|
|
);
|
|
const extractISOTimeAndOffset = combineExtractors(
|
|
extractISOTime,
|
|
extractISOOffset,
|
|
extractIANAZone
|
|
);
|
|
function parseISODate(s2) {
|
|
return parse(
|
|
s2,
|
|
[isoYmdWithTimeExtensionRegex, extractISOYmdTimeAndOffset],
|
|
[isoWeekWithTimeExtensionRegex, extractISOWeekTimeAndOffset],
|
|
[isoOrdinalWithTimeExtensionRegex, extractISOOrdinalDateAndTime],
|
|
[isoTimeCombinedRegex, extractISOTimeAndOffset]
|
|
);
|
|
}
|
|
function parseRFC2822Date(s2) {
|
|
return parse(preprocessRFC2822(s2), [rfc2822, extractRFC2822]);
|
|
}
|
|
function parseHTTPDate(s2) {
|
|
return parse(
|
|
s2,
|
|
[rfc1123, extractRFC1123Or850],
|
|
[rfc850, extractRFC1123Or850],
|
|
[ascii, extractASCII]
|
|
);
|
|
}
|
|
function parseISODuration(s2) {
|
|
return parse(s2, [isoDuration, extractISODuration]);
|
|
}
|
|
const extractISOTimeOnly = combineExtractors(extractISOTime);
|
|
function parseISOTimeOnly(s2) {
|
|
return parse(s2, [isoTimeOnly, extractISOTimeOnly]);
|
|
}
|
|
const sqlYmdWithTimeExtensionRegex = combineRegexes(sqlYmdRegex, sqlTimeExtensionRegex);
|
|
const sqlTimeCombinedRegex = combineRegexes(sqlTimeRegex);
|
|
const extractISOTimeOffsetAndIANAZone = combineExtractors(
|
|
extractISOTime,
|
|
extractISOOffset,
|
|
extractIANAZone
|
|
);
|
|
function parseSQL(s2) {
|
|
return parse(
|
|
s2,
|
|
[sqlYmdWithTimeExtensionRegex, extractISOYmdTimeAndOffset],
|
|
[sqlTimeCombinedRegex, extractISOTimeOffsetAndIANAZone]
|
|
);
|
|
}
|
|
const INVALID$2 = "Invalid Duration";
|
|
const lowOrderMatrix = {
|
|
weeks: {
|
|
days: 7,
|
|
hours: 7 * 24,
|
|
minutes: 7 * 24 * 60,
|
|
seconds: 7 * 24 * 60 * 60,
|
|
milliseconds: 7 * 24 * 60 * 60 * 1e3
|
|
},
|
|
days: {
|
|
hours: 24,
|
|
minutes: 24 * 60,
|
|
seconds: 24 * 60 * 60,
|
|
milliseconds: 24 * 60 * 60 * 1e3
|
|
},
|
|
hours: { minutes: 60, seconds: 60 * 60, milliseconds: 60 * 60 * 1e3 },
|
|
minutes: { seconds: 60, milliseconds: 60 * 1e3 },
|
|
seconds: { milliseconds: 1e3 }
|
|
}, casualMatrix = {
|
|
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 * 1e3
|
|
},
|
|
quarters: {
|
|
months: 3,
|
|
weeks: 13,
|
|
days: 91,
|
|
hours: 91 * 24,
|
|
minutes: 91 * 24 * 60,
|
|
seconds: 91 * 24 * 60 * 60,
|
|
milliseconds: 91 * 24 * 60 * 60 * 1e3
|
|
},
|
|
months: {
|
|
weeks: 4,
|
|
days: 30,
|
|
hours: 30 * 24,
|
|
minutes: 30 * 24 * 60,
|
|
seconds: 30 * 24 * 60 * 60,
|
|
milliseconds: 30 * 24 * 60 * 60 * 1e3
|
|
},
|
|
...lowOrderMatrix
|
|
}, daysInYearAccurate = 146097 / 400, daysInMonthAccurate = 146097 / 4800, accurateMatrix = {
|
|
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 * 1e3
|
|
},
|
|
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 * 1e3 / 4
|
|
},
|
|
months: {
|
|
weeks: daysInMonthAccurate / 7,
|
|
days: daysInMonthAccurate,
|
|
hours: daysInMonthAccurate * 24,
|
|
minutes: daysInMonthAccurate * 24 * 60,
|
|
seconds: daysInMonthAccurate * 24 * 60 * 60,
|
|
milliseconds: daysInMonthAccurate * 24 * 60 * 60 * 1e3
|
|
},
|
|
...lowOrderMatrix
|
|
};
|
|
const orderedUnits$1 = [
|
|
"years",
|
|
"quarters",
|
|
"months",
|
|
"weeks",
|
|
"days",
|
|
"hours",
|
|
"minutes",
|
|
"seconds",
|
|
"milliseconds"
|
|
];
|
|
const reverseUnits = orderedUnits$1.slice(0).reverse();
|
|
function clone$1(dur, alts, clear = false) {
|
|
const conf = {
|
|
values: clear ? alts.values : { ...dur.values, ...alts.values || {} },
|
|
loc: dur.loc.clone(alts.loc),
|
|
conversionAccuracy: alts.conversionAccuracy || dur.conversionAccuracy,
|
|
matrix: alts.matrix || dur.matrix
|
|
};
|
|
return new Duration(conf);
|
|
}
|
|
function durationToMillis(matrix, vals) {
|
|
let sum = vals.milliseconds ?? 0;
|
|
for (const unit of reverseUnits.slice(1)) {
|
|
if (vals[unit]) {
|
|
sum += vals[unit] * matrix[unit]["milliseconds"];
|
|
}
|
|
}
|
|
return sum;
|
|
}
|
|
function normalizeValues(matrix, vals) {
|
|
const factor = durationToMillis(matrix, vals) < 0 ? -1 : 1;
|
|
orderedUnits$1.reduceRight((previous, current) => {
|
|
if (!isUndefined(vals[current])) {
|
|
if (previous) {
|
|
const previousVal = vals[previous] * factor;
|
|
const conv = matrix[current][previous];
|
|
const rollUp = Math.floor(previousVal / conv);
|
|
vals[current] += rollUp * factor;
|
|
vals[previous] -= rollUp * conv * factor;
|
|
}
|
|
return current;
|
|
} else {
|
|
return previous;
|
|
}
|
|
}, null);
|
|
orderedUnits$1.reduce((previous, current) => {
|
|
if (!isUndefined(vals[current])) {
|
|
if (previous) {
|
|
const fraction = vals[previous] % 1;
|
|
vals[previous] -= fraction;
|
|
vals[current] += fraction * matrix[previous][current];
|
|
}
|
|
return current;
|
|
} else {
|
|
return previous;
|
|
}
|
|
}, null);
|
|
}
|
|
function removeZeroes(vals) {
|
|
const newVals = {};
|
|
for (const [key, value] of Object.entries(vals)) {
|
|
if (value !== 0) {
|
|
newVals[key] = value;
|
|
}
|
|
}
|
|
return newVals;
|
|
}
|
|
class Duration {
|
|
/**
|
|
* @private
|
|
*/
|
|
constructor(config) {
|
|
const accurate = config.conversionAccuracy === "longterm" || false;
|
|
let matrix = accurate ? accurateMatrix : casualMatrix;
|
|
if (config.matrix) {
|
|
matrix = config.matrix;
|
|
}
|
|
this.values = config.values;
|
|
this.loc = config.loc || Locale.create();
|
|
this.conversionAccuracy = accurate ? "longterm" : "casual";
|
|
this.invalid = config.invalid || null;
|
|
this.matrix = matrix;
|
|
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({ 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 {Object} [opts=[]] - options for creating this Duration
|
|
* @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 preset conversion system to use
|
|
* @param {string} [opts.matrix=Object] - the custom conversion system to use
|
|
* @return {Duration}
|
|
*/
|
|
static fromObject(obj, opts = {}) {
|
|
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),
|
|
loc: Locale.fromObject(opts),
|
|
conversionAccuracy: opts.conversionAccuracy,
|
|
matrix: opts.matrix
|
|
});
|
|
}
|
|
/**
|
|
* Create a Duration from DurationLike.
|
|
*
|
|
* @param {Object | number | Duration} durationLike
|
|
* One of:
|
|
* - object with keys like 'years' and 'hours'.
|
|
* - number representing milliseconds
|
|
* - Duration instance
|
|
* @return {Duration}
|
|
*/
|
|
static fromDurationLike(durationLike) {
|
|
if (isNumber(durationLike)) {
|
|
return Duration.fromMillis(durationLike);
|
|
} else if (Duration.isDuration(durationLike)) {
|
|
return durationLike;
|
|
} else if (typeof durationLike === "object") {
|
|
return Duration.fromObject(durationLike);
|
|
} else {
|
|
throw new InvalidArgumentError(
|
|
`Unknown duration argument ${durationLike} of type ${typeof durationLike}`
|
|
);
|
|
}
|
|
}
|
|
/**
|
|
* 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 preset conversion system to use
|
|
* @param {string} [opts.matrix=Object] - the preset 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) {
|
|
return Duration.fromObject(parsed, opts);
|
|
} 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 preset conversion system to use
|
|
* @param {string} [opts.matrix=Object] - 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) {
|
|
return Duration.fromObject(parsed, opts);
|
|
} 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.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
|
|
* * `w` for weeks
|
|
* * `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
|
|
* * Tokens can be escaped by wrapping with single quotes.
|
|
* * 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 = {}) {
|
|
const fmtOpts = {
|
|
...opts,
|
|
floor: opts.round !== false && opts.floor !== false
|
|
};
|
|
return this.isValid ? Formatter.create(this.loc, fmtOpts).formatDurationFromString(this, fmt) : INVALID$2;
|
|
}
|
|
/**
|
|
* Returns a string representation of a Duration with all units included.
|
|
* To modify its behavior, use `listStyle` and any Intl.NumberFormat option, though `unitDisplay` is especially relevant.
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
|
|
* @param {Object} opts - Formatting options. Accepts the same keys as the options parameter of the native `Intl.NumberFormat` constructor, as well as `listStyle`.
|
|
* @param {string} [opts.listStyle='narrow'] - How to format the merged list. Corresponds to the `style` property of the options parameter of the native `Intl.ListFormat` constructor.
|
|
* @example
|
|
* ```js
|
|
* var dur = Duration.fromObject({ days: 1, hours: 5, minutes: 6 })
|
|
* dur.toHuman() //=> '1 day, 5 hours, 6 minutes'
|
|
* dur.toHuman({ listStyle: "long" }) //=> '1 day, 5 hours, and 6 minutes'
|
|
* dur.toHuman({ unitDisplay: "short" }) //=> '1 day, 5 hr, 6 min'
|
|
* ```
|
|
*/
|
|
toHuman(opts = {}) {
|
|
if (!this.isValid) return INVALID$2;
|
|
const l2 = orderedUnits$1.map((unit) => {
|
|
const val = this.values[unit];
|
|
if (isUndefined(val)) {
|
|
return null;
|
|
}
|
|
return this.loc.numberFormatter({ style: "unit", unitDisplay: "long", ...opts, unit: unit.slice(0, -1) }).format(val);
|
|
}).filter((n2) => n2);
|
|
return this.loc.listFormatter({ type: "conjunction", style: opts.listStyle || "narrow", ...opts }).format(l2);
|
|
}
|
|
/**
|
|
* Returns a JavaScript object with this Duration's values.
|
|
* @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toObject() //=> { years: 1, days: 6, seconds: 2 }
|
|
* @return {Object}
|
|
*/
|
|
toObject() {
|
|
if (!this.isValid) return {};
|
|
return { ...this.values };
|
|
}
|
|
/**
|
|
* 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() {
|
|
if (!this.isValid) return null;
|
|
let s2 = "P";
|
|
if (this.years !== 0) s2 += this.years + "Y";
|
|
if (this.months !== 0 || this.quarters !== 0) s2 += this.months + this.quarters * 3 + "M";
|
|
if (this.weeks !== 0) s2 += this.weeks + "W";
|
|
if (this.days !== 0) s2 += this.days + "D";
|
|
if (this.hours !== 0 || this.minutes !== 0 || this.seconds !== 0 || this.milliseconds !== 0)
|
|
s2 += "T";
|
|
if (this.hours !== 0) s2 += this.hours + "H";
|
|
if (this.minutes !== 0) s2 += this.minutes + "M";
|
|
if (this.seconds !== 0 || this.milliseconds !== 0)
|
|
s2 += roundTo(this.seconds + this.milliseconds / 1e3, 3) + "S";
|
|
if (s2 === "P") s2 += "T0S";
|
|
return s2;
|
|
}
|
|
/**
|
|
* 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 >= 864e5) return null;
|
|
opts = {
|
|
suppressMilliseconds: false,
|
|
suppressSeconds: false,
|
|
includePrefix: false,
|
|
format: "extended",
|
|
...opts,
|
|
includeOffset: false
|
|
};
|
|
const dateTime = DateTime.fromMillis(millis, { zone: "UTC" });
|
|
return dateTime.toISOTime(opts);
|
|
}
|
|
/**
|
|
* 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 a string representation of this Duration appropriate for the REPL.
|
|
* @return {string}
|
|
*/
|
|
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
if (this.isValid) {
|
|
return `Duration { values: ${JSON.stringify(this.values)} }`;
|
|
} else {
|
|
return `Duration { Invalid, reason: ${this.invalidReason} }`;
|
|
}
|
|
}
|
|
/**
|
|
* Returns an milliseconds value of this Duration.
|
|
* @return {number}
|
|
*/
|
|
toMillis() {
|
|
if (!this.isValid) return NaN;
|
|
return durationToMillis(this.matrix, this.values);
|
|
}
|
|
/**
|
|
* 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 = Duration.fromDurationLike(duration), result = {};
|
|
for (const k of orderedUnits$1) {
|
|
if (hasOwnProperty(dur.values, k) || hasOwnProperty(this.values, k)) {
|
|
result[k] = dur.get(k) + this.get(k);
|
|
}
|
|
}
|
|
return clone$1(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 = Duration.fromDurationLike(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 }).mapUnits(x => x * 2) //=> { hours: 2, minutes: 60 }
|
|
* @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnits((x, u) => u === "hours" ? 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$1(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 = { ...this.values, ...normalizeObject(values, Duration.normalizeUnit) };
|
|
return clone$1(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, matrix } = {}) {
|
|
const loc = this.loc.clone({ locale, numberingSystem });
|
|
const opts = { loc, matrix, conversionAccuracy };
|
|
return clone$1(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.
|
|
* Assuming the overall value of the Duration is positive, this means:
|
|
* - excessive values for lower-order units are converted to higher-order units (if possible, see first and second example)
|
|
* - negative lower-order units are converted to higher order units (there must be such a higher order unit, otherwise
|
|
* the overall value would be negative, see third example)
|
|
* - fractional values for higher-order units are converted to lower-order units (if possible, see fourth example)
|
|
*
|
|
* If the overall value is negative, the result of this method is equivalent to `this.negate().normalize().negate()`.
|
|
* @example Duration.fromObject({ years: 2, days: 5000 }).normalize().toObject() //=> { years: 15, days: 255 }
|
|
* @example Duration.fromObject({ days: 5000 }).normalize().toObject() //=> { days: 5000 }
|
|
* @example Duration.fromObject({ hours: 12, minutes: -45 }).normalize().toObject() //=> { hours: 11, minutes: 15 }
|
|
* @example Duration.fromObject({ years: 2.5, days: 0, hours: 0 }).normalize().toObject() //=> { years: 2, days: 182, hours: 12 }
|
|
* @return {Duration}
|
|
*/
|
|
normalize() {
|
|
if (!this.isValid) return this;
|
|
const vals = this.toObject();
|
|
normalizeValues(this.matrix, vals);
|
|
return clone$1(this, { values: vals }, true);
|
|
}
|
|
/**
|
|
* Rescale units to its largest representation
|
|
* @example Duration.fromObject({ milliseconds: 90000 }).rescale().toObject() //=> { minutes: 1, seconds: 30 }
|
|
* @return {Duration}
|
|
*/
|
|
rescale() {
|
|
if (!this.isValid) return this;
|
|
const vals = removeZeroes(this.normalize().shiftToAll().toObject());
|
|
return clone$1(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$1) {
|
|
if (units.indexOf(k) >= 0) {
|
|
lastUnit = k;
|
|
let own = 0;
|
|
for (const ak in accumulated) {
|
|
own += this.matrix[ak][k] * accumulated[ak];
|
|
accumulated[ak] = 0;
|
|
}
|
|
if (isNumber(vals[k])) {
|
|
own += vals[k];
|
|
}
|
|
const i = Math.trunc(own);
|
|
built[k] = i;
|
|
accumulated[k] = (own * 1e3 - i * 1e3) / 1e3;
|
|
} else if (isNumber(vals[k])) {
|
|
accumulated[k] = vals[k];
|
|
}
|
|
}
|
|
for (const key in accumulated) {
|
|
if (accumulated[key] !== 0) {
|
|
built[lastUnit] += key === lastUnit ? accumulated[key] : accumulated[key] / this.matrix[lastUnit][key];
|
|
}
|
|
}
|
|
normalizeValues(this.matrix, built);
|
|
return clone$1(this, { values: built }, true);
|
|
}
|
|
/**
|
|
* Shift this Duration to all available units.
|
|
* Same as shiftTo("years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds")
|
|
* @return {Duration}
|
|
*/
|
|
shiftToAll() {
|
|
if (!this.isValid) return this;
|
|
return this.shiftTo(
|
|
"years",
|
|
"months",
|
|
"weeks",
|
|
"days",
|
|
"hours",
|
|
"minutes",
|
|
"seconds",
|
|
"milliseconds"
|
|
);
|
|
}
|
|
/**
|
|
* 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] === 0 ? 0 : -this.values[k];
|
|
}
|
|
return clone$1(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) {
|
|
if (v1 === void 0 || v1 === 0) return v2 === void 0 || v2 === 0;
|
|
return v1 === v2;
|
|
}
|
|
for (const u of orderedUnits$1) {
|
|
if (!eq(this.values[u], other.values[u])) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
const INVALID$1 = "Invalid Interval";
|
|
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;
|
|
}
|
|
}
|
|
class Interval {
|
|
/**
|
|
* @private
|
|
*/
|
|
constructor(config) {
|
|
this.s = config.start;
|
|
this.e = config.end;
|
|
this.invalid = config.invalid || null;
|
|
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.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 = Duration.fromDurationLike(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 = Duration.fromDurationLike(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 [s2, e] = (text || "").split("/", 2);
|
|
if (s2 && e) {
|
|
let start, startIsValid;
|
|
try {
|
|
start = DateTime.fromISO(s2, opts);
|
|
startIsValid = start.isValid;
|
|
} catch (e2) {
|
|
startIsValid = false;
|
|
}
|
|
let end, endIsValid;
|
|
try {
|
|
end = DateTime.fromISO(e, opts);
|
|
endIsValid = end.isValid;
|
|
} catch (e2) {
|
|
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(s2, 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 Interval#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.
|
|
* @param {Object} opts - options
|
|
* @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week; this operation will always use the locale of the start DateTime
|
|
* @return {number}
|
|
*/
|
|
count(unit = "milliseconds", opts) {
|
|
if (!this.isValid) return NaN;
|
|
const start = this.start.startOf(unit, opts);
|
|
let end;
|
|
if (opts == null ? void 0 : opts.useLocaleWeeks) {
|
|
end = this.end.reconfigure({ locale: start.locale });
|
|
} else {
|
|
end = this.end;
|
|
}
|
|
end = end.startOf(unit, opts);
|
|
return Math.floor(end.diff(start, unit).get(unit)) + (end.valueOf() !== this.end.valueOf());
|
|
}
|
|
/**
|
|
* 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 {Array}
|
|
*/
|
|
splitAt(...dateTimes) {
|
|
if (!this.isValid) return [];
|
|
const sorted = dateTimes.map(friendlyDateTime).filter((d) => this.contains(d)).sort((a, b) => a.toMillis() - b.toMillis()), results = [];
|
|
let { s: s2 } = this, i = 0;
|
|
while (s2 < this.e) {
|
|
const added = sorted[i] || this.e, next = +added > +this.e ? this.e : added;
|
|
results.push(Interval.fromDateTimes(s2, next));
|
|
s2 = 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 {Array}
|
|
*/
|
|
splitBy(duration) {
|
|
const dur = Duration.fromDurationLike(duration);
|
|
if (!this.isValid || !dur.isValid || dur.as("milliseconds") === 0) {
|
|
return [];
|
|
}
|
|
let { s: s2 } = this, idx = 1, next;
|
|
const results = [];
|
|
while (s2 < this.e) {
|
|
const added = this.start.plus(dur.mapUnits((x) => x * idx));
|
|
next = +added > +this.e ? this.e : added;
|
|
results.push(Interval.fromDateTimes(s2, next));
|
|
s2 = 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 {Array}
|
|
*/
|
|
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;
|
|
}
|
|
/**
|
|
* Returns true if this Interval fully contains the specified Interval, specifically if the intersect (of this Interval and the other Interval) is equal to the other Interval; false otherwise.
|
|
* @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 s2 = this.s > other.s ? this.s : other.s, e = this.e < other.e ? this.e : other.e;
|
|
if (s2 >= e) {
|
|
return null;
|
|
} else {
|
|
return Interval.fromDateTimes(s2, 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 s2 = this.s < other.s ? this.s : other.s, e = this.e > other.e ? this.e : other.e;
|
|
return Interval.fromDateTimes(s2, e);
|
|
}
|
|
/**
|
|
* Merge an array of Intervals into a equivalent minimal set of Intervals.
|
|
* Combines overlapping and adjacent Intervals.
|
|
* @param {Array} intervals
|
|
* @return {Array}
|
|
*/
|
|
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 {Array} intervals
|
|
* @return {Array}
|
|
*/
|
|
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 {Array}
|
|
*/
|
|
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 a string representation of this Interval appropriate for the REPL.
|
|
* @return {string}
|
|
*/
|
|
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
if (this.isValid) {
|
|
return `Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`;
|
|
} else {
|
|
return `Interval { Invalid, reason: ${this.invalidReason} }`;
|
|
}
|
|
}
|
|
/**
|
|
* Returns a localized string representing this Interval. Accepts the same options as the
|
|
* Intl.DateTimeFormat constructor and any presets defined by Luxon, such as
|
|
* {@link DateTime.DATE_FULL} or {@link DateTime.TIME_SIMPLE}. The exact behavior of this method
|
|
* is browser-specific, but in general it will return an appropriate representation of the
|
|
* Interval 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 {Object} [formatOpts=DateTime.DATE_SHORT] - Either a DateTime preset or
|
|
* Intl.DateTimeFormat constructor options.
|
|
* @param {Object} opts - Options to override the configuration of the start DateTime.
|
|
* @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(); //=> 11/7/2022 – 11/8/2022
|
|
* @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(DateTime.DATE_FULL); //=> November 7 – 8, 2022
|
|
* @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(DateTime.DATE_FULL, { locale: 'fr-FR' }); //=> 7–8 novembre 2022
|
|
* @example Interval.fromISO('2022-11-07T17:00Z/2022-11-07T19:00Z').toLocaleString(DateTime.TIME_SIMPLE); //=> 6:00 – 8:00 PM
|
|
* @example Interval.fromISO('2022-11-07T17:00Z/2022-11-07T19:00Z').toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> Mon, Nov 07, 6:00 – 8:00 p
|
|
* @return {string}
|
|
*/
|
|
toLocaleString(formatOpts = DATE_SHORT, opts = {}) {
|
|
return this.isValid ? Formatter.create(this.s.loc.clone(opts), formatOpts).formatInterval(this) : INVALID$1;
|
|
}
|
|
/**
|
|
* 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. **You may not want this.** See {@link Interval#toLocaleString} for a more flexible
|
|
* formatting tool.
|
|
* @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));
|
|
}
|
|
}
|
|
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.defaultZone) {
|
|
const proto = DateTime.now().setZone(zone).set({ month: 12 });
|
|
return !zone.isUniversal && 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.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.defaultZone);
|
|
}
|
|
/**
|
|
* Get the weekday on which the week starts according to the given locale.
|
|
* @param {Object} opts - options
|
|
* @param {string} [opts.locale] - the locale code
|
|
* @param {string} [opts.locObj=null] - an existing locale object to use
|
|
* @returns {number} the start of the week, 1 for Monday through 7 for Sunday
|
|
*/
|
|
static getStartOfWeek({ locale = null, locObj = null } = {}) {
|
|
return (locObj || Locale.create(locale)).getStartOfWeek();
|
|
}
|
|
/**
|
|
* Get the minimum number of days necessary in a week before it is considered part of the next year according
|
|
* to the given locale.
|
|
* @param {Object} opts - options
|
|
* @param {string} [opts.locale] - the locale code
|
|
* @param {string} [opts.locObj=null] - an existing locale object to use
|
|
* @returns {number}
|
|
*/
|
|
static getMinimumDaysInFirstWeek({ locale = null, locObj = null } = {}) {
|
|
return (locObj || Locale.create(locale)).getMinDaysInFirstWeek();
|
|
}
|
|
/**
|
|
* Get the weekdays, which are considered the weekend according to the given locale
|
|
* @param {Object} opts - options
|
|
* @param {string} [opts.locale] - the locale code
|
|
* @param {string} [opts.locObj=null] - an existing locale object to use
|
|
* @returns {number[]} an array of weekdays, 1 for Monday through 7 for Sunday
|
|
*/
|
|
static getWeekendWeekdays({ locale = null, locObj = null } = {}) {
|
|
return (locObj || Locale.create(locale)).getWeekendDays().slice();
|
|
}
|
|
/**
|
|
* 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 {Array}
|
|
*/
|
|
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 Info#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 {Array}
|
|
*/
|
|
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 {Array}
|
|
*/
|
|
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 Info#weekdays}
|
|
* @param {string} [length='long'] - the length of the month 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 {Array}
|
|
*/
|
|
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 {Array}
|
|
*/
|
|
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 {Array}
|
|
*/
|
|
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, relative time formatting support is not available. Use this function to figure out if that's the case.
|
|
* Keys:
|
|
* * `relative`: whether this environment supports relative time formatting
|
|
* * `localeWeek`: whether this environment supports different weekdays for the start of the week based on the locale
|
|
* @example Info.features() //=> { relative: false, localeWeek: true }
|
|
* @return {Object}
|
|
*/
|
|
static features() {
|
|
return { relative: hasRelative(), localeWeek: hasLocaleWeekInfo() };
|
|
}
|
|
}
|
|
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 + (b.year - a.year) * 4],
|
|
["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 = {};
|
|
const earlier = cursor;
|
|
let lowestOrder, highWater;
|
|
for (const [unit, differ] of differs) {
|
|
if (units.indexOf(unit) >= 0) {
|
|
lowestOrder = unit;
|
|
results[unit] = differ(cursor, later);
|
|
highWater = earlier.plus(results);
|
|
if (highWater > later) {
|
|
results[unit]--;
|
|
cursor = earlier.plus(results);
|
|
if (cursor > later) {
|
|
highWater = cursor;
|
|
results[unit]--;
|
|
cursor = earlier.plus(results);
|
|
}
|
|
} else {
|
|
cursor = highWater;
|
|
}
|
|
}
|
|
}
|
|
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(results, opts);
|
|
if (lowerOrderUnits.length > 0) {
|
|
return Duration.fromMillis(remainingMillis, opts).shiftTo(...lowerOrderUnits).plus(duration);
|
|
} else {
|
|
return duration;
|
|
}
|
|
}
|
|
const MISSING_FTP = "missing Intl.DateTimeFormat.formatToParts support";
|
|
function intUnit(regex, post = (i) => i) {
|
|
return { regex, deser: ([s2]) => post(parseDigits(s2)) };
|
|
}
|
|
const NBSP = String.fromCharCode(160);
|
|
const spaceOrNBSP = `[ ${NBSP}]`;
|
|
const spaceOrNBSPRegExp = new RegExp(spaceOrNBSP, "g");
|
|
function fixListRegex(s2) {
|
|
return s2.replace(/\./g, "\\.?").replace(spaceOrNBSPRegExp, spaceOrNBSP);
|
|
}
|
|
function stripInsensitivities(s2) {
|
|
return s2.replace(/\./g, "").replace(spaceOrNBSPRegExp, " ").toLowerCase();
|
|
}
|
|
function oneOf(strings, startIndex) {
|
|
if (strings === null) {
|
|
return null;
|
|
} else {
|
|
return {
|
|
regex: RegExp(strings.map(fixListRegex).join("|")),
|
|
deser: ([s2]) => strings.findIndex((i) => stripInsensitivities(s2) === stripInsensitivities(i)) + startIndex
|
|
};
|
|
}
|
|
}
|
|
function offset(regex, groups) {
|
|
return { regex, deser: ([, h2, m]) => signedOffset(h2, m), groups };
|
|
}
|
|
function simple(regex) {
|
|
return { regex, deser: ([s2]) => s2 };
|
|
}
|
|
function escapeToken(value) {
|
|
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: ([s2]) => s2, literal: true }), unitate = (t) => {
|
|
if (token.literal) {
|
|
return literal(t);
|
|
}
|
|
switch (t.val) {
|
|
// era
|
|
case "G":
|
|
return oneOf(loc.eras("short"), 0);
|
|
case "GG":
|
|
return oneOf(loc.eras("long"), 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), 1);
|
|
case "MMMM":
|
|
return oneOf(loc.months("long", true), 1);
|
|
case "L":
|
|
return intUnit(oneOrTwo);
|
|
case "LL":
|
|
return intUnit(two);
|
|
case "LLL":
|
|
return oneOf(loc.months("short", false), 1);
|
|
case "LLLL":
|
|
return oneOf(loc.months("long", 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);
|
|
case "uu":
|
|
return simple(oneOrTwo);
|
|
case "uuu":
|
|
return intUnit(one);
|
|
// 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), 1);
|
|
case "EEEE":
|
|
return oneOf(loc.weekdays("long", false), 1);
|
|
case "ccc":
|
|
return oneOf(loc.weekdays("short", true), 1);
|
|
case "cccc":
|
|
return oneOf(loc.weekdays("long", true), 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);
|
|
// this special-case "token" represents a place where a macro-token expanded into a white-space literal
|
|
// in this case we accept any non-newline white-space
|
|
case " ":
|
|
return simple(/[^\S\n\r]/);
|
|
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",
|
|
hour12: {
|
|
numeric: "h",
|
|
"2-digit": "hh"
|
|
},
|
|
hour24: {
|
|
numeric: "H",
|
|
"2-digit": "HH"
|
|
},
|
|
minute: {
|
|
numeric: "m",
|
|
"2-digit": "mm"
|
|
},
|
|
second: {
|
|
numeric: "s",
|
|
"2-digit": "ss"
|
|
},
|
|
timeZoneName: {
|
|
long: "ZZZZZ",
|
|
short: "ZZZ"
|
|
}
|
|
};
|
|
function tokenForPart(part, formatOpts, resolvedOpts) {
|
|
const { type, value } = part;
|
|
if (type === "literal") {
|
|
const isSpace = /^\s+$/.test(value);
|
|
return {
|
|
literal: !isSpace,
|
|
val: isSpace ? " " : value
|
|
};
|
|
}
|
|
const style2 = formatOpts[type];
|
|
let actualType = type;
|
|
if (type === "hour") {
|
|
if (formatOpts.hour12 != null) {
|
|
actualType = formatOpts.hour12 ? "hour12" : "hour24";
|
|
} else if (formatOpts.hourCycle != null) {
|
|
if (formatOpts.hourCycle === "h11" || formatOpts.hourCycle === "h12") {
|
|
actualType = "hour12";
|
|
} else {
|
|
actualType = "hour24";
|
|
}
|
|
} else {
|
|
actualType = resolvedOpts.hour12 ? "hour12" : "hour24";
|
|
}
|
|
}
|
|
let val = partTypeStyleToTokenVal[actualType];
|
|
if (typeof val === "object") {
|
|
val = val[style2];
|
|
}
|
|
if (val) {
|
|
return {
|
|
literal: false,
|
|
val
|
|
};
|
|
}
|
|
return void 0;
|
|
}
|
|
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 h2 = handlers[i], groups = h2.groups ? h2.groups + 1 : 1;
|
|
if (!h2.literal && h2.token) {
|
|
all[h2.token.val[0]] = h2.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 = null;
|
|
let specificOffset;
|
|
if (!isUndefined(matches.z)) {
|
|
zone = IANAZone.create(matches.z);
|
|
}
|
|
if (!isUndefined(matches.Z)) {
|
|
if (!zone) {
|
|
zone = new FixedOffsetZone(matches.Z);
|
|
}
|
|
specificOffset = matches.Z;
|
|
}
|
|
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, specificOffset];
|
|
}
|
|
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);
|
|
const tokens = formatOptsToTokens(formatOpts, locale);
|
|
if (tokens == null || tokens.includes(void 0)) {
|
|
return token;
|
|
}
|
|
return tokens;
|
|
}
|
|
function expandMacroTokens(tokens, locale) {
|
|
return Array.prototype.concat(...tokens.map((t) => maybeExpandMacroToken(t, locale)));
|
|
}
|
|
class TokenParser {
|
|
constructor(locale, format) {
|
|
this.locale = locale;
|
|
this.format = format;
|
|
this.tokens = expandMacroTokens(Formatter.parseFormat(format), locale);
|
|
this.units = this.tokens.map((t) => unitForToken(t, locale));
|
|
this.disqualifyingUnit = this.units.find((t) => t.invalidReason);
|
|
if (!this.disqualifyingUnit) {
|
|
const [regexString, handlers] = buildRegex(this.units);
|
|
this.regex = RegExp(regexString, "i");
|
|
this.handlers = handlers;
|
|
}
|
|
}
|
|
explainFromTokens(input) {
|
|
if (!this.isValid) {
|
|
return { input, tokens: this.tokens, invalidReason: this.invalidReason };
|
|
} else {
|
|
const [rawMatches, matches] = match(input, this.regex, this.handlers), [result, zone, specificOffset] = matches ? dateTimeFromMatches(matches) : [null, null, void 0];
|
|
if (hasOwnProperty(matches, "a") && hasOwnProperty(matches, "H")) {
|
|
throw new ConflictingSpecificationError(
|
|
"Can't include meridiem when specifying 24-hour format"
|
|
);
|
|
}
|
|
return {
|
|
input,
|
|
tokens: this.tokens,
|
|
regex: this.regex,
|
|
rawMatches,
|
|
matches,
|
|
result,
|
|
zone,
|
|
specificOffset
|
|
};
|
|
}
|
|
}
|
|
get isValid() {
|
|
return !this.disqualifyingUnit;
|
|
}
|
|
get invalidReason() {
|
|
return this.disqualifyingUnit ? this.disqualifyingUnit.invalidReason : null;
|
|
}
|
|
}
|
|
function explainFromTokens(locale, input, format) {
|
|
const parser = new TokenParser(locale, format);
|
|
return parser.explainFromTokens(input);
|
|
}
|
|
function parseFromTokens(locale, input, format) {
|
|
const { result, zone, specificOffset, invalidReason } = explainFromTokens(locale, input, format);
|
|
return [result, zone, specificOffset, invalidReason];
|
|
}
|
|
function formatOptsToTokens(formatOpts, locale) {
|
|
if (!formatOpts) {
|
|
return null;
|
|
}
|
|
const formatter = Formatter.create(locale, formatOpts);
|
|
const df = formatter.dtFormatter(getDummyDateTime());
|
|
const parts = df.formatToParts();
|
|
const resolvedOpts = df.resolvedOptions();
|
|
return parts.map((p) => tokenForPart(p, formatOpts, resolvedOpts));
|
|
}
|
|
const INVALID = "Invalid DateTime";
|
|
const MAX_DATE = 864e13;
|
|
function unsupportedZone(zone) {
|
|
return new Invalid("unsupported zone", `the zone "${zone.name}" is not supported`);
|
|
}
|
|
function possiblyCachedWeekData(dt) {
|
|
if (dt.weekData === null) {
|
|
dt.weekData = gregorianToWeek(dt.c);
|
|
}
|
|
return dt.weekData;
|
|
}
|
|
function possiblyCachedLocalWeekData(dt) {
|
|
if (dt.localWeekData === null) {
|
|
dt.localWeekData = gregorianToWeek(
|
|
dt.c,
|
|
dt.loc.getMinDaysInFirstWeek(),
|
|
dt.loc.getStartOfWeek()
|
|
);
|
|
}
|
|
return dt.localWeekData;
|
|
}
|
|
function clone(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({ ...current, ...alts, old: current });
|
|
}
|
|
function fixOffset(localTS, o, tz) {
|
|
let utcGuess = localTS - o * 60 * 1e3;
|
|
const o2 = tz.offset(utcGuess);
|
|
if (o === o2) {
|
|
return [utcGuess, o];
|
|
}
|
|
utcGuess -= (o2 - o) * 60 * 1e3;
|
|
const o3 = tz.offset(utcGuess);
|
|
if (o2 === o3) {
|
|
return [utcGuess, o2];
|
|
}
|
|
return [localTS - Math.min(o2, o3) * 60 * 1e3, Math.max(o2, o3)];
|
|
}
|
|
function tsToObj(ts, offset2) {
|
|
ts += offset2 * 60 * 1e3;
|
|
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()
|
|
};
|
|
}
|
|
function objToTS(obj, offset2, zone) {
|
|
return fixOffset(objToLocalTS(obj), offset2, zone);
|
|
}
|
|
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, c2 = {
|
|
...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(c2);
|
|
let [ts, o] = fixOffset(localTS, oPre, inst.zone);
|
|
if (millisToAdd !== 0) {
|
|
ts += millisToAdd;
|
|
o = inst.zone.offset(ts);
|
|
}
|
|
return { ts, o };
|
|
}
|
|
function parseDataToDateTime(parsed, parsedZone, opts, format, text, specificOffset) {
|
|
const { setZone, zone } = opts;
|
|
if (parsed && Object.keys(parsed).length !== 0 || parsedZone) {
|
|
const interpretationZone = parsedZone || zone, inst = DateTime.fromObject(parsed, {
|
|
...opts,
|
|
zone: interpretationZone,
|
|
specificOffset
|
|
});
|
|
return setZone ? inst : inst.setZone(zone);
|
|
} else {
|
|
return DateTime.invalid(
|
|
new Invalid("unparsable", `the input "${text}" can't be parsed as ${format}`)
|
|
);
|
|
}
|
|
}
|
|
function toTechFormat(dt, format, allowZ = true) {
|
|
return dt.isValid ? Formatter.create(Locale.create("en-US"), {
|
|
allowZ,
|
|
forceSimple: true
|
|
}).formatDateTimeFromString(dt, format) : null;
|
|
}
|
|
function toISODate(o, extended) {
|
|
const longFormat = o.c.year > 9999 || o.c.year < 0;
|
|
let c2 = "";
|
|
if (longFormat && o.c.year >= 0) c2 += "+";
|
|
c2 += padStart(o.c.year, longFormat ? 6 : 4);
|
|
if (extended) {
|
|
c2 += "-";
|
|
c2 += padStart(o.c.month);
|
|
c2 += "-";
|
|
c2 += padStart(o.c.day);
|
|
} else {
|
|
c2 += padStart(o.c.month);
|
|
c2 += padStart(o.c.day);
|
|
}
|
|
return c2;
|
|
}
|
|
function toISOTime(o, extended, suppressSeconds, suppressMilliseconds, includeOffset, extendedZone) {
|
|
let c2 = padStart(o.c.hour);
|
|
if (extended) {
|
|
c2 += ":";
|
|
c2 += padStart(o.c.minute);
|
|
if (o.c.millisecond !== 0 || o.c.second !== 0 || !suppressSeconds) {
|
|
c2 += ":";
|
|
}
|
|
} else {
|
|
c2 += padStart(o.c.minute);
|
|
}
|
|
if (o.c.millisecond !== 0 || o.c.second !== 0 || !suppressSeconds) {
|
|
c2 += padStart(o.c.second);
|
|
if (o.c.millisecond !== 0 || !suppressMilliseconds) {
|
|
c2 += ".";
|
|
c2 += padStart(o.c.millisecond, 3);
|
|
}
|
|
}
|
|
if (includeOffset) {
|
|
if (o.isOffsetFixed && o.offset === 0 && !extendedZone) {
|
|
c2 += "Z";
|
|
} else if (o.o < 0) {
|
|
c2 += "-";
|
|
c2 += padStart(Math.trunc(-o.o / 60));
|
|
c2 += ":";
|
|
c2 += padStart(Math.trunc(-o.o % 60));
|
|
} else {
|
|
c2 += "+";
|
|
c2 += padStart(Math.trunc(o.o / 60));
|
|
c2 += ":";
|
|
c2 += padStart(Math.trunc(o.o % 60));
|
|
}
|
|
}
|
|
if (extendedZone) {
|
|
c2 += "[" + o.zone.ianaName + "]";
|
|
}
|
|
return c2;
|
|
}
|
|
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
|
|
};
|
|
const orderedUnits = ["year", "month", "day", "hour", "minute", "second", "millisecond"], orderedWeekUnits = [
|
|
"weekYear",
|
|
"weekNumber",
|
|
"weekday",
|
|
"hour",
|
|
"minute",
|
|
"second",
|
|
"millisecond"
|
|
], orderedOrdinalUnits = ["year", "ordinal", "hour", "minute", "second", "millisecond"];
|
|
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;
|
|
}
|
|
function normalizeUnitWithLocalWeeks(unit) {
|
|
switch (unit.toLowerCase()) {
|
|
case "localweekday":
|
|
case "localweekdays":
|
|
return "localWeekday";
|
|
case "localweeknumber":
|
|
case "localweeknumbers":
|
|
return "localWeekNumber";
|
|
case "localweekyear":
|
|
case "localweekyears":
|
|
return "localWeekYear";
|
|
default:
|
|
return normalizeUnit(unit);
|
|
}
|
|
}
|
|
function guessOffsetForZone(zone) {
|
|
if (!zoneOffsetGuessCache[zone]) {
|
|
if (zoneOffsetTs === void 0) {
|
|
zoneOffsetTs = Settings.now();
|
|
}
|
|
zoneOffsetGuessCache[zone] = zone.offset(zoneOffsetTs);
|
|
}
|
|
return zoneOffsetGuessCache[zone];
|
|
}
|
|
function quickDT(obj, opts) {
|
|
const zone = normalizeZone(opts.zone, Settings.defaultZone);
|
|
if (!zone.isValid) {
|
|
return DateTime.invalid(unsupportedZone(zone));
|
|
}
|
|
const loc = Locale.fromObject(opts);
|
|
let ts, o;
|
|
if (!isUndefined(obj.year)) {
|
|
for (const u of orderedUnits) {
|
|
if (isUndefined(obj[u])) {
|
|
obj[u] = defaultUnitValues[u];
|
|
}
|
|
}
|
|
const invalid = hasInvalidGregorianData(obj) || hasInvalidTimeData(obj);
|
|
if (invalid) {
|
|
return DateTime.invalid(invalid);
|
|
}
|
|
const offsetProvis = guessOffsetForZone(zone);
|
|
[ts, o] = objToTS(obj, offsetProvis, zone);
|
|
} else {
|
|
ts = Settings.now();
|
|
}
|
|
return new DateTime({ ts, zone, loc, o });
|
|
}
|
|
function diffRelative(start, end, opts) {
|
|
const round = isUndefined(opts.round) ? true : opts.round, format = (c2, unit) => {
|
|
c2 = roundTo(c2, round || opts.calendary ? 0 : 2, true);
|
|
const formatter = end.loc.clone(opts).relFormatter(opts);
|
|
return formatter.format(c2, 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]);
|
|
}
|
|
function lastOpts(argList) {
|
|
let opts = {}, args;
|
|
if (argList.length > 0 && typeof argList[argList.length - 1] === "object") {
|
|
opts = argList[argList.length - 1];
|
|
args = Array.from(argList).slice(0, argList.length - 1);
|
|
} else {
|
|
args = Array.from(argList);
|
|
}
|
|
return [opts, args];
|
|
}
|
|
let zoneOffsetTs;
|
|
let zoneOffsetGuessCache = {};
|
|
class DateTime {
|
|
/**
|
|
* @access private
|
|
*/
|
|
constructor(config) {
|
|
const zone = config.zone || Settings.defaultZone;
|
|
let invalid = config.invalid || (Number.isNaN(config.ts) ? new Invalid("invalid input") : null) || (!zone.isValid ? unsupportedZone(zone) : null);
|
|
this.ts = isUndefined(config.ts) ? Settings.now() : config.ts;
|
|
let c2 = null, o = null;
|
|
if (!invalid) {
|
|
const unchanged = config.old && config.old.ts === this.ts && config.old.zone.equals(zone);
|
|
if (unchanged) {
|
|
[c2, o] = [config.old.c, config.old.o];
|
|
} else {
|
|
const ot = isNumber(config.o) && !config.old ? config.o : zone.offset(this.ts);
|
|
c2 = tsToObj(this.ts, ot);
|
|
invalid = Number.isNaN(c2.year) ? new Invalid("invalid input") : null;
|
|
c2 = invalid ? null : c2;
|
|
o = invalid ? null : ot;
|
|
}
|
|
}
|
|
this._zone = zone;
|
|
this.loc = config.loc || Locale.create();
|
|
this.invalid = invalid;
|
|
this.weekData = null;
|
|
this.localWeekData = null;
|
|
this.c = c2;
|
|
this.o = o;
|
|
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({ zone: "America/New_York" }) //~> now, in US east coast time
|
|
* @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, { locale: "fr" }) //~> 2017-03-12T00:00:00, with a French locale
|
|
* @example DateTime.local(2017, 3, 12, 5) //~> 2017-03-12T05:00:00
|
|
* @example DateTime.local(2017, 3, 12, 5, { zone: "utc" }) //~> 2017-03-12T05:00:00, in UTC
|
|
* @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() {
|
|
const [opts, args] = lastOpts(arguments), [year, month, day, hour, minute, second, millisecond] = args;
|
|
return quickDT({ year, month, day, hour, minute, second, millisecond }, opts);
|
|
}
|
|
/**
|
|
* 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
|
|
* @param {Object} options - configuration options for the DateTime
|
|
* @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
|
|
* @param {string} [options.weekSettings] - the week settings to set on the resulting DateTime instance
|
|
* @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, { locale: "fr" }) //~> 2017-03-12T05:45:00Z with a French locale
|
|
* @example DateTime.utc(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10Z
|
|
* @example DateTime.utc(2017, 3, 12, 5, 45, 10, 765, { locale: "fr" }) //~> 2017-03-12T05:45:10.765Z with a French locale
|
|
* @return {DateTime}
|
|
*/
|
|
static utc() {
|
|
const [opts, args] = lastOpts(arguments), [year, month, day, hour, minute, second, millisecond] = args;
|
|
opts.zone = FixedOffsetZone.utcInstance;
|
|
return quickDT({ year, month, day, hour, minute, second, millisecond }, opts);
|
|
}
|
|
/**
|
|
* 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.defaultZone);
|
|
if (!zoneToUse.isValid) {
|
|
return DateTime.invalid(unsupportedZone(zoneToUse));
|
|
}
|
|
return new DateTime({
|
|
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
|
|
* @param {string} options.weekSettings - the week settings 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 < -864e13 || milliseconds > MAX_DATE) {
|
|
return DateTime.invalid("Timestamp out of range");
|
|
} else {
|
|
return new DateTime({
|
|
ts: milliseconds,
|
|
zone: normalizeZone(options.zone, Settings.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
|
|
* @param {string} options.weekSettings - the week settings 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 * 1e3,
|
|
zone: normalizeZone(options.zone, Settings.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.localWeekYear - a week year, according to the locale
|
|
* @param {number} obj.localWeekNumber - a week number, between 1 and 52 or 53, depending on the year, according to the locale
|
|
* @param {number} obj.localWeekday - a weekday, 1-7, where 1 is the first and 7 is the last day of the week, according to the locale
|
|
* @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 {Object} opts - options for creating this DateTime
|
|
* @param {string|Zone} [opts.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} [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
|
|
* @param {string} opts.weekSettings - the week settings 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'
|
|
* @example DateTime.fromObject({ localWeekYear: 2022, localWeekNumber: 1, localWeekday: 1 }, { locale: "en-US" }).toISODate() //=> '2021-12-26'
|
|
* @return {DateTime}
|
|
*/
|
|
static fromObject(obj, opts = {}) {
|
|
obj = obj || {};
|
|
const zoneToUse = normalizeZone(opts.zone, Settings.defaultZone);
|
|
if (!zoneToUse.isValid) {
|
|
return DateTime.invalid(unsupportedZone(zoneToUse));
|
|
}
|
|
const loc = Locale.fromObject(opts);
|
|
const normalized = normalizeObject(obj, normalizeUnitWithLocalWeeks);
|
|
const { minDaysInFirstWeek, startOfWeek } = usesLocalWeekValues(normalized, loc);
|
|
const tsNow = Settings.now(), offsetProvis = !isUndefined(opts.specificOffset) ? opts.specificOffset : zoneToUse.offset(tsNow), 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");
|
|
}
|
|
const useWeekData = definiteWeekDef || normalized.weekday && !containsGregor;
|
|
let units, defaultValues, objNow = tsToObj(tsNow, offsetProvis);
|
|
if (useWeekData) {
|
|
units = orderedWeekUnits;
|
|
defaultValues = defaultWeekUnitValues;
|
|
objNow = gregorianToWeek(objNow, minDaysInFirstWeek, startOfWeek);
|
|
} else if (containsOrdinal) {
|
|
units = orderedOrdinalUnits;
|
|
defaultValues = defaultOrdinalUnitValues;
|
|
objNow = gregorianToOrdinal(objNow);
|
|
} else {
|
|
units = orderedUnits;
|
|
defaultValues = defaultUnitValues;
|
|
}
|
|
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];
|
|
}
|
|
}
|
|
const higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized), invalid = higherOrderInvalid || hasInvalidTimeData(normalized);
|
|
if (invalid) {
|
|
return DateTime.invalid(invalid);
|
|
}
|
|
const gregorian = useWeekData ? weekToGregorian(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? ordinalToGregorian(normalized) : normalized, [tsFinal, offsetFinal] = objToTS(gregorian, offsetProvis, zoneToUse), inst = new DateTime({
|
|
ts: tsFinal,
|
|
zone: zoneToUse,
|
|
o: offsetFinal,
|
|
loc
|
|
});
|
|
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()}`
|
|
);
|
|
}
|
|
if (!inst.isValid) {
|
|
return DateTime.invalid(inst.invalid);
|
|
}
|
|
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
|
|
* @param {string} [opts.weekSettings] - the week settings 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
|
|
* @param {string} opts.weekSettings - the week settings 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
|
|
* @param {string} opts.weekSettings - the week settings 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. For a table of tokens and their interpretations, see [here](https://moment.github.io/luxon/#/parsing?id=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.weekSettings - the week settings to set on the resulting DateTime instance
|
|
* @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, specificOffset, invalid] = parseFromTokens(localeToUse, text, fmt);
|
|
if (invalid) {
|
|
return DateTime.invalid(invalid);
|
|
} else {
|
|
return parseDataToDateTime(vals, parsedZone, opts, `format ${fmt}`, text, specificOffset);
|
|
}
|
|
}
|
|
/**
|
|
* @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.weekSettings - the week settings to set on the resulting DateTime instance
|
|
* @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.throwOnInvalid) {
|
|
throw new InvalidDateTimeError(invalid);
|
|
} else {
|
|
return new DateTime({ invalid });
|
|
}
|
|
}
|
|
/**
|
|
* Check if an object is an instance of DateTime. Works across context boundaries
|
|
* @param {object} o
|
|
* @return {boolean}
|
|
*/
|
|
static isDateTime(o) {
|
|
return o && o.isLuxonDateTime || false;
|
|
}
|
|
/**
|
|
* Produce the format string for a set of options
|
|
* @param formatOpts
|
|
* @param localeOpts
|
|
* @returns {string}
|
|
*/
|
|
static parseFormatForOpts(formatOpts, localeOpts = {}) {
|
|
const tokenList = formatOptsToTokens(formatOpts, Locale.fromObject(localeOpts));
|
|
return !tokenList ? null : tokenList.map((t) => t ? t.val : null).join("");
|
|
}
|
|
/**
|
|
* Produce the the fully expanded format token for the locale
|
|
* Does NOT quote characters, so quoted tokens will not round trip correctly
|
|
* @param fmt
|
|
* @param localeOpts
|
|
* @returns {string}
|
|
*/
|
|
static expandFormat(fmt, localeOpts = {}) {
|
|
const expanded = expandMacroTokens(Formatter.parseFormat(fmt), Locale.fromObject(localeOpts));
|
|
return expanded.map((t) => t.val).join("");
|
|
}
|
|
static resetCache() {
|
|
zoneOffsetTs = void 0;
|
|
zoneOffsetGuessCache = {};
|
|
}
|
|
// 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;
|
|
}
|
|
/**
|
|
* Returns true if this date is on a weekend according to the locale, false otherwise
|
|
* @returns {boolean}
|
|
*/
|
|
get isWeekend() {
|
|
return this.isValid && this.loc.getWeekendDays().includes(this.weekday);
|
|
}
|
|
/**
|
|
* Get the day of the week according to the locale.
|
|
* 1 is the first day of the week and 7 is the last day of the week.
|
|
* If the locale assigns Sunday as the first day of the week, then a date which is a Sunday will return 1,
|
|
* @returns {number}
|
|
*/
|
|
get localWeekday() {
|
|
return this.isValid ? possiblyCachedLocalWeekData(this).weekday : NaN;
|
|
}
|
|
/**
|
|
* Get the week number of the week year according to the locale. Different locales assign week numbers differently,
|
|
* because the week can start on different days of the week (see localWeekday) and because a different number of days
|
|
* is required for a week to count as the first week of a year.
|
|
* @returns {number}
|
|
*/
|
|
get localWeekNumber() {
|
|
return this.isValid ? possiblyCachedLocalWeekData(this).weekNumber : NaN;
|
|
}
|
|
/**
|
|
* Get the week year according to the locale. Different locales assign week numbers (and therefor week years)
|
|
* differently, see localWeekNumber.
|
|
* @returns {number}
|
|
*/
|
|
get localWeekYear() {
|
|
return this.isValid ? possiblyCachedLocalWeekData(this).weekYear : 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.isUniversal : 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, day: 1 }).offset || this.offset > this.set({ month: 5 }).offset;
|
|
}
|
|
}
|
|
/**
|
|
* Get those DateTimes which have the same local time as this DateTime, but a different offset from UTC
|
|
* in this DateTime's zone. During DST changes local time can be ambiguous, for example
|
|
* `2023-10-29T02:30:00` in `Europe/Berlin` can have offset `+01:00` or `+02:00`.
|
|
* This method will return both possible DateTimes if this DateTime's local time is ambiguous.
|
|
* @returns {DateTime[]}
|
|
*/
|
|
getPossibleOffsets() {
|
|
if (!this.isValid || this.isOffsetFixed) {
|
|
return [this];
|
|
}
|
|
const dayMs = 864e5;
|
|
const minuteMs = 6e4;
|
|
const localTS = objToLocalTS(this.c);
|
|
const oEarlier = this.zone.offset(localTS - dayMs);
|
|
const oLater = this.zone.offset(localTS + dayMs);
|
|
const o1 = this.zone.offset(localTS - oEarlier * minuteMs);
|
|
const o2 = this.zone.offset(localTS - oLater * minuteMs);
|
|
if (o1 === o2) {
|
|
return [this];
|
|
}
|
|
const ts1 = localTS - o1 * minuteMs;
|
|
const ts2 = localTS - o2 * minuteMs;
|
|
const c1 = tsToObj(ts1, o1);
|
|
const c2 = tsToObj(ts2, o2);
|
|
if (c1.hour === c2.hour && c1.minute === c2.minute && c1.second === c2.second && c1.millisecond === c2.millisecond) {
|
|
return [clone(this, { ts: ts1 }), clone(this, { ts: ts2 })];
|
|
}
|
|
return [this];
|
|
}
|
|
/**
|
|
* 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 number of weeks in this DateTime's local week year
|
|
* @example DateTime.local(2020, 6, {locale: 'en-US'}).weeksInLocalWeekYear //=> 52
|
|
* @example DateTime.local(2020, 6, {locale: 'de-DE'}).weeksInLocalWeekYear //=> 53
|
|
* @type {number}
|
|
*/
|
|
get weeksInLocalWeekYear() {
|
|
return this.isValid ? weeksInWeekYear(
|
|
this.localWeekYear,
|
|
this.loc.getMinDaysInFirstWeek(),
|
|
this.loc.getStartOfWeek()
|
|
) : 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}
|
|
*/
|
|
resolvedLocaleOptions(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 DateTime#setZone}('utc')
|
|
* @param {number} [offset=0] - optionally, an offset from UTC in minutes
|
|
* @param {Object} [opts={}] - options to pass to `setZone()`
|
|
* @return {DateTime}
|
|
*/
|
|
toUTC(offset2 = 0, opts = {}) {
|
|
return this.setZone(FixedOffsetZone.instance(offset2), 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.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 DateTime#plus}. You may wish to use {@link DateTime#toLocal} and {@link DateTime#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 DateTime#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.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(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(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 DateTime#reconfigure} and {@link DateTime#setZone}.
|
|
*
|
|
* This method also supports setting locale-based week units, i.e. `localWeekday`, `localWeekNumber` and `localWeekYear`.
|
|
* They cannot be mixed with ISO-week units like `weekday`.
|
|
* @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, normalizeUnitWithLocalWeeks);
|
|
const { minDaysInFirstWeek, startOfWeek } = usesLocalWeekValues(normalized, this.loc);
|
|
const 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(
|
|
{ ...gregorianToWeek(this.c, minDaysInFirstWeek, startOfWeek), ...normalized },
|
|
minDaysInFirstWeek,
|
|
startOfWeek
|
|
);
|
|
} else if (!isUndefined(normalized.ordinal)) {
|
|
mixed = ordinalToGregorian({ ...gregorianToOrdinal(this.c), ...normalized });
|
|
} else {
|
|
mixed = { ...this.toObject(), ...normalized };
|
|
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(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 = Duration.fromDurationLike(duration);
|
|
return clone(this, adjustTime(this, dur));
|
|
}
|
|
/**
|
|
* Subtract a period of time to this DateTime and return the resulting DateTime
|
|
* See {@link DateTime#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 = Duration.fromDurationLike(duration).negate();
|
|
return clone(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'.
|
|
* @param {Object} opts - options
|
|
* @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week
|
|
* @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, { useLocaleWeeks = false } = {}) {
|
|
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;
|
|
}
|
|
if (normalizedUnit === "weeks") {
|
|
if (useLocaleWeeks) {
|
|
const startOfWeek = this.loc.getStartOfWeek();
|
|
const { weekday } = this;
|
|
if (weekday < startOfWeek) {
|
|
o.weekNumber = this.weekNumber - 1;
|
|
}
|
|
o.weekday = startOfWeek;
|
|
} else {
|
|
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'.
|
|
* @param {Object} opts - options
|
|
* @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week
|
|
* @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, opts) {
|
|
return this.isValid ? this.plus({ [unit]: 1 }).startOf(unit, opts).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 DateTime#toLocaleString} for a more flexible formatting tool. For a table of tokens and their interpretations, see [here](https://moment.github.io/luxon/#/formatting?id=table-of-tokens).
|
|
* Defaults to en-US if no locale has been specified, regardless of the system's locale.
|
|
* @param {string} fmt - the format string
|
|
* @param {Object} opts - opts to override the configuration options on this DateTime
|
|
* @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;
|
|
}
|
|
/**
|
|
* 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 formatOpts {Object} - Intl.DateTimeFormat constructor options and configuration options
|
|
* @param {Object} opts - opts to override the configuration options on this DateTime
|
|
* @example DateTime.now().toLocaleString(); //=> 4/20/2017
|
|
* @example DateTime.now().setLocale('en-gb').toLocaleString(); //=> '20/04/2017'
|
|
* @example DateTime.now().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017'
|
|
* @example DateTime.now().toLocaleString(DateTime.DATE_FULL, { locale: 'fr' }); //=> '28 août 2022'
|
|
* @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', hourCycle: 'h23' }); //=> '11:32'
|
|
* @return {string}
|
|
*/
|
|
toLocaleString(formatOpts = DATE_SHORT, opts = {}) {
|
|
return this.isValid ? Formatter.create(this.loc.clone(opts), formatOpts).formatDateTime(this) : INVALID;
|
|
}
|
|
/**
|
|
* 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 {boolean} [opts.extendedZone=false] - add the time zone format extension
|
|
* @param {string} [opts.format='extended'] - choose between the basic and extended format
|
|
* @example DateTime.utc(1983, 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({
|
|
format = "extended",
|
|
suppressSeconds = false,
|
|
suppressMilliseconds = false,
|
|
includeOffset = true,
|
|
extendedZone = false
|
|
} = {}) {
|
|
if (!this.isValid) {
|
|
return null;
|
|
}
|
|
const ext = format === "extended";
|
|
let c2 = toISODate(this, ext);
|
|
c2 += "T";
|
|
c2 += toISOTime(this, ext, suppressSeconds, suppressMilliseconds, includeOffset, extendedZone);
|
|
return c2;
|
|
}
|
|
/**
|
|
* 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" } = {}) {
|
|
if (!this.isValid) {
|
|
return null;
|
|
}
|
|
return toISODate(this, format === "extended");
|
|
}
|
|
/**
|
|
* 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.extendedZone=true] - add the time zone format extension
|
|
* @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,
|
|
extendedZone = false,
|
|
format = "extended"
|
|
} = {}) {
|
|
if (!this.isValid) {
|
|
return null;
|
|
}
|
|
let c2 = includePrefix ? "T" : "";
|
|
return c2 + toISOTime(
|
|
this,
|
|
format === "extended",
|
|
suppressSeconds,
|
|
suppressMilliseconds,
|
|
includeOffset,
|
|
extendedZone
|
|
);
|
|
}
|
|
/**
|
|
* Returns an RFC 2822-compatible string representation of this DateTime
|
|
* @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. The output is always expressed in GMT.
|
|
* 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() {
|
|
if (!this.isValid) {
|
|
return null;
|
|
}
|
|
return toISODate(this, true);
|
|
}
|
|
/**
|
|
* 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'
|
|
* @param {boolean} [opts.includeOffsetSpace=true] - include the space between the time and the offset, such as '05:15:16.345 -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, includeOffsetSpace = true } = {}) {
|
|
let fmt = "HH:mm:ss.SSS";
|
|
if (includeZone || includeOffset) {
|
|
if (includeOffsetSpace) {
|
|
fmt += " ";
|
|
}
|
|
if (includeZone) {
|
|
fmt += "z";
|
|
} else if (includeOffset) {
|
|
fmt += "ZZ";
|
|
}
|
|
}
|
|
return toTechFormat(this, fmt, 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'
|
|
* @param {boolean} [opts.includeOffsetSpace=true] - include the space between the time and the offset, such as '05:15:16.345 -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;
|
|
}
|
|
/**
|
|
* Returns a string representation of this DateTime appropriate for the REPL.
|
|
* @return {string}
|
|
*/
|
|
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
if (this.isValid) {
|
|
return `DateTime { ts: ${this.toISO()}, zone: ${this.zone.name}, locale: ${this.locale} }`;
|
|
} else {
|
|
return `DateTime { Invalid, reason: ${this.invalidReason} }`;
|
|
}
|
|
}
|
|
/**
|
|
* Returns the epoch milliseconds of this DateTime. Alias of {@link DateTime#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 / 1e3 : NaN;
|
|
}
|
|
/**
|
|
* Returns the epoch seconds (as a whole number) of this DateTime.
|
|
* @return {number}
|
|
*/
|
|
toUnixInteger() {
|
|
return this.isValid ? Math.floor(this.ts / 1e3) : 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 = { ...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("created by diffing an invalid DateTime");
|
|
}
|
|
const durOpts = { 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 DateTime#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 DateTime#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
|
|
* @param {Object} opts - options
|
|
* @param {boolean} [opts.useLocaleWeeks=false] - If true, use weeks based on the locale, i.e. use the locale-dependent start of the week; only the locale of this DateTime is used
|
|
* @example DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
|
|
* @return {boolean}
|
|
*/
|
|
hasSame(otherDateTime, unit, opts) {
|
|
if (!this.isValid) return false;
|
|
const inputMs = otherDateTime.valueOf();
|
|
const adjustedToZone = this.setZone(otherDateTime.zone, { keepLocalTime: true });
|
|
return adjustedToZone.startOf(unit, opts) <= inputMs && inputMs <= adjustedToZone.endOf(unit, opts);
|
|
}
|
|
/**
|
|
* Equality check
|
|
* Two DateTimes are equal if and only if 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 = void 0;
|
|
}
|
|
return diffRelative(base, this.plus(padding), {
|
|
...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, {
|
|
...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);
|
|
}
|
|
/**
|
|
* Build a parser for `fmt` using the given locale. This parser can be passed
|
|
* to {@link DateTime.fromFormatParser} to a parse a date in this format. This
|
|
* can be used to optimize cases where many dates need to be parsed in a
|
|
* specific format.
|
|
*
|
|
* @param {String} fmt - the format the string is expected to be in (see
|
|
* description)
|
|
* @param {Object} options - options used to set locale and numberingSystem
|
|
* for parser
|
|
* @returns {TokenParser} - opaque object to be used
|
|
*/
|
|
static buildFormatParser(fmt, options = {}) {
|
|
const { locale = null, numberingSystem = null } = options, localeToUse = Locale.fromOpts({
|
|
locale,
|
|
numberingSystem,
|
|
defaultToEN: true
|
|
});
|
|
return new TokenParser(localeToUse, fmt);
|
|
}
|
|
/**
|
|
* Create a DateTime from an input string and format parser.
|
|
*
|
|
* The format parser must have been created with the same locale as this call.
|
|
*
|
|
* @param {String} text - the string to parse
|
|
* @param {TokenParser} formatParser - parser from {@link DateTime.buildFormatParser}
|
|
* @param {Object} opts - options taken by fromFormat()
|
|
* @returns {DateTime}
|
|
*/
|
|
static fromFormatParser(text, formatParser, opts = {}) {
|
|
if (isUndefined(text) || isUndefined(formatParser)) {
|
|
throw new InvalidArgumentError(
|
|
"fromFormatParser requires an input string and a format parser"
|
|
);
|
|
}
|
|
const { locale = null, numberingSystem = null } = opts, localeToUse = Locale.fromOpts({
|
|
locale,
|
|
numberingSystem,
|
|
defaultToEN: true
|
|
});
|
|
if (!localeToUse.equals(formatParser.locale)) {
|
|
throw new InvalidArgumentError(
|
|
`fromFormatParser called with a locale of ${localeToUse}, but the format parser was created for ${formatParser.locale}`
|
|
);
|
|
}
|
|
const { result, zone, specificOffset, invalidReason } = formatParser.explainFromTokens(text);
|
|
if (invalidReason) {
|
|
return DateTime.invalid(invalidReason);
|
|
} else {
|
|
return parseDataToDateTime(
|
|
result,
|
|
zone,
|
|
opts,
|
|
`format ${formatParser.format}`,
|
|
text,
|
|
specificOffset
|
|
);
|
|
}
|
|
}
|
|
// FORMAT PRESETS
|
|
/**
|
|
* {@link DateTime#toLocaleString} format like 10/14/1983
|
|
* @type {Object}
|
|
*/
|
|
static get DATE_SHORT() {
|
|
return DATE_SHORT;
|
|
}
|
|
/**
|
|
* {@link DateTime#toLocaleString} format like 'Oct 14, 1983'
|
|
* @type {Object}
|
|
*/
|
|
static get DATE_MED() {
|
|
return DATE_MED;
|
|
}
|
|
/**
|
|
* {@link DateTime#toLocaleString} format like 'Fri, Oct 14, 1983'
|
|
* @type {Object}
|
|
*/
|
|
static get DATE_MED_WITH_WEEKDAY() {
|
|
return DATE_MED_WITH_WEEKDAY;
|
|
}
|
|
/**
|
|
* {@link DateTime#toLocaleString} format like 'October 14, 1983'
|
|
* @type {Object}
|
|
*/
|
|
static get DATE_FULL() {
|
|
return DATE_FULL;
|
|
}
|
|
/**
|
|
* {@link DateTime#toLocaleString} format like 'Tuesday, October 14, 1983'
|
|
* @type {Object}
|
|
*/
|
|
static get DATE_HUGE() {
|
|
return DATE_HUGE;
|
|
}
|
|
/**
|
|
* {@link DateTime#toLocaleString} format like '09:30 AM'. Only 12-hour if the locale is.
|
|
* @type {Object}
|
|
*/
|
|
static get TIME_SIMPLE() {
|
|
return TIME_SIMPLE;
|
|
}
|
|
/**
|
|
* {@link DateTime#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 DateTime#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 DateTime#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 DateTime#toLocaleString} format like '09:30', always 24-hour.
|
|
* @type {Object}
|
|
*/
|
|
static get TIME_24_SIMPLE() {
|
|
return TIME_24_SIMPLE;
|
|
}
|
|
/**
|
|
* {@link DateTime#toLocaleString} format like '09:30:23', always 24-hour.
|
|
* @type {Object}
|
|
*/
|
|
static get TIME_24_WITH_SECONDS() {
|
|
return TIME_24_WITH_SECONDS;
|
|
}
|
|
/**
|
|
* {@link DateTime#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 DateTime#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 DateTime#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 DateTime#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 DateTime#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 DateTime#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 DateTime#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 DateTime#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 DateTime#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 DateTime#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 DateTime#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;
|
|
}
|
|
}
|
|
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 Refresh = {};
|
|
var hasRequiredRefresh;
|
|
function requireRefresh() {
|
|
if (hasRequiredRefresh) return Refresh;
|
|
hasRequiredRefresh = 1;
|
|
Object.defineProperty(Refresh, "__esModule", { value: true });
|
|
const vue_1 = requireVue();
|
|
const _hoisted_13 = {
|
|
xmlns: "http://www.w3.org/2000/svg",
|
|
"xmlns:xlink": "http://www.w3.org/1999/xlink",
|
|
viewBox: "0 0 24 24"
|
|
};
|
|
Refresh.default = (0, vue_1.defineComponent)({
|
|
name: "Refresh",
|
|
render: function render(_ctx, _cache) {
|
|
return (0, vue_1.openBlock)(), (0, vue_1.createElementBlock)(
|
|
"svg",
|
|
_hoisted_13,
|
|
_cache[0] || (_cache[0] = [
|
|
(0, vue_1.createElementVNode)(
|
|
"g",
|
|
{
|
|
fill: "none",
|
|
stroke: "currentColor",
|
|
"stroke-width": "2",
|
|
"stroke-linecap": "round",
|
|
"stroke-linejoin": "round"
|
|
},
|
|
[
|
|
(0, vue_1.createElementVNode)("path", {
|
|
d: "M20 11A8.1 8.1 0 0 0 4.5 9M4 5v4h4"
|
|
}),
|
|
(0, vue_1.createElementVNode)("path", {
|
|
d: "M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4"
|
|
})
|
|
],
|
|
-1
|
|
/* HOISTED */
|
|
)
|
|
])
|
|
);
|
|
}
|
|
});
|
|
return Refresh;
|
|
}
|
|
var RefreshExports = /* @__PURE__ */ requireRefresh();
|
|
const RefreshIcon = /* @__PURE__ */ getDefaultExportFromCjs(RefreshExports);
|
|
const _hoisted_1$2 = { key: 0 };
|
|
const _hoisted_2$1 = { key: 1 };
|
|
const _hoisted_3$1 = { class: "plan-container" };
|
|
const _hoisted_4$1 = { class: "header-days" };
|
|
const _hoisted_5 = { class: "today-header" };
|
|
const _hoisted_6 = { class: "today-name" };
|
|
const _hoisted_7 = { class: "stage-area" };
|
|
const _hoisted_8 = ["title"];
|
|
const _hoisted_9 = { class: "action-area" };
|
|
const _hoisted_10 = {
|
|
key: 0,
|
|
xmlns: "http://www.w3.org/2000/svg",
|
|
viewBox: "0 0 24 24"
|
|
};
|
|
const _hoisted_11 = {
|
|
key: 1,
|
|
xmlns: "http://www.w3.org/2000/svg",
|
|
viewBox: "0 0 24 24"
|
|
};
|
|
const _hoisted_12 = {
|
|
key: 2,
|
|
xmlns: "http://www.w3.org/2000/svg",
|
|
viewBox: "0 0 24 24"
|
|
};
|
|
const _sfc_main$7 = {
|
|
__name: "WeeklyPlan",
|
|
setup(__props) {
|
|
const config = useConfigStore();
|
|
const { conf } = storeToRefs(config);
|
|
const weekday_display_name = ["一", "二", "三", "四", "五", "六", "日"];
|
|
const general_important_stages = ["", "Annihilation"];
|
|
const general_unimportant_stages = [
|
|
// 通用非重要关卡 (主要是材料本和芯片本)
|
|
"1-7",
|
|
"LS-6",
|
|
"CE-6",
|
|
"AP-5",
|
|
"SK-5",
|
|
"CA-5",
|
|
"PR-A-2",
|
|
"PR-A-1",
|
|
"PR-B-2",
|
|
"PR-B-1",
|
|
"PR-C-2",
|
|
"PR-C-1",
|
|
"PR-D-2",
|
|
"PR-D-1"
|
|
];
|
|
const time_table = {
|
|
CE: [1, 3, 5, 6],
|
|
AP: [0, 3, 5, 6],
|
|
SK: [0, 2, 4, 5],
|
|
CA: [1, 2, 4, 6],
|
|
"PR-A": [0, 3, 4, 6],
|
|
"PR-B": [0, 1, 4, 5],
|
|
"PR-C": [2, 3, 5, 6],
|
|
"PR-D": [1, 2, 5, 6]
|
|
};
|
|
const stageDisplayNames = {
|
|
"": "上次作战",
|
|
Annihilation: "当期剿灭",
|
|
"LS-6": "经验书",
|
|
"CE-6": "龙门币",
|
|
"AP-5": "红票",
|
|
"SK-5": "碳本",
|
|
"CA-5": "技能书",
|
|
"PR-A-1": "医疗重装1",
|
|
"PR-A-2": "医疗重装2",
|
|
"PR-B-1": "狙击术师1",
|
|
"PR-B-2": "狙击术师2",
|
|
"PR-C-1": "先锋辅助1",
|
|
"PR-C-2": "先锋辅助2",
|
|
"PR-D-1": "近卫特种1",
|
|
"PR-D-2": "近卫特种2",
|
|
"1-7": "1-7"
|
|
};
|
|
function display_name(stage) {
|
|
return stageDisplayNames[stage] ?? stage;
|
|
}
|
|
function weekday() {
|
|
const day = (/* @__PURE__ */ new Date()).getDay();
|
|
return day === 0 ? 6 : day - 1;
|
|
}
|
|
const stageAvailability = computed(() => {
|
|
const availabilityMap = /* @__PURE__ */ new Map();
|
|
const allDaysAvailable = Array(7).fill(true);
|
|
general_important_stages.forEach((stage) => availabilityMap.set(stage, allDaysAvailable));
|
|
general_unimportant_stages.forEach((stage) => {
|
|
let availableDays = allDaysAvailable;
|
|
for (const [prefix, days] of Object.entries(time_table)) {
|
|
if (stage.startsWith(prefix)) {
|
|
const weekAvailability = Array(7).fill(false);
|
|
days.forEach((dayIndex) => {
|
|
weekAvailability[dayIndex] = true;
|
|
});
|
|
availableDays = weekAvailability;
|
|
break;
|
|
}
|
|
}
|
|
availabilityMap.set(stage, availableDays);
|
|
});
|
|
conf.value.custom_stages.forEach((stage) => {
|
|
if (stage) {
|
|
availabilityMap.set(stage, allDaysAvailable);
|
|
}
|
|
});
|
|
return availabilityMap;
|
|
});
|
|
const plan = computed(() => {
|
|
const result = [];
|
|
const currentPlan = conf.value.weekly_plan;
|
|
const generateWeekAndState = (stage, isCustom) => {
|
|
var _a, _b;
|
|
const week = [];
|
|
const available = stageAvailability.value.get(stage) ?? Array(7).fill(true);
|
|
const planType = isCustom ? "custom" : "general";
|
|
let availableCount = 0;
|
|
let enabledCount = 0;
|
|
for (let dayIndex = 0; dayIndex < 7; ++dayIndex) {
|
|
const isAvailable = available[dayIndex];
|
|
const isEnabled = ((_b = (_a = currentPlan[dayIndex]) == null ? void 0 : _a[planType]) == null ? void 0 : _b.includes(stage)) ?? false;
|
|
week.push({
|
|
available: isAvailable,
|
|
enable: isEnabled
|
|
});
|
|
if (isAvailable) {
|
|
availableCount++;
|
|
if (isEnabled) {
|
|
enabledCount++;
|
|
}
|
|
}
|
|
}
|
|
let selectionState = "empty";
|
|
if (availableCount > 0) {
|
|
if (enabledCount === 0) {
|
|
selectionState = "empty";
|
|
} else if (enabledCount === availableCount) {
|
|
selectionState = "all";
|
|
} else {
|
|
selectionState = "some";
|
|
}
|
|
}
|
|
return { week, selectionState };
|
|
};
|
|
general_important_stages.forEach(
|
|
(stage) => result.push({ stage, ...generateWeekAndState(stage, false) })
|
|
);
|
|
conf.value.custom_stages.forEach(
|
|
(stage) => result.push({
|
|
stage,
|
|
...generateWeekAndState(stage, true)
|
|
// 对所有自定义关卡(包括 null)调用 generateWeekAndState
|
|
})
|
|
);
|
|
general_unimportant_stages.forEach(
|
|
(stage) => result.push({ stage, ...generateWeekAndState(stage, false) })
|
|
);
|
|
return result;
|
|
});
|
|
function toggle_plan(stageIndex, dayIndex) {
|
|
const stageInfo = plan.value[stageIndex];
|
|
if (!stageInfo || stageInfo.stage === null || !stageInfo.week[dayIndex].available) return;
|
|
const stage = stageInfo.stage;
|
|
const isCustom = conf.value.custom_stages.includes(stage);
|
|
const planType = isCustom ? "custom" : "general";
|
|
const dayPlan = conf.value.weekly_plan[dayIndex];
|
|
const list = dayPlan[planType];
|
|
const isCurrentlyEnabled = list.includes(stage);
|
|
if (isCurrentlyEnabled) {
|
|
const indexInList = list.indexOf(stage);
|
|
if (indexInList > -1) list.splice(indexInList, 1);
|
|
} else {
|
|
list.push(stage);
|
|
}
|
|
}
|
|
function select_all(stageIndex) {
|
|
const stageInfo = plan.value[stageIndex];
|
|
if (!stageInfo || stageInfo.stage === null) return;
|
|
const stage = stageInfo.stage;
|
|
const isCustom = conf.value.custom_stages.includes(stage);
|
|
const planType = isCustom ? "custom" : "general";
|
|
const availabilityWeek = stageInfo.week;
|
|
const currentState = stageInfo.selectionState;
|
|
const shouldEnableAllAvailable = currentState !== "all";
|
|
for (let dayIndex = 0; dayIndex < 7; ++dayIndex) {
|
|
if (availabilityWeek[dayIndex].available) {
|
|
const list = conf.value.weekly_plan[dayIndex][planType];
|
|
const isCurrentlyEnabled = list.includes(stage);
|
|
if (shouldEnableAllAvailable && !isCurrentlyEnabled) {
|
|
list.push(stage);
|
|
} else if (!shouldEnableAllAvailable && isCurrentlyEnabled) {
|
|
const indexInList = list.indexOf(stage);
|
|
if (indexInList > -1) list.splice(indexInList, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function create_tag(label) {
|
|
label = label.toUpperCase();
|
|
if (label === " " || label === "上次作战") return { label: "上次作战", value: "" };
|
|
if (label === "当期剿灭") return { label: "当期剿灭", value: "Annihilation" };
|
|
if (label.endsWith("磨难") || label.endsWith("标准")) {
|
|
const baseLabel = label.slice(0, -2);
|
|
return { label: baseLabel, value: baseLabel };
|
|
}
|
|
return { label, value: label };
|
|
}
|
|
const mobile = inject("mobile");
|
|
const activity_url = `${""}/activity`;
|
|
const activity = ref([]);
|
|
const axios2 = inject("axios");
|
|
async function get_activity() {
|
|
try {
|
|
const { data } = await axios2.get(activity_url);
|
|
activity.value = data;
|
|
} catch (error) {
|
|
console.error("Failed to fetch activity data:", error);
|
|
activity.value = [];
|
|
}
|
|
}
|
|
onMounted(() => {
|
|
get_activity();
|
|
});
|
|
function drag(stageName, ev) {
|
|
ev.dataTransfer.setData("text/plain", stageName);
|
|
}
|
|
function dropOnCustomStage(customStageArrayIndex, ev) {
|
|
ev.preventDefault();
|
|
const stageName = ev.dataTransfer.getData("text/plain");
|
|
if (stageName && customStageArrayIndex >= 0 && customStageArrayIndex < conf.value.custom_stages.length) {
|
|
clearStagePlan(conf.value.custom_stages[customStageArrayIndex]);
|
|
conf.value.custom_stages[customStageArrayIndex] = stageName;
|
|
}
|
|
}
|
|
function clearCustomStage(customStageIndex) {
|
|
if (conf.value.custom_stages.length > customStageIndex) {
|
|
clearStagePlan(conf.value.custom_stages[customStageIndex]);
|
|
conf.value.custom_stages[customStageIndex] = null;
|
|
}
|
|
}
|
|
function clearStagePlan(stage, isCustom) {
|
|
var _a;
|
|
if (!stage) return;
|
|
const planType = "custom";
|
|
for (let dayIndex = 0; dayIndex < 7; ++dayIndex) {
|
|
const list = (_a = conf.value.weekly_plan[dayIndex]) == null ? void 0 : _a[planType];
|
|
if (list) {
|
|
const indexInList = list.indexOf(stage);
|
|
if (indexInList > -1) {
|
|
list.splice(indexInList, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function updateCustomStage(value, customStageIndex) {
|
|
clearStagePlan(conf.value.custom_stages[customStageIndex]);
|
|
conf.value.custom_stages[customStageIndex] = value;
|
|
}
|
|
const todayIndex = computed(() => weekday());
|
|
const todayName = computed(() => weekday_display_name[todayIndex.value] || "");
|
|
return (_ctx, _cache) => {
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_n_input_number = __unplugin_components_15;
|
|
const _component_n_flex = __unplugin_components_2$1;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_n_form = __unplugin_components_17;
|
|
const _component_n_avatar = __unplugin_components_7;
|
|
const _component_n_tag = __unplugin_components_4$2;
|
|
const _component_n_tooltip = __unplugin_components_6$2;
|
|
const _component_n_icon = NIcon;
|
|
const _component_n_button = Button;
|
|
const _component_n_select = __unplugin_components_5;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, null, {
|
|
header: withCtx(() => [
|
|
createBaseVNode("div", {
|
|
class: normalizeClass(["card-title", { disabled: !unref(conf).task["mower.solvers.operation.OperationManager"] }])
|
|
}, " 刷理智周计划 ", 2),
|
|
createVNode(_component_help_text, null, {
|
|
default: withCtx(() => [
|
|
!unref(conf).task["mower.solvers.operation.OperationManager"] ? (openBlock(), createElementBlock("div", _hoisted_1$2, "需开启日常任务")) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
_cache[8] || (_cache[8] = createBaseVNode("div", null, "支持所有主线关卡;", -1)),
|
|
_cache[9] || (_cache[9] = createBaseVNode("div", null, "含磨难的主线关卡仅需填写关卡名,会自动选择难度。", -1)),
|
|
_cache[10] || (_cache[10] = createBaseVNode("div", null, "点击表头“全选”或关卡右侧图标可在全选/半选/全不选之间切换。", -1)),
|
|
_cache[11] || (_cache[11] = createBaseVNode("div", null, "拖拽活动关卡或输入关卡名到自定义槽位。", -1))
|
|
], 64))
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "72",
|
|
"label-align": "left",
|
|
style: { "margin-bottom": "6px" }
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, {
|
|
class: "form-item",
|
|
"show-label": false
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, { style: { "gap": "8px 48px", "flex-wrap": "wrap" } }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).use_all_medicine,
|
|
"onUpdate:checked": _cache[0] || (_cache[0] = ($event) => unref(conf).use_all_medicine = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[12] || (_cache[12] = [
|
|
createTextVNode("自动使用全部理智药")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"]),
|
|
createVNode(_component_n_flex, {
|
|
align: "center",
|
|
style: { "flex-grow": "1", "min-width": "250px" }
|
|
}, {
|
|
default: withCtx(() => [
|
|
createBaseVNode("div", {
|
|
style: normalizeStyle({
|
|
color: unref(conf).use_all_medicine ? "inherit" : "var(--n-text-color-disabled)",
|
|
transition: "color 0.3s",
|
|
"white-space": "nowrap",
|
|
"margin-right": "8px"
|
|
})
|
|
}, " 吃源石数量 ", 4),
|
|
createVNode(_component_n_input_number, {
|
|
disabled: !unref(conf).use_all_medicine,
|
|
precision: 0,
|
|
min: 0,
|
|
style: { "flex-grow": "1" },
|
|
value: unref(conf).originite,
|
|
"onUpdate:value": _cache[1] || (_cache[1] = ($event) => unref(conf).originite = $event)
|
|
}, {
|
|
suffix: withCtx(() => _cache[13] || (_cache[13] = [
|
|
createTextVNode("颗")
|
|
])),
|
|
_: 1
|
|
}, 8, ["disabled", "value"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, {
|
|
class: "form-item",
|
|
"show-label": false
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, { style: { "flex-wrap": "wrap" } }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).maa_expiring_medicine,
|
|
"onUpdate:checked": _cache[2] || (_cache[2] = ($event) => unref(conf).maa_expiring_medicine = $event),
|
|
disabled: unref(conf).use_all_medicine
|
|
}, {
|
|
default: withCtx(() => _cache[14] || (_cache[14] = [
|
|
createTextVNode(" 自动使用将要过期(约3天)的理智药 ")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked", "disabled"]),
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).exipring_medicine_on_weekend,
|
|
"onUpdate:checked": _cache[3] || (_cache[3] = ($event) => unref(conf).exipring_medicine_on_weekend = $event),
|
|
disabled: unref(conf).use_all_medicine || !unref(conf).maa_expiring_medicine
|
|
}, {
|
|
default: withCtx(() => _cache[15] || (_cache[15] = [
|
|
createTextVNode(" 仅在周末使用 ")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked", "disabled"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"]),
|
|
createVNode(_component_n_flex, {
|
|
class: "activity",
|
|
style: { "margin-bottom": "12px" }
|
|
}, {
|
|
default: withCtx(() => [
|
|
activity.value.length > 0 ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(activity.value, (a) => {
|
|
return openBlock(), createBlock(_component_n_tooltip, {
|
|
trigger: "hover",
|
|
key: a.name,
|
|
animated: false,
|
|
delay: 0,
|
|
duration: 0
|
|
}, {
|
|
trigger: withCtx(() => [
|
|
createVNode(_component_n_tag, {
|
|
size: "large",
|
|
draggable: "true",
|
|
onDragstart: ($event) => drag(a.name, $event),
|
|
class: "progress-tag",
|
|
style: { "cursor": "grab" }
|
|
}, createSlots({
|
|
default: withCtx(() => [
|
|
_cache[16] || (_cache[16] = createBaseVNode("div", { class: "progress-bar" }, null, -1)),
|
|
createBaseVNode("div", {
|
|
class: "progress",
|
|
style: normalizeStyle({
|
|
width: `${Math.max(0, Math.min(100, (Date.now() / 1e3 - a.begin) / (a.end - a.begin) * 100))}%`
|
|
})
|
|
}, null, 4),
|
|
createBaseVNode("div", null, toDisplayString(a.name), 1)
|
|
]),
|
|
_: 2
|
|
}, [
|
|
a.drop ? {
|
|
name: "avatar",
|
|
fn: withCtx(() => [
|
|
createVNode(_component_n_avatar, {
|
|
src: `/depot/${a.drop}.webp`,
|
|
color: "transparent"
|
|
}, null, 8, ["src"])
|
|
]),
|
|
key: "0"
|
|
} : void 0
|
|
]), 1032, ["onDragstart"])
|
|
]),
|
|
default: withCtx(() => [
|
|
createBaseVNode("div", null, " 结束时间:" + toDisplayString(unref(DateTime).fromSeconds(a.end).setLocale("zh-CN").toLocaleString(unref(DateTime).DATE_MED_WITH_WEEKDAY)), 1),
|
|
createBaseVNode("div", null, " 剩余时间:" + toDisplayString(unref(Duration).fromObject(
|
|
{ seconds: Math.max(0, a.end - Date.now() / 1e3) },
|
|
{ locale: "zh-CN" }
|
|
).shiftTo("days", "hours").toHuman()), 1),
|
|
createBaseVNode("div", null, toDisplayString(a.drop) + " 已有:" + toDisplayString(a.count), 1)
|
|
]),
|
|
_: 2
|
|
}, 1024);
|
|
}), 128)) : (openBlock(), createElementBlock("div", _hoisted_2$1, "当前暂无活动开放")),
|
|
createVNode(_component_n_button, {
|
|
text: "",
|
|
type: "primary",
|
|
onClick: get_activity
|
|
}, {
|
|
icon: withCtx(() => [
|
|
createVNode(_component_n_icon, null, {
|
|
default: withCtx(() => [
|
|
createVNode(unref(RefreshIcon))
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
default: withCtx(() => [
|
|
_cache[17] || (_cache[17] = createTextVNode(" 刷新 "))
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}),
|
|
createBaseVNode("div", _hoisted_3$1, [
|
|
createVNode(_component_n_flex, {
|
|
class: "plan-header",
|
|
justify: "space-between",
|
|
align: "center"
|
|
}, {
|
|
default: withCtx(() => [
|
|
_cache[19] || (_cache[19] = createBaseVNode("div", { class: "header-stage" }, "关卡", -1)),
|
|
createBaseVNode("div", _hoisted_4$1, [
|
|
createBaseVNode("span", _hoisted_5, [
|
|
_cache[18] || (_cache[18] = createTextVNode("今天星期:")),
|
|
createBaseVNode("span", _hoisted_6, toDisplayString(todayName.value), 1)
|
|
])
|
|
]),
|
|
_cache[20] || (_cache[20] = createBaseVNode("div", { class: "header-action" }, "全选", -1))
|
|
]),
|
|
_: 1
|
|
}),
|
|
(openBlock(true), createElementBlock(Fragment, null, renderList(plan.value, ({ stage, week, selectionState }, stageIndex) => {
|
|
return openBlock(), createElementBlock("div", {
|
|
key: stage ?? `custom-${stageIndex}`,
|
|
class: "plan-item"
|
|
}, [
|
|
createVNode(_component_n_flex, {
|
|
justify: "space-between",
|
|
align: "center",
|
|
wrap: false
|
|
}, {
|
|
default: withCtx(() => [
|
|
createBaseVNode("div", _hoisted_7, [
|
|
stageIndex >= general_important_stages.length && stageIndex < general_important_stages.length + unref(conf).custom_stages.length ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
stage === null ? (openBlock(), createBlock(_component_n_select, {
|
|
key: 0,
|
|
placeholder: "拖拽或输入",
|
|
size: "small",
|
|
value: null,
|
|
filterable: "",
|
|
tag: "",
|
|
show: false,
|
|
"show-arrow": false,
|
|
options: [],
|
|
"on-create": create_tag,
|
|
mode: "single",
|
|
"onUpdate:value": (v) => updateCustomStage(v, stageIndex - general_important_stages.length),
|
|
onDragover: _cache[4] || (_cache[4] = withModifiers(() => {
|
|
}, ["prevent"])),
|
|
onDragenter: _cache[5] || (_cache[5] = withModifiers(() => {
|
|
}, ["prevent"])),
|
|
onDrop: ($event) => dropOnCustomStage(stageIndex - general_important_stages.length, $event),
|
|
class: "custom-stage-input"
|
|
}, null, 8, ["onUpdate:value", "onDrop"])) : (openBlock(), createBlock(_component_n_tag, {
|
|
key: 1,
|
|
closable: "",
|
|
size: "small",
|
|
class: "custom-stage-tag",
|
|
onClose: ($event) => clearCustomStage(stageIndex - general_important_stages.length),
|
|
onDragover: _cache[6] || (_cache[6] = withModifiers(() => {
|
|
}, ["prevent"])),
|
|
onDragenter: _cache[7] || (_cache[7] = withModifiers(() => {
|
|
}, ["prevent"])),
|
|
onDrop: ($event) => dropOnCustomStage(stageIndex - general_important_stages.length, $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
createTextVNode(toDisplayString(display_name(stage)), 1)
|
|
]),
|
|
_: 2
|
|
}, 1032, ["onClose", "onDrop"]))
|
|
], 64)) : (openBlock(), createElementBlock("span", {
|
|
key: 1,
|
|
class: "stage-name",
|
|
title: display_name(stage)
|
|
}, toDisplayString(display_name(stage)), 9, _hoisted_8))
|
|
]),
|
|
createVNode(_component_n_flex, {
|
|
class: "day-toggles",
|
|
justify: "space-around",
|
|
align: "center",
|
|
wrap: false
|
|
}, {
|
|
default: withCtx(() => [
|
|
(openBlock(true), createElementBlock(Fragment, null, renderList(week, (w, dayIndex) => {
|
|
return openBlock(), createElementBlock("div", {
|
|
key: dayIndex,
|
|
class: "day-toggle-placeholder"
|
|
}, [
|
|
w.available ? (openBlock(), createBlock(_component_n_button, {
|
|
key: 0,
|
|
onClick: ($event) => toggle_plan(stageIndex, dayIndex),
|
|
type: w.enable ? "success" : "default",
|
|
ghost: !w.enable,
|
|
class: normalizeClass({ "day-toggle": true, "today-button": todayIndex.value === dayIndex }),
|
|
size: "tiny",
|
|
circle: "",
|
|
"aria-label": `${display_name(stage)} 周${weekday_display_name[dayIndex]} ${w.enable ? "取消" : "选择"}`
|
|
}, {
|
|
default: withCtx(() => [
|
|
createTextVNode(toDisplayString(weekday_display_name[dayIndex]), 1)
|
|
]),
|
|
_: 2
|
|
}, 1032, ["onClick", "type", "ghost", "class", "aria-label"])) : createCommentVNode("", true)
|
|
]);
|
|
}), 128))
|
|
]),
|
|
_: 2
|
|
}, 1024),
|
|
createBaseVNode("div", _hoisted_9, [
|
|
createVNode(_component_n_button, {
|
|
quaternary: "",
|
|
size: "small",
|
|
onClick: ($event) => select_all(stageIndex),
|
|
disabled: stage === null,
|
|
"aria-label": "全选/取消选择当前行",
|
|
title: selectionState === "all" ? "取消全选" : selectionState === "some" ? "全选" : "全选"
|
|
}, {
|
|
icon: withCtx(() => [
|
|
createVNode(_component_n_icon, null, {
|
|
default: withCtx(() => [
|
|
selectionState === "all" ? (openBlock(), createElementBlock("svg", _hoisted_10, _cache[21] || (_cache[21] = [
|
|
createBaseVNode("path", {
|
|
fill: "currentColor",
|
|
d: "M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-9 14l-5-5l1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
|
|
}, null, -1)
|
|
]))) : selectionState === "some" ? (openBlock(), createElementBlock("svg", _hoisted_11, _cache[22] || (_cache[22] = [
|
|
createBaseVNode("path", {
|
|
fill: "currentColor",
|
|
d: "M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-2 10H7v-2h10v2z"
|
|
}, null, -1)
|
|
]))) : (openBlock(), createElementBlock("svg", _hoisted_12, _cache[23] || (_cache[23] = [
|
|
createBaseVNode("path", {
|
|
fill: "currentColor",
|
|
d: "M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"
|
|
}, null, -1)
|
|
])))
|
|
]),
|
|
_: 2
|
|
}, 1024)
|
|
]),
|
|
_: 2
|
|
}, 1032, ["onClick", "disabled", "title"])
|
|
])
|
|
]),
|
|
_: 2
|
|
}, 1024)
|
|
]);
|
|
}), 128))
|
|
])
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const WeeklyPlan = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["__scopeId", "data-v-d720c1de"]]);
|
|
const _sfc_main$6 = {
|
|
__name: "ReclamationAlgorithm",
|
|
setup(__props) {
|
|
const mobile = inject("mobile");
|
|
const store = useConfigStore();
|
|
const { conf } = storeToRefs(store);
|
|
return (_ctx, _cache) => {
|
|
const _component_n_input_number = __unplugin_components_15;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_n_form = __unplugin_components_17;
|
|
return openBlock(), createBlock(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "72",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, { label: "超时时长" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).reclamation_algorithm.timeout,
|
|
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => unref(conf).reclamation_algorithm.timeout = $event)
|
|
}, {
|
|
suffix: withCtx(() => _cache[1] || (_cache[1] = [
|
|
createTextVNode("秒")
|
|
])),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"]);
|
|
};
|
|
}
|
|
};
|
|
const _hoisted_1$1 = { class: "sss-container" };
|
|
const _hoisted_2 = {
|
|
key: 0,
|
|
class: "wrapper"
|
|
};
|
|
const _hoisted_3 = { class: "title" };
|
|
const _hoisted_4 = { key: 1 };
|
|
const _sfc_main$5 = {
|
|
__name: "Sss",
|
|
setup(__props) {
|
|
const mobile = inject("mobile");
|
|
const axios2 = inject("axios");
|
|
const sss_url = `${""}/sss-copilot`;
|
|
const sss_data = ref({ exists: false });
|
|
onMounted(async () => {
|
|
const { data } = await axios2.get(sss_url);
|
|
sss_data.value = data;
|
|
});
|
|
function import_sss({ event }) {
|
|
sss_data.value = JSON.parse(event.target.response);
|
|
}
|
|
const token = inject("token");
|
|
const maa_code_input = ref(false);
|
|
const maa_code = ref("");
|
|
const loading = ref(false);
|
|
const code = ref(null);
|
|
function start_input() {
|
|
maa_code.value = "";
|
|
maa_code_input.value = true;
|
|
nextTick(() => code.value.focus());
|
|
}
|
|
async function download_maa_copilot() {
|
|
loading.value = true;
|
|
const number = maa_code.value.replace("maa://", "");
|
|
const { data } = await axios2.get(`https://prts.maa.plus/copilot/get/${number}`, {
|
|
transformRequest: [
|
|
(data2, headers) => {
|
|
delete headers.token;
|
|
return JSON.stringify(data2);
|
|
}
|
|
]
|
|
});
|
|
const form_data = new FormData();
|
|
form_data.append("copilot", new Blob([data.data.content], { type: "application/json" }));
|
|
const response = await axios2.post(sss_url, form_data);
|
|
sss_data.value = response.data;
|
|
maa_code_input.value = false;
|
|
loading.value = false;
|
|
}
|
|
const store = useConfigStore();
|
|
const { conf } = storeToRefs(store);
|
|
return (_ctx, _cache) => {
|
|
const _component_n_alert = __unplugin_components_1$1;
|
|
const _component_n_radio = __unplugin_components_11;
|
|
const _component_n_flex = __unplugin_components_2$1;
|
|
const _component_n_radio_group = __unplugin_components_13;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_n_input_number = __unplugin_components_15;
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_n_input = __unplugin_components_0$2;
|
|
const _component_n_button = Button;
|
|
const _component_n_upload = __unplugin_components_7$1;
|
|
const _component_n_avatar = __unplugin_components_7;
|
|
const _component_n_form = __unplugin_components_17;
|
|
return openBlock(), createBlock(_component_n_flex, { vertical: "" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_alert, {
|
|
title: "请检查作业并修正其中的错误!",
|
|
type: "warning"
|
|
}),
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "72",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, { label: "难度选择" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio_group, {
|
|
value: unref(conf).sss.mode,
|
|
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => unref(conf).sss.mode = $event)
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, null, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_radio, { value: "normal" }, {
|
|
default: withCtx(() => _cache[6] || (_cache[6] = [
|
|
createTextVNode("标准补给模式")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_radio, { value: "ex" }, {
|
|
default: withCtx(() => _cache[7] || (_cache[7] = [
|
|
createTextVNode("应急补给模式")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "代理层数" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input_number, {
|
|
value: unref(conf).sss.ope_limit_stage,
|
|
"onUpdate:value": _cache[1] || (_cache[1] = ($event) => unref(conf).sss.ope_limit_stage = $event),
|
|
precision: 0,
|
|
min: 0,
|
|
max: 6
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).sss.choose_agent,
|
|
"onUpdate:checked": _cache[2] || (_cache[2] = ($event) => unref(conf).sss.choose_agent = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[8] || (_cache[8] = [
|
|
createTextVNode(" 自动编队(缺人时自动借助战) ")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).sss.finish_while_full,
|
|
"onUpdate:checked": _cache[3] || (_cache[3] = ($event) => unref(conf).sss.finish_while_full = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[9] || (_cache[9] = [
|
|
createTextVNode("模组刷满时直接结束")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "导入作业" }, {
|
|
default: withCtx(() => [
|
|
createBaseVNode("div", _hoisted_1$1, [
|
|
unref(maa_code_input) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
createVNode(_component_n_input, {
|
|
ref_key: "code",
|
|
ref: code,
|
|
value: unref(maa_code),
|
|
"onUpdate:value": _cache[4] || (_cache[4] = ($event) => isRef(maa_code) ? maa_code.value = $event : null),
|
|
type: "text",
|
|
placeholder: "maa://114514",
|
|
disabled: unref(loading)
|
|
}, null, 8, ["value", "disabled"]),
|
|
createVNode(_component_n_button, {
|
|
onClick: download_maa_copilot,
|
|
loading: unref(loading),
|
|
disabled: unref(loading)
|
|
}, {
|
|
default: withCtx(() => _cache[10] || (_cache[10] = [
|
|
createTextVNode(" 下载 ")
|
|
])),
|
|
_: 1
|
|
}, 8, ["loading", "disabled"]),
|
|
createVNode(_component_n_button, {
|
|
onClick: _cache[5] || (_cache[5] = ($event) => maa_code_input.value = false)
|
|
}, {
|
|
default: withCtx(() => _cache[11] || (_cache[11] = [
|
|
createTextVNode("取消")
|
|
])),
|
|
_: 1
|
|
})
|
|
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
createVNode(_component_n_button, {
|
|
style: { "flex-grow": "1" },
|
|
onClick: start_input
|
|
}, {
|
|
default: withCtx(() => _cache[12] || (_cache[12] = [
|
|
createTextVNode("输入“神秘代码”")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_upload, {
|
|
style: { "width": "auto", "flex-grow": "1" },
|
|
"trigger-style": "width: 100%",
|
|
action: sss_url,
|
|
headers: { token: unref(token) },
|
|
"show-file-list": false,
|
|
name: "copilot",
|
|
onFinish: import_sss
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_button, { style: { "width": "100%" } }, {
|
|
default: withCtx(() => _cache[13] || (_cache[13] = [
|
|
createTextVNode("选择作业文件")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["headers"])
|
|
], 64))
|
|
])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "作业信息" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_flex, { vertical: "" }, {
|
|
default: withCtx(() => [
|
|
unref(sss_data).exists ? (openBlock(), createElementBlock("div", _hoisted_2, [
|
|
createBaseVNode("div", _hoisted_3, toDisplayString(unref(sss_data).title), 1),
|
|
createTextVNode(" " + toDisplayString(unref(sss_data).details), 1)
|
|
])) : (openBlock(), createElementBlock("div", _hoisted_4, "未选择作业")),
|
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(sss_data).operators, (o) => {
|
|
return openBlock(), createBlock(_component_n_flex, { align: "center" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_avatar, {
|
|
src: `avatar/${o.name}.webp`,
|
|
color: "transparent"
|
|
}, null, 8, ["src"]),
|
|
createBaseVNode("div", null, toDisplayString(o.name) + "(" + toDisplayString(o.skill) + "技能)", 1)
|
|
]),
|
|
_: 2
|
|
}, 1024);
|
|
}), 256))
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"])
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const __unplugin_components_4 = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-a922d165"]]);
|
|
const _hoisted_1 = { class: "misc-container" };
|
|
const _sfc_main$4 = {
|
|
__name: "MaaBasic",
|
|
setup(__props) {
|
|
const axios2 = inject("axios");
|
|
const mobile = inject("mobile");
|
|
const config = useConfigStore();
|
|
const { conf } = storeToRefs(config);
|
|
async function select_maa_dir() {
|
|
const folder_path = await folder_dialog();
|
|
if (folder_path) {
|
|
conf.value.maa_path = folder_path;
|
|
}
|
|
}
|
|
const maa_msg = ref("");
|
|
async function test_maa() {
|
|
maa_msg.value = "正在测试……";
|
|
const response = await axios2.get(`${""}/check-maa`);
|
|
maa_msg.value = response.data;
|
|
}
|
|
const maa_conn_presets = ref([]);
|
|
async function get_maa_conn_presets() {
|
|
const response = await axios2.get(`${""}/maa-conn-preset`);
|
|
conf.value.maa_conn_presets = response.data.map((x) => {
|
|
return { label: x, value: x };
|
|
});
|
|
}
|
|
const maa_touch_options = ["maatouch", "minitouch", "adb"].map((x) => {
|
|
return { label: x, value: x };
|
|
});
|
|
return (_ctx, _cache) => {
|
|
const _component_n_divider = __unplugin_components_3;
|
|
const _component_n_h4 = NH4;
|
|
const _component_n_input = __unplugin_components_0$2;
|
|
const _component_n_button = Button;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_n_select = __unplugin_components_5;
|
|
const _component_n_form = __unplugin_components_17;
|
|
return openBlock(), createElementBlock(Fragment, null, [
|
|
createVNode(_component_n_divider),
|
|
createVNode(_component_n_h4, { class: "header" }, {
|
|
default: withCtx(() => _cache[3] || (_cache[3] = [
|
|
createTextVNode("Maa设置")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "96",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, { label: "Maa目录" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_input, {
|
|
type: "textarea",
|
|
autosize: true,
|
|
value: unref(conf).maa_path,
|
|
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => unref(conf).maa_path = $event)
|
|
}, null, 8, ["value"]),
|
|
createVNode(_component_n_button, {
|
|
onClick: select_maa_dir,
|
|
class: "dialog-btn"
|
|
}, {
|
|
default: withCtx(() => _cache[4] || (_cache[4] = [
|
|
createTextVNode("...")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "连接配置" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
options: unref(maa_conn_presets),
|
|
value: unref(conf).maa_conn_preset,
|
|
"onUpdate:value": _cache[1] || (_cache[1] = ($event) => unref(conf).maa_conn_preset = $event)
|
|
}, null, 8, ["options", "value"]),
|
|
createVNode(_component_n_button, {
|
|
onClick: get_maa_conn_presets,
|
|
class: "dialog-btn"
|
|
}, {
|
|
default: withCtx(() => _cache[5] || (_cache[5] = [
|
|
createTextVNode("刷新")
|
|
])),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "触控模式" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).maa_touch_option,
|
|
"onUpdate:value": _cache[2] || (_cache[2] = ($event) => unref(conf).maa_touch_option = $event),
|
|
options: unref(maa_touch_options)
|
|
}, null, 8, ["value", "options"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"]),
|
|
createVNode(_component_n_divider),
|
|
createBaseVNode("div", _hoisted_1, [
|
|
createVNode(_component_n_button, { onClick: test_maa }, {
|
|
default: withCtx(() => _cache[6] || (_cache[6] = [
|
|
createTextVNode("测试设置")
|
|
])),
|
|
_: 1
|
|
}),
|
|
createBaseVNode("div", null, toDisplayString(unref(maa_msg)), 1)
|
|
]),
|
|
createVNode(_component_n_divider, { style: { "margin": "12px 0 16px" } })
|
|
], 64);
|
|
};
|
|
}
|
|
};
|
|
const __unplugin_components_0 = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-b2d35691"]]);
|
|
const _sfc_main$3 = {
|
|
__name: "MaaRogue",
|
|
setup(__props) {
|
|
const mobile = inject("mobile");
|
|
const config_store = useConfigStore();
|
|
const { conf } = storeToRefs(config_store);
|
|
const plan_store = usePlanStore();
|
|
const { operators } = storeToRefs(plan_store);
|
|
const rogue_themes = [
|
|
{ label: "傀影与猩红孤钻", value: "Phantom" },
|
|
{ label: "水月与深蓝之树", value: "Mizuki" },
|
|
{ label: "探索者的银凇止境", value: "Sami" },
|
|
{ label: "萨卡兹的无终奇语", value: "Sarkaz" }
|
|
];
|
|
const squad = {
|
|
Phantom: [
|
|
"研究",
|
|
"指挥",
|
|
"集群",
|
|
"后勤",
|
|
"矛头",
|
|
"突击战术",
|
|
"堡垒战术",
|
|
"远程战术",
|
|
"破坏战术",
|
|
"高规格"
|
|
],
|
|
Mizuki: [
|
|
"心胜于物",
|
|
"物尽其用",
|
|
"以人为本",
|
|
"研究",
|
|
"指挥",
|
|
"集群",
|
|
"后勤",
|
|
"矛头",
|
|
"突击战术",
|
|
"堡垒战术",
|
|
"远程战术",
|
|
"破坏战术",
|
|
"高规格"
|
|
],
|
|
Sami: [
|
|
"永恒狩猎",
|
|
"生活至上",
|
|
"科学主义",
|
|
"特训",
|
|
"指挥",
|
|
"集群",
|
|
"后勤",
|
|
"矛头",
|
|
"突击战术",
|
|
"堡垒战术",
|
|
"远程战术",
|
|
"破坏战术",
|
|
"高规格"
|
|
],
|
|
Sarkaz: [
|
|
"因地制宜",
|
|
"魂灵护送",
|
|
"博闻广记",
|
|
"蓝图测绘",
|
|
"指挥",
|
|
"集群",
|
|
"后勤",
|
|
"矛头",
|
|
"突击战术",
|
|
"堡垒战术",
|
|
"远程战术",
|
|
"破坏战术",
|
|
"高规格"
|
|
]
|
|
};
|
|
for (const s2 in squad) {
|
|
squad[s2] = squad[s2].map((x) => {
|
|
return { label: x + "分队", value: x + "分队" };
|
|
});
|
|
}
|
|
const roles = [
|
|
{ label: "先手必胜(先锋、狙击、特种)", value: "先手必胜" },
|
|
{ label: "稳扎稳打(重装、术师、狙击)", value: "稳扎稳打" },
|
|
{ label: "取长补短(近卫、辅助、医疗)", value: "取长补短" },
|
|
{ label: "随心所欲(随机)", value: "随心所欲" }
|
|
];
|
|
const mode_list = [
|
|
{ label: "刷蜡烛,尽可能稳定地打更多层数", value: 0 },
|
|
{ label: "刷源石锭,第一层投资完就退出", value: 1 },
|
|
{ label: "【即将弃用】兼顾", value: 2 },
|
|
// { label: '开发中...', value: 3 },
|
|
{ label: "刷开局,到达第三层后直接退出", value: 4 },
|
|
{ label: "刷坍缩范式", value: 5 }
|
|
];
|
|
const col = [
|
|
"去量化",
|
|
"去量深化",
|
|
"实质性坍缩",
|
|
"蔓延性坍缩",
|
|
"非线性移动",
|
|
"非线性行动",
|
|
"情绪实体",
|
|
"恐怖实体",
|
|
"泛社会悖论",
|
|
"泛文明悖论",
|
|
"气压异常",
|
|
"气压失序",
|
|
"触发性损伤",
|
|
"触发性危殆",
|
|
"趋同性消耗",
|
|
"趋同性缺失",
|
|
"目空一些",
|
|
"睁眼瞎",
|
|
"图像损坏",
|
|
"一抹黑"
|
|
];
|
|
const col_list = [];
|
|
for (const c2 of col) {
|
|
col_list.push({ label: c2, value: c2 });
|
|
}
|
|
return (_ctx, _cache) => {
|
|
const _component_maa_basic = __unplugin_components_0;
|
|
const _component_n_select = __unplugin_components_5;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_n_form = __unplugin_components_17;
|
|
return openBlock(), createElementBlock(Fragment, null, [
|
|
createVNode(_component_maa_basic),
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
class: "conf.rogue"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, { label: "主题" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).maa_rg_theme,
|
|
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => unref(conf).maa_rg_theme = $event),
|
|
options: rogue_themes
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "分队" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).rogue.squad,
|
|
"onUpdate:value": _cache[1] || (_cache[1] = ($event) => unref(conf).rogue.squad = $event),
|
|
options: squad[unref(conf).maa_rg_theme]
|
|
}, null, 8, ["value", "options"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "职业" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).rogue.roles,
|
|
"onUpdate:value": _cache[2] || (_cache[2] = ($event) => unref(conf).rogue.roles = $event),
|
|
options: roles
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "干员" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
filterable: "",
|
|
options: unref(operators),
|
|
value: unref(conf).rogue.core_char,
|
|
"onUpdate:value": _cache[3] || (_cache[3] = ($event) => unref(conf).rogue.core_char = $event),
|
|
filter: (p, o) => unref(pinyin_match)(o.label, p),
|
|
"render-label": unref(render_op_label)
|
|
}, null, 8, ["options", "value", "filter", "render-label"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).rogue.use_support,
|
|
"onUpdate:checked": _cache[4] || (_cache[4] = ($event) => unref(conf).rogue.use_support = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[9] || (_cache[9] = [
|
|
createTextVNode("开局干员使用助战")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
unref(conf).rogue.use_support ? (openBlock(), createBlock(_component_n_form_item, {
|
|
key: 0,
|
|
"show-label": false
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).rogue.use_nonfriend_support,
|
|
"onUpdate:checked": _cache[5] || (_cache[5] = ($event) => unref(conf).rogue.use_nonfriend_support = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[10] || (_cache[10] = [
|
|
createTextVNode("开局干员使用非好友助战")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
createVNode(_component_n_form_item, { label: "策略" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
options: mode_list,
|
|
value: unref(conf).rogue.mode,
|
|
"onUpdate:value": _cache[6] || (_cache[6] = ($event) => unref(conf).rogue.mode = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).rogue.refresh_trader_with_dice,
|
|
"onUpdate:checked": _cache[7] || (_cache[7] = ($event) => unref(conf).rogue.refresh_trader_with_dice = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[11] || (_cache[11] = [
|
|
createTextVNode("刷新商店(指路鳞)")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { label: "坍缩范式" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
multiple: "",
|
|
options: col_list,
|
|
value: unref(conf).rogue.expected_collapsal_paradigms,
|
|
"onUpdate:value": _cache[8] || (_cache[8] = ($event) => unref(conf).rogue.expected_collapsal_paradigms = $event)
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"])
|
|
], 64);
|
|
};
|
|
}
|
|
};
|
|
const _sfc_main$2 = {
|
|
__name: "SecretFront",
|
|
setup(__props) {
|
|
const mobile = inject("mobile");
|
|
const store = useConfigStore();
|
|
const { conf } = storeToRefs(store);
|
|
const target_options = [
|
|
{ label: "1A→2A→3A→结局A", value: "结局A" },
|
|
{ label: "1A→2A→3A→结局B", value: "结局B" },
|
|
{ label: "1A→2A→3B→结局C", value: "结局C" },
|
|
{ label: "1A→2B→3C→结局D", value: "结局D" },
|
|
{ label: "1A→2B→3C→结局E", value: "结局E" }
|
|
];
|
|
return (_ctx, _cache) => {
|
|
const _component_n_select = __unplugin_components_5;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_n_form = __unplugin_components_17;
|
|
return openBlock(), createBlock(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "72",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, { label: "选择路线" }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).secret_front.target,
|
|
"onUpdate:value": _cache[0] || (_cache[0] = ($event) => unref(conf).secret_front.target = $event),
|
|
options: target_options
|
|
}, null, 8, ["value"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).secret_front.auto_next,
|
|
"onUpdate:checked": _cache[1] || (_cache[1] = ($event) => unref(conf).secret_front.auto_next = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[3] || (_cache[3] = [
|
|
createTextVNode(" 当前结局通关后自动切换至下一结局 ")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
}),
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).secret_front.stop_after_finish,
|
|
"onUpdate:checked": _cache[2] || (_cache[2] = ($event) => unref(conf).secret_front.stop_after_finish = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[4] || (_cache[4] = [
|
|
createTextVNode(" 通关后停止大型任务 ")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"]);
|
|
};
|
|
}
|
|
};
|
|
const _sfc_main$1 = {
|
|
__name: "VectorBreakthrough",
|
|
setup(__props) {
|
|
const mobile = inject("mobile");
|
|
const store = useConfigStore();
|
|
const { conf } = storeToRefs(store);
|
|
return (_ctx, _cache) => {
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_n_form_item = __unplugin_components_14;
|
|
const _component_n_form = __unplugin_components_17;
|
|
return openBlock(), createElementBlock(Fragment, null, [
|
|
_cache[2] || (_cache[2] = createBaseVNode("div", null, "原理是用维什戴尔反复刷 VEC-01", -1)),
|
|
_cache[3] || (_cache[3] = createBaseVNode("div", null, "需要手动过完“调整补给”的教程", -1)),
|
|
createVNode(_component_n_form, {
|
|
"label-placement": unref(mobile) ? "top" : "left",
|
|
"show-feedback": false,
|
|
"label-width": "72",
|
|
"label-align": "left"
|
|
}, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_form_item, { "show-label": false }, {
|
|
default: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).secret_front.stop_after_finish,
|
|
"onUpdate:checked": _cache[0] || (_cache[0] = ($event) => unref(conf).secret_front.stop_after_finish = $event)
|
|
}, {
|
|
default: withCtx(() => _cache[1] || (_cache[1] = [
|
|
createTextVNode(" 通关后停止大型任务 ")
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked"])
|
|
]),
|
|
_: 1
|
|
})
|
|
]),
|
|
_: 1
|
|
}, 8, ["label-placement"])
|
|
], 64);
|
|
};
|
|
}
|
|
};
|
|
const _sfc_main = {
|
|
__name: "LongTasks",
|
|
setup(__props) {
|
|
const config = useConfigStore();
|
|
const { conf } = storeToRefs(config);
|
|
const maa_long_task_options = [
|
|
{ label: "集成战略 (Maa)", value: "rogue" },
|
|
{ label: "保全派驻", value: "sss" },
|
|
{ label: "生息演算", value: "ra" },
|
|
{ label: "隐秘战线", value: "sf" },
|
|
{ label: "矢量突破", value: "vb" }
|
|
];
|
|
return (_ctx, _cache) => {
|
|
const _component_n_checkbox = __unplugin_components_1;
|
|
const _component_help_text = __unplugin_components_0$3;
|
|
const _component_n_select = __unplugin_components_5;
|
|
const _component_maa_rogue = _sfc_main$3;
|
|
const _component_sss = __unplugin_components_4;
|
|
const _component_reclamation_algorithm = _sfc_main$6;
|
|
const _component_n_card = __unplugin_components_0$5;
|
|
return openBlock(), createBlock(_component_n_card, null, {
|
|
header: withCtx(() => [
|
|
createVNode(_component_n_checkbox, {
|
|
checked: unref(conf).task["mower.solvers.long_task.LongTask"],
|
|
"onUpdate:checked": _cache[0] || (_cache[0] = ($event) => unref(conf).task["mower.solvers.long_task.LongTask"] = $event),
|
|
disabled: !unref(conf).task["mower.solvers.operation.OperationManager"]
|
|
}, {
|
|
default: withCtx(() => _cache[2] || (_cache[2] = [
|
|
createBaseVNode("div", { class: "card-title" }, "大型任务", -1)
|
|
])),
|
|
_: 1
|
|
}, 8, ["checked", "disabled"]),
|
|
!unref(conf).task["mower.solvers.operation.OperationManager"] ? (openBlock(), createBlock(_component_help_text, { key: 0 }, {
|
|
default: withCtx(() => _cache[3] || (_cache[3] = [
|
|
createTextVNode(" 需开启日常任务 ")
|
|
])),
|
|
_: 1
|
|
})) : createCommentVNode("", true),
|
|
createVNode(_component_n_select, {
|
|
value: unref(conf).maa_long_task_type,
|
|
"onUpdate:value": _cache[1] || (_cache[1] = ($event) => unref(conf).maa_long_task_type = $event),
|
|
options: maa_long_task_options
|
|
}, null, 8, ["value"])
|
|
]),
|
|
default: withCtx(() => [
|
|
unref(conf).maa_long_task_type == "rogue" ? (openBlock(), createBlock(_component_maa_rogue, { key: 0 })) : unref(conf).maa_long_task_type == "sss" ? (openBlock(), createBlock(_component_sss, { key: 1 })) : unref(conf).maa_long_task_type == "ra" ? (openBlock(), createBlock(_component_reclamation_algorithm, { key: 2 })) : unref(conf).maa_long_task_type == "sf" ? (openBlock(), createBlock(_sfc_main$2, { key: 3 })) : unref(conf).maa_long_task_type == "vb" ? (openBlock(), createBlock(_sfc_main$1, { key: 4 })) : createCommentVNode("", true)
|
|
]),
|
|
_: 1
|
|
});
|
|
};
|
|
}
|
|
};
|
|
export {
|
|
Appearance,
|
|
AutoFight,
|
|
Clue,
|
|
DailyMission,
|
|
Device,
|
|
Email,
|
|
RIIC,
|
|
Recruit,
|
|
WeeklyPlan,
|
|
_sfc_main,
|
|
_sfc_main$9 as _sfc_main$1,
|
|
_sfc_main$a as _sfc_main$2,
|
|
_sfc_main$f as _sfc_main$3
|
|
};
|