@fileverse-dev/formulajs 4.4.35 → 4.4.37
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 +32 -53
- package/lib/browser/formula.min.js +2 -2
- package/lib/browser/formula.min.js.map +1 -1
- package/lib/cjs/index.cjs +30 -57
- package/lib/esm/index.mjs +30 -57
- package/package.json +1 -1
package/lib/cjs/index.cjs
CHANGED
|
@@ -8104,6 +8104,20 @@ 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.getUTCDate());
|
|
8111
|
+
const month = pad(date.getUTCMonth() + 1);
|
|
8112
|
+
const year = date.getUTCFullYear();
|
|
8113
|
+
const hours = pad(date.getUTCHours());
|
|
8114
|
+
const minutes = pad(date.getUTCMinutes());
|
|
8115
|
+
const seconds = pad(date.getUTCSeconds());
|
|
8116
|
+
|
|
8117
|
+
return { day, month, year, hours, minutes, seconds };
|
|
8118
|
+
};
|
|
8119
|
+
|
|
8120
|
+
|
|
8107
8121
|
/**
|
|
8108
8122
|
* Returns the serial number of a particular date.
|
|
8109
8123
|
*
|
|
@@ -8129,10 +8143,8 @@ function DATE(year, month, day) {
|
|
|
8129
8143
|
if (result.getFullYear() < 0) {
|
|
8130
8144
|
result = num;
|
|
8131
8145
|
}
|
|
8132
|
-
|
|
8133
|
-
const dayResult =
|
|
8134
|
-
const monthResult = pad(result.getMonth() + 1);
|
|
8135
|
-
const yearResult = result.getFullYear();
|
|
8146
|
+
|
|
8147
|
+
const { day: dayResult, month: monthResult, year: yearResult } = datePartition(result);
|
|
8136
8148
|
result = `${dayResult}/${monthResult}/${yearResult}`;
|
|
8137
8149
|
}
|
|
8138
8150
|
|
|
@@ -8244,7 +8256,7 @@ function DATEVALUE(date_text) {
|
|
|
8244
8256
|
|
|
8245
8257
|
const dateValue = new Date(date_text);
|
|
8246
8258
|
|
|
8247
|
-
return
|
|
8259
|
+
return dateToSerial(dateValue);
|
|
8248
8260
|
}
|
|
8249
8261
|
|
|
8250
8262
|
/**
|
|
@@ -8396,10 +8408,7 @@ function EDATE(start_date, months) {
|
|
|
8396
8408
|
|
|
8397
8409
|
|
|
8398
8410
|
let widthoutSerial = start_date;
|
|
8399
|
-
const
|
|
8400
|
-
const dayResult = pad(widthoutSerial.getDate());
|
|
8401
|
-
const monthResult = pad(widthoutSerial.getMonth() + 1);
|
|
8402
|
-
const yearResult = widthoutSerial.getFullYear();
|
|
8411
|
+
const { day: dayResult, month: monthResult, year: yearResult } = datePartition(widthoutSerial);
|
|
8403
8412
|
widthoutSerial = `${dayResult}/${monthResult}/${yearResult}`;
|
|
8404
8413
|
|
|
8405
8414
|
return returnSerial ? dateToSerial(start_date) : widthoutSerial
|
|
@@ -8431,10 +8440,7 @@ function EOMONTH(start_date, months) {
|
|
|
8431
8440
|
|
|
8432
8441
|
|
|
8433
8442
|
let widthoutSerial = eoMonth;
|
|
8434
|
-
const
|
|
8435
|
-
const dayResult = pad(widthoutSerial.getDate());
|
|
8436
|
-
const monthResult = pad(widthoutSerial.getMonth() + 1);
|
|
8437
|
-
const yearResult = widthoutSerial.getFullYear();
|
|
8443
|
+
const { day: dayResult, month: monthResult, year: yearResult } = datePartition(widthoutSerial);
|
|
8438
8444
|
widthoutSerial = `${dayResult}/${monthResult}/${yearResult}`;
|
|
8439
8445
|
|
|
8440
8446
|
return returnSerial ? dateToSerial(eoMonth) : widthoutSerial
|
|
@@ -8464,15 +8470,8 @@ function EPOCHTODATE(timestamp, timeUnit = 1) {
|
|
|
8464
8470
|
}
|
|
8465
8471
|
|
|
8466
8472
|
const d = new Date(ms);
|
|
8467
|
-
const pad = (n) => n.toString().padStart(2, "0");
|
|
8468
|
-
|
|
8469
|
-
const day = pad(d.getDate());
|
|
8470
|
-
const month = pad(d.getMonth() + 1);
|
|
8471
|
-
const year = d.getFullYear();
|
|
8472
8473
|
|
|
8473
|
-
const hours =
|
|
8474
|
-
const minutes = pad(d.getMinutes());
|
|
8475
|
-
const seconds = pad(d.getSeconds());
|
|
8474
|
+
const { day, month, year, hours, minutes, seconds } = datePartition(d);
|
|
8476
8475
|
|
|
8477
8476
|
return `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`
|
|
8478
8477
|
}
|
|
@@ -8480,20 +8479,15 @@ function EPOCHTODATE(timestamp, timeUnit = 1) {
|
|
|
8480
8479
|
function SEQUENCE(rows, columns = 1, start = 1, step = 1) {
|
|
8481
8480
|
const result = [];
|
|
8482
8481
|
|
|
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);
|
|
8482
|
+
const isDateInput = (val) => {
|
|
8483
|
+
if (val instanceof Date) return true;
|
|
8484
|
+
if (typeof val === "string" && !isNaN(Date.parse(val))) return true;
|
|
8485
|
+
return false;
|
|
8494
8486
|
};
|
|
8495
8487
|
|
|
8496
|
-
|
|
8488
|
+
const isDate = isDateInput(start);
|
|
8489
|
+
|
|
8490
|
+
if (isDate) start = DATEVALUE(start);
|
|
8497
8491
|
|
|
8498
8492
|
for (let r = 0; r < rows; r++) {
|
|
8499
8493
|
const row = [];
|
|
@@ -8501,17 +8495,7 @@ function SEQUENCE(rows, columns = 1, start = 1, step = 1) {
|
|
|
8501
8495
|
for (let c = 0; c < columns; c++) {
|
|
8502
8496
|
const index = r * columns + c;
|
|
8503
8497
|
|
|
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
8498
|
row.push(start + index * step);
|
|
8514
|
-
}
|
|
8515
8499
|
}
|
|
8516
8500
|
|
|
8517
8501
|
result.push(row);
|
|
@@ -8717,16 +8701,7 @@ const NETWORKDAYS_INTL = NETWORKDAYS.INTL;
|
|
|
8717
8701
|
*/
|
|
8718
8702
|
function NOW() {
|
|
8719
8703
|
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
|
-
|
|
8704
|
+
const { day, month, year, hours, minutes, seconds } = datePartition(d);
|
|
8730
8705
|
return returnSerial ? dateToSerial(d) : `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`
|
|
8731
8706
|
}
|
|
8732
8707
|
|
|
@@ -9094,11 +9069,9 @@ function YEARFRAC(start_date, end_date, basis) {
|
|
|
9094
9069
|
}
|
|
9095
9070
|
|
|
9096
9071
|
|
|
9097
|
-
// const start = new Date(2025, 0, 1); // Jan 1 2025
|
|
9098
|
-
// const end = new Date(2025, 11, 31); // Dec 31 2025
|
|
9099
9072
|
|
|
9100
|
-
// const
|
|
9101
|
-
// console.log(
|
|
9073
|
+
// const r = SEQUENCE(2, 1, DATE(2025,1,1),1);
|
|
9074
|
+
// console.log(r);
|
|
9102
9075
|
|
|
9103
9076
|
function isValidBinaryNumber(number) {
|
|
9104
9077
|
return /^[01]{1,10}$/.test(number)
|
package/lib/esm/index.mjs
CHANGED
|
@@ -8102,6 +8102,20 @@ 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.getUTCDate());
|
|
8109
|
+
const month = pad(date.getUTCMonth() + 1);
|
|
8110
|
+
const year = date.getUTCFullYear();
|
|
8111
|
+
const hours = pad(date.getUTCHours());
|
|
8112
|
+
const minutes = pad(date.getUTCMinutes());
|
|
8113
|
+
const seconds = pad(date.getUTCSeconds());
|
|
8114
|
+
|
|
8115
|
+
return { day, month, year, hours, minutes, seconds };
|
|
8116
|
+
};
|
|
8117
|
+
|
|
8118
|
+
|
|
8105
8119
|
/**
|
|
8106
8120
|
* Returns the serial number of a particular date.
|
|
8107
8121
|
*
|
|
@@ -8127,10 +8141,8 @@ function DATE(year, month, day) {
|
|
|
8127
8141
|
if (result.getFullYear() < 0) {
|
|
8128
8142
|
result = num;
|
|
8129
8143
|
}
|
|
8130
|
-
|
|
8131
|
-
const dayResult =
|
|
8132
|
-
const monthResult = pad(result.getMonth() + 1);
|
|
8133
|
-
const yearResult = result.getFullYear();
|
|
8144
|
+
|
|
8145
|
+
const { day: dayResult, month: monthResult, year: yearResult } = datePartition(result);
|
|
8134
8146
|
result = `${dayResult}/${monthResult}/${yearResult}`;
|
|
8135
8147
|
}
|
|
8136
8148
|
|
|
@@ -8242,7 +8254,7 @@ function DATEVALUE(date_text) {
|
|
|
8242
8254
|
|
|
8243
8255
|
const dateValue = new Date(date_text);
|
|
8244
8256
|
|
|
8245
|
-
return
|
|
8257
|
+
return dateToSerial(dateValue);
|
|
8246
8258
|
}
|
|
8247
8259
|
|
|
8248
8260
|
/**
|
|
@@ -8394,10 +8406,7 @@ function EDATE(start_date, months) {
|
|
|
8394
8406
|
|
|
8395
8407
|
|
|
8396
8408
|
let widthoutSerial = start_date;
|
|
8397
|
-
const
|
|
8398
|
-
const dayResult = pad(widthoutSerial.getDate());
|
|
8399
|
-
const monthResult = pad(widthoutSerial.getMonth() + 1);
|
|
8400
|
-
const yearResult = widthoutSerial.getFullYear();
|
|
8409
|
+
const { day: dayResult, month: monthResult, year: yearResult } = datePartition(widthoutSerial);
|
|
8401
8410
|
widthoutSerial = `${dayResult}/${monthResult}/${yearResult}`;
|
|
8402
8411
|
|
|
8403
8412
|
return returnSerial ? dateToSerial(start_date) : widthoutSerial
|
|
@@ -8429,10 +8438,7 @@ function EOMONTH(start_date, months) {
|
|
|
8429
8438
|
|
|
8430
8439
|
|
|
8431
8440
|
let widthoutSerial = eoMonth;
|
|
8432
|
-
const
|
|
8433
|
-
const dayResult = pad(widthoutSerial.getDate());
|
|
8434
|
-
const monthResult = pad(widthoutSerial.getMonth() + 1);
|
|
8435
|
-
const yearResult = widthoutSerial.getFullYear();
|
|
8441
|
+
const { day: dayResult, month: monthResult, year: yearResult } = datePartition(widthoutSerial);
|
|
8436
8442
|
widthoutSerial = `${dayResult}/${monthResult}/${yearResult}`;
|
|
8437
8443
|
|
|
8438
8444
|
return returnSerial ? dateToSerial(eoMonth) : widthoutSerial
|
|
@@ -8462,15 +8468,8 @@ function EPOCHTODATE(timestamp, timeUnit = 1) {
|
|
|
8462
8468
|
}
|
|
8463
8469
|
|
|
8464
8470
|
const d = new Date(ms);
|
|
8465
|
-
const pad = (n) => n.toString().padStart(2, "0");
|
|
8466
|
-
|
|
8467
|
-
const day = pad(d.getDate());
|
|
8468
|
-
const month = pad(d.getMonth() + 1);
|
|
8469
|
-
const year = d.getFullYear();
|
|
8470
8471
|
|
|
8471
|
-
const hours =
|
|
8472
|
-
const minutes = pad(d.getMinutes());
|
|
8473
|
-
const seconds = pad(d.getSeconds());
|
|
8472
|
+
const { day, month, year, hours, minutes, seconds } = datePartition(d);
|
|
8474
8473
|
|
|
8475
8474
|
return `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`
|
|
8476
8475
|
}
|
|
@@ -8478,20 +8477,15 @@ function EPOCHTODATE(timestamp, timeUnit = 1) {
|
|
|
8478
8477
|
function SEQUENCE(rows, columns = 1, start = 1, step = 1) {
|
|
8479
8478
|
const result = [];
|
|
8480
8479
|
|
|
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);
|
|
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;
|
|
8492
8484
|
};
|
|
8493
8485
|
|
|
8494
|
-
|
|
8486
|
+
const isDate = isDateInput(start);
|
|
8487
|
+
|
|
8488
|
+
if (isDate) start = DATEVALUE(start);
|
|
8495
8489
|
|
|
8496
8490
|
for (let r = 0; r < rows; r++) {
|
|
8497
8491
|
const row = [];
|
|
@@ -8499,17 +8493,7 @@ function SEQUENCE(rows, columns = 1, start = 1, step = 1) {
|
|
|
8499
8493
|
for (let c = 0; c < columns; c++) {
|
|
8500
8494
|
const index = r * columns + c;
|
|
8501
8495
|
|
|
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
8496
|
row.push(start + index * step);
|
|
8512
|
-
}
|
|
8513
8497
|
}
|
|
8514
8498
|
|
|
8515
8499
|
result.push(row);
|
|
@@ -8715,16 +8699,7 @@ const NETWORKDAYS_INTL = NETWORKDAYS.INTL;
|
|
|
8715
8699
|
*/
|
|
8716
8700
|
function NOW() {
|
|
8717
8701
|
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
|
-
|
|
8702
|
+
const { day, month, year, hours, minutes, seconds } = datePartition(d);
|
|
8728
8703
|
return returnSerial ? dateToSerial(d) : `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`
|
|
8729
8704
|
}
|
|
8730
8705
|
|
|
@@ -9092,11 +9067,9 @@ function YEARFRAC(start_date, end_date, basis) {
|
|
|
9092
9067
|
}
|
|
9093
9068
|
|
|
9094
9069
|
|
|
9095
|
-
// const start = new Date(2025, 0, 1); // Jan 1 2025
|
|
9096
|
-
// const end = new Date(2025, 11, 31); // Dec 31 2025
|
|
9097
9070
|
|
|
9098
|
-
// const
|
|
9099
|
-
// console.log(
|
|
9071
|
+
// const r = SEQUENCE(2, 1, DATE(2025,1,1),1);
|
|
9072
|
+
// console.log(r);
|
|
9100
9073
|
|
|
9101
9074
|
function isValidBinaryNumber(number) {
|
|
9102
9075
|
return /^[01]{1,10}$/.test(number)
|