@rowsncolumns/utils 9.5.3 → 9.5.4
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/dist/cjs/date.d.ts +16 -0
- package/dist/cjs/date.d.ts.map +1 -1
- package/dist/cjs/date.js +33 -4
- package/dist/esm/date.d.ts +16 -0
- package/dist/esm/date.d.ts.map +1 -1
- package/dist/esm/date.js +22 -1
- package/package.json +1 -1
package/dist/cjs/date.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Excel's 1900 date system counts a day that never happened: serial 60 is
|
|
3
|
+
* 1900-02-29 (Lotus 1-2-3 compatibility). 1900-01-01 is 1, 1900-02-28 is 59,
|
|
4
|
+
* 1900-03-01 is 61. Google Sheets keeps the same numbering.
|
|
5
|
+
*/
|
|
6
|
+
export declare const EXCEL_LEAP_BUG_SERIAL = 60;
|
|
7
|
+
/** The calendar day Excel's serial 60 stands for, which no `Date` can hold. */
|
|
8
|
+
export declare const isExcelLeapDay: (year: number, month: number, day: number) => boolean;
|
|
1
9
|
export type DateSerialMode = "local" | "excel-utc";
|
|
2
10
|
/**
|
|
3
11
|
* Convert date to serial with explicit time zone behavior.
|
|
@@ -6,6 +14,14 @@ export type DateSerialMode = "local" | "excel-utc";
|
|
|
6
14
|
*/
|
|
7
15
|
export declare const toSerialWithMode: (date: Date, use1904?: boolean, mode?: DateSerialMode) => number;
|
|
8
16
|
export declare const toSerial: (date: Date, use1904?: boolean) => number;
|
|
17
|
+
/**
|
|
18
|
+
* Serial for calendar parts the way a user typed them. Unlike
|
|
19
|
+
* `toSerial(new Date(y, m, d))`, this never goes through a `Date`, so the
|
|
20
|
+
* phantom 1900-02-29 stays serial 60 instead of rolling over to March 1
|
|
21
|
+
* (rowsncolumns/spreadsheet#1026). Every other date takes the same path as
|
|
22
|
+
* `toSerial` in "local" mode. `month` is 0-based like `Date`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const toSerialFromParts: (year: number, month: number, day: number, hour?: number, minute?: number, second?: number, use1904?: boolean) => number;
|
|
9
25
|
/**
|
|
10
26
|
* Convert serial to date
|
|
11
27
|
* @param serial
|
package/dist/cjs/date.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../date.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../date.ts"],"names":[],"mappings":"AACA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,+EAA+E;AAC/E,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,KAAK,MAAM,YAC3B,CAAC;AAE7C,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,WAAW,CAAC;AAEnD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,IAAI,EACV,iBAAe,EACf,OAAM,cAAwB,WAwB/B,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,MAAM,IAAI,EAAE,iBAAe,WAEnD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,OAAO,MAAM,EACb,KAAK,MAAM,EACX,aAAQ,EACR,eAAU,EACV,eAAU,EACV,iBAAe,WAWhB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAI,QAAQ,MAAM,EAAE,iBAAe,SA+BrD,CAAC"}
|
package/dist/cjs/date.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toDate = exports.toSerial = exports.toSerialWithMode = void 0;
|
|
3
|
+
exports.toDate = exports.toSerialFromParts = exports.toSerial = exports.toSerialWithMode = exports.isExcelLeapDay = exports.EXCEL_LEAP_BUG_SERIAL = void 0;
|
|
4
4
|
var DAY_TO_MS = 24 * 60 * 60 * 1000;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Excel's 1900 date system counts a day that never happened: serial 60 is
|
|
7
|
+
* 1900-02-29 (Lotus 1-2-3 compatibility). 1900-01-01 is 1, 1900-02-28 is 59,
|
|
8
|
+
* 1900-03-01 is 61. Google Sheets keeps the same numbering.
|
|
9
|
+
*/
|
|
10
|
+
exports.EXCEL_LEAP_BUG_SERIAL = 60;
|
|
11
|
+
/** The calendar day Excel's serial 60 stands for, which no `Date` can hold. */
|
|
12
|
+
var isExcelLeapDay = function (year, month, day) {
|
|
13
|
+
return year === 1900 && month === 1 && day === 29;
|
|
14
|
+
};
|
|
15
|
+
exports.isExcelLeapDay = isExcelLeapDay;
|
|
6
16
|
/**
|
|
7
17
|
* Convert date to serial with explicit time zone behavior.
|
|
8
18
|
* - local: interpret date components in local time (UI entry behavior).
|
|
@@ -31,6 +41,25 @@ var toSerial = function (date, use1904) {
|
|
|
31
41
|
return (0, exports.toSerialWithMode)(date, use1904, "local");
|
|
32
42
|
};
|
|
33
43
|
exports.toSerial = toSerial;
|
|
44
|
+
/**
|
|
45
|
+
* Serial for calendar parts the way a user typed them. Unlike
|
|
46
|
+
* `toSerial(new Date(y, m, d))`, this never goes through a `Date`, so the
|
|
47
|
+
* phantom 1900-02-29 stays serial 60 instead of rolling over to March 1
|
|
48
|
+
* (rowsncolumns/spreadsheet#1026). Every other date takes the same path as
|
|
49
|
+
* `toSerial` in "local" mode. `month` is 0-based like `Date`.
|
|
50
|
+
*/
|
|
51
|
+
var toSerialFromParts = function (year, month, day, hour, minute, second, use1904) {
|
|
52
|
+
if (hour === void 0) { hour = 0; }
|
|
53
|
+
if (minute === void 0) { minute = 0; }
|
|
54
|
+
if (second === void 0) { second = 0; }
|
|
55
|
+
if (use1904 === void 0) { use1904 = false; }
|
|
56
|
+
var timeFraction = (hour * 3600 + minute * 60 + second) / (24 * 60 * 60);
|
|
57
|
+
if (!use1904 && (0, exports.isExcelLeapDay)(year, month, day)) {
|
|
58
|
+
return exports.EXCEL_LEAP_BUG_SERIAL + timeFraction;
|
|
59
|
+
}
|
|
60
|
+
return (0, exports.toSerialWithMode)(new Date(year, month, day, hour, minute, second, 0), use1904, "local");
|
|
61
|
+
};
|
|
62
|
+
exports.toSerialFromParts = toSerialFromParts;
|
|
34
63
|
/**
|
|
35
64
|
* Convert serial to date
|
|
36
65
|
* @param serial
|
|
@@ -44,11 +73,11 @@ var toDate = function (serial, use1904) {
|
|
|
44
73
|
var utcDate_1 = new Date(utcMillis_1);
|
|
45
74
|
return new Date(utcDate_1.getUTCFullYear(), utcDate_1.getUTCMonth(), utcDate_1.getUTCDate(), utcDate_1.getUTCHours(), utcDate_1.getUTCMinutes(), utcDate_1.getUTCSeconds(), utcDate_1.getUTCMilliseconds());
|
|
46
75
|
}
|
|
47
|
-
if (serial === EXCEL_LEAP_BUG_SERIAL) {
|
|
76
|
+
if (serial === exports.EXCEL_LEAP_BUG_SERIAL) {
|
|
48
77
|
return new Date(1900, 1, 28);
|
|
49
78
|
}
|
|
50
79
|
var baseUtc = Date.UTC(1899, 11, 31);
|
|
51
|
-
var dayCount = serial < EXCEL_LEAP_BUG_SERIAL ? serial : serial - 1;
|
|
80
|
+
var dayCount = serial < exports.EXCEL_LEAP_BUG_SERIAL ? serial : serial - 1;
|
|
52
81
|
var utcMillis = baseUtc + dayCount * DAY_TO_MS;
|
|
53
82
|
var utcDate = new Date(utcMillis);
|
|
54
83
|
return new Date(utcDate.getUTCFullYear(), utcDate.getUTCMonth(), utcDate.getUTCDate(), utcDate.getUTCHours(), utcDate.getUTCMinutes(), utcDate.getUTCSeconds(), utcDate.getUTCMilliseconds());
|
package/dist/esm/date.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Excel's 1900 date system counts a day that never happened: serial 60 is
|
|
3
|
+
* 1900-02-29 (Lotus 1-2-3 compatibility). 1900-01-01 is 1, 1900-02-28 is 59,
|
|
4
|
+
* 1900-03-01 is 61. Google Sheets keeps the same numbering.
|
|
5
|
+
*/
|
|
6
|
+
export declare const EXCEL_LEAP_BUG_SERIAL = 60;
|
|
7
|
+
/** The calendar day Excel's serial 60 stands for, which no `Date` can hold. */
|
|
8
|
+
export declare const isExcelLeapDay: (year: number, month: number, day: number) => boolean;
|
|
1
9
|
export type DateSerialMode = "local" | "excel-utc";
|
|
2
10
|
/**
|
|
3
11
|
* Convert date to serial with explicit time zone behavior.
|
|
@@ -6,6 +14,14 @@ export type DateSerialMode = "local" | "excel-utc";
|
|
|
6
14
|
*/
|
|
7
15
|
export declare const toSerialWithMode: (date: Date, use1904?: boolean, mode?: DateSerialMode) => number;
|
|
8
16
|
export declare const toSerial: (date: Date, use1904?: boolean) => number;
|
|
17
|
+
/**
|
|
18
|
+
* Serial for calendar parts the way a user typed them. Unlike
|
|
19
|
+
* `toSerial(new Date(y, m, d))`, this never goes through a `Date`, so the
|
|
20
|
+
* phantom 1900-02-29 stays serial 60 instead of rolling over to March 1
|
|
21
|
+
* (rowsncolumns/spreadsheet#1026). Every other date takes the same path as
|
|
22
|
+
* `toSerial` in "local" mode. `month` is 0-based like `Date`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const toSerialFromParts: (year: number, month: number, day: number, hour?: number, minute?: number, second?: number, use1904?: boolean) => number;
|
|
9
25
|
/**
|
|
10
26
|
* Convert serial to date
|
|
11
27
|
* @param serial
|
package/dist/esm/date.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../date.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../date.ts"],"names":[],"mappings":"AACA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,+EAA+E;AAC/E,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,KAAK,MAAM,YAC3B,CAAC;AAE7C,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,WAAW,CAAC;AAEnD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,IAAI,EACV,iBAAe,EACf,OAAM,cAAwB,WAwB/B,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,MAAM,IAAI,EAAE,iBAAe,WAEnD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,OAAO,MAAM,EACb,KAAK,MAAM,EACX,aAAQ,EACR,eAAU,EACV,eAAU,EACV,iBAAe,WAWhB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAI,QAAQ,MAAM,EAAE,iBAAe,SA+BrD,CAAC"}
|
package/dist/esm/date.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
const DAY_TO_MS = 24 * 60 * 60 * 1000;
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Excel's 1900 date system counts a day that never happened: serial 60 is
|
|
4
|
+
* 1900-02-29 (Lotus 1-2-3 compatibility). 1900-01-01 is 1, 1900-02-28 is 59,
|
|
5
|
+
* 1900-03-01 is 61. Google Sheets keeps the same numbering.
|
|
6
|
+
*/
|
|
7
|
+
export const EXCEL_LEAP_BUG_SERIAL = 60;
|
|
8
|
+
/** The calendar day Excel's serial 60 stands for, which no `Date` can hold. */
|
|
9
|
+
export const isExcelLeapDay = (year, month, day) => year === 1900 && month === 1 && day === 29;
|
|
3
10
|
/**
|
|
4
11
|
* Convert date to serial with explicit time zone behavior.
|
|
5
12
|
* - local: interpret date components in local time (UI entry behavior).
|
|
@@ -23,6 +30,20 @@ export const toSerialWithMode = (date, use1904 = false, mode = "local") => {
|
|
|
23
30
|
export const toSerial = (date, use1904 = false) => {
|
|
24
31
|
return toSerialWithMode(date, use1904, "local");
|
|
25
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Serial for calendar parts the way a user typed them. Unlike
|
|
35
|
+
* `toSerial(new Date(y, m, d))`, this never goes through a `Date`, so the
|
|
36
|
+
* phantom 1900-02-29 stays serial 60 instead of rolling over to March 1
|
|
37
|
+
* (rowsncolumns/spreadsheet#1026). Every other date takes the same path as
|
|
38
|
+
* `toSerial` in "local" mode. `month` is 0-based like `Date`.
|
|
39
|
+
*/
|
|
40
|
+
export const toSerialFromParts = (year, month, day, hour = 0, minute = 0, second = 0, use1904 = false) => {
|
|
41
|
+
const timeFraction = (hour * 3600 + minute * 60 + second) / (24 * 60 * 60);
|
|
42
|
+
if (!use1904 && isExcelLeapDay(year, month, day)) {
|
|
43
|
+
return EXCEL_LEAP_BUG_SERIAL + timeFraction;
|
|
44
|
+
}
|
|
45
|
+
return toSerialWithMode(new Date(year, month, day, hour, minute, second, 0), use1904, "local");
|
|
46
|
+
};
|
|
26
47
|
/**
|
|
27
48
|
* Convert serial to date
|
|
28
49
|
* @param serial
|