@bbn/bbn 2.0.104 → 2.0.105

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.
@@ -4,6 +4,7 @@ export default class bbnDtDate extends bbnDt<Temporal.PlainDate> {
4
4
  readonly kind: bbnDtKind;
5
5
  constructor(y?: any, m?: number, d?: number);
6
6
  protected compareSameKind(other: this): -1 | 0 | 1;
7
+ format(format?: string | boolean): string;
7
8
  ftime(withSeconds?: boolean): string;
8
9
  fdate(long?: boolean, weekday?: boolean): string;
9
10
  }
@@ -1,5 +1,6 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
+ import getRow from '../../fn/object/getRow.js';
3
4
  export default class bbnDtDate extends bbnDt {
4
5
  constructor(y, m, d) {
5
6
  let value;
@@ -31,6 +32,17 @@ export default class bbnDtDate extends bbnDt {
31
32
  const cmp = Temporal.PlainDate.compare(this.value, other.value);
32
33
  return (cmp < 0 ? -1 : cmp > 0 ? 1 : 0);
33
34
  }
35
+ format(format) {
36
+ // long
37
+ if (format === true) {
38
+ format = getRow(bbn.dt.locales.date, { year: 'numeric', month: 'long', day: 'long', weekday: 'long' }).pattern;
39
+ }
40
+ // short
41
+ if (!format) {
42
+ format = getRow(bbn.dt.locales.date, { year: 'numeric', month: 'numeric', day: 'numeric' }).pattern;
43
+ }
44
+ return bbnDt.constructor.prototype.formatDate.call(this, this.value, format);
45
+ }
34
46
  ftime(withSeconds = false) {
35
47
  return '00:00' + (withSeconds ? ':00' : '');
36
48
  }
@@ -3,6 +3,7 @@ import bbnDt from './dt.js';
3
3
  export default class bbnDtDateTime extends bbnDt<Temporal.PlainDateTime> {
4
4
  readonly kind: bbnDtKind;
5
5
  constructor(y?: any, m?: number, d?: number, h?: number, i?: number, s?: number, ms?: number);
6
+ format(format?: string | boolean): string;
6
7
  fdate(long?: boolean, withTime?: boolean, weekday?: boolean): string;
7
8
  ftime(withSeconds?: boolean): string;
8
9
  }
@@ -1,5 +1,6 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
+ import getRow from '../../fn/object/getRow.js';
3
4
  export default class bbnDtDateTime extends bbnDt {
4
5
  constructor(y, m, d, h, i, s, ms) {
5
6
  let value;
@@ -27,6 +28,17 @@ export default class bbnDtDateTime extends bbnDt {
27
28
  super(value);
28
29
  this.kind = 'datetime';
29
30
  }
31
+ format(format) {
32
+ // long
33
+ if (format === true) {
34
+ format = getRow(bbn.dt.locales.date, { year: 'numeric', month: 'long', day: 'long', weekday: 'long', hour: '2-digit', minute: '2-digit', second: undefined }).pattern;
35
+ }
36
+ // short
37
+ if (!format) {
38
+ format = getRow(bbn.dt.locales.date, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: '2-digit', second: undefined }).pattern;
39
+ }
40
+ return bbnDt.constructor.prototype.formatDate.call(this, this.value, format);
41
+ }
30
42
  fdate(long = false, withTime = false, weekday = false) {
31
43
  if (!this.value) {
32
44
  return '';
@@ -3,5 +3,6 @@ import bbnDt from './dt.js';
3
3
  export default class bbnDtYearMonth extends bbnDt<Temporal.PlainYearMonth> {
4
4
  readonly kind: bbnDtKind;
5
5
  constructor(y?: any, m?: number);
6
+ format(format?: string | boolean): string;
6
7
  fdate(long?: boolean, withTime?: boolean, weekday?: boolean): string;
7
8
  }
@@ -1,5 +1,6 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
+ import getRow from '../../fn/object/getRow.js';
3
4
  export default class bbnDtYearMonth extends bbnDt {
4
5
  constructor(y, m) {
5
6
  let value;
@@ -28,6 +29,21 @@ export default class bbnDtYearMonth extends bbnDt {
28
29
  super(value);
29
30
  this.kind = 'year-month';
30
31
  }
32
+ format(format) {
33
+ // long
34
+ if (format === true) {
35
+ format = getRow(bbn.dt.locales.date, d => (d.year === 'numeric')
36
+ && (d.month === 'long')
37
+ && !('day' in d)).pattern;
38
+ }
39
+ // short
40
+ if (!format) {
41
+ format = getRow(bbn.dt.locales.date, d => (d.year === 'numeric')
42
+ && (d.month === 'numeric')
43
+ && !('day' in d)).pattern;
44
+ }
45
+ return bbnDt.constructor.prototype.formatDate.call(this, this.value, format);
46
+ }
31
47
  fdate(long = false, withTime = false, weekday = false) {
32
48
  if (!this.value) {
33
49
  return '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.104",
3
+ "version": "2.0.105",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",