@bbn/bbn 2.0.177 → 2.0.178

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.
@@ -181,7 +181,8 @@ export class bbnDt {
181
181
  throw new TypeError('Both arguments must be Temporal values');
182
182
  }
183
183
  const tz = Temporal.Now.timeZoneId();
184
- const realUnit = unitsCorrespondence[unit] ? getRow(units, d => d[0] === unitsCorrespondence[unit])[1] : undefined;
184
+ let realUnit = unitsCorrespondence[unit] ? getRow(units, d => d[0] === unitsCorrespondence[unit])[1] : undefined;
185
+ realUnit = realUnit ? realUnit + 's' : undefined;
185
186
  const isBbnDt = (x) => x instanceof bbnDt;
186
187
  // --- helper: get underlying Temporal value if wrapper ---
187
188
  const unwrap = (x) => isBbnDt(x) ? x.value : x;
@@ -224,17 +225,19 @@ export class bbnDt {
224
225
  const rawB = unwrap(b);
225
226
  if (rawA.constructor === rawB.constructor) {
226
227
  const Ctor = rawA.constructor;
228
+ const comp = Ctor.compare(rawA, rawB);
227
229
  if (realUnit === undefined) {
228
230
  if (typeof Ctor.compare !== 'function') {
229
231
  throw new TypeError('This Temporal type has no static compare');
230
232
  }
231
- return Ctor.compare(rawA, rawB); // -1, 0, 1
233
+ return comp;
232
234
  }
233
- if (typeof rawA.until !== 'function') {
235
+ if ((typeof rawA.until !== 'function')
236
+ || (typeof rawA.since !== 'function')) {
234
237
  throw new TypeError('This Temporal type does not support until/since');
235
238
  }
236
- const diff = rawA.until(rawB, { smallestUnit: realUnit, largestUnit: realUnit, roundingMode: 'floor' });
237
- //bbn.fn.log(['compare0', diff, realUnit, diff.sign, a.date(), b.date(), rawA.day, rawB.day]);
239
+ const diff = rawA[comp === 1 ? 'since' : 'until'](rawB, { smallestUnit: realUnit, largestUnit: realUnit, roundingMode: 'floor' });
240
+ //bbn.fn.log(['compare0', comp, diff, realUnit, diff.sign, a.date(), b.date(), rawA.day, rawB.day]);
238
241
  return diff.sign;
239
242
  }
240
243
  // ---- CASE 2: different constructors, but convertible bbnDt kinds ----
@@ -250,13 +253,15 @@ export class bbnDt {
250
253
  convertibleKinds.has(b.kind)) {
251
254
  const za = toZdt(a);
252
255
  const zb = toZdt(b);
256
+ const comp = Temporal.ZonedDateTime.compare(za, zb);
253
257
  if (realUnit === undefined) {
254
- return Temporal.ZonedDateTime.compare(za, zb);
258
+ return comp;
255
259
  }
256
- if (typeof za.until !== 'function') {
260
+ if ((typeof za.until !== 'function')
261
+ || (typeof za.since !== 'function')) {
257
262
  throw new TypeError('ZonedDateTime does not support until/since');
258
263
  }
259
- const diff = za.until(zb, { smallestUnit: realUnit, largestUnit: realUnit, roundingMode: 'floor' });
264
+ const diff = za[comp === 1 ? 'since' : 'until'](zb, { smallestUnit: realUnit, largestUnit: realUnit, roundingMode: 'floor' });
260
265
  //bbn.fn.log(['compare', diff, realUnit, diff.sign, a.date(), b.date(), za.day, zb.day]);
261
266
  return diff.sign;
262
267
  }
package/dist/dt.js CHANGED
@@ -195,7 +195,7 @@ const dt = (value, inputFormat = null, cls = 'auto') => {
195
195
  }
196
196
  }
197
197
  if (typeof value === 'number') {
198
- return new bbnDtDateTime(Math.abs(value) < 99999999999 ? Math.floor(value * 1000) : value);
198
+ return new bbnDtDateTime(Math.floor(Math.abs(value) < 99999999999 ? value * 1000 : value));
199
199
  }
200
200
  else if (value.__isBbnDt) {
201
201
  return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.177",
3
+ "version": "2.0.178",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",