@bbn/bbn 2.0.127 → 2.0.128

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.
@@ -26,7 +26,7 @@ export default class bbnDtDateTime extends bbnDt {
26
26
  value = new Temporal.PlainDateTime(y, m, d || 1, h || 0, i || 0, s || 0, ms || 0);
27
27
  }
28
28
  super(value);
29
- this.kind = 'datetime';
29
+ this.kind = 'dateTime';
30
30
  }
31
31
  format(format) {
32
32
  // long
@@ -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?: 'auto' | 'zoned' | 'dateTime' | 'date' | 'time' | 'yearMonth' | 'monthDay', locale?: {
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?: 'auto' | 'zoned' | 'dateTime' | 'date' | 'time' | 'yearMonth' | 'monthDay'): bbnDt<any>;
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>;
@@ -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 'datetime': {
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 'year-month': {
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 'month-day': {
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 'datetime':
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 'year-month': {
140
+ case 'yearMonth': {
142
141
  const d = Temporal.Now.plainDateISO();
143
142
  return new Temporal.PlainYearMonth(d.year, d.month);
144
143
  }
145
- case 'month-day': {
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 'datetime': {
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 'year-month': {
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
- 'datetime',
223
+ 'dateTime',
225
224
  'date',
226
- 'year-month',
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 || camelToCss(this.kind));
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 === 'date') {
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 "datetime": {
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 "year-month": {
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 "month-day": {
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 "datetime":
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 "year-month": {
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 "month-day": {
1021
+ case "monthDay": {
1020
1022
  const p = end.toPlainDate();
1021
1023
  return this.withValue(new Temporal.PlainMonthDay(p.month, p.day));
1022
1024
  }
@@ -26,7 +26,7 @@ export default class bbnDtMonthDay extends bbnDt {
26
26
  value = new Temporal.PlainMonthDay(m, d);
27
27
  }
28
28
  super(value);
29
- this.kind = 'month-day';
29
+ this.kind = 'monthDay';
30
30
  }
31
31
  fdate(long = false, withTime = false, weekday = false) {
32
32
  if (!this.value) {
@@ -27,7 +27,7 @@ export default class bbnDtYearMonth extends bbnDt {
27
27
  value = new Temporal.PlainYearMonth(y, m);
28
28
  }
29
29
  super(value);
30
- this.kind = 'year-month';
30
+ this.kind = 'yearMonth';
31
31
  }
32
32
  format(format) {
33
33
  // long
@@ -7,6 +7,7 @@ const MYSQL_AND_NATIVE_FORMATS = [
7
7
  // Date + time
8
8
  'YYYY-MM-DD HH:II:SS.ms',
9
9
  'YYYY-MM-DD HH:II:SS',
10
+ 'YYYY-MM-DD HH:II:SS[ GMT]Z',
10
11
  'YYYY-MM-DD HH:II',
11
12
  // Time only
12
13
  // --- ISO 8601 / JS toISOString() ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.127",
3
+ "version": "2.0.128",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",