@fileverse-dev/formulajs 4.4.35 → 4.4.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/formula.js +31 -52
- package/lib/browser/formula.min.js +1 -1
- package/lib/browser/formula.min.js.map +1 -1
- package/lib/cjs/index.cjs +28 -57
- package/lib/esm/index.mjs +28 -57
- package/package.json +1 -1
package/lib/cjs/index.cjs
CHANGED
|
@@ -8104,6 +8104,18 @@ const WEEKEND_TYPES = [
|
|
|
8104
8104
|
[6, 6]
|
|
8105
8105
|
];
|
|
8106
8106
|
|
|
8107
|
+
const datePartition = (date) => {
|
|
8108
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
8109
|
+
|
|
8110
|
+
const day = pad(date.getDate());
|
|
8111
|
+
const month = pad(date.getMonth() + 1);
|
|
8112
|
+
const year = date.getFullYear();
|
|
8113
|
+
const hours = pad(date.getHours());
|
|
8114
|
+
const minutes = pad(date.getMinutes());
|
|
8115
|
+
const seconds = pad(date.getSeconds());
|
|
8116
|
+
return { day, month, year, hours, minutes, seconds };
|
|
8117
|
+
};
|
|
8118
|
+
|
|
8107
8119
|
/**
|
|
8108
8120
|
* Returns the serial number of a particular date.
|
|
8109
8121
|
*
|
|
@@ -8129,10 +8141,8 @@ function DATE(year, month, day) {
|
|
|
8129
8141
|
if (result.getFullYear() < 0) {
|
|
8130
8142
|
result = num;
|
|
8131
8143
|
}
|
|
8132
|
-
|
|
8133
|
-
const dayResult =
|
|
8134
|
-
const monthResult = pad(result.getMonth() + 1);
|
|
8135
|
-
const yearResult = result.getFullYear();
|
|
8144
|
+
|
|
8145
|
+
const { day: dayResult, month: monthResult, year: yearResult } = datePartition(result);
|
|
8136
8146
|
result = `${dayResult}/${monthResult}/${yearResult}`;
|
|
8137
8147
|
}
|
|
8138
8148
|
|
|
@@ -8244,7 +8254,7 @@ function DATEVALUE(date_text) {
|
|
|
8244
8254
|
|
|
8245
8255
|
const dateValue = new Date(date_text);
|
|
8246
8256
|
|
|
8247
|
-
return
|
|
8257
|
+
return dateToSerial(dateValue);
|
|
8248
8258
|
}
|
|
8249
8259
|
|
|
8250
8260
|
/**
|
|
@@ -8396,10 +8406,7 @@ function EDATE(start_date, months) {
|
|
|
8396
8406
|
|
|
8397
8407
|
|
|
8398
8408
|
let widthoutSerial = start_date;
|
|
8399
|
-
const
|
|
8400
|
-
const dayResult = pad(widthoutSerial.getDate());
|
|
8401
|
-
const monthResult = pad(widthoutSerial.getMonth() + 1);
|
|
8402
|
-
const yearResult = widthoutSerial.getFullYear();
|
|
8409
|
+
const { day: dayResult, month: monthResult, year: yearResult } = datePartition(widthoutSerial);
|
|
8403
8410
|
widthoutSerial = `${dayResult}/${monthResult}/${yearResult}`;
|
|
8404
8411
|
|
|
8405
8412
|
return returnSerial ? dateToSerial(start_date) : widthoutSerial
|
|
@@ -8431,10 +8438,7 @@ function EOMONTH(start_date, months) {
|
|
|
8431
8438
|
|
|
8432
8439
|
|
|
8433
8440
|
let widthoutSerial = eoMonth;
|
|
8434
|
-
const
|
|
8435
|
-
const dayResult = pad(widthoutSerial.getDate());
|
|
8436
|
-
const monthResult = pad(widthoutSerial.getMonth() + 1);
|
|
8437
|
-
const yearResult = widthoutSerial.getFullYear();
|
|
8441
|
+
const { day: dayResult, month: monthResult, year: yearResult } = datePartition(widthoutSerial);
|
|
8438
8442
|
widthoutSerial = `${dayResult}/${monthResult}/${yearResult}`;
|
|
8439
8443
|
|
|
8440
8444
|
return returnSerial ? dateToSerial(eoMonth) : widthoutSerial
|
|
@@ -8464,15 +8468,8 @@ function EPOCHTODATE(timestamp, timeUnit = 1) {
|
|
|
8464
8468
|
}
|
|
8465
8469
|
|
|
8466
8470
|
const d = new Date(ms);
|
|
8467
|
-
const pad = (n) => n.toString().padStart(2, "0");
|
|
8468
8471
|
|
|
8469
|
-
const day =
|
|
8470
|
-
const month = pad(d.getMonth() + 1);
|
|
8471
|
-
const year = d.getFullYear();
|
|
8472
|
-
|
|
8473
|
-
const hours = pad(d.getHours());
|
|
8474
|
-
const minutes = pad(d.getMinutes());
|
|
8475
|
-
const seconds = pad(d.getSeconds());
|
|
8472
|
+
const { day, month, year, hours, minutes, seconds } = datePartition(d);
|
|
8476
8473
|
|
|
8477
8474
|
return `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`
|
|
8478
8475
|
}
|
|
@@ -8480,20 +8477,15 @@ function EPOCHTODATE(timestamp, timeUnit = 1) {
|
|
|
8480
8477
|
function SEQUENCE(rows, columns = 1, start = 1, step = 1) {
|
|
8481
8478
|
const result = [];
|
|
8482
8479
|
|
|
8483
|
-
const
|
|
8484
|
-
|
|
8485
|
-
|
|
8486
|
-
|
|
8487
|
-
new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
|
|
8488
|
-
|
|
8489
|
-
// Convert JS date → Google Sheets serial number
|
|
8490
|
-
const dateToSerial = (d) => {
|
|
8491
|
-
const utcDate = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
8492
|
-
const gsEpoch = Date.UTC(1899, 11, 30); // Google Sheets epoch
|
|
8493
|
-
return (utcDate - gsEpoch) / (1000 * 60 * 60 * 24);
|
|
8480
|
+
const isDateInput = (val) => {
|
|
8481
|
+
if (val instanceof Date) return true;
|
|
8482
|
+
if (typeof val === "string" && !isNaN(Date.parse(val))) return true;
|
|
8483
|
+
return false;
|
|
8494
8484
|
};
|
|
8495
8485
|
|
|
8496
|
-
|
|
8486
|
+
const isDate = isDateInput(start);
|
|
8487
|
+
|
|
8488
|
+
if (isDate) start = DATEVALUE(start);
|
|
8497
8489
|
|
|
8498
8490
|
for (let r = 0; r < rows; r++) {
|
|
8499
8491
|
const row = [];
|
|
@@ -8501,17 +8493,7 @@ function SEQUENCE(rows, columns = 1, start = 1, step = 1) {
|
|
|
8501
8493
|
for (let c = 0; c < columns; c++) {
|
|
8502
8494
|
const index = r * columns + c;
|
|
8503
8495
|
|
|
8504
|
-
if (isDate) {
|
|
8505
|
-
// Date sequence → step = days
|
|
8506
|
-
const d = new Date(start);
|
|
8507
|
-
d.setUTCDate(start.getUTCDate() + index * step);
|
|
8508
|
-
|
|
8509
|
-
// Return the DATEVALUE serial number instead of Date
|
|
8510
|
-
row.push(dateToSerial(d));
|
|
8511
|
-
} else {
|
|
8512
|
-
// Numeric sequence
|
|
8513
8496
|
row.push(start + index * step);
|
|
8514
|
-
}
|
|
8515
8497
|
}
|
|
8516
8498
|
|
|
8517
8499
|
result.push(row);
|
|
@@ -8717,16 +8699,7 @@ const NETWORKDAYS_INTL = NETWORKDAYS.INTL;
|
|
|
8717
8699
|
*/
|
|
8718
8700
|
function NOW() {
|
|
8719
8701
|
const d = new Date();
|
|
8720
|
-
const
|
|
8721
|
-
|
|
8722
|
-
const day = pad(d.getDate());
|
|
8723
|
-
const month = pad(d.getMonth() + 1);
|
|
8724
|
-
const year = d.getFullYear();
|
|
8725
|
-
|
|
8726
|
-
const hours = pad(d.getHours());
|
|
8727
|
-
const minutes = pad(d.getMinutes());
|
|
8728
|
-
const seconds = pad(d.getSeconds());
|
|
8729
|
-
|
|
8702
|
+
const { day, month, year, hours, minutes, seconds } = datePartition(d);
|
|
8730
8703
|
return returnSerial ? dateToSerial(d) : `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`
|
|
8731
8704
|
}
|
|
8732
8705
|
|
|
@@ -9094,11 +9067,9 @@ function YEARFRAC(start_date, end_date, basis) {
|
|
|
9094
9067
|
}
|
|
9095
9068
|
|
|
9096
9069
|
|
|
9097
|
-
// const start = new Date(2025, 0, 1); // Jan 1 2025
|
|
9098
|
-
// const end = new Date(2025, 11, 31); // Dec 31 2025
|
|
9099
9070
|
|
|
9100
|
-
// const
|
|
9101
|
-
// console.log(
|
|
9071
|
+
// const r = SEQUENCE(2, 1, DATE(2025,1,1),1);
|
|
9072
|
+
// console.log(r);
|
|
9102
9073
|
|
|
9103
9074
|
function isValidBinaryNumber(number) {
|
|
9104
9075
|
return /^[01]{1,10}$/.test(number)
|
package/lib/esm/index.mjs
CHANGED
|
@@ -8102,6 +8102,18 @@ const WEEKEND_TYPES = [
|
|
|
8102
8102
|
[6, 6]
|
|
8103
8103
|
];
|
|
8104
8104
|
|
|
8105
|
+
const datePartition = (date) => {
|
|
8106
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
8107
|
+
|
|
8108
|
+
const day = pad(date.getDate());
|
|
8109
|
+
const month = pad(date.getMonth() + 1);
|
|
8110
|
+
const year = date.getFullYear();
|
|
8111
|
+
const hours = pad(date.getHours());
|
|
8112
|
+
const minutes = pad(date.getMinutes());
|
|
8113
|
+
const seconds = pad(date.getSeconds());
|
|
8114
|
+
return { day, month, year, hours, minutes, seconds };
|
|
8115
|
+
};
|
|
8116
|
+
|
|
8105
8117
|
/**
|
|
8106
8118
|
* Returns the serial number of a particular date.
|
|
8107
8119
|
*
|
|
@@ -8127,10 +8139,8 @@ function DATE(year, month, day) {
|
|
|
8127
8139
|
if (result.getFullYear() < 0) {
|
|
8128
8140
|
result = num;
|
|
8129
8141
|
}
|
|
8130
|
-
|
|
8131
|
-
const dayResult =
|
|
8132
|
-
const monthResult = pad(result.getMonth() + 1);
|
|
8133
|
-
const yearResult = result.getFullYear();
|
|
8142
|
+
|
|
8143
|
+
const { day: dayResult, month: monthResult, year: yearResult } = datePartition(result);
|
|
8134
8144
|
result = `${dayResult}/${monthResult}/${yearResult}`;
|
|
8135
8145
|
}
|
|
8136
8146
|
|
|
@@ -8242,7 +8252,7 @@ function DATEVALUE(date_text) {
|
|
|
8242
8252
|
|
|
8243
8253
|
const dateValue = new Date(date_text);
|
|
8244
8254
|
|
|
8245
|
-
return
|
|
8255
|
+
return dateToSerial(dateValue);
|
|
8246
8256
|
}
|
|
8247
8257
|
|
|
8248
8258
|
/**
|
|
@@ -8394,10 +8404,7 @@ function EDATE(start_date, months) {
|
|
|
8394
8404
|
|
|
8395
8405
|
|
|
8396
8406
|
let widthoutSerial = start_date;
|
|
8397
|
-
const
|
|
8398
|
-
const dayResult = pad(widthoutSerial.getDate());
|
|
8399
|
-
const monthResult = pad(widthoutSerial.getMonth() + 1);
|
|
8400
|
-
const yearResult = widthoutSerial.getFullYear();
|
|
8407
|
+
const { day: dayResult, month: monthResult, year: yearResult } = datePartition(widthoutSerial);
|
|
8401
8408
|
widthoutSerial = `${dayResult}/${monthResult}/${yearResult}`;
|
|
8402
8409
|
|
|
8403
8410
|
return returnSerial ? dateToSerial(start_date) : widthoutSerial
|
|
@@ -8429,10 +8436,7 @@ function EOMONTH(start_date, months) {
|
|
|
8429
8436
|
|
|
8430
8437
|
|
|
8431
8438
|
let widthoutSerial = eoMonth;
|
|
8432
|
-
const
|
|
8433
|
-
const dayResult = pad(widthoutSerial.getDate());
|
|
8434
|
-
const monthResult = pad(widthoutSerial.getMonth() + 1);
|
|
8435
|
-
const yearResult = widthoutSerial.getFullYear();
|
|
8439
|
+
const { day: dayResult, month: monthResult, year: yearResult } = datePartition(widthoutSerial);
|
|
8436
8440
|
widthoutSerial = `${dayResult}/${monthResult}/${yearResult}`;
|
|
8437
8441
|
|
|
8438
8442
|
return returnSerial ? dateToSerial(eoMonth) : widthoutSerial
|
|
@@ -8462,15 +8466,8 @@ function EPOCHTODATE(timestamp, timeUnit = 1) {
|
|
|
8462
8466
|
}
|
|
8463
8467
|
|
|
8464
8468
|
const d = new Date(ms);
|
|
8465
|
-
const pad = (n) => n.toString().padStart(2, "0");
|
|
8466
8469
|
|
|
8467
|
-
const day =
|
|
8468
|
-
const month = pad(d.getMonth() + 1);
|
|
8469
|
-
const year = d.getFullYear();
|
|
8470
|
-
|
|
8471
|
-
const hours = pad(d.getHours());
|
|
8472
|
-
const minutes = pad(d.getMinutes());
|
|
8473
|
-
const seconds = pad(d.getSeconds());
|
|
8470
|
+
const { day, month, year, hours, minutes, seconds } = datePartition(d);
|
|
8474
8471
|
|
|
8475
8472
|
return `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`
|
|
8476
8473
|
}
|
|
@@ -8478,20 +8475,15 @@ function EPOCHTODATE(timestamp, timeUnit = 1) {
|
|
|
8478
8475
|
function SEQUENCE(rows, columns = 1, start = 1, step = 1) {
|
|
8479
8476
|
const result = [];
|
|
8480
8477
|
|
|
8481
|
-
const
|
|
8482
|
-
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
|
|
8486
|
-
|
|
8487
|
-
// Convert JS date → Google Sheets serial number
|
|
8488
|
-
const dateToSerial = (d) => {
|
|
8489
|
-
const utcDate = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
|
|
8490
|
-
const gsEpoch = Date.UTC(1899, 11, 30); // Google Sheets epoch
|
|
8491
|
-
return (utcDate - gsEpoch) / (1000 * 60 * 60 * 24);
|
|
8478
|
+
const isDateInput = (val) => {
|
|
8479
|
+
if (val instanceof Date) return true;
|
|
8480
|
+
if (typeof val === "string" && !isNaN(Date.parse(val))) return true;
|
|
8481
|
+
return false;
|
|
8492
8482
|
};
|
|
8493
8483
|
|
|
8494
|
-
|
|
8484
|
+
const isDate = isDateInput(start);
|
|
8485
|
+
|
|
8486
|
+
if (isDate) start = DATEVALUE(start);
|
|
8495
8487
|
|
|
8496
8488
|
for (let r = 0; r < rows; r++) {
|
|
8497
8489
|
const row = [];
|
|
@@ -8499,17 +8491,7 @@ function SEQUENCE(rows, columns = 1, start = 1, step = 1) {
|
|
|
8499
8491
|
for (let c = 0; c < columns; c++) {
|
|
8500
8492
|
const index = r * columns + c;
|
|
8501
8493
|
|
|
8502
|
-
if (isDate) {
|
|
8503
|
-
// Date sequence → step = days
|
|
8504
|
-
const d = new Date(start);
|
|
8505
|
-
d.setUTCDate(start.getUTCDate() + index * step);
|
|
8506
|
-
|
|
8507
|
-
// Return the DATEVALUE serial number instead of Date
|
|
8508
|
-
row.push(dateToSerial(d));
|
|
8509
|
-
} else {
|
|
8510
|
-
// Numeric sequence
|
|
8511
8494
|
row.push(start + index * step);
|
|
8512
|
-
}
|
|
8513
8495
|
}
|
|
8514
8496
|
|
|
8515
8497
|
result.push(row);
|
|
@@ -8715,16 +8697,7 @@ const NETWORKDAYS_INTL = NETWORKDAYS.INTL;
|
|
|
8715
8697
|
*/
|
|
8716
8698
|
function NOW() {
|
|
8717
8699
|
const d = new Date();
|
|
8718
|
-
const
|
|
8719
|
-
|
|
8720
|
-
const day = pad(d.getDate());
|
|
8721
|
-
const month = pad(d.getMonth() + 1);
|
|
8722
|
-
const year = d.getFullYear();
|
|
8723
|
-
|
|
8724
|
-
const hours = pad(d.getHours());
|
|
8725
|
-
const minutes = pad(d.getMinutes());
|
|
8726
|
-
const seconds = pad(d.getSeconds());
|
|
8727
|
-
|
|
8700
|
+
const { day, month, year, hours, minutes, seconds } = datePartition(d);
|
|
8728
8701
|
return returnSerial ? dateToSerial(d) : `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`
|
|
8729
8702
|
}
|
|
8730
8703
|
|
|
@@ -9092,11 +9065,9 @@ function YEARFRAC(start_date, end_date, basis) {
|
|
|
9092
9065
|
}
|
|
9093
9066
|
|
|
9094
9067
|
|
|
9095
|
-
// const start = new Date(2025, 0, 1); // Jan 1 2025
|
|
9096
|
-
// const end = new Date(2025, 11, 31); // Dec 31 2025
|
|
9097
9068
|
|
|
9098
|
-
// const
|
|
9099
|
-
// console.log(
|
|
9069
|
+
// const r = SEQUENCE(2, 1, DATE(2025,1,1),1);
|
|
9070
|
+
// console.log(r);
|
|
9100
9071
|
|
|
9101
9072
|
function isValidBinaryNumber(number) {
|
|
9102
9073
|
return /^[01]{1,10}$/.test(number)
|