namirasoft-core 1.5.2 → 1.5.3
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/SKILL.md +223 -223
- package/dist/TimeOperation.d.ts +1 -0
- package/dist/TimeOperation.js +4 -0
- package/dist/TimeOperation.js.map +1 -1
- package/package.json +26 -26
- package/src/BaseDatabaseRow.ts +6 -6
- package/src/BaseLogger.ts +24 -24
- package/src/BaseMetaColumn.ts +17 -17
- package/src/BaseMetaDatabase.ts +30 -30
- package/src/BaseMetaTable.ts +40 -40
- package/src/BaseServer.ts +150 -150
- package/src/BaseUUID.ts +76 -76
- package/src/ByteOperation.ts +57 -57
- package/src/CacheService.ts +76 -76
- package/src/ColorOperation.ts +153 -153
- package/src/ConsoleOperation.ts +68 -68
- package/src/ConvertService.ts +123 -123
- package/src/CookieService.ts +33 -33
- package/src/Countries.ts +486 -486
- package/src/Country.ts +21 -21
- package/src/CountryOperation.ts +98 -98
- package/src/CronOperation.ts +121 -121
- package/src/EncodingOperation.ts +46 -46
- package/src/EnvService.ts +28 -28
- package/src/ErrorOperation.ts +13 -13
- package/src/FileOperation.ts +60 -60
- package/src/FilterItem.ts +117 -117
- package/src/FilterItemColumnType.ts +9 -9
- package/src/FilterItemOperator.ts +52 -52
- package/src/GeoOperation.ts +18 -18
- package/src/HTTPError.ts +8 -8
- package/src/HTTPMethod.ts +7 -7
- package/src/HashOperation.ts +24 -24
- package/src/ILogger.ts +17 -17
- package/src/IStorage.ts +5 -5
- package/src/IStorageCookie.ts +52 -52
- package/src/IStorageJsonFile.ts +45 -45
- package/src/IStorageLocal.ts +16 -16
- package/src/IStorageMemoryDedicated.ts +17 -17
- package/src/IStorageMemoryShared.ts +21 -21
- package/src/IStorageSession.ts +16 -16
- package/src/LogLevel.ts +11 -11
- package/src/NamingConvention.ts +199 -199
- package/src/ObjectService.ts +27 -27
- package/src/PackageService.ts +76 -76
- package/src/PasswordOperation.ts +12 -12
- package/src/PhoneOperation.ts +8 -8
- package/src/PriceOperation.ts +20 -20
- package/src/SearchOperation.ts +31 -31
- package/src/SetTimeouService.ts +32 -32
- package/src/SortItem.ts +88 -88
- package/src/StringOperation.ts +22 -22
- package/src/TimeOperation.ts +303 -299
- package/src/TimeUnitOperation.ts +82 -82
- package/src/URLOperation.ts +66 -66
- package/src/VersionOperation.ts +46 -46
- package/src/index.ts +52 -52
package/src/TimeOperation.ts
CHANGED
|
@@ -1,300 +1,304 @@
|
|
|
1
|
-
import moment from "moment";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
export class TimeOperation
|
|
7
|
-
{
|
|
8
|
-
static
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
static
|
|
19
|
-
{
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
static
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
date
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
date
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
date
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
date
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
static
|
|
180
|
-
{
|
|
181
|
-
return this.
|
|
182
|
-
}
|
|
183
|
-
static
|
|
184
|
-
{
|
|
185
|
-
return this.
|
|
186
|
-
}
|
|
187
|
-
static
|
|
188
|
-
{
|
|
189
|
-
return this.
|
|
190
|
-
}
|
|
191
|
-
static
|
|
192
|
-
{
|
|
193
|
-
return this.
|
|
194
|
-
}
|
|
195
|
-
static
|
|
196
|
-
{
|
|
197
|
-
return this.
|
|
198
|
-
}
|
|
199
|
-
static
|
|
200
|
-
{
|
|
201
|
-
return this.
|
|
202
|
-
}
|
|
203
|
-
static
|
|
204
|
-
{
|
|
205
|
-
return this.
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return
|
|
219
|
-
}
|
|
220
|
-
static
|
|
221
|
-
{
|
|
222
|
-
return this.later(
|
|
223
|
-
}
|
|
224
|
-
static
|
|
225
|
-
{
|
|
226
|
-
return this.later(
|
|
227
|
-
}
|
|
228
|
-
static
|
|
229
|
-
{
|
|
230
|
-
return this.later(
|
|
231
|
-
}
|
|
232
|
-
static
|
|
233
|
-
{
|
|
234
|
-
return this.later(
|
|
235
|
-
}
|
|
236
|
-
static
|
|
237
|
-
{
|
|
238
|
-
return this.later(
|
|
239
|
-
}
|
|
240
|
-
static
|
|
241
|
-
{
|
|
242
|
-
return this.later(
|
|
243
|
-
}
|
|
244
|
-
static
|
|
245
|
-
{
|
|
246
|
-
return this.later(
|
|
247
|
-
}
|
|
248
|
-
static
|
|
249
|
-
{
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
s
|
|
257
|
-
let
|
|
258
|
-
s
|
|
259
|
-
let
|
|
260
|
-
s.add(
|
|
261
|
-
let
|
|
262
|
-
s.add(
|
|
263
|
-
let
|
|
264
|
-
s.add(
|
|
265
|
-
let
|
|
266
|
-
s.add(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
total
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
return
|
|
291
|
-
}
|
|
292
|
-
static
|
|
293
|
-
{
|
|
294
|
-
return moment(value).isValid();
|
|
295
|
-
}
|
|
296
|
-
static
|
|
297
|
-
{
|
|
298
|
-
return moment(value).isValid();
|
|
299
|
-
}
|
|
1
|
+
import moment from "moment";
|
|
2
|
+
|
|
3
|
+
export type YMD = { year: number, month: number, day: number };
|
|
4
|
+
export type DateInterval = { start_date: Date, end_date: Date };
|
|
5
|
+
|
|
6
|
+
export class TimeOperation
|
|
7
|
+
{
|
|
8
|
+
static MONTH_NAMES = [
|
|
9
|
+
"January", "February", "March", "April", "May", "June",
|
|
10
|
+
"July", "August", "September", "October", "November", "December"
|
|
11
|
+
];
|
|
12
|
+
static toDBFormat(date: Date): string
|
|
13
|
+
{
|
|
14
|
+
return date.toISOString().
|
|
15
|
+
replace(/T/, ' ').
|
|
16
|
+
replace(/\..+/, '');
|
|
17
|
+
}
|
|
18
|
+
static format(date: Date, format: string): string
|
|
19
|
+
{
|
|
20
|
+
return moment(date).format(format);
|
|
21
|
+
}
|
|
22
|
+
static toDate(year: number, month: number, day: number): Date
|
|
23
|
+
{
|
|
24
|
+
return new Date(`${year}/${month}/${day}`);
|
|
25
|
+
}
|
|
26
|
+
static toDateByWeek(year: number, week: number, firstDay: number): Date
|
|
27
|
+
{
|
|
28
|
+
if (!firstDay)
|
|
29
|
+
firstDay = 0;
|
|
30
|
+
let offset = new Date(year, 0, 1).getDay();
|
|
31
|
+
return new Date(year, 0, 1 + firstDay - offset + (week - 1) * 7, 0, 0, 0, 0);
|
|
32
|
+
}
|
|
33
|
+
static fromDate(date: Date): YMD
|
|
34
|
+
{
|
|
35
|
+
let year = this.yearNumber(date);
|
|
36
|
+
let month = this.monthNumber(date);
|
|
37
|
+
let day = this.dayNumber(date);
|
|
38
|
+
return { year, month, day };
|
|
39
|
+
}
|
|
40
|
+
static getLARange(date: Date): DateInterval
|
|
41
|
+
{
|
|
42
|
+
let start_date = this.hoursLater(8, date);
|
|
43
|
+
let end_date = this.daysLater(1, start_date);
|
|
44
|
+
return {
|
|
45
|
+
start_date,
|
|
46
|
+
end_date
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
static diffInSecond(t1: Date, t2: Date, abs: boolean): number
|
|
50
|
+
{
|
|
51
|
+
let ans = (t1.getTime() - t2.getTime()) / 1000;
|
|
52
|
+
if (abs)
|
|
53
|
+
ans = Math.abs(ans);
|
|
54
|
+
return ans;
|
|
55
|
+
}
|
|
56
|
+
static diffInMinute(t1: Date, t2: Date, abs: boolean): number
|
|
57
|
+
{
|
|
58
|
+
return this.diffInSecond(t1, t2, abs) / 60;
|
|
59
|
+
}
|
|
60
|
+
//year
|
|
61
|
+
static yearNumber(date: Date | null = null): number
|
|
62
|
+
{
|
|
63
|
+
if (!date)
|
|
64
|
+
date = new Date();
|
|
65
|
+
return date.getUTCFullYear();
|
|
66
|
+
}
|
|
67
|
+
static beginningOfYear(date: Date | null = null): Date
|
|
68
|
+
{
|
|
69
|
+
date = this.beginningOfMonth(date);
|
|
70
|
+
date.setUTCMonth(0);
|
|
71
|
+
return date;
|
|
72
|
+
}
|
|
73
|
+
//month
|
|
74
|
+
static monthNumber(date: Date | null = null): number
|
|
75
|
+
{
|
|
76
|
+
if (!date)
|
|
77
|
+
date = new Date();
|
|
78
|
+
return date.getUTCMonth() + 1;
|
|
79
|
+
}
|
|
80
|
+
static beginningOfMonth(date: Date | null = null): Date
|
|
81
|
+
{
|
|
82
|
+
date = this.beginningOfDay(date);
|
|
83
|
+
date.setUTCDate(1);
|
|
84
|
+
return date;
|
|
85
|
+
}
|
|
86
|
+
static endOfMonth(date: Date | null = null): Date
|
|
87
|
+
{
|
|
88
|
+
date = this.beginningOfMonth(date);
|
|
89
|
+
date = this.monthsLater(1, date);
|
|
90
|
+
date = this.secondsAgo(1, date);
|
|
91
|
+
return date;
|
|
92
|
+
}
|
|
93
|
+
//week
|
|
94
|
+
static weekNumber(date: Date | null = null): number
|
|
95
|
+
{
|
|
96
|
+
if (!date)
|
|
97
|
+
date = new Date();
|
|
98
|
+
let first = this.beginningOfYear(date);
|
|
99
|
+
let secs = this.diffInSecond(date, first, true);
|
|
100
|
+
return (secs / 60 / 60 / 24 / 7) + 1;
|
|
101
|
+
}
|
|
102
|
+
static beginningOfWeek(date: Date | null = null): Date
|
|
103
|
+
{
|
|
104
|
+
date = this.beginningOfDay(date);
|
|
105
|
+
let day = (date.getDay() - 1) % 7;
|
|
106
|
+
return this.daysAgo(day, date);
|
|
107
|
+
}
|
|
108
|
+
static endOfWeek(date: Date | null = null): Date
|
|
109
|
+
{
|
|
110
|
+
date = this.beginningOfWeek(date);
|
|
111
|
+
return this.secondsAgo(1, this.daysLater(7, date));
|
|
112
|
+
}
|
|
113
|
+
// day
|
|
114
|
+
static dayNumber(date: Date | null = null): number
|
|
115
|
+
{
|
|
116
|
+
if (!date)
|
|
117
|
+
date = new Date();
|
|
118
|
+
return date.getUTCDate();
|
|
119
|
+
}
|
|
120
|
+
static beginningOfDay(date: Date | null = null): Date
|
|
121
|
+
{
|
|
122
|
+
date = this.beginningOfHour(date);
|
|
123
|
+
date.setUTCHours(0);
|
|
124
|
+
return date;
|
|
125
|
+
}
|
|
126
|
+
static endOfDay(date: Date | null = null): Date
|
|
127
|
+
{
|
|
128
|
+
date = this.beginningOfDay(date);
|
|
129
|
+
return this.daysLater(1, date);
|
|
130
|
+
}
|
|
131
|
+
static dayNumberInYear(date: Date | null = null): number
|
|
132
|
+
{
|
|
133
|
+
if (!date)
|
|
134
|
+
date = new Date();
|
|
135
|
+
var start = new Date(date.getFullYear(), 0, 0);
|
|
136
|
+
var diff = date.getTime() - start.getTime();
|
|
137
|
+
var oneDay = 1000 * 60 * 60 * 24;
|
|
138
|
+
return Math.floor(diff / oneDay);
|
|
139
|
+
}
|
|
140
|
+
static addedDaysInMonth(days: number, date: Date): Date
|
|
141
|
+
{
|
|
142
|
+
date = this.beginningOfMonth(date);
|
|
143
|
+
return this.daysLater(days, date);
|
|
144
|
+
}
|
|
145
|
+
//hour
|
|
146
|
+
static hourNumberInWeek(date: Date | null = null): number
|
|
147
|
+
{
|
|
148
|
+
if (!date)
|
|
149
|
+
date = new Date();
|
|
150
|
+
let first = this.beginningOfWeek(date);
|
|
151
|
+
let secs = this.diffInSecond(date, first, true);
|
|
152
|
+
return (secs / 3600);
|
|
153
|
+
}
|
|
154
|
+
static hourNumberInMonth(date: Date | null = null): number
|
|
155
|
+
{
|
|
156
|
+
if (!date)
|
|
157
|
+
date = new Date();
|
|
158
|
+
let first = this.beginningOfMonth(date);
|
|
159
|
+
let secs = this.diffInSecond(date, first, true);
|
|
160
|
+
return (secs / 3600);
|
|
161
|
+
}
|
|
162
|
+
static addedHoursInWeek(hours: number, date: Date): Date
|
|
163
|
+
{
|
|
164
|
+
date = this.beginningOfWeek(date);
|
|
165
|
+
return this.hoursLater(hours, date);
|
|
166
|
+
}
|
|
167
|
+
static beginningOfHour(date: Date | null = null): Date
|
|
168
|
+
{
|
|
169
|
+
if (!date)
|
|
170
|
+
date = new Date();
|
|
171
|
+
else
|
|
172
|
+
date = new Date(date);
|
|
173
|
+
date.setUTCMilliseconds(0);
|
|
174
|
+
date.setUTCSeconds(0);
|
|
175
|
+
date.setUTCMinutes(0);
|
|
176
|
+
return date;
|
|
177
|
+
}
|
|
178
|
+
// ago
|
|
179
|
+
static yearsAgo(years: number, date: Date): Date
|
|
180
|
+
{
|
|
181
|
+
return this.yearsLater(years * -1, date);
|
|
182
|
+
}
|
|
183
|
+
static monthsAgo(months: number, date: Date): Date
|
|
184
|
+
{
|
|
185
|
+
return this.monthsLater(months * -1, date);
|
|
186
|
+
}
|
|
187
|
+
static weeksAgo(weeks: number, date: Date): Date
|
|
188
|
+
{
|
|
189
|
+
return this.weeksLater(weeks * -1, date);
|
|
190
|
+
}
|
|
191
|
+
static daysAgo(days: number, date: Date): Date
|
|
192
|
+
{
|
|
193
|
+
return this.daysLater(days * -1, date);
|
|
194
|
+
}
|
|
195
|
+
static hoursAgo(hours: number, date: Date): Date
|
|
196
|
+
{
|
|
197
|
+
return this.hoursLater(hours * -1, date);
|
|
198
|
+
}
|
|
199
|
+
static minutesAgo(minutes: number, date: Date): Date
|
|
200
|
+
{
|
|
201
|
+
return this.minutesLater(minutes * -1, date);
|
|
202
|
+
}
|
|
203
|
+
static secondsAgo(seconds: number, date: Date): Date
|
|
204
|
+
{
|
|
205
|
+
return this.secondsLater(seconds * -1, date);
|
|
206
|
+
}
|
|
207
|
+
static millisecondsAgo(milliseconds: number, date: Date): Date
|
|
208
|
+
{
|
|
209
|
+
return this.millisecondsLater(milliseconds * -1, date);
|
|
210
|
+
}
|
|
211
|
+
// later
|
|
212
|
+
static later(num: number, type: moment.DurationInputArg2, date: Date | null = null): Date
|
|
213
|
+
{
|
|
214
|
+
if (!date)
|
|
215
|
+
date = new Date();
|
|
216
|
+
else
|
|
217
|
+
date = new Date(date);
|
|
218
|
+
return moment(date).add(num, type).toDate();
|
|
219
|
+
}
|
|
220
|
+
static yearsLater(years: number, date: Date): Date
|
|
221
|
+
{
|
|
222
|
+
return this.later(years, 'years', date);
|
|
223
|
+
}
|
|
224
|
+
static monthsLater(months: number, date: Date): Date
|
|
225
|
+
{
|
|
226
|
+
return this.later(months, 'months', date);
|
|
227
|
+
}
|
|
228
|
+
static weeksLater(weeks: number, date: Date): Date
|
|
229
|
+
{
|
|
230
|
+
return this.later(weeks, 'weeks', date);
|
|
231
|
+
}
|
|
232
|
+
static daysLater(days: number, date: Date): Date
|
|
233
|
+
{
|
|
234
|
+
return this.later(days, 'days', date);
|
|
235
|
+
}
|
|
236
|
+
static hoursLater(hours: number, date: Date): Date
|
|
237
|
+
{
|
|
238
|
+
return this.later(hours, 'hours', date);
|
|
239
|
+
}
|
|
240
|
+
static minutesLater(minutes: number, date: Date): Date
|
|
241
|
+
{
|
|
242
|
+
return this.later(minutes, 'minutes', date);
|
|
243
|
+
}
|
|
244
|
+
static secondsLater(seconds: number, date: Date): Date
|
|
245
|
+
{
|
|
246
|
+
return this.later(seconds, 'seconds', date);
|
|
247
|
+
}
|
|
248
|
+
static millisecondsLater(milliseconds: number, date: Date): Date
|
|
249
|
+
{
|
|
250
|
+
return this.later(milliseconds, 'milliseconds', date);
|
|
251
|
+
}
|
|
252
|
+
static getDuration(startDate: Date, endDate: Date, zeroAllOnPassed: boolean = false)
|
|
253
|
+
{
|
|
254
|
+
if (!endDate)
|
|
255
|
+
endDate = new Date();
|
|
256
|
+
let s = moment(startDate);
|
|
257
|
+
let e = moment(endDate);
|
|
258
|
+
let passed = e < s;
|
|
259
|
+
let year = e.diff(s, 'years', false);
|
|
260
|
+
s.add(year, 'years');
|
|
261
|
+
let month = e.diff(s, 'months', false);
|
|
262
|
+
s.add(month, 'months');
|
|
263
|
+
let day = e.diff(s, 'days', false);
|
|
264
|
+
s.add(day, 'days');
|
|
265
|
+
let hour = e.diff(s, 'hours', false);
|
|
266
|
+
s.add(hour, 'hours');
|
|
267
|
+
let minute = e.diff(s, 'minutes', false);
|
|
268
|
+
s.add(minute, 'minutes');
|
|
269
|
+
let second = e.diff(s, 'seconds', false);
|
|
270
|
+
s.add(second, 'seconds');
|
|
271
|
+
|
|
272
|
+
if (passed)
|
|
273
|
+
if (zeroAllOnPassed)
|
|
274
|
+
year = month = day = hour = minute = second = 0;
|
|
275
|
+
let total = year * 12 + month;
|
|
276
|
+
total = total * 30 + day;
|
|
277
|
+
total = total * 24 + hour;
|
|
278
|
+
total = total * 60 + minute;
|
|
279
|
+
total += second;
|
|
280
|
+
|
|
281
|
+
return {
|
|
282
|
+
passed, year, month, day, hour, minute, second, total
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
static calculateAge(date: Date): number
|
|
286
|
+
{
|
|
287
|
+
let birthday = new Date(date);
|
|
288
|
+
let ageDifMs = Date.now() - birthday.getTime();
|
|
289
|
+
var ageDate = new Date(ageDifMs); // miliseconds from epoch
|
|
290
|
+
return Math.abs(ageDate.getUTCFullYear() - 1970);
|
|
291
|
+
}
|
|
292
|
+
static isValidDate(value: string): boolean
|
|
293
|
+
{
|
|
294
|
+
return moment(value).isValid();
|
|
295
|
+
}
|
|
296
|
+
static isValidDateTime(value: string): boolean
|
|
297
|
+
{
|
|
298
|
+
return moment(value).isValid();
|
|
299
|
+
}
|
|
300
|
+
static isValidTime(value: string): boolean
|
|
301
|
+
{
|
|
302
|
+
return moment(value).isValid();
|
|
303
|
+
}
|
|
300
304
|
}
|