@bbn/bbn 2.0.94 → 2.0.96

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.
@@ -7,6 +7,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
7
7
  readonly __bbnNoData = true;
8
8
  constructor(value?: TValue);
9
9
  get value(): TValue | undefined;
10
+ get hasFullDate(): boolean;
10
11
  /** System time zone ID (e.g. "Europe/Rome") */
11
12
  private static readonly systemTimeZoneId;
12
13
  /**
@@ -37,7 +38,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
37
38
  weekdaysLong?: string[];
38
39
  weekdaysShort?: string[];
39
40
  }): bbnDt<any>;
40
- parse(input: string, format: string): bbnDt<any>;
41
+ parse(input: string, format: string, cls?: 'auto' | 'zoned' | 'dateTime' | 'date' | 'time' | 'yearMonth' | 'monthDay'): bbnDt<any>;
41
42
  compare(other: any, unit?: string): -1 | 0 | 1;
42
43
  add(amount: number | bbnDtDuration | object, unit?: string): bbnDt<any>;
43
44
  subtract(amount: number | bbnDtDuration | object, unit?: string): bbnDt<any>;
@@ -50,7 +50,9 @@ export class bbnDt {
50
50
  get value() {
51
51
  return __classPrivateFieldGet(this, _bbnDt_value, "f");
52
52
  }
53
- ;
53
+ get hasFullDate() {
54
+ return ('year' in this.value) && ('month' in this.value) && ('day' in this.value);
55
+ }
54
56
  /**
55
57
  * Convert this.value (PlainDate, PlainTime, PlainDateTime, YearMonth,
56
58
  * MonthDay, ZonedDateTime) into epoch milliseconds, using the system
@@ -231,8 +233,8 @@ export class bbnDt {
231
233
  static parse(input, format, cls = 'auto', locale) {
232
234
  return bbn.dt(input, format, cls, locale);
233
235
  }
234
- parse(input, format) {
235
- return bbnDt.parse(input, format, camelToCss(this.kind));
236
+ parse(input, format, cls) {
237
+ return bbnDt.parse(input, format, cls || camelToCss(this.kind));
236
238
  }
237
239
  compare(other, unit) {
238
240
  if (!(other instanceof bbnDt)) {
@@ -362,6 +364,9 @@ export class bbnDt {
362
364
  return undefined;
363
365
  }
364
366
  if (!('hour' in this.value)) {
367
+ if (this.hasFullDate) {
368
+ return 0;
369
+ }
365
370
  throw new Error('hour() is not supported for this type');
366
371
  }
367
372
  if ((v !== undefined) && !(v instanceof Event)) {
@@ -375,6 +380,9 @@ export class bbnDt {
375
380
  return undefined;
376
381
  }
377
382
  if (!('minute' in this.value)) {
383
+ if (this.hasFullDate) {
384
+ return 0;
385
+ }
378
386
  throw new Error('minute() is not supported for this type');
379
387
  }
380
388
  if ((v !== undefined) && !(v instanceof Event)) {
@@ -388,6 +396,9 @@ export class bbnDt {
388
396
  return undefined;
389
397
  }
390
398
  if (!('second' in this.value)) {
399
+ if (this.hasFullDate) {
400
+ return 0;
401
+ }
391
402
  throw new Error('second() is not supported for this type');
392
403
  }
393
404
  if ((v !== undefined) && !(v instanceof Event)) {
@@ -412,7 +423,7 @@ export class bbnDt {
412
423
  if (!this.value) {
413
424
  return undefined;
414
425
  }
415
- if (!('year' in this.value) || !('month' in this.value) || !('day' in this.value)) {
426
+ if (!this.hasFullDate) {
416
427
  throw new Error('date() is not supported for this type');
417
428
  }
418
429
  if (0 in arguments && (v !== undefined) && !(v instanceof Event)) {
@@ -422,12 +433,18 @@ export class bbnDt {
422
433
  }
423
434
  datetime(v) {
424
435
  if (0 in arguments && (v !== undefined) && !(v instanceof Event)) {
436
+ if (this instanceof bbnDtDate) {
437
+ return this.parse(this.date() + ' ' + v, 'Y-m-d H:i:s', 'dateTime');
438
+ }
425
439
  return this.parse(v, 'Y-m-d H:i:s');
426
440
  }
427
441
  return this.YYYY + '-' + this.MM + '-' + this.DD + ' ' + this.HH + ':' + this.II + ':' + this.SS;
428
442
  }
429
443
  time(v) {
430
444
  if (0 in arguments && (v !== undefined) && !(v instanceof Event)) {
445
+ if (this instanceof bbnDtDate) {
446
+ return this.parse(this.date() + ' ' + v, 'Y-m-d H:i:s', 'dateTime');
447
+ }
431
448
  return this.parse(v, 'H:i:s');
432
449
  }
433
450
  return this.HH + ':' + this.II + ':' + this.SS;
@@ -520,12 +537,18 @@ export class bbnDt {
520
537
  const h = parseInt(this.hour().toString());
521
538
  return h < 10 ? '0' + h.toString() : h.toString();
522
539
  }
540
+ else if (this.hasFullDate) {
541
+ return '00';
542
+ }
523
543
  return undefined;
524
544
  }
525
545
  get H() {
526
546
  if ('hour' in this.value) {
527
547
  return this.hour().toString();
528
548
  }
549
+ else if (this.hasFullDate) {
550
+ return '0';
551
+ }
529
552
  return undefined;
530
553
  }
531
554
  get II() {
@@ -533,6 +556,9 @@ export class bbnDt {
533
556
  const i = parseInt(this.minute().toString());
534
557
  return i < 10 ? '0' + i.toString() : i.toString();
535
558
  }
559
+ else if (this.hasFullDate) {
560
+ return '00';
561
+ }
536
562
  return undefined;
537
563
  }
538
564
  get mm() {
@@ -540,12 +566,18 @@ export class bbnDt {
540
566
  const i = parseInt(this.minute().toString());
541
567
  return i < 10 ? '0' + i.toString() : i.toString();
542
568
  }
569
+ else if (this.hasFullDate) {
570
+ return '00';
571
+ }
543
572
  return undefined;
544
573
  }
545
574
  get I() {
546
575
  if ('minute' in this.value) {
547
576
  return this.minute().toString();
548
577
  }
578
+ else if (this.hasFullDate) {
579
+ return '0';
580
+ }
549
581
  return undefined;
550
582
  }
551
583
  get SS() {
@@ -553,12 +585,18 @@ export class bbnDt {
553
585
  const s = parseInt(this.second().toString());
554
586
  return s < 10 ? '0' + s.toString() : s.toString();
555
587
  }
588
+ else if (this.hasFullDate) {
589
+ return '00';
590
+ }
556
591
  return undefined;
557
592
  }
558
593
  get S() {
559
594
  if ('second' in this.value) {
560
595
  return this.second().toString();
561
596
  }
597
+ else if (this.hasFullDate) {
598
+ return '0';
599
+ }
562
600
  return undefined;
563
601
  }
564
602
  get WW() {
@@ -0,0 +1,8 @@
1
+ import bbnDtDate from './classes/date.js';
2
+ import bbnDtDateTime from './classes/dateTime.js';
3
+ import bbnDtTime from './classes/time.js';
4
+ import bbnDtYearMonth from './classes/yearMonth.js';
5
+ import bbnDtMonthDay from './classes/monthDay.js';
6
+ import bbnDtZoned from './classes/zoned.js';
7
+ import bbnDtDuration from './classes/duration.js';
8
+ export { bbnDtDate, bbnDtDateTime, bbnDtTime, bbnDtYearMonth, bbnDtMonthDay, bbnDtZoned, bbnDtDuration };
@@ -0,0 +1,8 @@
1
+ import bbnDtDate from './classes/date.js';
2
+ import bbnDtDateTime from './classes/dateTime.js';
3
+ import bbnDtTime from './classes/time.js';
4
+ import bbnDtYearMonth from './classes/yearMonth.js';
5
+ import bbnDtMonthDay from './classes/monthDay.js';
6
+ import bbnDtZoned from './classes/zoned.js';
7
+ import bbnDtDuration from './classes/duration.js';
8
+ export { bbnDtDate, bbnDtDateTime, bbnDtTime, bbnDtYearMonth, bbnDtMonthDay, bbnDtZoned, bbnDtDuration };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
+ import { bbnDtDate, bbnDtDateTime, bbnDtTime, bbnDtYearMonth, bbnDtMonthDay, bbnDtZoned, bbnDtDuration } from './dt/index.js';
2
3
  declare const bbn: Bbn;
3
- export { bbn as default, bbn, Temporal };
4
+ export { bbn as default, bbn, Temporal, bbnDtDate, bbnDtDateTime, bbnDtTime, bbnDtYearMonth, bbnDtMonthDay, bbnDtZoned, bbnDtDuration };
package/dist/index.js CHANGED
@@ -7,8 +7,8 @@ import env from './env.js';
7
7
  import com from './com.js';
8
8
  import db from './db.js';
9
9
  import fn from './fn.js';
10
- import date from './date.js';
11
10
  import dt from './dt.js';
11
+ import { bbnDtDate, bbnDtDateTime, bbnDtTime, bbnDtYearMonth, bbnDtMonthDay, bbnDtZoned, bbnDtDuration } from './dt/index.js';
12
12
  const bbn = {
13
13
  version: "1.0.1",
14
14
  opt: {
@@ -19,7 +19,6 @@ const bbn = {
19
19
  $,
20
20
  lng,
21
21
  var: vars,
22
- date,
23
22
  dt,
24
23
  com,
25
24
  env,
@@ -100,4 +99,4 @@ if ('undefined' !== typeof window) {
100
99
  window.Temporal = Temporal;
101
100
  }
102
101
  }
103
- export { bbn as default, bbn, Temporal };
102
+ export { bbn as default, bbn, Temporal, bbnDtDate, bbnDtDateTime, bbnDtTime, bbnDtYearMonth, bbnDtMonthDay, bbnDtZoned, bbnDtDuration };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.94",
3
+ "version": "2.0.96",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/dist/date.d.ts DELETED
@@ -1,127 +0,0 @@
1
- declare class bbnDateTool {
2
- #private;
3
- /**
4
- * Parses a date string strictly according to a format.
5
- *
6
- * Supported tokens:
7
- * Years: YYYY, YY, Y
8
- * Months: MMMM, MMM, MM, M, m
9
- * Days: DD, D, d
10
- * Weekday: dddd, ddd, EE (validation only)
11
- * Hours: HH, H, h
12
- * Minutes: II, I, i
13
- * Seconds: SS, S, s
14
- * Milli: ms
15
- * Weeks: WWWW, WWW, WW, W (parsed but not used to build the Date)
16
- *
17
- * @throws Error if parsing fails or the date is invalid.
18
- */
19
- static parse(input: string, format: string, locale?: {
20
- monthsLong?: string[];
21
- monthsShort?: string[];
22
- weekdaysLong?: string[];
23
- weekdaysShort?: string[];
24
- }): Date;
25
- /**
26
- * Compare 2 dates with a given precision.
27
- * @returns -1 if this < other, 0 if equal, 1 if this > other
28
- */
29
- static compare(date1: any, date2: any, unit?: string): -1 | 0 | 1;
30
- constructor(value: any, inputFormat?: null | String);
31
- parse(input: string, format: string): bbnDateTool;
32
- matchFormat(value: any, format: string): boolean;
33
- toString(): string;
34
- year(v?: any): number | bbnDateTool;
35
- month(v?: any): number | bbnDateTool;
36
- day(v?: any): number | bbnDateTool;
37
- hour(v?: any): number | bbnDateTool;
38
- minute(v?: any): number | bbnDateTool;
39
- second(v?: any): number | bbnDateTool;
40
- weekday(v?: any, past?: boolean): number | bbnDateTool;
41
- /**
42
- * Returns the ISO-8601 week number of this date.
43
- * Week starts on Monday, and week 1 is the week with Jan 4.
44
- *
45
- * @returns {number} ISO week number (1–53)
46
- */
47
- week(): number;
48
- get tst(): number;
49
- get mtst(): number;
50
- get YYYY(): string;
51
- get YY(): string;
52
- get MMMM(): string;
53
- get MMM(): string;
54
- get MM(): string;
55
- get M(): string;
56
- get EE(): string;
57
- get DD(): string;
58
- get d(): string;
59
- get dddd(): string;
60
- get ddd(): string;
61
- get D(): string;
62
- get HH(): string;
63
- get H(): string;
64
- get II(): string;
65
- get mm(): string;
66
- get I(): string;
67
- get SS(): string;
68
- get S(): string;
69
- get WW(): string;
70
- get isValid(): boolean;
71
- dateFromFormat(value: string, unit: string | null): Date;
72
- date(v?: any): string | bbnDateTool;
73
- datetime(v?: any): string | bbnDateTool;
74
- time(v?: any): string | bbnDateTool;
75
- fdate(long?: boolean, withTime?: boolean, weekday?: boolean): string;
76
- ftime(withSeconds?: boolean): string;
77
- format(format?: string): string;
78
- unix(ms?: boolean | number): number | bbnDateTool;
79
- sql(noTime?: boolean): string;
80
- inLeapYear(): boolean;
81
- daysInMonth(): number;
82
- valueOf(): number;
83
- /**
84
- * Compare this date to another date with a given precision.
85
- * @returns -1 if this < other, 0 if equal, 1 if this > other
86
- */
87
- compare(date: any, unit?: string): -1 | 0 | 1;
88
- add(value: number, unit?: string): bbnDateTool | null;
89
- subtract(value: number, unit?: string): bbnDateTool;
90
- isBefore(date: any, unit?: string): Boolean;
91
- isAfter(date: any, unit?: string): Boolean;
92
- isSame(date: any, unit?: string): Boolean;
93
- isAfterOrSame(date: any, unit?: string): Boolean;
94
- isBeforeOrSame(date: any, unit?: string): Boolean;
95
- fromNow(unit?: string): string;
96
- fromDate(date: any, unit?: string): string;
97
- guessUnit(valueInMs: number): string | null;
98
- diff(date: any, unit?: string, abs?: boolean): number;
99
- calendar(format: string): string;
100
- getWeekday(n: 0 | 1 | 2 | 3 | 4 | 5 | 6, mode?: string, locale?: string): any;
101
- getWeekdayIndex(name: string, locale?: string): number;
102
- /**
103
- * Returns a NEW date that is the next (or previous if past=true)
104
- * occurrence of the given weekday, starting from this.#value.
105
- *
106
- * @param {number|string} weekday - Weekday index (0=Sunday…6=Saturday)
107
- * or a localized weekday name.
108
- * @param {boolean} past - If true → return previous occurrence instead of next.
109
- * @param {string} [locale] - Optional locale for weekday names.
110
- */
111
- setWeekday(weekday: number | string, past?: boolean, locale?: string): bbnDateTool;
112
- copy(): Date;
113
- clone(): bbnDateTool;
114
- /**
115
- * Returns a NEW bbnDateTool at the start of the given unit.
116
- * Units: year, month, week, day, hour, minute, second
117
- */
118
- startOf(unit?: string): bbnDateTool;
119
- /**
120
- * Returns a NEW bbnDateTool at the end of the given unit.
121
- * Units: year, month, week, day, hour, minute, second
122
- */
123
- endOf(unit?: string): bbnDateTool;
124
- duration(num: number, unit?: string): any;
125
- }
126
- declare function generatorFunction(value: any, inputFormat?: null | String): bbnDateTool;
127
- export default generatorFunction;