Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(formula): add some date function (#2729)
wpxp12345626af2cc0ac6a
diff --git a/packages/engine-formula/src/basics/date.ts b/packages/engine-formula/src/basics/date.tsindex f1290e6ea9..b094b70712 100644--- a/packages/engine-formula/src/basics/date.ts+++ b/packages/engine-formula/src/basics/date.ts@@ -16,6 +16,10 @@// @ts-ignoreimport numfmt from 'numfmt';+import { isRealNum } from '@univerjs/core';+import type { BaseValueObject } from '../engine/value-object/base-value-object';+import { ErrorValueObject } from '../engine/value-object/base-value-object';+import { ErrorType } from './error-type';export const DEFAULT_DATE_FORMAT = 'yyyy/mm/dd;@';export const DEFAULT_NOW_FORMAT = 'yyyy/mm/dd hh:mm';@@ -84,6 +88,25 @@ export function excelSerialToDate(serial: number): Date {return resultDate;}+export function excelSerialToDateTime(serial: number): Date {+ const baseDate = new Date(Date.UTC(1900, 0, 1, 0, 0, 0)); // January 1, 1900, UTC+ const leapDayDate = new Date(Date.UTC(1900, 1, 28, 0, 0, 0)); // February 28, 1900, UTC++ let dayDifference = serial - 1; // Adjust for Excel serial number starting from 1++ // If the serial number corresponds to a date later than February 28, 1900, adjust the day difference+ if (dayDifference > (leapDayDate.getTime() - baseDate.getTime()) / (1000 * 3600 * 24)) {+ dayDifference -= 1;+ }++ if (dayDifference < 0) {+ dayDifference = serial;+ }++ const resultDate = new Date(baseDate.getTime() + dayDifference * (1000 * 3600 * 24));+ return resultDate;+}+export function formatDateDefault(date: Date): string {// Get the year from the date objectconst year: number = date.getFullYear();@@ -150,3 +173,172 @@ export function parseFormattedTime(value: string) {export function isDate(format: string) {return numfmt.isDate(format);}++// Weekend is a weekend number or string that specifies when weekends occur.+const weekendNumberMap: {+ [index: number]: number[];+} = {+ 1: [6, 0], // Saturday, Sunday+ 2: [0, 1], // Sunday, Monday+ 3: [1, 2], // Monday, Tuesday+ 4: [2, 3], // Tuesday, Wednesday+ 5: [3, 4], // Wednesday, Thursday+ 6: [4, 5], // Thursday, Friday+ 7: [5, 6], // Friday, Saturday+ 11: [0], // Sunday only+ 12: [1], // Monday only+ 13: [2], // Tuesday only+ 14: [3], // Wednesday only+ 15: [4], // Thursday only+ 16: [5], // Friday only+ 17: [6], // Saturday only+};++export function isValidWeekend(weekend: number | string): boolean {+ // Weekend string values are seven characters long and each character in the string represents a day of the week, starting with Monday.+ if (typeof weekend === 'string' && /^[0|1]{7}/.test(weekend)) {+ return true;+ }++ if (weekendNumberMap[Number(weekend)]) {+ return true;+ }++ return false;+}++export function getWeekendArray(weekend: number | string): number[] {+ if (!isValidWeekend(weekend)) {+ return [];+ }++ if (typeof weekend === 'string' && /^[0|1]{7}/.test(weekend)) {+ // 1 represents a non-workday and 0 represents a workday. Only the characters 1 and 0 are permitted in the string. Using 1111111 will always return 0.+ const result = [];++ for (let i = 1; i <= weekend.length; i++) {+ if (`${weekend[i - 1]}` === '1') {+ if (i === weekend.length) {+ result.push(0);+ } else {+ result.push(i);+ }+ }+ }++ return result;+ }++ return weekendNumberMap[Number(weekend)] || [];+}++export function countWorkingDays(startDateSerialNumber: number, endDateSerialNumber: number, weekend: number | string = 1, holidays?: number[]): number {+ const weekendArray = getWeekendArray(weekend);++ const start = Math.floor(startDateSerialNumber);+ const end = Math.floor(endDateSerialNumber);+ const startSerialNumber = end > start ? start : end;++ let workingDays = 0;++ const daysDiff = Math.abs(Math.floor(endDateSerialNumber) - Math.floor(startDateSerialNumber)) + 1;++ for (let i = 0; i < daysDiff; i++) {+ const currentDateSerialNumber = startSerialNumber + i;++ if (holidays && holidays.length > 0 && holidays.some((item) => Math.floor(item) === currentDateSerialNumber)) {+ continue;+ }++ const weekDay = getWeekDayByDateSerialNumber(currentDateSerialNumber);++ if (weekendArray.includes(weekDay)) {+ continue;+ }++ workingDays++;+ }++ return end > start ? workingDays : -workingDays;+}++export function getDateSerialNumberByWorkingDays(startDateSerialNumber: number, workingDays: number, weekend: number | string = 1, holidays?: number[]): (number | ErrorValueObject) {+ const weekendArray = getWeekendArray(weekend);++ startDateSerialNumber = Math.floor(startDateSerialNumber);+ let targetDateSerialNumber = startDateSerialNumber;++ let days = Math.abs(workingDays);++ for (let i = 1; i <= days; i++) {+ const currentDateSerialNumber = workingDays < 0 ? startDateSerialNumber - i : startDateSerialNumber + i;++ if (currentDateSerialNumber < 0) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ if (holidays && holidays.length > 0 && holidays.some((item) => Math.floor(item) === currentDateSerialNumber)) {+ days++;+ continue;+ }++ const weekDay = getWeekDayByDateSerialNumber(currentDateSerialNumber);++ if (weekendArray.includes(weekDay)) {+ days++;+ continue;+ }++ targetDateSerialNumber = currentDateSerialNumber;+ }++ return targetDateSerialNumber;+}++export function getDateSerialNumberByObject(serialNumberObject: BaseValueObject): (ErrorValueObject | number) {+ const dateValue = serialNumberObject.getValue();++ if (serialNumberObject.isString()) {+ let dateSerial;++ if (parseFormattedDate(`${dateValue}`)) {+ dateSerial = parseFormattedDate(`${dateValue}`).v;+ } else if (parseFormattedTime(`${dateValue}`)) {+ dateSerial = parseFormattedTime(`${dateValue}`).v;+ } else if (isRealNum(dateValue)) {+ dateSerial = +dateValue;+ } else {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (+dateSerial < 0 || +dateSerial > 2958465) { // 2958465 = 9999/12/31+ return ErrorValueObject.create(ErrorType.NUM);+ }++ return dateSerial;+ } else {+ const dateSerial = +serialNumberObject.getValue();++ if (dateSerial < 0 || dateSerial > 2958465) { // 2958465 = 9999/12/31+ return ErrorValueObject.create(ErrorType.NUM);+ }++ return dateSerial;+ }+}++export function getWeekDayByDateSerialNumber(dateSerialNumber: number): number {+ // special date 1990-02-29(serialNumber = 60)+ const isDate19000229 = Math.floor(dateSerialNumber) === 60;++ let date = excelSerialToDate(dateSerialNumber);++ const dateTime = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())).getTime();+ const leapDayDateTime = new Date(Date.UTC(1900, 1, 28)).getTime(); // February 28, 1900, UTC++ if (!isDate19000229 && dateTime <= leapDayDateTime) {+ date = new Date(dateTime - 24 * 3600 * 1000);+ }++ return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())).getUTCDay();+}diff --git a/packages/engine-formula/src/functions/date/function-map.ts b/packages/engine-formula/src/functions/date/function-map.tsindex db149ccb61..d9361818c5 100644--- a/packages/engine-formula/src/functions/date/function-map.ts+++ b/packages/engine-formula/src/functions/date/function-map.ts@@ -19,11 +19,19 @@ import { Datevalue } from './datevalue';import { Day } from './day';import { Edate } from './edate';import { FUNCTION_NAMES_DATE } from './function-names';+import { Hour } from './hour';+import { Minute } from './minute';import { Month } from './month';+import { Networkdays } from './networkdays';+import { NetworkdaysIntl } from './networkdays-intl';import { Now } from './now';+import { Second } from './second';import { Time } from './time';import { Timevalue } from './timevalue';import { Today } from './today';+import { Weekday } from './weekday';+import { Workday } from './workday';+import { WorkdayIntl } from './workday-intl';import { Year } from './year';export const functionDate = [@@ -31,10 +39,18 @@ export const functionDate = [[Datevalue, FUNCTION_NAMES_DATE.DATEVALUE],[Day, FUNCTION_NAMES_DATE.DAY],[Edate, FUNCTION_NAMES_DATE.EDATE],+ [Hour, FUNCTION_NAMES_DATE.HOUR],+ [Minute, FUNCTION_NAMES_DATE.MINUTE],[Month, FUNCTION_NAMES_DATE.MONTH],+ [Networkdays, FUNCTION_NAMES_DATE.NETWORKDAYS],+ [NetworkdaysIntl, FUNCTION_NAMES_DATE.NETWORKDAYS_INTL],[Now, FUNCTION_NAMES_DATE.NOW],+ [Second, FUNCTION_NAMES_DATE.SECOND],[Time, FUNCTION_NAMES_DATE.TIME],[Timevalue, FUNCTION_NAMES_DATE.TIMEVALUE],[Today, FUNCTION_NAMES_DATE.TODAY],+ [Weekday, FUNCTION_NAMES_DATE.WEEKDAY],+ [Workday, FUNCTION_NAMES_DATE.WORKDAY],+ [WorkdayIntl, FUNCTION_NAMES_DATE.WORKDAY_INTL],[Year, FUNCTION_NAMES_DATE.YEAR],];diff --git a/packages/engine-formula/src/functions/date/hour/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/hour/__tests__/index.spec.tsnew file mode 100644index 0000000000..ea3534a002--- /dev/null+++ b/packages/engine-formula/src/functions/date/hour/__tests__/index.spec.ts@@ -0,0 +1,68 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_DATE } from '../../function-names';+import { Hour } from '../index';+import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../../basics/error-type';++describe('Test hour function', () => {+ const testFunction = new Hour(FUNCTION_NAMES_DATE.HOUR);++ describe('Hour', () => {+ it('Serial number is normal', () => {+ const serialNumber = NumberValueObject.create(43832.233);+ const result = testFunction.calculate(serialNumber);+ expect(result.getValue()).toStrictEqual(5);+ });++ it('Serial number is error', () => {+ const serialNumber = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(serialNumber);+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);+ });++ it('Serial number is date string', () => {+ const serialNumber = StringValueObject.create('2020-01-02 7:45');+ const result = testFunction.calculate(serialNumber);+ expect(result.getValue()).toStrictEqual(7);+ });++ it('Serial number is array', () => {+ const serialNumber = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [ErrorType.NAME, 0.75, '2011-7-18 7:45', '2012-4-21'],+ [true, 'test', false, -1],+ ]),+ rowCount: 2,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(serialNumber);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [ErrorType.NAME, 18, 7, 0],+ [0, ErrorType.VALUE, 0, ErrorType.NUM],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/date/hour/index.ts b/packages/engine-formula/src/functions/date/hour/index.tsnew file mode 100644index 0000000000..94c139a6be--- /dev/null+++ b/packages/engine-formula/src/functions/date/hour/index.ts@@ -0,0 +1,61 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { excelSerialToDateTime, getDateSerialNumberByObject } from '../../../basics/date';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Hour extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(serialNumber: BaseValueObject) {+ if (serialNumber.isError()) {+ return serialNumber;+ }++ if (serialNumber.isArray()) {+ return serialNumber.map((serialNumberObject) => {+ if (serialNumberObject.isError()) {+ return serialNumberObject;+ }++ return this._handleSingleObject(serialNumberObject);+ });+ }++ return this._handleSingleObject(serialNumber);+ }++ private _handleSingleObject(serialNumberObject: BaseValueObject) {+ const dateSerialNumber = getDateSerialNumberByObject(serialNumberObject);++ if (typeof dateSerialNumber !== 'number') {+ return dateSerialNumber;+ }++ if (dateSerialNumber === 0) {+ return NumberValueObject.create(0);+ }++ const date = excelSerialToDateTime(dateSerialNumber);+ const hours = date.getUTCHours();++ return NumberValueObject.create(hours);+ }+}diff --git a/packages/engine-formula/src/functions/date/minute/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/minute/__tests__/index.spec.tsnew file mode 100644index 0000000000..2d22eae4eb--- /dev/null+++ b/packages/engine-formula/src/functions/date/minute/__tests__/index.spec.ts@@ -0,0 +1,68 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_DATE } from '../../function-names';+import { Minute } from '../index';+import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../../basics/error-type';++describe('Test minute function', () => {+ const testFunction = new Minute(FUNCTION_NAMES_DATE.MINUTE);++ describe('Minute', () => {+ it('Serial number is normal', () => {+ const serialNumber = NumberValueObject.create(43832.233);+ const result = testFunction.calculate(serialNumber);+ expect(result.getValue()).toStrictEqual(35);+ });++ it('Serial number is error', () => {+ const serialNumber = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(serialNumber);+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);+ });++ it('Serial number is date string', () => {+ const serialNumber = StringValueObject.create('2020-01-02 7:45');+ const result = testFunction.calculate(serialNumber);+ expect(result.getValue()).toStrictEqual(45);+ });++ it('Serial number is array', () => {+ const serialNumber = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [ErrorType.NAME, 0.75, '2011-7-18 7:45', '2012-4-21'],+ [true, 'test', false, -1],+ ]),+ rowCount: 2,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(serialNumber);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [ErrorType.NAME, 0, 45, 0],+ [0, ErrorType.VALUE, 0, ErrorType.NUM],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/date/minute/index.ts b/packages/engine-formula/src/functions/date/minute/index.tsnew file mode 100644index 0000000000..5ba642f106--- /dev/null+++ b/packages/engine-formula/src/functions/date/minute/index.ts@@ -0,0 +1,61 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { excelSerialToDateTime, getDateSerialNumberByObject } from '../../../basics/date';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Minute extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(serialNumber: BaseValueObject) {+ if (serialNumber.isError()) {+ return serialNumber;+ }++ if (serialNumber.isArray()) {+ return serialNumber.map((serialNumberObject) => {+ if (serialNumberObject.isError()) {+ return serialNumberObject;+ }++ return this._handleSingleObject(serialNumberObject);+ });+ }++ return this._handleSingleObject(serialNumber);+ }++ private _handleSingleObject(serialNumberObject: BaseValueObject) {+ const dateSerialNumber = getDateSerialNumberByObject(serialNumberObject);++ if (typeof dateSerialNumber !== 'number') {+ return dateSerialNumber;+ }++ if (dateSerialNumber === 0) {+ return NumberValueObject.create(0);+ }++ const date = excelSerialToDateTime(dateSerialNumber);+ const minutes = date.getUTCMinutes();++ return NumberValueObject.create(minutes);+ }+}diff --git a/packages/engine-formula/src/functions/date/networkdays-intl/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/networkdays-intl/__tests__/index.spec.tsnew file mode 100644index 0000000000..98e8399463--- /dev/null+++ b/packages/engine-formula/src/functions/date/networkdays-intl/__tests__/index.spec.ts@@ -0,0 +1,205 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_DATE } from '../../function-names';+import { NetworkdaysIntl } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../../basics/error-type';++describe('Test networkdays.intl function', () => {+ const testFunction = new NetworkdaysIntl(FUNCTION_NAMES_DATE.NETWORKDAYS);++ describe('NetworkdaysIntl', () => {+ it('Value is all date string', () => {+ const startDate = StringValueObject.create('2012-10-1');+ const endDate = StringValueObject.create('2013-3-1');+ const result = testFunction.calculate(startDate, endDate);+ expect(result.getValue()).toStrictEqual(110);++ const weekend2 = NumberValueObject.create(6);+ const holidays2 = StringValueObject.create('2012-11-22');+ const result2 = testFunction.calculate(startDate, endDate, weekend2, holidays2);+ expect(result2.getValue()).toStrictEqual(108);++ const weekend3 = StringValueObject.create('0011001');+ const holidays3 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['2012-11-22'],+ ['2012-12-4'],+ ['2013-1-21'],+ ]),+ rowCount: 3,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result3 = testFunction.calculate(startDate, endDate, weekend3, holidays3);+ expect(result3.getValue()).toStrictEqual(85);+ });++ it('Value is number or date string', () => {+ const startDate = NumberValueObject.create(45122);+ const endDate = StringValueObject.create('2013-3-1');+ const result = testFunction.calculate(startDate, endDate);+ expect(result.getValue()).toStrictEqual(-2706);+ });++ it('Value is not date string', () => {+ const startDate = StringValueObject.create('test');+ const endDate = StringValueObject.create('2013-3-1');+ const result = testFunction.calculate(startDate, endDate);+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate2 = StringValueObject.create('2012-10-1');+ const endDate2 = StringValueObject.create('test');+ const result2 = testFunction.calculate(startDate2, endDate2);+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate3 = StringValueObject.create('2012-10-1');+ const endDate3 = StringValueObject.create('2013-3-1');+ const weekend3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(startDate3, endDate3, weekend3);+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate4 = StringValueObject.create('2012-10-1');+ const endDate4 = StringValueObject.create('2013-3-1');+ const weekend4 = StringValueObject.create('1110001');+ const holidays4 = StringValueObject.create('test');+ const result4 = testFunction.calculate(startDate4, endDate4, weekend4, holidays4);+ expect(result4.getValue()).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is blank cell', () => {+ const startDate = NullValueObject.create();+ const endDate = StringValueObject.create('2013-3-1');+ const result = testFunction.calculate(startDate, endDate);+ expect(result.getValue()).toStrictEqual(29525);++ const startDate2 = StringValueObject.create('2012-10-1');+ const endDate2 = NullValueObject.create();+ const result2 = testFunction.calculate(startDate2, endDate2);+ expect(result2.getValue()).toStrictEqual(-29416);++ const startDate3 = StringValueObject.create('2012-10-1');+ const endDate3 = StringValueObject.create('2013-3-1');+ const weekend3 = NullValueObject.create();+ const result3 = testFunction.calculate(startDate3, endDate3, weekend3);+ expect(result3.getValue()).toStrictEqual(ErrorType.NUM);++ const startDate4 = StringValueObject.create('2012-10-1');+ const endDate4 = StringValueObject.create('2013-3-1');+ const weekend4 = NumberValueObject.create(5);+ const holidays4 = NullValueObject.create();+ const result4 = testFunction.calculate(startDate4, endDate4, weekend4, holidays4);+ expect(result4.getValue()).toStrictEqual(108);+ });++ it('Value is boolean', () => {+ const startDate = BooleanValueObject.create(true);+ const endDate = StringValueObject.create('2013-3-1');+ const result = testFunction.calculate(startDate, endDate);+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate2 = StringValueObject.create('2012-10-1');+ const endDate2 = BooleanValueObject.create(false);+ const result2 = testFunction.calculate(startDate2, endDate2);+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate3 = StringValueObject.create('2012-10-1');+ const endDate3 = StringValueObject.create('2013-3-1');+ const weekend3 = BooleanValueObject.create(true);+ const result3 = testFunction.calculate(startDate3, endDate3, weekend3);+ expect(result3.getValue()).toStrictEqual(110);++ const startDate4 = StringValueObject.create('2012-10-1');+ const endDate4 = StringValueObject.create('2013-3-1');+ const weekend4 = NumberValueObject.create(1);+ const holidays4 = BooleanValueObject.create(true);+ const result4 = testFunction.calculate(startDate4, endDate4, weekend4, holidays4);+ expect(result4.getValue()).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is error', () => {+ const startDate = ErrorValueObject.create(ErrorType.NAME);+ const endDate = StringValueObject.create('2013-3-1');+ const result = testFunction.calculate(startDate, endDate);+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);++ const startDate2 = StringValueObject.create('2012-10-1');+ const endDate2 = ErrorValueObject.create(ErrorType.NAME);+ const result2 = testFunction.calculate(startDate2, endDate2);+ expect(result2.getValue()).toStrictEqual(ErrorType.NAME);++ const startDate3 = StringValueObject.create('2012-10-1');+ const endDate3 = StringValueObject.create('2013-3-1');+ const weekend3 = ErrorValueObject.create(ErrorType.NAME);+ const result3 = testFunction.calculate(startDate3, endDate3, weekend3);+ expect(result3.getValue()).toStrictEqual(ErrorType.NAME);++ const startDate4 = StringValueObject.create('2012-10-1');+ const endDate4 = StringValueObject.create('2013-3-1');+ const weekend4 = NumberValueObject.create(1);+ const holidays4 = ErrorValueObject.create(ErrorType.NAME);+ const result4 = testFunction.calculate(startDate4, endDate4, weekend4, holidays4);+ expect(result4.getValue()).toStrictEqual(ErrorType.NAME);+ });++ it('Weekend value is array', () => {+ const startDate = StringValueObject.create('2012-10-1');+ const endDate = StringValueObject.create('2013-3-1');+ const weekend = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [true, null, null],+ ['abc', null, null],+ [6, null, null],+ [8, null, null],+ ]),+ rowCount: 4,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const holidays = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['2012-11-22'],+ ['2012-12-4'],+ ['2013-1-21'],+ ]),+ rowCount: 3,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(startDate, endDate, weekend, holidays);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [107, ErrorType.NUM, ErrorType.NUM],+ [ErrorType.VALUE, ErrorType.NUM, ErrorType.NUM],+ [106, ErrorType.NUM, ErrorType.NUM],+ [ErrorType.NUM, ErrorType.NUM, ErrorType.NUM],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/date/networkdays-intl/index.ts b/packages/engine-formula/src/functions/date/networkdays-intl/index.tsnew file mode 100644index 0000000000..aa9922af7d--- /dev/null+++ b/packages/engine-formula/src/functions/date/networkdays-intl/index.ts@@ -0,0 +1,160 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { countWorkingDays, getDateSerialNumberByObject, isValidWeekend } from '../../../basics/date';+import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class NetworkdaysIntl extends BaseFunction {+ override minParams = 2;++ override maxParams = 4;++ override calculate(startDate: BaseValueObject, endDate: BaseValueObject, weekend?: BaseValueObject, holidays?: BaseValueObject) {+ if (startDate.isError()) {+ return startDate;+ }++ if (endDate.isError()) {+ return endDate;+ }++ if (weekend?.isError()) {+ return weekend;+ }++ if (holidays?.isError()) {+ return holidays;+ }++ if (weekend?.isArray()) {+ return weekend.map((weekendItem) => this._handleSingleObject(startDate, endDate, weekendItem, holidays));+ }++ return this._handleSingleObject(startDate, endDate, weekend, holidays);+ }++ private _handleSingleObject(startDate: BaseValueObject, endDate: BaseValueObject, weekend?: BaseValueObject, holidays?: BaseValueObject) {+ let weekendValue: number | string = 1;++ if (weekend) {+ weekendValue = weekend.getValue() as number | string;++ if (weekend.isBoolean()) {+ weekendValue = +weekendValue;+ }++ if (weekend.isString() && !isValidWeekend(weekendValue)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (!isValidWeekend(weekendValue)) {+ return ErrorValueObject.create(ErrorType.NUM);+ }+ }++ if (startDate.isArray()) {+ if ((startDate as ArrayValueObject).getRowCount() > 1 || (startDate as ArrayValueObject).getColumnCount() > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ startDate = (startDate as ArrayValueObject).get(0, 0) as BaseValueObject;++ if (startDate.isError()) {+ return startDate;+ }+ }++ if (endDate.isArray()) {+ if ((endDate as ArrayValueObject).getRowCount() > 1 || (endDate as ArrayValueObject).getColumnCount() > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ endDate = (endDate as ArrayValueObject).get(0, 0) as BaseValueObject;++ if (endDate.isError()) {+ return endDate;+ }+ }++ if (startDate.isBoolean() || endDate.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const startDateSerialNumber = getDateSerialNumberByObject(startDate);++ if (typeof startDateSerialNumber !== 'number') {+ return startDateSerialNumber;+ }++ const endDateSerialNumber = getDateSerialNumberByObject(endDate);++ if (typeof endDateSerialNumber !== 'number') {+ return endDateSerialNumber;+ }++ let result: number;++ if (holidays) {+ const holidaysValueArray = [];++ if (holidays?.isArray()) {+ const rowCount = (holidays as ArrayValueObject).getRowCount();+ const columnCount = (holidays as ArrayValueObject).getColumnCount();++ for (let r = 0; r < rowCount; r++) {+ for (let c = 0; c < columnCount; c++) {+ const cell = (holidays as ArrayValueObject).get(r, c) as BaseValueObject;++ if (cell.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const holidaySerialNumber = getDateSerialNumberByObject(cell);++ if (typeof holidaySerialNumber !== 'number') {+ return holidaySerialNumber;+ }++ holidaysValueArray.push(holidaySerialNumber);+ }+ }+ } else {+ if (holidays.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const holidaySerialNumber = getDateSerialNumberByObject(holidays);++ if (typeof holidaySerialNumber !== 'number') {+ return holidaySerialNumber;+ }++ holidaysValueArray.push(holidaySerialNumber);+ }++ result = countWorkingDays(startDateSerialNumber, endDateSerialNumber, weekendValue, holidaysValueArray);+ } else {+ result = countWorkingDays(startDateSerialNumber, endDateSerialNumber, weekendValue);+ }++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/date/networkdays/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/networkdays/__tests__/index.spec.tsnew file mode 100644index 0000000000..427bcbf93d--- /dev/null+++ b/packages/engine-formula/src/functions/date/networkdays/__tests__/index.spec.ts@@ -0,0 +1,140 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_DATE } from '../../function-names';+import { Networkdays } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../../basics/error-type';++describe('Test networkdays function', () => {+ const testFunction = new Networkdays(FUNCTION_NAMES_DATE.NETWORKDAYS);++ describe('Networkdays', () => {+ it('Value is all date string', () => {+ const startDate = StringValueObject.create('2012-10-1');+ const endDate = StringValueObject.create('2013-3-1');+ const result = testFunction.calculate(startDate, endDate);+ expect(result.getValue()).toStrictEqual(110);++ const holidays2 = StringValueObject.create('2012-11-22');+ const result2 = testFunction.calculate(startDate, endDate, holidays2);+ expect(result2.getValue()).toStrictEqual(109);++ const holidays3 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['2012-11-22'],+ ['2012-12-4'],+ ['2013-1-21'],+ ]),+ rowCount: 3,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result3 = testFunction.calculate(startDate, endDate, holidays3);+ expect(result3.getValue()).toStrictEqual(107);+ });++ it('Value is number or date string', () => {+ const startDate = NumberValueObject.create(45122);+ const endDate = StringValueObject.create('2013-3-1');+ const result = testFunction.calculate(startDate, endDate);+ expect(result.getValue()).toStrictEqual(-2706);++ const holidays2 = NumberValueObject.create(45001);+ const result2 = testFunction.calculate(startDate, endDate, holidays2);+ expect(result2.getValue()).toStrictEqual(-2705);+ });++ it('Value is not date string', () => {+ const startDate = StringValueObject.create('test');+ const endDate = StringValueObject.create('2013-3-1');+ const result = testFunction.calculate(startDate, endDate);+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate2 = StringValueObject.create('2012-10-1');+ const endDate2 = StringValueObject.create('test');+ const result2 = testFunction.calculate(startDate2, endDate2);+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate3 = StringValueObject.create('2012-10-1');+ const endDate3 = StringValueObject.create('2013-3-1');+ const holidays3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(startDate3, endDate3, holidays3);+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is blank cell', () => {+ const startDate = NullValueObject.create();+ const endDate = StringValueObject.create('2013-3-1');+ const result = testFunction.calculate(startDate, endDate);+ expect(result.getValue()).toStrictEqual(29525);++ const startDate2 = StringValueObject.create('2012-10-1');+ const endDate2 = NullValueObject.create();+ const result2 = testFunction.calculate(startDate2, endDate2);+ expect(result2.getValue()).toStrictEqual(-29416);++ const startDate3 = StringValueObject.create('2012-10-1');+ const endDate3 = StringValueObject.create('2013-3-1');+ const holidays3 = NullValueObject.create();+ const result3 = testFunction.calculate(startDate3, endDate3, holidays3);+ expect(result3.getValue()).toStrictEqual(110);+ });++ it('Value is boolean', () => {+ const startDate = BooleanValueObject.create(true);+ const endDate = StringValueObject.create('2013-3-1');+ const result = testFunction.calculate(startDate, endDate);+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate2 = StringValueObject.create('2012-10-1');+ const endDate2 = BooleanValueObject.create(false);+ const result2 = testFunction.calculate(startDate2, endDate2);+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate3 = StringValueObject.create('2012-10-1');+ const endDate3 = StringValueObject.create('2013-3-1');+ const holidays3 = BooleanValueObject.create(true);+ const result3 = testFunction.calculate(startDate3, endDate3, holidays3);+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is error', () => {+ const startDate = ErrorValueObject.create(ErrorType.NAME);+ const endDate = StringValueObject.create('2013-3-1');+ const result = testFunction.calculate(startDate, endDate);+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);++ const startDate2 = StringValueObject.create('2012-10-1');+ const endDate2 = ErrorValueObject.create(ErrorType.NAME);+ const result2 = testFunction.calculate(startDate2, endDate2);+ expect(result2.getValue()).toStrictEqual(ErrorType.NAME);++ const startDate3 = StringValueObject.create('2012-10-1');+ const endDate3 = StringValueObject.create('2013-3-1');+ const holidays3 = ErrorValueObject.create(ErrorType.NAME);+ const result3 = testFunction.calculate(startDate3, endDate3, holidays3);+ expect(result3.getValue()).toStrictEqual(ErrorType.NAME);+ });+ });+});diff --git a/packages/engine-formula/src/functions/date/networkdays/index.ts b/packages/engine-formula/src/functions/date/networkdays/index.tsnew file mode 100644index 0000000000..c7318ac0ee--- /dev/null+++ b/packages/engine-formula/src/functions/date/networkdays/index.ts@@ -0,0 +1,130 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { countWorkingDays, getDateSerialNumberByObject } from '../../../basics/date';+import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Networkdays extends BaseFunction {+ override minParams = 2;++ override maxParams = 3;++ override calculate(startDate: BaseValueObject, endDate: BaseValueObject, holidays?: BaseValueObject) {+ if (startDate.isError()) {+ return startDate;+ }++ if (endDate.isError()) {+ return endDate;+ }++ if (holidays?.isError()) {+ return holidays;+ }++ if (startDate.isArray()) {+ if ((startDate as ArrayValueObject).getRowCount() > 1 || (startDate as ArrayValueObject).getColumnCount() > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ startDate = (startDate as ArrayValueObject).get(0, 0) as BaseValueObject;++ if (startDate.isError()) {+ return startDate;+ }+ }++ if (endDate.isArray()) {+ if ((endDate as ArrayValueObject).getRowCount() > 1 || (endDate as ArrayValueObject).getColumnCount() > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ endDate = (endDate as ArrayValueObject).get(0, 0) as BaseValueObject;++ if (endDate.isError()) {+ return endDate;+ }+ }++ if (startDate.isBoolean() || endDate.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const startDateSerialNumber = getDateSerialNumberByObject(startDate);++ if (typeof startDateSerialNumber !== 'number') {+ return startDateSerialNumber;+ }++ const endDateSerialNumber = getDateSerialNumberByObject(endDate);++ if (typeof endDateSerialNumber !== 'number') {+ return endDateSerialNumber;+ }++ let result: number;++ if (holidays) {+ const holidaysValueArray = [];++ if (holidays?.isArray()) {+ const rowCount = (holidays as ArrayValueObject).getRowCount();+ const columnCount = (holidays as ArrayValueObject).getColumnCount();++ for (let r = 0; r < rowCount; r++) {+ for (let c = 0; c < columnCount; c++) {+ const cell = (holidays as ArrayValueObject).get(r, c) as BaseValueObject;++ if (cell.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const holidaySerialNumber = getDateSerialNumberByObject(cell);++ if (typeof holidaySerialNumber !== 'number') {+ return holidaySerialNumber;+ }++ holidaysValueArray.push(holidaySerialNumber);+ }+ }+ } else {+ if (holidays.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const holidaySerialNumber = getDateSerialNumberByObject(holidays);++ if (typeof holidaySerialNumber !== 'number') {+ return holidaySerialNumber;+ }++ holidaysValueArray.push(holidaySerialNumber);+ }++ result = countWorkingDays(startDateSerialNumber, endDateSerialNumber, 1, holidaysValueArray);+ } else {+ result = countWorkingDays(startDateSerialNumber, endDateSerialNumber);+ }++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/date/second/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/second/__tests__/index.spec.tsnew file mode 100644index 0000000000..fb40306836--- /dev/null+++ b/packages/engine-formula/src/functions/date/second/__tests__/index.spec.ts@@ -0,0 +1,68 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_DATE } from '../../function-names';+import { Second } from '../index';+import { NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../../basics/error-type';++describe('Test second function', () => {+ const testFunction = new Second(FUNCTION_NAMES_DATE.SECOND);++ describe('Second', () => {+ it('Serial number is normal', () => {+ const serialNumber = NumberValueObject.create(43832.233);+ const result = testFunction.calculate(serialNumber);+ expect(result.getValue()).toStrictEqual(31);+ });++ it('Serial number is error', () => {+ const serialNumber = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(serialNumber);+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);+ });++ it('Serial number is date string', () => {+ const serialNumber = StringValueObject.create('2020-01-02 7:45:18');+ const result = testFunction.calculate(serialNumber);+ expect(result.getValue()).toStrictEqual(18);+ });++ it('Serial number is array', () => {+ const serialNumber = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [ErrorType.NAME, 0.75, '2011-7-18 7:45:18', '2012-4-21'],+ [true, 'test', false, -1],+ ]),+ rowCount: 2,+ columnCount: 4,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(serialNumber);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [ErrorType.NAME, 0, 18, 0],+ [0, ErrorType.VALUE, 0, ErrorType.NUM],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/date/second/index.ts b/packages/engine-formula/src/functions/date/second/index.tsnew file mode 100644index 0000000000..5e4bbd170c--- /dev/null+++ b/packages/engine-formula/src/functions/date/second/index.ts@@ -0,0 +1,61 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { excelSerialToDateTime, getDateSerialNumberByObject } from '../../../basics/date';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Second extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(serialNumber: BaseValueObject) {+ if (serialNumber.isError()) {+ return serialNumber;+ }++ if (serialNumber.isArray()) {+ return serialNumber.map((serialNumberObject) => {+ if (serialNumberObject.isError()) {+ return serialNumberObject;+ }++ return this._handleSingleObject(serialNumberObject);+ });+ }++ return this._handleSingleObject(serialNumber);+ }++ private _handleSingleObject(serialNumberObject: BaseValueObject) {+ const dateSerialNumber = getDateSerialNumberByObject(serialNumberObject);++ if (typeof dateSerialNumber !== 'number') {+ return dateSerialNumber;+ }++ if (dateSerialNumber === 0) {+ return NumberValueObject.create(0);+ }++ const date = excelSerialToDateTime(dateSerialNumber);+ const seconds = date.getUTCSeconds();++ return NumberValueObject.create(seconds);+ }+}diff --git a/packages/engine-formula/src/functions/date/weekday/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/weekday/__tests__/index.spec.tsnew file mode 100644index 0000000000..e797300f62--- /dev/null+++ b/packages/engine-formula/src/functions/date/weekday/__tests__/index.spec.ts@@ -0,0 +1,119 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_DATE } from '../../function-names';+import { Weekday } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../../basics/error-type';++describe('Test weekday function', () => {+ const testFunction = new Weekday(FUNCTION_NAMES_DATE.WEEKDAY);++ describe('Weekday', () => {+ it('Value is all normal', () => {+ const serialNumber = NumberValueObject.create(43832);+ const returnType = NumberValueObject.create(2);+ const result = testFunction.calculate(serialNumber, returnType);+ expect(result.getValue()).toStrictEqual(4);++ const serialNumber2 = StringValueObject.create('2008-11-26');+ const returnType2 = NumberValueObject.create(1);+ const result2 = testFunction.calculate(serialNumber2, returnType2);+ expect(result2.getValue()).toStrictEqual(4);+ });++ it('Value is error', () => {+ const serialNumber = ErrorValueObject.create(ErrorType.NAME);+ const returnType = NumberValueObject.create(2);+ const result = testFunction.calculate(serialNumber, returnType);+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);++ const serialNumber2 = StringValueObject.create('2008-11-26');+ const returnType2 = ErrorValueObject.create(ErrorType.NAME);+ const result2 = testFunction.calculate(serialNumber2, returnType2);+ expect(result2.getValue()).toStrictEqual(ErrorType.NAME);+ });++ it('Value is boolean', () => {+ const serialNumber = BooleanValueObject.create(false);+ const returnType = NumberValueObject.create(2);+ const result = testFunction.calculate(serialNumber, returnType);+ expect(result.getValue()).toStrictEqual(6);++ const serialNumber2 = StringValueObject.create('2008-11-26');+ const returnType2 = BooleanValueObject.create(true);+ const result2 = testFunction.calculate(serialNumber2, returnType2);+ expect(result2.getValue()).toStrictEqual(4);+ });++ it('Value is blank cell', () => {+ const serialNumber = NullValueObject.create();+ const returnType = NumberValueObject.create(2);+ const result = testFunction.calculate(serialNumber, returnType);+ expect(result.getValue()).toStrictEqual(6);++ const serialNumber2 = StringValueObject.create('2008-11-26');+ const returnType2 = NullValueObject.create();+ const result2 = testFunction.calculate(serialNumber2, returnType2);+ expect(result2.getValue()).toStrictEqual(ErrorType.NUM);+ });++ it('Value is array', () => {+ const serialNumber = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['2008-11-26', '2008-12-4', '2009-1-21'],+ ]),+ rowCount: 1,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const returnType = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1],+ [2.5],+ [3],+ [true],+ ['abc'],+ [-6],+ [999999],+ ]),+ rowCount: 7,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(serialNumber, returnType);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [4, 5, 4],+ [3, 4, 3],+ [2, 3, 2],+ [4, 5, 4],+ [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE],+ [ErrorType.NUM, ErrorType.NUM, ErrorType.NUM],+ [ErrorType.NUM, ErrorType.NUM, ErrorType.NUM],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/date/weekday/index.ts b/packages/engine-formula/src/functions/date/weekday/index.tsnew file mode 100644index 0000000000..94cd0b0ba7--- /dev/null+++ b/packages/engine-formula/src/functions/date/weekday/index.ts@@ -0,0 +1,124 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { getDateSerialNumberByObject, getWeekDayByDateSerialNumber } from '../../../basics/date';+import { ErrorType } from '../../../basics/error-type';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Weekday extends BaseFunction {+ override minParams = 1;++ override maxParams = 2;++ override calculate(serialNumber: BaseValueObject, returnType?: BaseValueObject) {+ if (serialNumber.isError()) {+ return serialNumber;+ }++ if (returnType?.isError()) {+ return returnType;+ }++ // get max row length+ const maxRowLength = Math.max(+ serialNumber.isArray() ? (serialNumber as ArrayValueObject).getRowCount() : 1,+ returnType?.isArray() ? (returnType as ArrayValueObject).getRowCount() : 1+ );++ // get max column length+ const maxColumnLength = Math.max(+ serialNumber.isArray() ? (serialNumber as ArrayValueObject).getColumnCount() : 1,+ returnType?.isArray() ? (returnType as ArrayValueObject).getColumnCount() : 1+ );++ const serialNumberArray = expandArrayValueObject(maxRowLength, maxColumnLength, serialNumber, ErrorValueObject.create(ErrorType.NA));+ const returnTypeArray = returnType ? expandArrayValueObject(maxRowLength, maxColumnLength, returnType, ErrorValueObject.create(ErrorType.NA)) : [];++ const resultArray = serialNumberArray.map((serialNumberObject, rowIndex, columnIndex) => {+ if (returnType) {+ const returnTypeObject = (returnTypeArray as ArrayValueObject).get(rowIndex, columnIndex) as BaseValueObject;+ return this._handleSingleObject(serialNumberObject, returnTypeObject);+ } else {+ return this._handleSingleObject(serialNumberObject);+ }+ });++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return resultArray.getArrayValue()[0][0] as NumberValueObject;+ }++ return resultArray;+ }++ private _handleSingleObject(serialNumberObject: BaseValueObject, returnTypeObject?: BaseValueObject) {+ if (serialNumberObject.isError()) {+ return serialNumberObject;+ }++ if (returnTypeObject?.isError()) {+ return returnTypeObject;+ }++ const dateSerialNumber = getDateSerialNumberByObject(serialNumberObject);++ if (typeof dateSerialNumber !== 'number') {+ return dateSerialNumber;+ }++ const returnTypeMap: {+ [index: number]: number[];+ } = {+ 1: [1, 2, 3, 4, 5, 6, 7], // Sunday = 1 ~ Saturday = 7+ 2: [7, 1, 2, 3, 4, 5, 6], // Monday = 1 ~ Sunday = 7+ 3: [6, 0, 1, 2, 3, 4, 5], // Monday = 0 ~ Sunday = 6+ 11: [7, 1, 2, 3, 4, 5, 6], // Monday = 1 ~ Sunday = 7+ 12: [6, 7, 1, 2, 3, 4, 5], // Tuesday = 1 ~ Monday = 7+ 13: [5, 6, 7, 1, 2, 3, 4], // Wednesday = 1 ~ Tuesday = 7+ 14: [4, 5, 6, 7, 1, 2, 3], // Thursday = 1 ~ Wednesday = 7+ 15: [3, 4, 5, 6, 7, 1, 2], // Friday = 1 ~ Thursday = 7+ 16: [2, 3, 4, 5, 6, 7, 1], // Saturday = 1 ~ Friday = 7+ 17: [1, 2, 3, 4, 5, 6, 7], // Sunday = 1 ~ Saturday = 7+ };++ let returnType = 1;++ if (returnTypeObject) {+ if (returnTypeObject.isString()) {+ returnTypeObject = returnTypeObject.convertToNumberObjectValue();+ }++ if (returnTypeObject.isError()) {+ return returnTypeObject;+ }++ returnType = Math.floor(+returnTypeObject.getValue());++ if (!returnTypeMap[returnType]) {+ return ErrorValueObject.create(ErrorType.NUM);+ }+ }++ const weekDay = getWeekDayByDateSerialNumber(dateSerialNumber);++ const result = returnTypeMap[returnType][weekDay];++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/date/workday-intl/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/workday-intl/__tests__/index.spec.tsnew file mode 100644index 0000000000..356979ee60--- /dev/null+++ b/packages/engine-formula/src/functions/date/workday-intl/__tests__/index.spec.ts@@ -0,0 +1,198 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_DATE } from '../../function-names';+import { WorkdayIntl } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../../basics/error-type';++describe('Test workday.intl function', () => {+ const testFunction = new WorkdayIntl(FUNCTION_NAMES_DATE.NETWORKDAYS);++ describe('WorkdayIntl', () => {+ it('Value is all normal', () => {+ const startDate = StringValueObject.create('2008-10-1');+ const days = NumberValueObject.create(151);+ const result = testFunction.calculate(startDate, days);+ expect(result.getValue()).toStrictEqual(39933);++ const weekend2 = NumberValueObject.create(6);+ const holidays2 = StringValueObject.create('2008-11-26');+ const result2 = testFunction.calculate(startDate, days, weekend2, holidays2);+ expect(result2.getValue()).toStrictEqual(39936);++ const weekend3 = StringValueObject.create('0011001');+ const holidays3 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['2008-11-26'],+ ['2008-12-4'],+ ['2009-1-21'],+ ]),+ rowCount: 3,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result3 = testFunction.calculate(startDate, days, weekend3, holidays3);+ expect(result3.getValue()).toStrictEqual(39986);+ });++ it('Value is not date string', () => {+ const startDate = StringValueObject.create('test');+ const days = NumberValueObject.create(151);+ const result = testFunction.calculate(startDate, days);+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate2 = StringValueObject.create('2008-10-1');+ const days2 = StringValueObject.create('test');+ const result2 = testFunction.calculate(startDate2, days2);+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate3 = StringValueObject.create('2008-10-1');+ const days3 = NumberValueObject.create(151);+ const weekend3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(startDate3, days3, weekend3);+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate4 = StringValueObject.create('2008-10-1');+ const days4 = NumberValueObject.create(151);+ const weekend4 = StringValueObject.create('1110001');+ const holidays4 = StringValueObject.create('test');+ const result4 = testFunction.calculate(startDate4, days4, weekend4, holidays4);+ expect(result4.getValue()).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is blank cell', () => {+ const startDate = NullValueObject.create();+ const days = NumberValueObject.create(151);+ const result = testFunction.calculate(startDate, days);+ expect(result.getValue()).toStrictEqual(212);++ const startDate2 = StringValueObject.create('2008-10-1');+ const days2 = NullValueObject.create();+ const result2 = testFunction.calculate(startDate2, days2);+ expect(result2.getValue()).toStrictEqual(39722);++ const startDate3 = StringValueObject.create('2008-10-1');+ const days3 = NumberValueObject.create(151);+ const weekend3 = NullValueObject.create();+ const result3 = testFunction.calculate(startDate3, days3, weekend3);+ expect(result3.getValue()).toStrictEqual(ErrorType.NUM);++ const startDate4 = StringValueObject.create('2008-10-1');+ const days4 = NumberValueObject.create(151);+ const weekend4 = NumberValueObject.create(5);+ const holidays4 = NullValueObject.create();+ const result4 = testFunction.calculate(startDate4, days4, weekend4, holidays4);+ expect(result4.getValue()).toStrictEqual(39934);+ });++ it('Value is boolean', () => {+ const startDate = BooleanValueObject.create(true);+ const days = NumberValueObject.create(151);+ const result = testFunction.calculate(startDate, days);+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate2 = StringValueObject.create('2008-10-1');+ const days2 = BooleanValueObject.create(false);+ const result2 = testFunction.calculate(startDate2, days2);+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate3 = StringValueObject.create('2008-10-1');+ const days3 = NumberValueObject.create(151);+ const weekend3 = BooleanValueObject.create(true);+ const result3 = testFunction.calculate(startDate3, days3, weekend3);+ expect(result3.getValue()).toStrictEqual(39933);++ const startDate4 = StringValueObject.create('2008-10-1');+ const days4 = NumberValueObject.create(151);+ const weekend4 = NumberValueObject.create(1);+ const holidays4 = BooleanValueObject.create(true);+ const result4 = testFunction.calculate(startDate4, days4, weekend4, holidays4);+ expect(result4.getValue()).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is error', () => {+ const startDate = ErrorValueObject.create(ErrorType.NAME);+ const days = NumberValueObject.create(151);+ const result = testFunction.calculate(startDate, days);+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);++ const startDate2 = StringValueObject.create('2008-10-1');+ const days2 = ErrorValueObject.create(ErrorType.NAME);+ const result2 = testFunction.calculate(startDate2, days2);+ expect(result2.getValue()).toStrictEqual(ErrorType.NAME);++ const startDate3 = StringValueObject.create('2008-10-1');+ const days3 = NumberValueObject.create(151);+ const weekend3 = ErrorValueObject.create(ErrorType.NAME);+ const result3 = testFunction.calculate(startDate3, days3, weekend3);+ expect(result3.getValue()).toStrictEqual(ErrorType.NAME);++ const startDate4 = StringValueObject.create('2008-10-1');+ const days4 = NumberValueObject.create(151);+ const weekend4 = NumberValueObject.create(1);+ const holidays4 = ErrorValueObject.create(ErrorType.NAME);+ const result4 = testFunction.calculate(startDate4, days4, weekend4, holidays4);+ expect(result4.getValue()).toStrictEqual(ErrorType.NAME);+ });++ it('Weekend value is array', () => {+ const startDate = StringValueObject.create('2008-10-1');+ const days = NumberValueObject.create(151);+ const weekend = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [true, null, null],+ ['abc', null, null],+ [-6, null, null],+ [7, null, null],+ ]),+ rowCount: 4,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const holidays = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['2008-11-26'],+ ['2008-12-4'],+ ['2009-1-21'],+ ]),+ rowCount: 3,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(startDate, days, weekend, holidays);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [39938, ErrorType.NUM, ErrorType.NUM],+ [ErrorType.VALUE, ErrorType.NUM, ErrorType.NUM],+ [ErrorType.NUM, ErrorType.NUM, ErrorType.NUM],+ [39938, ErrorType.NUM, ErrorType.NUM],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/date/workday-intl/index.ts b/packages/engine-formula/src/functions/date/workday-intl/index.tsnew file mode 100644index 0000000000..4377f9d73b--- /dev/null+++ b/packages/engine-formula/src/functions/date/workday-intl/index.ts@@ -0,0 +1,169 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { getDateSerialNumberByObject, getDateSerialNumberByWorkingDays, isValidWeekend } from '../../../basics/date';+import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class WorkdayIntl extends BaseFunction {+ override minParams = 2;++ override maxParams = 4;++ override calculate(startDate: BaseValueObject, days: BaseValueObject, weekend?: BaseValueObject, holidays?: BaseValueObject) {+ if (startDate.isError()) {+ return startDate;+ }++ if (days.isError()) {+ return days;+ }++ if (weekend?.isError()) {+ return weekend;+ }++ if (holidays?.isError()) {+ return holidays;+ }++ if (weekend?.isArray()) {+ return weekend.map((weekendItem) => this._handleSingleObject(startDate, days, weekendItem, holidays));+ }++ return this._handleSingleObject(startDate, days, weekend, holidays);+ }++ private _handleSingleObject(startDate: BaseValueObject, days: BaseValueObject, weekend?: BaseValueObject, holidays?: BaseValueObject) {+ let weekendValue: number | string = 1;++ if (weekend) {+ weekendValue = weekend.getValue() as number | string;++ if (weekend.isBoolean()) {+ weekendValue = +weekendValue;+ }++ // 1111111 is an invalid string.+ if (weekend.isString() && (!isValidWeekend(weekendValue) || weekendValue === '1111111')) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (!isValidWeekend(weekendValue)) {+ return ErrorValueObject.create(ErrorType.NUM);+ }+ }++ if (startDate.isArray()) {+ if ((startDate as ArrayValueObject).getRowCount() > 1 || (startDate as ArrayValueObject).getColumnCount() > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ startDate = (startDate as ArrayValueObject).get(0, 0) as BaseValueObject;++ if (startDate.isError()) {+ return startDate;+ }+ }++ if (days.isArray()) {+ if ((days as ArrayValueObject).getRowCount() > 1 || (days as ArrayValueObject).getColumnCount() > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ days = (days as ArrayValueObject).get(0, 0) as BaseValueObject;++ if (days.isError()) {+ return days;+ }+ }++ if (startDate.isBoolean() || days.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const startDateSerialNumber = getDateSerialNumberByObject(startDate);++ if (typeof startDateSerialNumber !== 'number') {+ return startDateSerialNumber;+ }++ if (days.isString()) {+ days = days.convertToNumberObjectValue();++ if (days.isError()) {+ return days;+ }+ }++ const workingDays = +days.getValue();++ let result: number | ErrorValueObject;++ if (holidays) {+ const holidaysValueArray = [];++ if (holidays?.isArray()) {+ const rowCount = (holidays as ArrayValueObject).getRowCount();+ const columnCount = (holidays as ArrayValueObject).getColumnCount();++ for (let r = 0; r < rowCount; r++) {+ for (let c = 0; c < columnCount; c++) {+ const cell = (holidays as ArrayValueObject).get(r, c) as BaseValueObject;++ if (cell.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const holidaySerialNumber = getDateSerialNumberByObject(cell);++ if (typeof holidaySerialNumber !== 'number') {+ return holidaySerialNumber;+ }++ holidaysValueArray.push(holidaySerialNumber);+ }+ }+ } else {+ if (holidays.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const holidaySerialNumber = getDateSerialNumberByObject(holidays);++ if (typeof holidaySerialNumber !== 'number') {+ return holidaySerialNumber;+ }++ holidaysValueArray.push(holidaySerialNumber);+ }++ result = getDateSerialNumberByWorkingDays(startDateSerialNumber, workingDays, weekendValue, holidaysValueArray);+ } else {+ result = getDateSerialNumberByWorkingDays(startDateSerialNumber, workingDays, weekendValue);+ }++ if (typeof result !== 'number') {+ return result;+ }++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/date/workday/__tests__/index.spec.ts b/packages/engine-formula/src/functions/date/workday/__tests__/index.spec.tsnew file mode 100644index 0000000000..54a248c0c5--- /dev/null+++ b/packages/engine-formula/src/functions/date/workday/__tests__/index.spec.ts@@ -0,0 +1,129 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_DATE } from '../../function-names';+import { Workday } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { ErrorType } from '../../../../basics/error-type';++describe('Test workday function', () => {+ const testFunction = new Workday(FUNCTION_NAMES_DATE.WORKDAY);++ describe('Workday', () => {+ it('Value is all normal', () => {+ const startDate = StringValueObject.create('2008-10-1');+ const days = NumberValueObject.create(151);+ const result = testFunction.calculate(startDate, days);+ expect(result.getValue()).toStrictEqual(39933);++ const holidays2 = StringValueObject.create('2008-11-26');+ const result2 = testFunction.calculate(startDate, days, holidays2);+ expect(result2.getValue()).toStrictEqual(39934);++ const holidays3 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['2008-11-26'],+ ['2008-12-4'],+ ['2009-1-21'],+ ]),+ rowCount: 3,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result3 = testFunction.calculate(startDate, days, holidays3);+ expect(result3.getValue()).toStrictEqual(39938);+ });++ it('Value is not date string', () => {+ const startDate = StringValueObject.create('test');+ const days = NumberValueObject.create(151);+ const result = testFunction.calculate(startDate, days);+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate2 = StringValueObject.create('2008-10-1');+ const days2 = StringValueObject.create('test');+ const result2 = testFunction.calculate(startDate2, days2);+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate3 = StringValueObject.create('2008-10-1');+ const days3 = NumberValueObject.create(151);+ const holidays3 = StringValueObject.create('test');+ const result3 = testFunction.calculate(startDate3, days3, holidays3);+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is blank cell', () => {+ const startDate = NullValueObject.create();+ const days = NumberValueObject.create(151);+ const result = testFunction.calculate(startDate, days);+ expect(result.getValue()).toStrictEqual(212);++ const startDate2 = StringValueObject.create('2008-10-1');+ const days2 = NullValueObject.create();+ const result2 = testFunction.calculate(startDate2, days2);+ expect(result2.getValue()).toStrictEqual(39722);++ const startDate3 = StringValueObject.create('2008-10-1');+ const days3 = NumberValueObject.create(-151);+ const holidays3 = NullValueObject.create();+ const result3 = testFunction.calculate(startDate3, days3, holidays3);+ expect(result3.getValue()).toStrictEqual(39511);+ });++ it('Value is boolean', () => {+ const startDate = BooleanValueObject.create(true);+ const days = NumberValueObject.create(151);+ const result = testFunction.calculate(startDate, days);+ expect(result.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate2 = StringValueObject.create('2008-10-1');+ const days2 = BooleanValueObject.create(false);+ const result2 = testFunction.calculate(startDate2, days2);+ expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);++ const startDate3 = StringValueObject.create('2008-10-1');+ const days3 = NumberValueObject.create(151);+ const holidays3 = BooleanValueObject.create(true);+ const result3 = testFunction.calculate(startDate3, days3, holidays3);+ expect(result3.getValue()).toStrictEqual(ErrorType.VALUE);+ });++ it('Value is error', () => {+ const startDate = ErrorValueObject.create(ErrorType.NAME);+ const days = NumberValueObject.create(151);+ const result = testFunction.calculate(startDate, days);+ expect(result.getValue()).toStrictEqual(ErrorType.NAME);++ const startDate2 = StringValueObject.create('2008-10-1');+ const days2 = ErrorValueObject.create(ErrorType.NAME);+ const result2 = testFunction.calculate(startDate2, days2);+ expect(result2.getValue()).toStrictEqual(ErrorType.NAME);++ const startDate3 = StringValueObject.create('2008-10-1');+ const days3 = NumberValueObject.create(151);+ const holidays3 = ErrorValueObject.create(ErrorType.NAME);+ const result3 = testFunction.calculate(startDate3, days3, holidays3);+ expect(result3.getValue()).toStrictEqual(ErrorType.NAME);+ });+ });+});diff --git a/packages/engine-formula/src/functions/date/workday/index.ts b/packages/engine-formula/src/functions/date/workday/index.tsnew file mode 100644index 0000000000..061e063a4c--- /dev/null+++ b/packages/engine-formula/src/functions/date/workday/index.ts@@ -0,0 +1,138 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { getDateSerialNumberByObject, getDateSerialNumberByWorkingDays } from '../../../basics/date';+import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Workday extends BaseFunction {+ override minParams = 2;++ override maxParams = 3;++ override calculate(startDate: BaseValueObject, days: BaseValueObject, holidays?: BaseValueObject) {+ if (startDate.isError()) {+ return startDate;+ }++ if (days.isError()) {+ return days;+ }++ if (holidays?.isError()) {+ return holidays;+ }++ if (startDate.isArray()) {+ if ((startDate as ArrayValueObject).getRowCount() > 1 || (startDate as ArrayValueObject).getColumnCount() > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ startDate = (startDate as ArrayValueObject).get(0, 0) as BaseValueObject;++ if (startDate.isError()) {+ return startDate;+ }+ }++ if (days.isArray()) {+ if ((days as ArrayValueObject).getRowCount() > 1 || (days as ArrayValueObject).getColumnCount() > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ days = (days as ArrayValueObject).get(0, 0) as BaseValueObject;++ if (days.isError()) {+ return days;+ }+ }++ if (startDate.isBoolean() || days.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const startDateSerialNumber = getDateSerialNumberByObject(startDate);++ if (typeof startDateSerialNumber !== 'number') {+ return startDateSerialNumber;+ }++ if (days.isString()) {+ days = days.convertToNumberObjectValue();++ if (days.isError()) {+ return days;+ }+ }++ const workingDays = +days.getValue();++ let result: number | ErrorValueObject;++ if (holidays) {+ const holidaysValueArray: number[] = [];++ if (holidays?.isArray()) {+ const rowCount = (holidays as ArrayValueObject).getRowCount();+ const columnCount = (holidays as ArrayValueObject).getColumnCount();++ for (let r = 0; r < rowCount; r++) {+ for (let c = 0; c < columnCount; c++) {+ const cell = (holidays as ArrayValueObject).get(r, c) as BaseValueObject;++ if (cell.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const holidaySerialNumber = getDateSerialNumberByObject(cell);++ if (typeof holidaySerialNumber !== 'number') {+ return holidaySerialNumber;+ }++ holidaysValueArray.push(holidaySerialNumber);+ }+ }+ } else {+ if (holidays.isBoolean()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const holidaySerialNumber = getDateSerialNumberByObject(holidays);++ if (typeof holidaySerialNumber !== 'number') {+ return holidaySerialNumber;+ }++ holidaysValueArray.push(holidaySerialNumber);+ }++ result = getDateSerialNumberByWorkingDays(startDateSerialNumber, workingDays, 1, holidaysValueArray);+ } else {+ result = getDateSerialNumberByWorkingDays(startDateSerialNumber, workingDays);+ }++ if (typeof result !== 'number') {+ return result;+ }++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/math/function-map.ts b/packages/engine-formula/src/functions/math/function-map.tsindex 41a22b9a7c..52e93ef257 100644--- a/packages/engine-formula/src/functions/math/function-map.ts+++ b/packages/engine-formula/src/functions/math/function-map.ts@@ -41,6 +41,7 @@ import { Subtotal } from './subtotal';import { Sum } from './sum';import { Sumif } from './sumif';import { Sumifs } from './sumifs';+import { Sumproduct } from './sumproduct';import { Tan } from './tan';import { Tanh } from './tanh';@@ -71,6 +72,7 @@ export const functionMath = [[Sum, FUNCTION_NAMES_MATH.SUM],[Sumif, FUNCTION_NAMES_MATH.SUMIF],[Sumifs, FUNCTION_NAMES_MATH.SUMIFS],+ [Sumproduct, FUNCTION_NAMES_MATH.SUMPRODUCT],[Tan, FUNCTION_NAMES_MATH.TAN],[Tanh, FUNCTION_NAMES_MATH.TANH],];diff --git a/packages/engine-formula/src/functions/math/sumproduct/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/sumproduct/__tests__/index.spec.tsnew file mode 100644index 0000000000..b427694fd9--- /dev/null+++ b/packages/engine-formula/src/functions/math/sumproduct/__tests__/index.spec.ts@@ -0,0 +1,125 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { Sumproduct } from '../index';++describe('Test sumproduct function', () => {+ const testFunction = new Sumproduct(FUNCTION_NAMES_MATH.SUMPRODUCT);++ describe('Sumproduct', () => {+ it('Array1 is array, not includes error', () => {+ const array1 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, '2', 3],+ [null, 'test', 2],+ [true, ' ', false],+ ]),+ rowCount: 3,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(array1);+ expect(result.getValue()).toBe(8);+ });++ it('Array1 is array, includes error', () => {+ const array1 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, '2', 3],+ [null, 'test', ErrorType.NUM],+ [true, ' ', false],+ ]),+ rowCount: 3,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(array1);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Array1 is array, other variants has same dimension', () => {+ const array1 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, '2', 3],+ [null, 'test', 2],+ [true, ' ', false],+ ]),+ rowCount: 3,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const array2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 1, 1],+ [null, 'test', 2],+ [true, 1, false],+ ]),+ rowCount: 3,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(array1, array2);+ expect(result.getValue()).toBe(10);+ });++ it('Array1 is array, other variants is not same dimension', () => {+ const array1 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, '2', 3],+ [null, 'test', 2],+ [true, ' ', false],+ ]),+ rowCount: 3,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const array2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 1, 1],+ [true, 1, false],+ ]),+ rowCount: 2,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(array1, array2);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/sumproduct/index.ts b/packages/engine-formula/src/functions/math/sumproduct/index.tsnew file mode 100644index 0000000000..eb635b952f--- /dev/null+++ b/packages/engine-formula/src/functions/math/sumproduct/index.ts@@ -0,0 +1,126 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { isRealNum } from '@univerjs/core';+import { ErrorType } from '../../../basics/error-type';+import { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Sumproduct extends BaseFunction {+ override minParams = 1;++ override maxParams = 255;++ override calculate(array1: BaseValueObject, ...variants: BaseValueObject[]) {+ if (array1.isError()) {+ return array1;+ }++ if (!array1.isArray()) {+ array1 = ArrayValueObject.create({+ calculateValueList: [[array1]],+ rowCount: 1,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ }++ if (variants.length > 0) {+ const rowCount = (array1 as ArrayValueObject).getRowCount();+ const columnCount = (array1 as ArrayValueObject).getColumnCount();++ const resultArray: number[][] = [];++ for (let r = 0; r < rowCount; r++) {+ const row: number[] = [];++ for (let c = 0; c < columnCount; c++) {+ const array1ValueObject = (array1 as ArrayValueObject).get(r, c) as BaseValueObject;++ if (array1ValueObject.isError()) {+ return array1ValueObject;+ }++ const array1Value = array1ValueObject.getValue();++ if (!array1Value || !isRealNum(array1Value)) {+ row.push(0);+ } else {+ row.push(+array1Value);+ }+ }++ resultArray.push(row);+ }++ for (let i = 0; i < variants.length; i++) {+ if (variants[i].isError()) {+ return variants[i];+ }++ let variantRowCount = 1;+ let variantColumnCount = 1;++ if (variants[i].isArray()) {+ variantRowCount = (variants[i] as ArrayValueObject).getRowCount();+ variantColumnCount = (variants[i] as ArrayValueObject).getColumnCount();+ }++ if (variantRowCount !== rowCount || variantColumnCount !== columnCount) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ for (let r = 0; r < rowCount; r++) {+ const row: number[] = [];++ for (let c = 0; c < columnCount; c++) {+ let variantValueObject = variants[i] as BaseValueObject;++ if (variants[i].isArray()) {+ variantValueObject = (variants[i] as ArrayValueObject).get(r, c) as BaseValueObject;+ }++ if (variantValueObject.isError()) {+ return variantValueObject;+ }++ const variantValue = variantValueObject.getValue();++ if (!variantValue || !isRealNum(variantValue)) {+ row.push(0);+ } else {+ row.push(+variantValue * resultArray[r][c]);+ }+ }++ resultArray[r] = row;+ }+ }++ const result = resultArray.reduce((acc, cur) => acc.concat(cur)).reduce((acc, cur) => acc + cur, 0);++ return NumberValueObject.create(result);+ } else {+ return array1.sum();+ }+ }+}diff --git a/packages/sheets-formula/src/locale/function-list/date/en-US.ts b/packages/sheets-formula/src/locale/function-list/date/en-US.tsindex 8a1935f1c7..89b6355182 100644--- a/packages/sheets-formula/src/locale/function-list/date/en-US.ts+++ b/packages/sheets-formula/src/locale/function-list/date/en-US.ts@@ -136,8 +136,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: 'serial_number', detail: 'The date of the day you are trying to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008.' },},},ISOWEEKNUM: {@@ -164,8 +163,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: 'serial_number', detail: 'The date of the day you are trying to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008.' },},},MONTH: {@@ -191,8 +189,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ startDate: { name: 'start_date', detail: 'A date that represents the start date.' },+ endDate: { name: 'end_date', detail: 'A date that represents the end date.' },+ holidays: { name: 'holidays', detail: 'An optional range of one or more dates to exclude from the working calendar, such as state and federal holidays and floating holidays. ' },},},NETWORKDAYS_INTL: {@@ -205,8 +204,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ startDate: { name: 'start_date', detail: 'A date that represents the start date.' },+ endDate: { name: 'end_date', detail: 'A date that represents the end date.' },+ weekend: { name: 'weekend', detail: 'is a weekend number or string that specifies when weekends occur.' },+ holidays: { name: 'holidays', detail: 'An optional range of one or more dates to exclude from the working calendar, such as state and federal holidays and floating holidays. ' },},},NOW: {@@ -231,8 +232,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: 'serial_number', detail: 'The date of the day you are trying to find. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008.' },},},TIME: {@@ -285,8 +285,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: 'serial_number', detail: 'A sequential number that represents the date of the day you are trying to find.' },+ returnType: { name: 'return_type', detail: 'A number that determines the type of return value.' },},},WEEKNUM: {@@ -313,8 +313,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ startDate: { name: 'start_date', detail: 'A date that represents the start date.' },+ days: { name: 'days', detail: 'The number of nonweekend and nonholiday days before or after start_date. A positive value for days yields a future date; a negative value yields a past date.' },+ holidays: { name: 'holidays', detail: 'An optional range of one or more dates to exclude from the working calendar, such as state and federal holidays and floating holidays. ' },},},WORKDAY_INTL: {@@ -327,8 +328,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ startDate: { name: 'start_date', detail: 'A date that represents the start date.' },+ days: { name: 'days', detail: 'The number of nonweekend and nonholiday days before or after start_date. A positive value for days yields a future date; a negative value yields a past date.' },+ weekend: { name: 'weekend', detail: 'is a weekend number or string that specifies when weekends occur.' },+ holidays: { name: 'holidays', detail: 'An optional range of one or more dates to exclude from the working calendar, such as state and federal holidays and floating holidays. ' },},},YEAR: {diff --git a/packages/sheets-formula/src/locale/function-list/date/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/date/ja-JP.tsindex 322ac1f974..086e6f0a5d 100644--- a/packages/sheets-formula/src/locale/function-list/date/ja-JP.ts+++ b/packages/sheets-formula/src/locale/function-list/date/ja-JP.ts@@ -136,8 +136,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: 'シリアル値', detail: '検索する日付を指定します。 日付は、DATE 関数を使って入力するか、他の数式または他の関数の結果を指定します。 たとえば、2008 年 5 月 23 日を入力する場合は、DATE(2008,5,23) を使用します。' },},},ISOWEEKNUM: {@@ -164,8 +163,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: 'シリアル値', detail: '検索する日付を指定します。 日付は、DATE 関数を使って入力するか、他の数式または他の関数の結果を指定します。 たとえば、2008 年 5 月 23 日を入力する場合は、DATE(2008,5,23) を使用します。' },},},MONTH: {@@ -191,8 +189,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ startDate: { name: '開始日', detail: '起算日を表す日付を指定します。' },+ endDate: { name: '終了日', detail: '対象期間の最終日を表す日付を指定します。' },+ holidays: { name: '休日', detail: '国民の祝日や変動休日など、稼働日数の計算から除外する日付のリストを指定します。' },},},NETWORKDAYS_INTL: {@@ -205,8 +204,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ startDate: { name: '開始日', detail: '起算日を表す日付を指定します。' },+ endDate: { name: '終了日', detail: '対象期間の最終日を表す日付を指定します。' },+ weekend: { name: '週末', detail: 'は、週末を示す週末番号または文字列で指定します。' },+ holidays: { name: '休日', detail: '国民の祝日や変動休日など、稼働日数の計算から除外する日付のリストを指定します。' },},},NOW: {@@ -231,8 +232,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: 'シリアル値', detail: '検索する日付を指定します。 日付は、DATE 関数を使って入力するか、他の数式または他の関数の結果を指定します。 たとえば、2008 年 5 月 23 日を入力する場合は、DATE(2008,5,23) を使用します。' },},},TIME: {@@ -285,8 +285,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: 'シリアル値', detail: '検索する日付のシリアル値を指定します。' },+ returnType: { name: '週の基準', detail: '戻り値の種類を数値で指定します。' },},},WEEKNUM: {@@ -313,8 +313,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ startDate: { name: '開始日', detail: '起算日を表す日付を指定します。' },+ days: { name: '日数', detail: '開始日から起算して、週末や祭日を除く週日の日数を指定します。 日数に正の数を指定すると、起算日より後の日付となり、負の数を指定すると、起算日より前の日付となります。' },+ holidays: { name: '休日', detail: '国民の祝日や変動休日など、稼働日数の計算から除外する日付のリストを指定します。' },},},WORKDAY_INTL: {@@ -327,8 +328,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ startDate: { name: '開始日', detail: '起算日を表す日付を指定します。' },+ days: { name: '日数', detail: '開始日から起算して、週末や祭日を除く週日の日数を指定します。 日数に正の数を指定すると、起算日より後の日付となり、負の数を指定すると、起算日より前の日付となります。' },+ weekend: { name: '週末', detail: 'は、週末を示す週末番号または文字列で指定します。' },+ holidays: { name: '休日', detail: '国民の祝日や変動休日など、稼働日数の計算から除外する日付のリストを指定します。' },},},YEAR: {diff --git a/packages/sheets-formula/src/locale/function-list/date/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/date/zh-CN.tsindex 1666ce3564..a5e3ab7f03 100644--- a/packages/sheets-formula/src/locale/function-list/date/zh-CN.ts+++ b/packages/sheets-formula/src/locale/function-list/date/zh-CN.ts@@ -136,8 +136,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: '日期序列号', detail: '要查找的日期。 应使用 DATE 函数输入日期,或者将日期作为其他公式或函数的结果输入。 例如,使用函数 DATE(2008,5,23) 输入 2008 年 5 月 23 日。' },},},ISOWEEKNUM: {@@ -164,8 +163,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: '日期序列号', detail: '要查找的日期。 应使用 DATE 函数输入日期,或者将日期作为其他公式或函数的结果输入。 例如,使用函数 DATE(2008,5,23) 输入 2008 年 5 月 23 日。' },},},MONTH: {@@ -191,8 +189,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ startDate: { name: '开始日期', detail: '一个代表开始日期的日期' },+ endDate: { name: '终止日期', detail: '一个代表终止日期的日期' },+ holidays: { name: '休息日期', detail: '不在工作日历中的一个或多个日期所构成的可选区域' },},},NETWORKDAYS_INTL: {@@ -205,8 +204,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ startDate: { name: '开始日期', detail: '一个代表开始日期的日期' },+ endDate: { name: '终止日期', detail: '一个代表终止日期的日期' },+ weekend: { name: '周末', detail: '是一个用于指定周末日的周末数字或字符串' },+ holidays: { name: '休息日期', detail: '不在工作日历中的一个或多个日期所构成的可选区域' },},},NOW: {@@ -231,8 +232,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: '日期序列号', detail: '要查找的日期。 应使用 DATE 函数输入日期,或者将日期作为其他公式或函数的结果输入。 例如,使用函数 DATE(2008,5,23) 输入 2008 年 5 月 23 日。' },},},TIME: {@@ -285,8 +285,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: '日期序列号', detail: '一个序列号,代表尝试查找的那一天的日期。' },+ returnType: { name: '返回值类型', detail: '用于确定返回值类型的数字。' },},},WEEKNUM: {@@ -313,8 +313,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ startDate: { name: '开始日期', detail: '一个代表开始日期的日期。' },+ days: { name: '天数', detail: '开始日期之前或之后不含周末及节假日的天数。为正值将生成未来日期;为负值生成过去日期。' },+ holidays: { name: '休息日期', detail: '不在工作日历中的一个或多个日期所构成的可选区域。' },},},WORKDAY_INTL: {@@ -327,8 +328,10 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ startDate: { name: '开始日期', detail: '一个代表开始日期的日期。' },+ days: { name: '天数', detail: '开始日期之前或之后不含周末及节假日的天数。为正值将生成未来日期;为负值生成过去日期。' },+ weekend: { name: '周末', detail: '是一个用于指定周末日的周末数字或字符串' },+ holidays: { name: '休息日期', detail: '不在工作日历中的一个或多个日期所构成的可选区域。' },},},YEAR: {diff --git a/packages/sheets-formula/src/locale/function-list/date/zh-TW.ts b/packages/sheets-formula/src/locale/function-list/date/zh-TW.tsindex 6796ca0b20..1d8eafff43 100644--- a/packages/sheets-formula/src/locale/function-list/date/zh-TW.ts+++ b/packages/sheets-formula/src/locale/function-list/date/zh-TW.ts@@ -136,8 +136,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: '日期序號', detail: '要找的日期。 應使用 DATE 函數輸入日期,或將日期輸入為其他公式或函數的結果。 例如,使用函數 DATE(2008,5,23) 輸入 2008 年 5 月 23 日。 ' },},},ISOWEEKNUM: {@@ -164,8 +163,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: '日期序號', detail: '要找的日期。 應使用 DATE 函數輸入日期,或將日期輸入為其他公式或函數的結果。 例如,使用函數 DATE(2008,5,23) 輸入 2008 年 5 月 23 日。 ' },},},MONTH: {@@ -231,8 +229,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ serialNumber: { name: '日期序號', detail: '要找的日期。 應使用 DATE 函數輸入日期,或將日期輸入為其他公式或函數的結果。 例如,使用函數 DATE(2008,5,23) 輸入 2008 年 5 月 23 日。 ' },},},TIME: {diff --git a/packages/sheets-formula/src/locale/function-list/math/en-US.ts b/packages/sheets-formula/src/locale/function-list/math/en-US.tsindex 7502ec2190..fff49711ea 100644--- a/packages/sheets-formula/src/locale/function-list/math/en-US.ts+++ b/packages/sheets-formula/src/locale/function-list/math/en-US.ts@@ -1068,8 +1068,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array1: { name: 'array', detail: 'The first array argument whose components you want to multiply and then add.' },+ array2: { name: 'array', detail: 'Array arguments 2 to 255 whose components you want to multiply and then add.' },},},SUMSQ: {diff --git a/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/math/ja-JP.tsindex 31f1be8c56..8a94541651 100644--- a/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts+++ b/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts@@ -1059,8 +1059,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array1: { name: '配列', detail: '計算の対象となる要素を含む最初の配列引数を指定します。' },+ array2: { name: '配列', detail: '計算の対象となる要素を含む、2 から 255 個までの配列引数を指定します。' },},},SUMSQ: {diff --git a/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/math/zh-CN.tsindex 6b50413ee5..6a8c306edf 100644--- a/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts+++ b/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts@@ -1069,8 +1069,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array1: { name: '数组', detail: '其相应元素需要进行相乘并求和的第一个数组参数。' },+ array2: { name: '数组', detail: '2 到 255 个数组参数,其相应元素需要进行相乘并求和。' },},},SUMSQ: {diff --git a/packages/sheets-formula/src/locale/function-list/math/zh-TW.ts b/packages/sheets-formula/src/locale/function-list/math/zh-TW.tsindex 485616aa67..f5a7b2a113 100644--- a/packages/sheets-formula/src/locale/function-list/math/zh-TW.ts+++ b/packages/sheets-formula/src/locale/function-list/math/zh-TW.ts@@ -1079,8 +1079,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ array1: { name: '陣列', detail: '這是您要求元素乘積和的第一個陣列引數。' },+ array2: { name: '陣列', detail: '這是您要求元素乘積和的第 2 個到第 255 個陣列引數。' },},},SUMSQ: {diff --git a/packages/sheets-formula/src/services/function-list/date.ts b/packages/sheets-formula/src/services/function-list/date.tsindex bd3f2d2a8e..8f60b4e411 100644--- a/packages/sheets-formula/src/services/function-list/date.ts+++ b/packages/sheets-formula/src/services/function-list/date.ts@@ -193,16 +193,9 @@ export const FUNCTION_LIST_DATE: IFunctionInfo[] = [abstract: 'formula.functionList.HOUR.abstract',functionParameter: [{- name: 'formula.functionList.HOUR.functionParameter.number1.name',- detail: 'formula.functionList.HOUR.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.HOUR.functionParameter.number2.name',- detail: 'formula.functionList.HOUR.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.HOUR.functionParameter.serialNumber.name',+ detail: 'formula.functionList.HOUR.functionParameter.serialNumber.detail',+ example: '"2011-7-18 7:45"',require: 1,repeat: 0,},@@ -237,16 +230,9 @@ export const FUNCTION_LIST_DATE: IFunctionInfo[] = [abstract: 'formula.functionList.MINUTE.abstract',functionParameter: [{- name: 'formula.functionList.MINUTE.functionParameter.number1.name',- detail: 'formula.functionList.MINUTE.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.MINUTE.functionParameter.number2.name',- detail: 'formula.functionList.MINUTE.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.MINUTE.functionParameter.serialNumber.name',+ detail: 'formula.functionList.MINUTE.functionParameter.serialNumber.detail',+ example: '"12:45"',require: 1,repeat: 0,},@@ -274,19 +260,26 @@ export const FUNCTION_LIST_DATE: IFunctionInfo[] = [abstract: 'formula.functionList.NETWORKDAYS.abstract',functionParameter: [{- name: 'formula.functionList.NETWORKDAYS.functionParameter.number1.name',- detail: 'formula.functionList.NETWORKDAYS.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.NETWORKDAYS.functionParameter.startDate.name',+ detail: 'formula.functionList.NETWORKDAYS.functionParameter.startDate.detail',+ example: '"2012-10-1"',require: 1,repeat: 0,},{- name: 'formula.functionList.NETWORKDAYS.functionParameter.number2.name',- detail: 'formula.functionList.NETWORKDAYS.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.NETWORKDAYS.functionParameter.endDate.name',+ detail: 'formula.functionList.NETWORKDAYS.functionParameter.endDate.detail',+ example: '"2013-3-1"',require: 1,repeat: 0,},+ {+ name: 'formula.functionList.NETWORKDAYS.functionParameter.holidays.name',+ detail: 'formula.functionList.NETWORKDAYS.functionParameter.holidays.detail',+ example: '"2012-11-22"',+ require: 0,+ repeat: 0,+ },],},{@@ -296,19 +289,33 @@ export const FUNCTION_LIST_DATE: IFunctionInfo[] = [abstract: 'formula.functionList.NETWORKDAYS_INTL.abstract',functionParameter: [{- name: 'formula.functionList.NETWORKDAYS_INTL.functionParameter.number1.name',- detail: 'formula.functionList.NETWORKDAYS_INTL.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.NETWORKDAYS_INTL.functionParameter.startDate.name',+ detail: 'formula.functionList.NETWORKDAYS_INTL.functionParameter.startDate.detail',+ example: '"2012-10-1"',require: 1,repeat: 0,},{- name: 'formula.functionList.NETWORKDAYS_INTL.functionParameter.number2.name',- detail: 'formula.functionList.NETWORKDAYS_INTL.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.NETWORKDAYS_INTL.functionParameter.endDate.name',+ detail: 'formula.functionList.NETWORKDAYS_INTL.functionParameter.endDate.detail',+ example: '"2013-3-1"',require: 1,repeat: 0,},+ {+ name: 'formula.functionList.NETWORKDAYS_INTL.functionParameter.weekend.name',+ detail: 'formula.functionList.NETWORKDAYS_INTL.functionParameter.weekend.detail',+ example: '6',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.NETWORKDAYS_INTL.functionParameter.holidays.name',+ detail: 'formula.functionList.NETWORKDAYS_INTL.functionParameter.holidays.detail',+ example: '"2012-11-22"',+ require: 0,+ repeat: 0,+ },],},{@@ -326,16 +333,9 @@ export const FUNCTION_LIST_DATE: IFunctionInfo[] = [abstract: 'formula.functionList.SECOND.abstract',functionParameter: [{- name: 'formula.functionList.SECOND.functionParameter.number1.name',- detail: 'formula.functionList.SECOND.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.SECOND.functionParameter.number2.name',- detail: 'formula.functionList.SECOND.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.SECOND.functionParameter.serialNumber.name',+ detail: 'formula.functionList.SECOND.functionParameter.serialNumber.detail',+ example: '"4:48:18"',require: 1,repeat: 0,},@@ -400,17 +400,17 @@ export const FUNCTION_LIST_DATE: IFunctionInfo[] = [abstract: 'formula.functionList.WEEKDAY.abstract',functionParameter: [{- name: 'formula.functionList.WEEKDAY.functionParameter.number1.name',- detail: 'formula.functionList.WEEKDAY.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.WEEKDAY.functionParameter.serialNumber.name',+ detail: 'formula.functionList.WEEKDAY.functionParameter.serialNumber.detail',+ example: '"2008-2-14"',require: 1,repeat: 0,},{- name: 'formula.functionList.WEEKDAY.functionParameter.number2.name',- detail: 'formula.functionList.WEEKDAY.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.WEEKDAY.functionParameter.returnType.name',+ detail: 'formula.functionList.WEEKDAY.functionParameter.returnType.detail',+ example: '2',+ require: 0,repeat: 0,},],@@ -444,19 +444,26 @@ export const FUNCTION_LIST_DATE: IFunctionInfo[] = [abstract: 'formula.functionList.WORKDAY.abstract',functionParameter: [{- name: 'formula.functionList.WORKDAY.functionParameter.number1.name',- detail: 'formula.functionList.WORKDAY.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.WORKDAY.functionParameter.startDate.name',+ detail: 'formula.functionList.WORKDAY.functionParameter.startDate.detail',+ example: '"2008-10-1"',require: 1,repeat: 0,},{- name: 'formula.functionList.WORKDAY.functionParameter.number2.name',- detail: 'formula.functionList.WORKDAY.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.WORKDAY.functionParameter.days.name',+ detail: 'formula.functionList.WORKDAY.functionParameter.days.detail',+ example: '151',require: 1,repeat: 0,},+ {+ name: 'formula.functionList.WORKDAY.functionParameter.holidays.name',+ detail: 'formula.functionList.WORKDAY.functionParameter.holidays.detail',+ example: '"2008-11-26"',+ require: 0,+ repeat: 0,+ },],},{@@ -466,19 +473,33 @@ export const FUNCTION_LIST_DATE: IFunctionInfo[] = [abstract: 'formula.functionList.WORKDAY_INTL.abstract',functionParameter: [{- name: 'formula.functionList.WORKDAY_INTL.functionParameter.number1.name',- detail: 'formula.functionList.WORKDAY_INTL.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.WORKDAY_INTL.functionParameter.startDate.name',+ detail: 'formula.functionList.WORKDAY_INTL.functionParameter.startDate.detail',+ example: '"2008-10-1"',require: 1,repeat: 0,},{- name: 'formula.functionList.WORKDAY_INTL.functionParameter.number2.name',- detail: 'formula.functionList.WORKDAY_INTL.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.WORKDAY_INTL.functionParameter.days.name',+ detail: 'formula.functionList.WORKDAY_INTL.functionParameter.days.detail',+ example: '151',require: 1,repeat: 0,},+ {+ name: 'formula.functionList.WORKDAY_INTL.functionParameter.weekend.name',+ detail: 'formula.functionList.WORKDAY_INTL.functionParameter.weekend.detail',+ example: '6',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.WORKDAY_INTL.functionParameter.holidays.name',+ detail: 'formula.functionList.WORKDAY_INTL.functionParameter.holidays.detail',+ example: '"2008-11-26"',+ require: 0,+ repeat: 0,+ },],},{diff --git a/packages/sheets-formula/src/services/function-list/math.ts b/packages/sheets-formula/src/services/function-list/math.tsindex 643817567b..a5b8e98b7e 100644--- a/packages/sheets-formula/src/services/function-list/math.ts+++ b/packages/sheets-formula/src/services/function-list/math.ts@@ -1578,18 +1578,18 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.SUMPRODUCT.abstract',functionParameter: [{- name: 'formula.functionList.SUMPRODUCT.functionParameter.number1.name',- detail: 'formula.functionList.SUMPRODUCT.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.SUMPRODUCT.functionParameter.array1.name',+ detail: 'formula.functionList.SUMPRODUCT.functionParameter.array1.detail',+ example: 'C2:C5',require: 1,repeat: 0,},{- name: 'formula.functionList.SUMPRODUCT.functionParameter.number2.name',- detail: 'formula.functionList.SUMPRODUCT.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,- repeat: 0,+ name: 'formula.functionList.SUMPRODUCT.functionParameter.array2.name',+ detail: 'formula.functionList.SUMPRODUCT.functionParameter.array2.detail',+ example: 'D2:D5',+ require: 0,+ repeat: 1,},],},