danholibraryjs 1.10.0 → 2.0.0
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/Classes/DanhoLogger.d.ts +23 -0
- package/dist/Classes/DanhoLogger.js +65 -0
- package/dist/Classes/Events/EventEmitter.d.ts +1 -1
- package/dist/Classes/Events/EventEmitter.js +1 -1
- package/dist/Classes/Time/Date.d.ts +1 -0
- package/dist/Classes/Time/Date.js +4 -1
- package/dist/Classes/Time/Time.d.ts +5 -4
- package/dist/Classes/Time/Time.js +7 -4
- package/dist/Classes/index.d.ts +1 -0
- package/dist/Classes/index.js +1 -0
- package/dist/Classes/store.d.ts +5 -9
- package/dist/Extensions/Array/array.extension.d.ts +42 -0
- package/dist/Extensions/Array/array.extension.js +57 -0
- package/dist/Extensions/Array/crud.extension.d.ts +24 -0
- package/dist/Extensions/Array/crud.extension.js +28 -0
- package/dist/Extensions/Array/index.d.ts +20 -0
- package/dist/Extensions/Array/index.js +40 -0
- package/dist/Extensions/Array/loop.extension.d.ts +18 -0
- package/dist/Extensions/Array/loop.extension.js +23 -0
- package/dist/Extensions/Array/random.extension.d.ts +23 -0
- package/dist/Extensions/Array/random.extension.js +35 -0
- package/dist/Extensions/Array/sort.extension.d.ts +27 -0
- package/dist/Extensions/Array/sort.extension.js +31 -0
- package/dist/Extensions/Array/string.extension.d.ts +13 -0
- package/dist/Extensions/Array/string.extension.js +14 -0
- package/dist/Extensions/Array.d.ts +17 -3
- package/dist/Extensions/Array.js +0 -12
- package/dist/Extensions/Function.d.ts +17 -2
- package/dist/Extensions/Function.js +15 -2
- package/dist/Extensions/Number.d.ts +13 -0
- package/dist/Extensions/Number.js +40 -0
- package/dist/Extensions/Object/arrays.extension.d.ts +17 -0
- package/dist/Extensions/Object/arrays.extension.js +13 -0
- package/dist/Extensions/Object/booleans.extension.d.ts +18 -0
- package/dist/Extensions/Object/booleans.extension.js +37 -0
- package/dist/Extensions/Object/extracts.extension.d.ts +38 -0
- package/dist/Extensions/Object/extracts.extension.js +72 -0
- package/dist/Extensions/Object/index.d.ts +8 -47
- package/dist/Extensions/Object/index.js +31 -33
- package/dist/Extensions/Object/properties.extension.d.ts +6 -0
- package/dist/Extensions/Object/properties.extension.js +4 -0
- package/dist/Extensions/Object/properties.js +1 -2
- package/dist/Extensions/String/case.extension.d.ts +12 -0
- package/dist/Extensions/String/case.extension.js +55 -0
- package/dist/Extensions/String/index.d.ts +4 -0
- package/dist/Extensions/String/index.js +30 -0
- package/dist/Extensions/index.d.ts +1 -12
- package/dist/Extensions/index.js +1 -9
- package/dist/Types/Able.d.ts +16 -0
- package/dist/Types/Able.js +2 -0
- package/dist/Types/Array.d.ts +6 -0
- package/dist/Types/Array.js +2 -0
- package/dist/Types/C#.d.ts +8 -0
- package/dist/Types/C#.js +2 -0
- package/dist/Types/Date.d.ts +1 -1
- package/dist/Types/Events.d.ts +2 -2
- package/dist/Types/Function.d.ts +5 -0
- package/dist/Types/Function.js +2 -0
- package/dist/Types/Object.d.ts +4 -0
- package/dist/Types/Object.js +2 -0
- package/dist/Types/PropertiesWith.d.ts +21 -0
- package/dist/Types/String.d.ts +1 -0
- package/dist/Types/String.js +2 -0
- package/dist/Types/TransformTypes.d.ts +9 -0
- package/dist/Types/index.d.ts +6 -28
- package/dist/Types/index.js +6 -0
- package/dist/Utils/ApiUtil/ApiTypes.d.ts +15 -0
- package/dist/Utils/ApiUtil/ApiTypes.js +15 -0
- package/dist/Utils/ApiUtil/RequestUtil.d.ts +19 -0
- package/dist/Utils/ApiUtil/RequestUtil.js +73 -0
- package/dist/Utils/ApiUtil/index.d.ts +20 -0
- package/dist/Utils/ApiUtil/index.js +33 -0
- package/dist/Utils/ApiUtils/ApiTypes.d.ts +15 -0
- package/dist/Utils/ApiUtils/ApiTypes.js +15 -0
- package/dist/Utils/ApiUtils/RequestUtil.d.ts +19 -0
- package/dist/Utils/ApiUtils/RequestUtil.js +73 -0
- package/dist/Utils/ApiUtils/index.d.ts +20 -0
- package/dist/Utils/ApiUtils/index.js +33 -0
- package/dist/Utils/ColorUtils.d.ts +11 -0
- package/dist/Utils/ColorUtils.js +93 -0
- package/dist/Utils/FormUtil.d.ts +6 -0
- package/dist/Utils/FormUtil.js +35 -0
- package/dist/Utils/FormUtils.d.ts +6 -0
- package/dist/Utils/FormUtils.js +35 -0
- package/dist/Utils/NumberUtils.d.ts +1 -0
- package/dist/Utils/NumberUtils.js +7 -0
- package/dist/Utils/PatcherUtils.d.ts +6 -0
- package/dist/Utils/PatcherUtils.js +80 -0
- package/dist/Utils/StringUtils.d.ts +3 -0
- package/dist/Utils/StringUtils.js +47 -0
- package/dist/Utils/TimeUtils/debounce.util.d.ts +22 -0
- package/dist/Utils/TimeUtils/debounce.util.js +78 -0
- package/dist/Utils/TimeUtils/functions.util.d.ts +4 -0
- package/dist/Utils/TimeUtils/functions.util.js +21 -0
- package/dist/Utils/TimeUtils/index.d.ts +15 -0
- package/dist/Utils/TimeUtils/index.js +34 -0
- package/dist/Utils/TimeUtils/throttle.util.d.ts +15 -0
- package/dist/Utils/TimeUtils/throttle.util.js +43 -0
- package/dist/Utils/index.d.ts +7 -0
- package/dist/Utils/index.js +23 -0
- package/package.json +4 -2
- package/src/Classes/DanhoLogger.ts +78 -0
- package/src/Classes/Events/Event.ts +96 -96
- package/src/Classes/Events/EventCollection.ts +90 -90
- package/src/Classes/Events/EventEmitter.ts +68 -68
- package/src/Classes/Time/Date.ts +219 -216
- package/src/Classes/Time/Time.ts +109 -104
- package/src/Classes/Time/TimeSpan.ts +171 -171
- package/src/Classes/index.ts +1 -0
- package/src/Classes/store.ts +22 -22
- package/src/Extensions/Array/array.extension.ts +103 -0
- package/src/Extensions/Array/crud.extension.ts +46 -0
- package/src/Extensions/Array/index.ts +15 -0
- package/src/Extensions/Array/loop.extension.ts +38 -0
- package/src/Extensions/Array/random.extension.ts +56 -0
- package/src/Extensions/Array/sort.extension.ts +52 -0
- package/src/Extensions/Array/string.extension.ts +22 -0
- package/src/Extensions/Document.ts +39 -39
- package/src/Extensions/Function.ts +37 -10
- package/src/Extensions/Map.ts +56 -56
- package/src/Extensions/Number.ts +50 -0
- package/src/Extensions/Object/arrays.extension.ts +27 -0
- package/src/Extensions/Object/booleans.extension.ts +46 -0
- package/src/Extensions/Object/extracts.extension.ts +102 -0
- package/src/Extensions/Object/index.ts +9 -80
- package/src/Extensions/Object/properties.extension.ts +11 -0
- package/src/Extensions/Object/properties.ts +35 -36
- package/src/Extensions/String/case.extension.ts +95 -0
- package/src/Extensions/String/index.ts +5 -0
- package/src/Extensions/index.ts +2 -20
- package/src/Interfaces/ElementOptions.ts +7 -7
- package/src/Interfaces/IReplacement.ts +2 -2
- package/src/Types/Able.ts +22 -0
- package/src/Types/Array.ts +7 -0
- package/src/Types/C#.ts +9 -0
- package/src/Types/Date.ts +1 -1
- package/src/Types/Events.ts +12 -12
- package/src/Types/Function.ts +10 -0
- package/src/Types/Object.ts +4 -0
- package/src/Types/PropertiesWith.ts +35 -4
- package/src/Types/String.ts +1 -0
- package/src/Types/TransformTypes.ts +23 -5
- package/src/Types/index.ts +7 -41
- package/src/Utils/ApiUtils/ApiTypes.ts +43 -0
- package/src/Utils/ApiUtils/RequestUtil.ts +87 -0
- package/src/Utils/ApiUtils/index.ts +39 -0
- package/src/Utils/ColorUtils.ts +102 -0
- package/src/Utils/FormUtils.ts +33 -0
- package/src/Utils/NumberUtils.ts +3 -0
- package/src/Utils/PatcherUtils.ts +111 -0
- package/src/Utils/StringUtils.ts +44 -0
- package/src/Utils/TimeUtils/debounce.util.ts +85 -0
- package/src/Utils/TimeUtils/functions.util.ts +18 -0
- package/src/Utils/TimeUtils/index.ts +9 -0
- package/src/Utils/TimeUtils/throttle.util.ts +44 -0
- package/src/Utils/index.ts +8 -0
- package/src/Extensions/Array.ts +0 -95
- package/src/Extensions/String.ts +0 -54
package/src/Classes/Time/Date.ts
CHANGED
|
@@ -15,250 +15,253 @@ type DateFormat = `${Double}/${Double}/${Quadruple}`;
|
|
|
15
15
|
export type DanhoDateConstructor = Data | DateFormat | number | Date;
|
|
16
16
|
|
|
17
17
|
class DanhoDate {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
constructor(data?: DanhoDateConstructor) {
|
|
26
|
-
// data not provided
|
|
27
|
-
if (!data) this.date = new Date();
|
|
28
|
-
// data is typeof Date
|
|
29
|
-
else if (typeof data === 'object' && data instanceof Date) {
|
|
30
|
-
this.date = new Date(data);
|
|
31
|
-
}
|
|
32
|
-
// data is typeof Data
|
|
33
|
-
else if (typeof data === 'object') {
|
|
34
|
-
this.date = new Date(data.years, data.months - 1);
|
|
35
|
-
if (data.days) this.date.setDate(data.days);
|
|
36
|
-
if (data.hours) this.date.setHours(data.hours);
|
|
37
|
-
if (data.minutes) this.date.setMinutes(data.minutes);
|
|
38
|
-
if (data.seconds) this.date.setSeconds(data.seconds);
|
|
39
|
-
if (data.milliseconds) this.date.setMilliseconds(data.milliseconds);
|
|
40
|
-
}
|
|
41
|
-
// data is string or number
|
|
42
|
-
else this.date = new Date(data);
|
|
18
|
+
/**
|
|
19
|
+
* Returns the value of the current irl time
|
|
20
|
+
*/
|
|
21
|
+
public static get now() {
|
|
22
|
+
return Date.now();
|
|
23
|
+
}
|
|
43
24
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
25
|
+
constructor(data?: DanhoDateConstructor) {
|
|
26
|
+
// data not provided
|
|
27
|
+
if (!data) this.date = new Date();
|
|
28
|
+
// data is typeof Date
|
|
29
|
+
else if (typeof data === 'object' && data instanceof Date) {
|
|
30
|
+
this.date = new Date(data);
|
|
31
|
+
}
|
|
32
|
+
// data is typeof Data
|
|
33
|
+
else if (typeof data === 'object') {
|
|
34
|
+
this.date = new Date(data.years, data.months - 1);
|
|
35
|
+
if (data.days) this.date.setDate(data.days);
|
|
36
|
+
if (data.hours) this.date.setHours(data.hours);
|
|
37
|
+
if (data.minutes) this.date.setMinutes(data.minutes);
|
|
38
|
+
if (data.seconds) this.date.setSeconds(data.seconds);
|
|
39
|
+
if (data.milliseconds) this.date.setMilliseconds(data.milliseconds);
|
|
40
|
+
}
|
|
41
|
+
// data is string or number
|
|
42
|
+
else this.date = new Date(data);
|
|
51
43
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
this._formats = new Map<string, string | number>([
|
|
45
|
+
['year', this.year],
|
|
46
|
+
['daysInMonth', this.daysInMonth],
|
|
47
|
+
['monthShort', this.monthNameShort],
|
|
48
|
+
['month', this.monthName],
|
|
49
|
+
['MM', Time.DoubleDigit(this.month)],
|
|
50
|
+
['M', this.month],
|
|
56
51
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
['weekMonth', this.weekOfMonth],
|
|
53
|
+
['weekDay', this.weekDay],
|
|
54
|
+
['weekDayShort', this.weekDayShort],
|
|
55
|
+
['week', this.week],
|
|
61
56
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
['mm', Time.DoubleDigit(this.minutes)],
|
|
67
|
-
['m', this.minutes],
|
|
68
|
-
['ss', Time.DoubleDigit(this.seconds)],
|
|
69
|
-
['s', this.seconds],
|
|
70
|
-
['msms', Time.DoubleDigit(this.milliseconds)],
|
|
71
|
-
['ms', this.milliseconds]
|
|
72
|
-
]).map((v, k) => [k, v.toString()])
|
|
73
|
-
}
|
|
57
|
+
['dd', Time.DoubleDigit(this.day)],
|
|
58
|
+
['ddth', `${Time.DoubleDigit(this.day)}${Time.th(this.day)}`],
|
|
59
|
+
['d', this.day],
|
|
60
|
+
['dth', Time.th(this.day, true)],
|
|
74
61
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
62
|
+
['hh12', `${Time.DoubleDigit(this.hours)}${this.hours < 12 ? 'AM' : 'PM'}`],
|
|
63
|
+
['h12', `${this.hours > 12 ? 12 - this.hours : this.hours}${this.hours < 12 ? 'AM' : 'PM'}`],
|
|
64
|
+
['hh24', Time.DoubleDigit(this.hours)],
|
|
65
|
+
['h24', this.hours],
|
|
66
|
+
['mm', Time.DoubleDigit(this.minutes)],
|
|
67
|
+
['m', this.minutes],
|
|
68
|
+
['ss', Time.DoubleDigit(this.seconds)],
|
|
69
|
+
['s', this.seconds],
|
|
70
|
+
['msms', Time.DoubleDigit(this.milliseconds)],
|
|
71
|
+
['ms', this.milliseconds]
|
|
72
|
+
]).map((v, k) => [k, v.toString()]);
|
|
73
|
+
}
|
|
83
74
|
|
|
84
|
-
|
|
75
|
+
private _formats: Map<string, string>;
|
|
76
|
+
private _format(format: string) {
|
|
77
|
+
return format
|
|
78
|
+
.split(/\$/)
|
|
79
|
+
.map(v => v.split(/\W/)[0])
|
|
80
|
+
.filter(v => v)
|
|
81
|
+
.reduce((result, key) => result.replaceAll(key, this._formats.get(key)!), format.replaceAll('$', ''));
|
|
82
|
+
}
|
|
85
83
|
|
|
86
|
-
|
|
87
|
-
* Year of the date
|
|
88
|
-
*/
|
|
89
|
-
public get year(): number { return this.date.getFullYear() }
|
|
90
|
-
public set year(value: number) { this.date.setFullYear(value); }
|
|
84
|
+
public date: Date;
|
|
91
85
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Year of the date
|
|
88
|
+
*/
|
|
89
|
+
public get year(): number { return this.date.getFullYear(); }
|
|
90
|
+
public set year(value: number) { this.date.setFullYear(value); }
|
|
97
91
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Month of the date
|
|
94
|
+
*/
|
|
95
|
+
public get month(): number { return this.date.getMonth() + 1; }
|
|
96
|
+
public set month(value: number) { this.date.setMonth(value); }
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const firstMonday = new Date(this.year, 1, 1);
|
|
98
|
+
/**
|
|
99
|
+
* Days in the month of the date
|
|
100
|
+
*/
|
|
101
|
+
public get daysInMonth() { return Time.daysInMonth[this.month - 1]; }
|
|
108
102
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
103
|
+
/**
|
|
104
|
+
* Week of the year the day is in
|
|
105
|
+
*/
|
|
106
|
+
public get week(): number {
|
|
107
|
+
const firstMonday = new Date(this.year, 1, 1);
|
|
115
108
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
if (firstMonday.getDay() !== 1) {
|
|
110
|
+
const daysToMon = Time.DayNames.reverse().reduce((result, day, i) =>
|
|
111
|
+
result.set(day, i + 1)
|
|
112
|
+
, new Map<LongDay, number>()).get(Time.DayNames[firstMonday.getDay() - 1])!;
|
|
113
|
+
firstMonday.setDate(firstMonday.getDate() + daysToMon);
|
|
120
114
|
}
|
|
121
|
-
public set week(value: number) { this.date.setDate(value * Time.week / Time.day); }
|
|
122
115
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
116
|
+
const timeDiff = Math.round(firstMonday.getTime() - this.time);
|
|
117
|
+
const timeSince = Time.millisecond % timeDiff;
|
|
118
|
+
const result = Math.ceil(timeSince / Time.week);
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
public set week(value: number) { this.date.setDate(value * Time.week / Time.day); }
|
|
127
122
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
public set day(value: number) { this.date.setDate(value); }
|
|
123
|
+
/**
|
|
124
|
+
* Week of the month the day is in
|
|
125
|
+
*/
|
|
126
|
+
public get weekOfMonth(): number { return Math.round(this.daysInMonth / (Time.week / Time.day)); }
|
|
133
127
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Day of the date
|
|
130
|
+
*/
|
|
131
|
+
public get day(): number { return this.date.getDate(); }
|
|
132
|
+
public set day(value: number) { this.date.setDate(value); }
|
|
137
133
|
|
|
138
|
-
|
|
139
|
-
|
|
134
|
+
public get dayOfWeek(): number { return this.date.getDay(); }
|
|
135
|
+
public set dayOfWeek(value: number) {
|
|
136
|
+
const current = this.dayOfWeek;
|
|
140
137
|
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
if (value > current) var diff = value - current;
|
|
139
|
+
else diff = current - value;
|
|
143
140
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
*/
|
|
147
|
-
public get hours(): number { return this.date.getHours(); }
|
|
148
|
-
public set hours(value: number) { this.date.setHours(value); }
|
|
141
|
+
this.day -= diff;
|
|
142
|
+
}
|
|
149
143
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Hours of the date
|
|
146
|
+
*/
|
|
147
|
+
public get hours(): number { return this.date.getHours(); }
|
|
148
|
+
public set hours(value: number) { this.date.setHours(value); }
|
|
153
149
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
public get isAM(): boolean {
|
|
151
|
+
return this.hours < 12;
|
|
152
|
+
}
|
|
153
|
+
public get isPM(): boolean {
|
|
154
|
+
return this.hours >= 12;
|
|
155
|
+
}
|
|
159
156
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Minutes of the date
|
|
159
|
+
*/
|
|
160
|
+
public get minutes(): number { return this.date.getMinutes(); }
|
|
161
|
+
public set minutes(value: number) { this.date.setMinutes(value); }
|
|
165
162
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Seconds of the date
|
|
165
|
+
*/
|
|
166
|
+
public get seconds(): number { return this.date.getSeconds(); }
|
|
167
|
+
public set seconds(value: number) { this.date.setSeconds(value); }
|
|
171
168
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Milliseconds of the date
|
|
171
|
+
*/
|
|
172
|
+
public get milliseconds(): number { return this.date.getMilliseconds(); }
|
|
173
|
+
public set milliseconds(value: number) { this.date.setMilliseconds(value); }
|
|
177
174
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
* Short week day i.e. Mon
|
|
184
|
-
*/
|
|
185
|
-
public get weekDayShort(): ShortDay { return this.weekDay.substring(0, 3) as ShortDay; }
|
|
186
|
-
/**
|
|
187
|
-
* Month name i.e. February
|
|
188
|
-
*/
|
|
189
|
-
public get monthName(): LongMonth { return Time.MonthNames[this.month - 1] || Time.MonthNames.at(-1); }
|
|
190
|
-
/**
|
|
191
|
-
* Short month name i.e. Feb
|
|
192
|
-
*/
|
|
193
|
-
public get monthNameShort(): ShortMonth { return this.monthName.substring(0, 3) as ShortMonth; }
|
|
175
|
+
/**
|
|
176
|
+
* Millisecond value of internal time
|
|
177
|
+
*/
|
|
178
|
+
public get time(): number { return this.date.getTime(); }
|
|
179
|
+
public set time(value: number) { this.date.setTime(value); }
|
|
194
180
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Week day i.e. Monday
|
|
183
|
+
*/
|
|
184
|
+
public get weekDay(): LongDay { return Time.DayNames[this.dayOfWeek - 1] || Time.DayNames.at(-1); }
|
|
185
|
+
/**
|
|
186
|
+
* Short week day i.e. Mon
|
|
187
|
+
*/
|
|
188
|
+
public get weekDayShort(): ShortDay { return this.weekDay.substring(0, 3) as ShortDay; }
|
|
189
|
+
/**
|
|
190
|
+
* Month name i.e. February
|
|
191
|
+
*/
|
|
192
|
+
public get monthName(): LongMonth { return Time.MonthNames[this.month - 1] || Time.MonthNames.at(-1); }
|
|
193
|
+
/**
|
|
194
|
+
* Short month name i.e. Feb
|
|
195
|
+
*/
|
|
196
|
+
public get monthNameShort(): ShortMonth { return this.monthName.substring(0, 3) as ShortMonth; }
|
|
207
197
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Sets internal date property
|
|
200
|
+
* @param data Time properties to set - replacement of i.e. Date.setHours(value: number): number
|
|
201
|
+
* @returns This, with updated properties
|
|
202
|
+
*/
|
|
203
|
+
public set(data: Partial<Data>) {
|
|
204
|
+
const { years, months, days, hours, minutes, seconds, milliseconds } = data;
|
|
205
|
+
const ymd = this.date.setFullYear(years || this.year, months, days);
|
|
206
|
+
const hmsms = new Date(ymd).setHours(hours || this.hours, minutes, seconds, milliseconds);
|
|
207
|
+
this.date = new Date(hmsms);
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
220
210
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Calculates the time between this and provided date
|
|
213
|
+
* @param date Date information
|
|
214
|
+
* @returns TimeSpan between this and provided date
|
|
215
|
+
*/
|
|
216
|
+
public between(date?: DanhoDate | DanhoDateConstructor): TimeSpan {
|
|
217
|
+
if (!date) return new TimeSpan(this.date, new Date());
|
|
218
|
+
else if (date instanceof DanhoDate) return new TimeSpan(this.date, date.date);
|
|
219
|
+
else if (date instanceof Date) return new TimeSpan(this.date, date);
|
|
220
|
+
else if (typeof date === 'object') return new DanhoDate(date).between(this.date);
|
|
221
|
+
return new TimeSpan(this.date, new Date(date));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* String representation of this
|
|
226
|
+
* @param format String format of date
|
|
227
|
+
* @returns String representation of this
|
|
228
|
+
*
|
|
229
|
+
* @$year Replaced with year of the date i.e. 2022
|
|
230
|
+
*
|
|
231
|
+
* @$month Replaced with month name i.e. March
|
|
232
|
+
* @$daysInMonth Replaced with the amount of days in the month i.e. 31
|
|
233
|
+
* @$MM replaced with double digit month i.e. 01
|
|
234
|
+
* @$M replaced with single digit month i.e. 1
|
|
235
|
+
*
|
|
236
|
+
* @$week Replaced with week of the year i.e. 32
|
|
237
|
+
* @$weekOfMonth Replaced with the week of the month i.e. 3
|
|
238
|
+
*
|
|
239
|
+
* @$weekday Replaced with day of the week i.e. Wednesday
|
|
240
|
+
* @$dd Replaced with double digit day i.e. 02
|
|
241
|
+
* @$d Replaced with single digit day i.e. 2
|
|
242
|
+
* @$ddth Replaced with double digit day + "th" i.e. 05th
|
|
243
|
+
* @$dth Replaced with double digit day + "th" i.e. 5th
|
|
244
|
+
*
|
|
245
|
+
* @$hh12 Replaced with double digit hour in 12-hour format i.e. 09
|
|
246
|
+
* @$hh24 Replaced with double digit hour in 24-hour format i.e. 21
|
|
247
|
+
* @$h12 Replaced with single digit hour in 12-hour format i.e. 9
|
|
248
|
+
* @$h24 Replaced with single digit hour in 24-hour format i.e. 9
|
|
249
|
+
*
|
|
250
|
+
* @$mm Replaced with double digit minute i.e. 05
|
|
251
|
+
* @$m Replaced with single digit minute i.e. 5
|
|
252
|
+
*
|
|
253
|
+
* @$ss Replaced with double digit second i.e. 03
|
|
254
|
+
* @$s Replaced with single digit second i.e. 3
|
|
255
|
+
*
|
|
256
|
+
* @msms Replaced with double digit millisecond i.e. 02
|
|
257
|
+
* @ms Replaced with single digit millisecond i.e. 2
|
|
258
|
+
*
|
|
259
|
+
* @$relative Replaced with relative timeformat as TimeSpan
|
|
260
|
+
*/
|
|
261
|
+
public toString(format = "$dd/$MM/$year", relativeFormat?: TimeSpanFormat) {
|
|
262
|
+
return this._format(format.replaceAll('$relative', this.between(new Date()).toString(relativeFormat)));
|
|
263
|
+
}
|
|
261
264
|
|
|
262
265
|
}
|
|
263
|
-
export { DanhoDate as Date }
|
|
266
|
+
export { DanhoDate as Date };
|
|
264
267
|
export default DanhoDate;
|