@bbn/bbn 2.0.62 → 2.0.64
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.
- package/dist/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/dt/classes/date.d.ts +6 -1
- package/dist/dt/classes/date.js +14 -1
- package/dist/dt/classes/dateTime.d.ts +6 -1
- package/dist/dt/classes/dateTime.js +28 -1
- package/dist/dt/classes/dt.d.ts +70 -0
- package/dist/dt/classes/dt.js +450 -0
- package/dist/dt/classes/duration.d.ts +39 -0
- package/dist/dt/classes/duration.js +185 -0
- package/dist/dt/classes/monthDay.d.ts +5 -1
- package/dist/dt/classes/monthDay.js +16 -1
- package/dist/dt/classes/time.d.ts +4 -1
- package/dist/dt/classes/time.js +19 -1
- package/dist/dt/classes/yearMonth.d.ts +5 -1
- package/dist/dt/classes/yearMonth.js +16 -1
- package/dist/dt/classes/zoned.d.ts +6 -1
- package/dist/dt/classes/zoned.js +28 -1
- package/dist/dt/functions/getWeekday.d.ts +3 -0
- package/dist/dt/functions/getWeekday.js +58 -0
- package/dist/dt/vars/types.d.ts +3 -0
- package/dist/dt/vars/types.js +1 -0
- package/dist/dt/vars/units.d.ts +11 -0
- package/dist/dt/vars/units.js +109 -0
- package/dist/dt.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
|
|
2
|
+
import bbnDt from './dt.js';
|
|
3
|
+
import { BbnDtKind } from '../vars/types.js';
|
|
4
|
+
export default class bbnDtDate extends bbnDt<Temporal.PlainDate> {
|
|
3
5
|
#private;
|
|
6
|
+
readonly kind: BbnDtKind;
|
|
4
7
|
constructor(y?: any, m?: number, d?: number);
|
|
8
|
+
protected compareSameKind(other: this): -1 | 0 | 1;
|
|
5
9
|
get value(): Temporal.PlainDate;
|
|
10
|
+
fdate(long?: boolean, weekday?: boolean): string;
|
|
6
11
|
}
|
package/dist/dt/classes/date.js
CHANGED
|
@@ -11,9 +11,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _bbnDtDate_value;
|
|
13
13
|
import { Temporal } from 'temporal-polyfill';
|
|
14
|
-
|
|
14
|
+
import bbnDt from './dt.js';
|
|
15
|
+
class bbnDtDate extends bbnDt {
|
|
15
16
|
constructor(y, m, d) {
|
|
17
|
+
super();
|
|
16
18
|
_bbnDtDate_value.set(this, void 0);
|
|
19
|
+
this.kind = 'date';
|
|
17
20
|
if (!y) {
|
|
18
21
|
__classPrivateFieldSet(this, _bbnDtDate_value, Temporal.PlainDate.from(Temporal.Now.plainDateISO()), "f");
|
|
19
22
|
}
|
|
@@ -33,9 +36,19 @@ class bbnDtDate {
|
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
}
|
|
39
|
+
compareSameKind(other) {
|
|
40
|
+
const cmp = Temporal.PlainDate.compare(__classPrivateFieldGet(this, _bbnDtDate_value, "f"), other.value);
|
|
41
|
+
return (cmp < 0 ? -1 : cmp > 0 ? 1 : 0);
|
|
42
|
+
}
|
|
36
43
|
get value() {
|
|
37
44
|
return __classPrivateFieldGet(this, _bbnDtDate_value, "f");
|
|
38
45
|
}
|
|
46
|
+
fdate(long = false, weekday = false) {
|
|
47
|
+
const date = new Date(this.year(), this.month() - 1, this.day());
|
|
48
|
+
const opt = Object.assign({ year: 'numeric', month: long ? 'long' : 'numeric', day: 'numeric' }, (weekday ? { weekday: (long ? 'long' : 'short') } : {}));
|
|
49
|
+
const d = new Intl.DateTimeFormat([bbn.env.lang, ...navigator.languages], opt);
|
|
50
|
+
return d.format(date);
|
|
51
|
+
}
|
|
39
52
|
}
|
|
40
53
|
_bbnDtDate_value = new WeakMap();
|
|
41
54
|
export default bbnDtDate;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
|
|
2
|
+
import { BbnDtKind } from '../vars/types.js';
|
|
3
|
+
import bbnDt from './dt.js';
|
|
4
|
+
export default class bbnDtDateTime extends bbnDt<Temporal.PlainDateTime> {
|
|
3
5
|
#private;
|
|
6
|
+
readonly kind: BbnDtKind;
|
|
4
7
|
constructor(y?: any, m?: number, d?: number, h?: number, i?: number, s?: number, ms?: number);
|
|
5
8
|
get value(): Temporal.PlainDateTime;
|
|
9
|
+
fdate(long?: boolean, withTime?: boolean, weekday?: boolean): string;
|
|
10
|
+
ftime(withSeconds?: boolean): string;
|
|
6
11
|
}
|
|
@@ -11,9 +11,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _bbnDtDateTime_value;
|
|
13
13
|
import { Temporal } from 'temporal-polyfill';
|
|
14
|
-
|
|
14
|
+
import bbnDt from './dt.js';
|
|
15
|
+
class bbnDtDateTime extends bbnDt {
|
|
15
16
|
constructor(y, m, d, h, i, s, ms) {
|
|
17
|
+
super();
|
|
16
18
|
_bbnDtDateTime_value.set(this, void 0);
|
|
19
|
+
this.kind = 'datetime';
|
|
17
20
|
if (!y) {
|
|
18
21
|
__classPrivateFieldSet(this, _bbnDtDateTime_value, Temporal.PlainDateTime.from(Temporal.Now.plainDateISO()), "f");
|
|
19
22
|
}
|
|
@@ -39,6 +42,30 @@ class bbnDtDateTime {
|
|
|
39
42
|
get value() {
|
|
40
43
|
return __classPrivateFieldGet(this, _bbnDtDateTime_value, "f");
|
|
41
44
|
}
|
|
45
|
+
fdate(long = false, withTime = false, weekday = false) {
|
|
46
|
+
if (!this.value) {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
const date = new Date(this.year(), this.month() - 1, this.day(), this.hour(), this.minute(), this.second());
|
|
50
|
+
const opt = Object.assign(Object.assign({ year: 'numeric', month: long ? 'long' : 'numeric', day: 'numeric' }, (weekday ? { weekday: (long ? 'long' : 'short') } : {})), (withTime ? { hour: (long ? '2-digit' : 'numeric'), minute: '2-digit' } : {}));
|
|
51
|
+
const d = new Intl.DateTimeFormat([bbn.env.lang, ...navigator.languages], opt);
|
|
52
|
+
return d.format(date);
|
|
53
|
+
}
|
|
54
|
+
ftime(withSeconds = false) {
|
|
55
|
+
if (!this.value) {
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
const date = new Date(2000, 1, 1, this.hour(), this.minute(), this.second());
|
|
59
|
+
const opt = {
|
|
60
|
+
hour: '2-digit',
|
|
61
|
+
minute: '2-digit',
|
|
62
|
+
};
|
|
63
|
+
if (withSeconds) {
|
|
64
|
+
opt.second = '2-digit';
|
|
65
|
+
}
|
|
66
|
+
const t = new Intl.DateTimeFormat([bbn.env.lang, ...navigator.languages], opt);
|
|
67
|
+
return t.format(date);
|
|
68
|
+
}
|
|
42
69
|
}
|
|
43
70
|
_bbnDtDateTime_value = new WeakMap();
|
|
44
71
|
export default bbnDtDateTime;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { BbnDtKind, BbnDtTemporal } from '../vars/types.js';
|
|
2
|
+
import bbnDtDuration from './duration.js';
|
|
3
|
+
export declare abstract class bbnDt<TValue extends BbnDtTemporal> {
|
|
4
|
+
abstract readonly kind: BbnDtKind;
|
|
5
|
+
abstract get value(): TValue;
|
|
6
|
+
static compare(a: any, b: any, unit: string | undefined): -1 | 0 | 1;
|
|
7
|
+
static parse(input: string, format: string | string[], cls?: 'auto' | 'zoned' | 'dateTime' | 'date' | 'time' | 'yearMonth' | 'monthDay', locale?: {
|
|
8
|
+
monthsLong?: string[];
|
|
9
|
+
monthsShort?: string[];
|
|
10
|
+
weekdaysLong?: string[];
|
|
11
|
+
weekdaysShort?: string[];
|
|
12
|
+
}): bbnDt<any>;
|
|
13
|
+
parse(input: string, format: string): bbnDt<any>;
|
|
14
|
+
compare(other: any, unit?: string): -1 | 0 | 1;
|
|
15
|
+
add(amount: number | bbnDtDuration | object, unit?: string): TValue;
|
|
16
|
+
subtract(amount: number | bbnDtDuration | object, unit?: string): TValue;
|
|
17
|
+
isBefore(other: bbnDt<any>): boolean;
|
|
18
|
+
isAfter(other: bbnDt<any>): boolean;
|
|
19
|
+
isSame(other: bbnDt<any>): boolean;
|
|
20
|
+
equals(other: bbnDt<any>): boolean;
|
|
21
|
+
toJSON(): {
|
|
22
|
+
kind: BbnDtKind;
|
|
23
|
+
value: string;
|
|
24
|
+
};
|
|
25
|
+
toString(): string;
|
|
26
|
+
year(v?: any): number | TValue;
|
|
27
|
+
month(v?: any): number | TValue;
|
|
28
|
+
day(v?: any): number | TValue;
|
|
29
|
+
hour(v?: any): number | TValue;
|
|
30
|
+
minute(v?: any): number | TValue;
|
|
31
|
+
second(v?: any): number | TValue;
|
|
32
|
+
weekday(v?: any, past?: any): number | TValue;
|
|
33
|
+
date(v?: any): string | bbnDt<any>;
|
|
34
|
+
datetime(v?: any): string | bbnDt<any>;
|
|
35
|
+
time(v?: any): string | bbnDt<any>;
|
|
36
|
+
week(): number;
|
|
37
|
+
get YYYY(): string;
|
|
38
|
+
get YY(): string;
|
|
39
|
+
get MMMM(): string;
|
|
40
|
+
get MMM(): string;
|
|
41
|
+
get MM(): string;
|
|
42
|
+
get M(): string;
|
|
43
|
+
get EE(): string;
|
|
44
|
+
get DD(): string;
|
|
45
|
+
get d(): string;
|
|
46
|
+
get dddd(): string;
|
|
47
|
+
get ddd(): string;
|
|
48
|
+
get D(): string;
|
|
49
|
+
get HH(): string;
|
|
50
|
+
get H(): string;
|
|
51
|
+
get II(): string;
|
|
52
|
+
get mm(): string;
|
|
53
|
+
get I(): string;
|
|
54
|
+
get SS(): string;
|
|
55
|
+
get S(): string;
|
|
56
|
+
get WW(): string;
|
|
57
|
+
get W(): string;
|
|
58
|
+
format(format?: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Returns a NEW date that is the next (or previous if past=true)
|
|
61
|
+
* occurrence of the given weekday, starting from this.#value.
|
|
62
|
+
*
|
|
63
|
+
* @param {number|string} weekday - Weekday index (0=Sunday…6=Saturday)
|
|
64
|
+
* or a localized weekday name.
|
|
65
|
+
* @param {boolean} past - If true → return previous occurrence instead of next.
|
|
66
|
+
* @param {string} [locale] - Optional locale for weekday names.
|
|
67
|
+
*/
|
|
68
|
+
setWeekday(weekday: number | string, past?: boolean, locale?: string): TValue;
|
|
69
|
+
}
|
|
70
|
+
export default bbnDt;
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { Temporal } from 'temporal-polyfill';
|
|
2
|
+
import substr from '../../fn/string/substr.js';
|
|
3
|
+
import { getWeekdayIndex, getWeekday } from '../functions/getWeekday.js';
|
|
4
|
+
import { unitsCorrespondence, formatsMap } from '../vars/units.js';
|
|
5
|
+
import each from '../../fn/loop/each.js';
|
|
6
|
+
import isPrimitive from '../../fn/type/isPrimitive.js';
|
|
7
|
+
import bbnDtDuration from './duration.js';
|
|
8
|
+
import parse from '../functions/parse.js';
|
|
9
|
+
import camelToCss from '../../fn/string/camelToCss.js';
|
|
10
|
+
export class bbnDt {
|
|
11
|
+
static compare(a, b, unit) {
|
|
12
|
+
if (!a || !b) {
|
|
13
|
+
throw new TypeError('Both arguments must be Temporal values');
|
|
14
|
+
}
|
|
15
|
+
if (a.constructor !== b.constructor) {
|
|
16
|
+
throw new TypeError('Cannot compare different Temporal types');
|
|
17
|
+
}
|
|
18
|
+
const Ctor = a.constructor;
|
|
19
|
+
// No unit → delegate to the built-in static compare
|
|
20
|
+
if (unit === undefined) {
|
|
21
|
+
if (typeof Ctor.compare !== 'function') {
|
|
22
|
+
throw new TypeError('This Temporal type has no static compare');
|
|
23
|
+
}
|
|
24
|
+
return Ctor.compare(a, b); // -1, 0, 1
|
|
25
|
+
}
|
|
26
|
+
// With unit → use .until() and let Temporal validate the unit
|
|
27
|
+
if (typeof a.until !== 'function') {
|
|
28
|
+
throw new TypeError('This Temporal type does not support until/since');
|
|
29
|
+
}
|
|
30
|
+
// If `unit` is invalid for this Temporal type, this will throw RangeError
|
|
31
|
+
const diff = a.until(b, { largestUnit: unit });
|
|
32
|
+
return diff.sign; // -1 / 0 / 1
|
|
33
|
+
}
|
|
34
|
+
static parse(input, format, cls = 'auto', locale) {
|
|
35
|
+
return parse(input, format, cls, locale);
|
|
36
|
+
}
|
|
37
|
+
parse(input, format) {
|
|
38
|
+
return bbnDt.parse(input, format, camelToCss(this.kind));
|
|
39
|
+
}
|
|
40
|
+
compare(other, unit) {
|
|
41
|
+
if (!(other instanceof bbnDt)) {
|
|
42
|
+
other = bbn.dt(other, this.kind);
|
|
43
|
+
}
|
|
44
|
+
return bbnDt.compare(this.value, other.value, unit);
|
|
45
|
+
}
|
|
46
|
+
add(amount, unit) {
|
|
47
|
+
if (!this.value) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
if (this.value instanceof Temporal.PlainMonthDay || typeof this.value.add !== 'function') {
|
|
51
|
+
throw new TypeError('This Temporal type does not support add/subtract');
|
|
52
|
+
}
|
|
53
|
+
if (amount instanceof bbnDtDuration) {
|
|
54
|
+
const d = this.value.add(amount.value);
|
|
55
|
+
return new this.constructor(d);
|
|
56
|
+
}
|
|
57
|
+
else if (typeof amount === 'object') {
|
|
58
|
+
const dur = new bbnDtDuration(amount);
|
|
59
|
+
const d = this.value.add(dur.value);
|
|
60
|
+
return new this.constructor(d);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
if (!unit) {
|
|
64
|
+
throw new Error('Unit must be specified when adding a number');
|
|
65
|
+
}
|
|
66
|
+
const dur = bbnDtDuration.fromUnit(amount, unit);
|
|
67
|
+
const d = this.value.add(dur.value);
|
|
68
|
+
return new this.constructor(d);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
subtract(amount, unit) {
|
|
72
|
+
if (!this.value) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
if (this.value instanceof Temporal.PlainMonthDay || typeof this.value.subtract !== 'function') {
|
|
76
|
+
throw new TypeError('This Temporal type does not support add/subtract');
|
|
77
|
+
}
|
|
78
|
+
if (amount instanceof bbnDtDuration) {
|
|
79
|
+
const d = this.value.subtract(amount.value);
|
|
80
|
+
return new this.constructor(d);
|
|
81
|
+
}
|
|
82
|
+
else if (typeof amount === 'object') {
|
|
83
|
+
const dur = new bbnDtDuration(amount);
|
|
84
|
+
const d = this.value.subtract(dur.value);
|
|
85
|
+
return new this.constructor(d);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (!unit) {
|
|
89
|
+
throw new Error('Unit must be specified when adding a number');
|
|
90
|
+
}
|
|
91
|
+
const dur = bbnDtDuration.fromUnit(amount, unit);
|
|
92
|
+
const d = this.value.subtract(dur.value);
|
|
93
|
+
return new this.constructor(d);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
isBefore(other) {
|
|
97
|
+
return this.compare(other) < 0;
|
|
98
|
+
}
|
|
99
|
+
isAfter(other) {
|
|
100
|
+
return this.compare(other) > 0;
|
|
101
|
+
}
|
|
102
|
+
isSame(other) {
|
|
103
|
+
return this.compare(other) === 0;
|
|
104
|
+
}
|
|
105
|
+
equals(other) {
|
|
106
|
+
return this.isSame(other);
|
|
107
|
+
}
|
|
108
|
+
// ---- Serialization ----
|
|
109
|
+
toJSON() {
|
|
110
|
+
return {
|
|
111
|
+
kind: this.kind,
|
|
112
|
+
value: String(this.value)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
toString() {
|
|
116
|
+
return String(this.value);
|
|
117
|
+
}
|
|
118
|
+
year(v) {
|
|
119
|
+
if (!this.value) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
if (!('year' in this.value)) {
|
|
123
|
+
throw new Error('year() is not supported for this type');
|
|
124
|
+
}
|
|
125
|
+
if ((v !== undefined) && !(v instanceof Event)) {
|
|
126
|
+
const d = this.value.with({ year: v });
|
|
127
|
+
return new this.constructor(d);
|
|
128
|
+
}
|
|
129
|
+
return this.value.year;
|
|
130
|
+
}
|
|
131
|
+
month(v) {
|
|
132
|
+
if (!this.value) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
if (!('month' in this.value)) {
|
|
136
|
+
throw new Error('month() is not supported for this type');
|
|
137
|
+
}
|
|
138
|
+
if ((v !== undefined) && !(v instanceof Event)) {
|
|
139
|
+
const d = this.value.with({ month: v });
|
|
140
|
+
return new this.constructor(d);
|
|
141
|
+
}
|
|
142
|
+
return this.value.month;
|
|
143
|
+
}
|
|
144
|
+
day(v) {
|
|
145
|
+
if (!this.value) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
if (!('day' in this.value)) {
|
|
149
|
+
throw new Error('day() is not supported for this type');
|
|
150
|
+
}
|
|
151
|
+
if ((v !== undefined) && !(v instanceof Event)) {
|
|
152
|
+
const d = this.value.with({ day: v });
|
|
153
|
+
return new this.constructor(d);
|
|
154
|
+
}
|
|
155
|
+
return this.value.day;
|
|
156
|
+
}
|
|
157
|
+
hour(v) {
|
|
158
|
+
if (!this.value) {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
if (!('hour' in this.value)) {
|
|
162
|
+
throw new Error('hour() is not supported for this type');
|
|
163
|
+
}
|
|
164
|
+
if ((v !== undefined) && !(v instanceof Event)) {
|
|
165
|
+
const d = this.value.with({ hour: v });
|
|
166
|
+
return new this.constructor(d);
|
|
167
|
+
}
|
|
168
|
+
return this.value.hour;
|
|
169
|
+
}
|
|
170
|
+
minute(v) {
|
|
171
|
+
if (!this.value) {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
if (!('minute' in this.value)) {
|
|
175
|
+
throw new Error('minute() is not supported for this type');
|
|
176
|
+
}
|
|
177
|
+
if ((v !== undefined) && !(v instanceof Event)) {
|
|
178
|
+
const d = this.value.with({ minute: v });
|
|
179
|
+
return new this.constructor(d);
|
|
180
|
+
}
|
|
181
|
+
return this.value.minute;
|
|
182
|
+
}
|
|
183
|
+
second(v) {
|
|
184
|
+
if (!this.value) {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
if (!('second' in this.value)) {
|
|
188
|
+
throw new Error('second() is not supported for this type');
|
|
189
|
+
}
|
|
190
|
+
if ((v !== undefined) && !(v instanceof Event)) {
|
|
191
|
+
const d = this.value.with({ second: v });
|
|
192
|
+
return new this.constructor(d);
|
|
193
|
+
}
|
|
194
|
+
return this.value.second;
|
|
195
|
+
}
|
|
196
|
+
weekday(v, past) {
|
|
197
|
+
if (!this.value) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
if (!('dayOfWeek' in this.value)) {
|
|
201
|
+
throw new Error('weekday() is not supported for this type');
|
|
202
|
+
}
|
|
203
|
+
if ((v !== undefined) && !(v instanceof Event)) {
|
|
204
|
+
return this.setWeekday(v, past);
|
|
205
|
+
}
|
|
206
|
+
return this.value.dayOfWeek;
|
|
207
|
+
}
|
|
208
|
+
date(v) {
|
|
209
|
+
if (!this.value) {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
if (!('year' in this.value) || !('month' in this.value) || !('day' in this.value)) {
|
|
213
|
+
throw new Error('date() is not supported for this type');
|
|
214
|
+
}
|
|
215
|
+
return this.parse(v, 'Y-m-d');
|
|
216
|
+
}
|
|
217
|
+
datetime(v) {
|
|
218
|
+
if (0 in arguments && (v !== undefined) && !(v instanceof Event)) {
|
|
219
|
+
return this.parse(v, 'Y-m-d H:i:s');
|
|
220
|
+
}
|
|
221
|
+
return this.format('Y-m-d H:i:s');
|
|
222
|
+
}
|
|
223
|
+
time(v) {
|
|
224
|
+
if (0 in arguments && (v !== undefined) && !(v instanceof Event)) {
|
|
225
|
+
return this.parse(v, 'H:i:s');
|
|
226
|
+
}
|
|
227
|
+
return this.format('H:i:s');
|
|
228
|
+
}
|
|
229
|
+
week() {
|
|
230
|
+
if (!this.value) {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
if (!('weekOfYear' in this.value)) {
|
|
234
|
+
throw new Error('week() is not supported for this type');
|
|
235
|
+
}
|
|
236
|
+
return this.value.weekOfYear;
|
|
237
|
+
}
|
|
238
|
+
get YYYY() {
|
|
239
|
+
if ('year' in this.value) {
|
|
240
|
+
return this.year().toString();
|
|
241
|
+
}
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
get YY() {
|
|
245
|
+
if ('year' in this.value) {
|
|
246
|
+
return substr(this.year().toString(), 2, 2);
|
|
247
|
+
}
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
get MMMM() {
|
|
251
|
+
if ('month' in this.value) {
|
|
252
|
+
return this.format('MMMM');
|
|
253
|
+
}
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
get MMM() {
|
|
257
|
+
if ('month' in this.value) {
|
|
258
|
+
return this.format('MMM');
|
|
259
|
+
}
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
get MM() {
|
|
263
|
+
if ('month' in this.value) {
|
|
264
|
+
const m = parseInt(this.month().toString());
|
|
265
|
+
return m < 10 ? '0' + m.toString() : m.toString();
|
|
266
|
+
}
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
get M() {
|
|
270
|
+
if ('month' in this.value) {
|
|
271
|
+
return this.month().toString();
|
|
272
|
+
}
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
get EE() {
|
|
276
|
+
if ('dayOfWeek' in this.value) {
|
|
277
|
+
return this.value.dayOfWeek.toString();
|
|
278
|
+
}
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
get DD() {
|
|
282
|
+
if ('day' in this.value) {
|
|
283
|
+
const d = parseInt(this.day().toString());
|
|
284
|
+
return d < 10 ? '0' + d.toString() : d.toString();
|
|
285
|
+
}
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
get d() {
|
|
289
|
+
if ('day' in this.value) {
|
|
290
|
+
return this.day().toString();
|
|
291
|
+
}
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
get dddd() {
|
|
295
|
+
if ('dayOfWeek' in this.value) {
|
|
296
|
+
return getWeekday(0, 'long');
|
|
297
|
+
}
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
get ddd() {
|
|
301
|
+
if ('day' in this.value) {
|
|
302
|
+
return getWeekday(0, 'short');
|
|
303
|
+
}
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
get D() {
|
|
307
|
+
if ('day' in this.value) {
|
|
308
|
+
return this.day().toString();
|
|
309
|
+
}
|
|
310
|
+
return undefined;
|
|
311
|
+
}
|
|
312
|
+
get HH() {
|
|
313
|
+
if ('hour' in this.value) {
|
|
314
|
+
const h = parseInt(this.hour().toString());
|
|
315
|
+
return h < 10 ? '0' + h.toString() : h.toString();
|
|
316
|
+
}
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
get H() {
|
|
320
|
+
if ('hour' in this.value) {
|
|
321
|
+
return this.hour().toString();
|
|
322
|
+
}
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
get II() {
|
|
326
|
+
if ('minute' in this.value) {
|
|
327
|
+
const i = parseInt(this.minute().toString());
|
|
328
|
+
return i < 10 ? '0' + i.toString() : i.toString();
|
|
329
|
+
}
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
get mm() {
|
|
333
|
+
if ('minute' in this.value) {
|
|
334
|
+
const i = parseInt(this.minute().toString());
|
|
335
|
+
return i < 10 ? '0' + i.toString() : i.toString();
|
|
336
|
+
}
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
get I() {
|
|
340
|
+
if ('minute' in this.value) {
|
|
341
|
+
return this.minute().toString();
|
|
342
|
+
}
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
345
|
+
get SS() {
|
|
346
|
+
if ('second' in this.value) {
|
|
347
|
+
const s = parseInt(this.second().toString());
|
|
348
|
+
return s < 10 ? '0' + s.toString() : s.toString();
|
|
349
|
+
}
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
get S() {
|
|
353
|
+
if ('second' in this.value) {
|
|
354
|
+
return this.second().toString();
|
|
355
|
+
}
|
|
356
|
+
return undefined;
|
|
357
|
+
}
|
|
358
|
+
get WW() {
|
|
359
|
+
if ('weekOfYear' in this.value) {
|
|
360
|
+
return this.value.weekOfYear.toString().padStart(2, '0');
|
|
361
|
+
}
|
|
362
|
+
return undefined;
|
|
363
|
+
}
|
|
364
|
+
get W() {
|
|
365
|
+
if ('weekOfYear' in this.value) {
|
|
366
|
+
return this.value.weekOfYear.toString();
|
|
367
|
+
}
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
format(format = 'YYYY-MM-DD HH:II:SS') {
|
|
371
|
+
let str = '';
|
|
372
|
+
if (format) {
|
|
373
|
+
const reg = new RegExp('(\[|\]|' + Object.keys(unitsCorrespondence).join('|') + ')', 'g');
|
|
374
|
+
let opened = 0;
|
|
375
|
+
const parts = format.split(reg);
|
|
376
|
+
each(parts, (part) => {
|
|
377
|
+
if (part === '[') {
|
|
378
|
+
opened++;
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
else if (part === ']') {
|
|
382
|
+
opened--;
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (opened > 0) {
|
|
386
|
+
str += part;
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
if (part in unitsCorrespondence) {
|
|
390
|
+
if (part in this && isPrimitive(this[part])) {
|
|
391
|
+
str += this[part];
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
const suffix = formatsMap[unitsCorrespondence[part]];
|
|
395
|
+
str += this[suffix];
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
str += part;
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
return str;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Returns a NEW date that is the next (or previous if past=true)
|
|
407
|
+
* occurrence of the given weekday, starting from this.#value.
|
|
408
|
+
*
|
|
409
|
+
* @param {number|string} weekday - Weekday index (0=Sunday…6=Saturday)
|
|
410
|
+
* or a localized weekday name.
|
|
411
|
+
* @param {boolean} past - If true → return previous occurrence instead of next.
|
|
412
|
+
* @param {string} [locale] - Optional locale for weekday names.
|
|
413
|
+
*/
|
|
414
|
+
setWeekday(weekday, past = false, locale) {
|
|
415
|
+
let targetDay;
|
|
416
|
+
if (typeof weekday === "string") {
|
|
417
|
+
// Use your previously defined reverse method:
|
|
418
|
+
weekday = getWeekdayIndex(weekday, locale);
|
|
419
|
+
}
|
|
420
|
+
// --- Normalize weekday ---
|
|
421
|
+
if (typeof weekday === "number") {
|
|
422
|
+
if (weekday < 0 || weekday > 6) {
|
|
423
|
+
throw new RangeError("weekday number must be between 0 and 6");
|
|
424
|
+
}
|
|
425
|
+
targetDay = weekday;
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
throw new TypeError("weekday must be a number (0–6) or a string");
|
|
429
|
+
}
|
|
430
|
+
const currentDay = this.weekday(); // JS weekday (0–6)
|
|
431
|
+
let diff;
|
|
432
|
+
if (!past) {
|
|
433
|
+
// ---------- NEXT occurrence ----------
|
|
434
|
+
diff = (targetDay - currentDay + 7) % 7;
|
|
435
|
+
if (diff === 0) {
|
|
436
|
+
diff = 7; // next week if same day
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
// ---------- PREVIOUS occurrence ----------
|
|
441
|
+
diff = (currentDay - targetDay + 7) % 7;
|
|
442
|
+
if (diff === 0) {
|
|
443
|
+
diff = 7; // previous week if same day
|
|
444
|
+
}
|
|
445
|
+
diff = -diff;
|
|
446
|
+
}
|
|
447
|
+
return this.add(diff, 'd');
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
export default bbnDt;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Temporal } from 'temporal-polyfill';
|
|
2
|
+
export default class bbnDtDuration {
|
|
3
|
+
#private;
|
|
4
|
+
static fromUnit(value: number, unit: string): bbnDtDuration;
|
|
5
|
+
constructor(y: Temporal.Duration | number | object, m?: number, d?: number, h?: number, i?: number, s?: number, ms?: number, unit?: string);
|
|
6
|
+
get value(): Temporal.Duration;
|
|
7
|
+
years(remaining?: boolean): number;
|
|
8
|
+
months(remaining?: boolean): number;
|
|
9
|
+
weeks(remaining?: boolean): number;
|
|
10
|
+
days(remaining?: boolean): number;
|
|
11
|
+
hours(remaining?: boolean): number;
|
|
12
|
+
minutes(remaining?: boolean): number;
|
|
13
|
+
seconds(remaining?: boolean): number;
|
|
14
|
+
toJSON(): {
|
|
15
|
+
years: number;
|
|
16
|
+
months: number;
|
|
17
|
+
days: number;
|
|
18
|
+
hours: number;
|
|
19
|
+
minutes: number;
|
|
20
|
+
seconds: number;
|
|
21
|
+
milliseconds: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Returns the full duration expressed as X (float), like Day.js.
|
|
25
|
+
*/
|
|
26
|
+
asYears(): number;
|
|
27
|
+
asMonths(): number;
|
|
28
|
+
asWeeks(): number;
|
|
29
|
+
asDays(): number;
|
|
30
|
+
asHours(): number;
|
|
31
|
+
asMinutes(): number;
|
|
32
|
+
asSeconds(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Add any unit (or instance default).
|
|
35
|
+
*/
|
|
36
|
+
add(value: number, unit?: string): bbnDtDuration;
|
|
37
|
+
subtract(value: number, unit?: string): bbnDtDuration;
|
|
38
|
+
toMilliseconds(): number;
|
|
39
|
+
}
|