@bbn/bbn 2.0.147 → 2.0.148

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.
@@ -5,7 +5,7 @@ export default class bbnDtDateTime extends bbnDt {
5
5
  constructor(y, m, d, h, i, s, ms) {
6
6
  let value;
7
7
  if (!y) {
8
- value = Temporal.PlainDateTime.from(Temporal.Now.plainDateISO());
8
+ value = Temporal.PlainDateTime.from(Temporal.Now.plainDateTimeISO());
9
9
  }
10
10
  else if (m === undefined) {
11
11
  if (y instanceof Temporal.PlainDateTime) {
@@ -108,7 +108,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
108
108
  setWeekday(weekday: number | string, past?: boolean, locale?: string): bbnDt<any>;
109
109
  diff(date: any, unit?: string, abs?: boolean): number;
110
110
  guessUnit(valueInMs: number): string | null;
111
- fromNow(unit?: string): string;
111
+ fromNow(unit?: string): any;
112
112
  fromDate(date: any, unit?: string): string;
113
113
  startOf(unit?: string): bbnDt<any>;
114
114
  endOf(unit?: string): bbnDt<any>;
@@ -684,7 +684,7 @@ export class bbnDt {
684
684
  return str;
685
685
  }
686
686
  calendar(short) {
687
- const now = this.constructor.now();
687
+ const now = new this.constructor();
688
688
  const startThis = this.startOf("day");
689
689
  const startNow = now.startOf("day");
690
690
  const diffDays = startThis.diff(startNow, "day");
@@ -495,6 +495,7 @@ export default function parse(input, format, cls = 'auto', force, locale) {
495
495
  let pattern = '';
496
496
  const applyFns = [];
497
497
  let i = 0;
498
+ let lastPositionMatch = 0;
498
499
  while (i < fmt.length) {
499
500
  // 1) Handle [literal] blocks first
500
501
  if (fmt[i] === '[') {
@@ -525,6 +526,7 @@ export default function parse(input, format, cls = 'auto', force, locale) {
525
526
  }
526
527
  if (matchedToken) {
527
528
  pattern += `(${matchedToken.regex})`;
529
+ lastPositionMatch = pattern.length;
528
530
  if (matchedToken.apply) {
529
531
  applyFns.push(value => matchedToken.apply(value, ctx));
530
532
  }
@@ -539,7 +541,7 @@ export default function parse(input, format, cls = 'auto', force, locale) {
539
541
  i += 1;
540
542
  }
541
543
  }
542
- const fullRegex = new RegExp('^' + pattern + '$');
544
+ const fullRegex = new RegExp('^' + bbn.fn.substr(pattern, 0, lastPositionMatch));
543
545
  let match = fullRegex.exec(input);
544
546
  if (!match) {
545
547
  if (force) {
@@ -605,8 +607,8 @@ export default function parse(input, format, cls = 'auto', force, locale) {
605
607
  }
606
608
  }
607
609
  // ---------- 2) No timezone: decide which Plain* type ----------
608
- else if (isClsDateTime || (isClsAuto && hasDate && hasTime)) {
609
- if (!hasFullDate) {
610
+ else if (isClsDateTime || (isClsAuto && (isValid || (hasDate && hasTime)))) {
611
+ if (!hasFullDate && !isValid) {
610
612
  throw new Error('PlainDateTime requires year, month and day');
611
613
  }
612
614
  const d = new T.PlainDateTime(ctx.year, ctx.month, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms * 1000000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.147",
3
+ "version": "2.0.148",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "pub": "npm version patch && npm publish",
16
16
  "build": "./node_modules/.bin/rollup -c",
17
17
  "all": "npm run type && npm run test && npm run gitauto && npm version patch && npm run build && npm run gitend && npm publish",
18
- "test": "IS_TESTING=true ./node_modules/.bin/mocha -r jsdom-global/register",
18
+ "test": "IS_TESTING=true mocha ./test/type.mjs",
19
19
  "wtf": "echo \"Error: no test specified\" && exit 1"
20
20
  },
21
21
  "keywords": [
@@ -30,10 +30,11 @@
30
30
  "@rollup/plugin-replace": "^6.0.3",
31
31
  "@rollup/plugin-terser": "^0.4.4",
32
32
  "@rollup/plugin-typescript": "^12.3.0",
33
+ "@types/mocha": "^10.0.10",
33
34
  "chai": "^6.2.1",
34
35
  "jsdom": "27.2.0",
35
36
  "jsdom-global": "3.0.2",
36
- "mocha": "^11.0.0",
37
+ "mocha": "^11.7.5",
37
38
  "rollup": "^4.53.2",
38
39
  "ts-loader": "^9.5.4",
39
40
  "tslib": "^2.8.1",