@bbn/bbn 2.0.127 → 2.0.129
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/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/com.js +14 -3
- package/dist/dt/classes/dateTime.js +1 -1
- package/dist/dt/classes/dt.d.ts +2 -2
- package/dist/dt/classes/dt.js +21 -19
- package/dist/dt/classes/monthDay.js +1 -1
- package/dist/dt/classes/yearMonth.js +1 -1
- package/dist/dt/functions/guessFormat.js +1 -0
- package/dist/dt/functions/parse.js +4 -0
- package/package.json +1 -1
package/dist/com.js
CHANGED
|
@@ -70,10 +70,21 @@ const fetchRequest = (method, url, config = {}, aborter) => {
|
|
|
70
70
|
const fetchPromise = fetch(url, fetchConfig).then((res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
71
|
let data;
|
|
72
72
|
const contentType = res.headers.get('content-type') || '';
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
try {
|
|
74
|
+
if (contentType.includes('application/json')) {
|
|
75
|
+
data = yield res.json();
|
|
76
|
+
}
|
|
77
|
+
else if (contentType.startsWith('text/')) {
|
|
78
|
+
data = yield res.text();
|
|
79
|
+
}
|
|
80
|
+
else if (contentType.includes("multipart/")) {
|
|
81
|
+
data = yield res.arrayBuffer();
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
data = yield res.blob();
|
|
85
|
+
}
|
|
75
86
|
}
|
|
76
|
-
|
|
87
|
+
catch (_a) {
|
|
77
88
|
data = yield res.text();
|
|
78
89
|
}
|
|
79
90
|
const response = {
|
package/dist/dt/classes/dt.d.ts
CHANGED
|
@@ -34,13 +34,13 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
|
|
|
34
34
|
*/
|
|
35
35
|
protected withValue(newValue: any): this;
|
|
36
36
|
static compare(a: any, b: any, unit: string | undefined): -1 | 0 | 1;
|
|
37
|
-
static parse(input: string, format: string | string[], cls?:
|
|
37
|
+
static parse(input: string, format: string | string[], cls?: bbnDtKindParams, locale?: {
|
|
38
38
|
monthsLong?: string[];
|
|
39
39
|
monthsShort?: string[];
|
|
40
40
|
weekdaysLong?: string[];
|
|
41
41
|
weekdaysShort?: string[];
|
|
42
42
|
}): bbnDt<any>;
|
|
43
|
-
parse(input: string, format: string, cls?:
|
|
43
|
+
parse(input: string, format: string, cls?: bbnDtKindParams): bbnDt<any>;
|
|
44
44
|
compare(other: any, unit?: string): -1 | 0 | 1;
|
|
45
45
|
add(amount: number | bbnDtDuration | object, unit?: string): bbnDt<any>;
|
|
46
46
|
subtract(amount: number | bbnDtDuration | object, unit?: string): bbnDt<any>;
|
package/dist/dt/classes/dt.js
CHANGED
|
@@ -18,7 +18,6 @@ import each from '../../fn/loop/each.js';
|
|
|
18
18
|
import getRow from '../../fn/object/getRow.js';
|
|
19
19
|
import isPrimitive from '../../fn/type/isPrimitive.js';
|
|
20
20
|
import bbnDtDuration from './duration.js';
|
|
21
|
-
import camelToCss from '../../fn/string/camelToCss.js';
|
|
22
21
|
export class bbnDt {
|
|
23
22
|
constructor(value) {
|
|
24
23
|
this.__bbnNoData = true;
|
|
@@ -84,7 +83,7 @@ export class bbnDt {
|
|
|
84
83
|
const v = this.value;
|
|
85
84
|
return v.toInstant().epochMilliseconds;
|
|
86
85
|
}
|
|
87
|
-
case '
|
|
86
|
+
case 'dateTime': {
|
|
88
87
|
const v = this.value;
|
|
89
88
|
// RFC 9557 string: "YYYY-MM-DDTHH:mm:ss[Europe/Rome]"
|
|
90
89
|
const iso = `${v.toString()}[${tz}]`;
|
|
@@ -106,14 +105,14 @@ export class bbnDt {
|
|
|
106
105
|
const zdt = Temporal.ZonedDateTime.from(iso);
|
|
107
106
|
return zdt.toInstant().epochMilliseconds;
|
|
108
107
|
}
|
|
109
|
-
case '
|
|
108
|
+
case 'yearMonth': {
|
|
110
109
|
const ym = this.value;
|
|
111
110
|
const d = ym.toPlainDate({ day: 1 }); // first day of month
|
|
112
111
|
const iso = `${d.toString()}T00:00[${tz}]`;
|
|
113
112
|
const zdt = Temporal.ZonedDateTime.from(iso);
|
|
114
113
|
return zdt.toInstant().epochMilliseconds;
|
|
115
114
|
}
|
|
116
|
-
case '
|
|
115
|
+
case 'monthDay': {
|
|
117
116
|
const md = this.value;
|
|
118
117
|
const today = Temporal.Now.plainDateISO();
|
|
119
118
|
const d = md.toPlainDate({ year: today.year }); // current year
|
|
@@ -132,17 +131,17 @@ export class bbnDt {
|
|
|
132
131
|
switch (kind) {
|
|
133
132
|
case 'zoned':
|
|
134
133
|
return Temporal.Now.zonedDateTimeISO();
|
|
135
|
-
case '
|
|
134
|
+
case 'dateTime':
|
|
136
135
|
return Temporal.Now.plainDateTimeISO();
|
|
137
136
|
case 'date':
|
|
138
137
|
return Temporal.Now.plainDateISO();
|
|
139
138
|
case 'time':
|
|
140
139
|
return Temporal.Now.plainTimeISO();
|
|
141
|
-
case '
|
|
140
|
+
case 'yearMonth': {
|
|
142
141
|
const d = Temporal.Now.plainDateISO();
|
|
143
142
|
return new Temporal.PlainYearMonth(d.year, d.month);
|
|
144
143
|
}
|
|
145
|
-
case '
|
|
144
|
+
case 'monthDay': {
|
|
146
145
|
const d = Temporal.Now.plainDateISO();
|
|
147
146
|
return new Temporal.PlainMonthDay(d.month, d.day, undefined, d.year);
|
|
148
147
|
}
|
|
@@ -175,7 +174,7 @@ export class bbnDt {
|
|
|
175
174
|
case 'zoned': {
|
|
176
175
|
return x.value;
|
|
177
176
|
}
|
|
178
|
-
case '
|
|
177
|
+
case 'dateTime': {
|
|
179
178
|
const v = x.value;
|
|
180
179
|
const iso = `${v.toString()}[${tz}]`;
|
|
181
180
|
return Temporal.ZonedDateTime.from(iso);
|
|
@@ -185,7 +184,7 @@ export class bbnDt {
|
|
|
185
184
|
const iso = `${d.toString()}T00:00[${tz}]`;
|
|
186
185
|
return Temporal.ZonedDateTime.from(iso);
|
|
187
186
|
}
|
|
188
|
-
case '
|
|
187
|
+
case 'yearMonth': {
|
|
189
188
|
const ym = x.value;
|
|
190
189
|
const d = ym.toPlainDate({ day: 1 });
|
|
191
190
|
const iso = `${d.toString()}T00:00[${tz}]`;
|
|
@@ -221,9 +220,9 @@ export class bbnDt {
|
|
|
221
220
|
// ---- CASE 2: different constructors, but convertible bbnDt kinds ----
|
|
222
221
|
const convertibleKinds = new Set([
|
|
223
222
|
'zoned',
|
|
224
|
-
'
|
|
223
|
+
'dateTime',
|
|
225
224
|
'date',
|
|
226
|
-
'
|
|
225
|
+
'yearMonth',
|
|
227
226
|
]);
|
|
228
227
|
if (isBbnDt(a) &&
|
|
229
228
|
isBbnDt(b) &&
|
|
@@ -247,7 +246,7 @@ export class bbnDt {
|
|
|
247
246
|
return bbn.dt(input, format, cls, locale);
|
|
248
247
|
}
|
|
249
248
|
parse(input, format, cls) {
|
|
250
|
-
return bbnDt.parse(input, format, cls ||
|
|
249
|
+
return bbnDt.parse(input, format, cls || this.kind);
|
|
251
250
|
}
|
|
252
251
|
compare(other, unit) {
|
|
253
252
|
if (!(other instanceof bbnDt)) {
|
|
@@ -455,7 +454,10 @@ export class bbnDt {
|
|
|
455
454
|
}
|
|
456
455
|
time(v) {
|
|
457
456
|
if (0 in arguments && (v !== undefined) && !(v instanceof Event)) {
|
|
458
|
-
if (this.kind === '
|
|
457
|
+
if (this.kind === 'zoned') {
|
|
458
|
+
return this.parse(this.date() + ' ' + v + ' GMT' + this.value.timeZoneId, 'Y-m-d H:i:s[ GMT]Z', 'dateTime');
|
|
459
|
+
}
|
|
460
|
+
if (['dateTime', 'date'].includes(this.kind)) {
|
|
459
461
|
return this.parse(this.date() + ' ' + v, 'Y-m-d H:i:s', 'dateTime');
|
|
460
462
|
}
|
|
461
463
|
return this.parse(v, 'H:i:s');
|
|
@@ -906,7 +908,7 @@ export class bbnDt {
|
|
|
906
908
|
switch (this.kind) {
|
|
907
909
|
case "zoned":
|
|
908
910
|
return this.value;
|
|
909
|
-
case "
|
|
911
|
+
case "dateTime": {
|
|
910
912
|
const pdt = this.value;
|
|
911
913
|
const iso = `${pdt.toString()}[${tz}]`;
|
|
912
914
|
return Temporal.ZonedDateTime.from(iso);
|
|
@@ -922,13 +924,13 @@ export class bbnDt {
|
|
|
922
924
|
const iso = `${today.toString()}T${t.toString()}[${tz}]`;
|
|
923
925
|
return Temporal.ZonedDateTime.from(iso);
|
|
924
926
|
}
|
|
925
|
-
case "
|
|
927
|
+
case "yearMonth": {
|
|
926
928
|
const ym = this.value;
|
|
927
929
|
const d = ym.toPlainDate({ day: 1 });
|
|
928
930
|
const iso = `${d.toString()}T00:00[${tz}]`;
|
|
929
931
|
return Temporal.ZonedDateTime.from(iso);
|
|
930
932
|
}
|
|
931
|
-
case "
|
|
933
|
+
case "monthDay": {
|
|
932
934
|
const md = this.value;
|
|
933
935
|
const today = Temporal.Now.plainDateISO();
|
|
934
936
|
const d = md.toPlainDate({ year: today.year });
|
|
@@ -1006,17 +1008,17 @@ export class bbnDt {
|
|
|
1006
1008
|
switch (this.kind) {
|
|
1007
1009
|
case "zoned":
|
|
1008
1010
|
return this.withValue(end);
|
|
1009
|
-
case "
|
|
1011
|
+
case "dateTime":
|
|
1010
1012
|
return this.withValue(end.toPlainDateTime());
|
|
1011
1013
|
case "date":
|
|
1012
1014
|
return this.withValue(end.toPlainDate());
|
|
1013
1015
|
case "time":
|
|
1014
1016
|
return this.withValue(end.toPlainTime());
|
|
1015
|
-
case "
|
|
1017
|
+
case "yearMonth": {
|
|
1016
1018
|
const p = end.toPlainDate();
|
|
1017
1019
|
return this.withValue(new Temporal.PlainYearMonth(p.year, p.month));
|
|
1018
1020
|
}
|
|
1019
|
-
case "
|
|
1021
|
+
case "monthDay": {
|
|
1020
1022
|
const p = end.toPlainDate();
|
|
1021
1023
|
return this.withValue(new Temporal.PlainMonthDay(p.month, p.day));
|
|
1022
1024
|
}
|
|
@@ -633,6 +633,10 @@ export default function parse(input, format, cls = 'auto', force, locale) {
|
|
|
633
633
|
const d = new T.PlainTime(ctx.hour, ctx.minute, ctx.second, ctx.ms * 1000000);
|
|
634
634
|
dtObj = new bbnDtTime(d);
|
|
635
635
|
}
|
|
636
|
+
else if (isClsAuto && !hasDate && !hasTime && ctx.hasYear) {
|
|
637
|
+
const d = new T.PlainDate(ctx.year, 1, 1);
|
|
638
|
+
dtObj = new bbnDtDate(d);
|
|
639
|
+
}
|
|
636
640
|
else {
|
|
637
641
|
throw new Error('No date or time information found in input');
|
|
638
642
|
}
|