lupine.components 1.1.13 → 1.1.14

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.
Files changed (92) hide show
  1. package/README.md +3 -3
  2. package/package.json +42 -42
  3. package/src/components/action-sheet.tsx +419 -419
  4. package/src/components/button-push-animation.tsx +147 -138
  5. package/src/components/button.tsx +55 -55
  6. package/src/components/desktop-footer.tsx +17 -17
  7. package/src/components/desktop-header.tsx +52 -52
  8. package/src/components/drag-refresh.tsx +129 -129
  9. package/src/components/editable-label.tsx +83 -83
  10. package/src/components/float-window.tsx +233 -233
  11. package/src/components/grid.tsx +18 -18
  12. package/src/components/html-load.tsx +41 -41
  13. package/src/components/html-var.tsx +81 -81
  14. package/src/components/index.ts +43 -44
  15. package/src/components/input-with-title.tsx +24 -24
  16. package/src/components/link-item.tsx +13 -13
  17. package/src/components/link-list.tsx +62 -62
  18. package/src/components/menu-bar.tsx +219 -219
  19. package/src/components/menu-item-props.tsx +13 -13
  20. package/src/components/menu-sidebar.tsx +325 -318
  21. package/src/components/message-box.tsx +44 -44
  22. package/src/components/meta-data.tsx +36 -36
  23. package/src/components/meta-description.tsx +12 -12
  24. package/src/components/mobile-components/icon-menu-item-props.ts +6 -6
  25. package/src/components/mobile-components/index.ts +8 -9
  26. package/src/components/mobile-components/mobile-footer-menu.tsx +95 -95
  27. package/src/components/mobile-components/mobile-header-component.tsx +101 -101
  28. package/src/components/mobile-components/mobile-header-title-icon.tsx +109 -101
  29. package/src/components/mobile-components/mobile-header-with-back.tsx +127 -117
  30. package/src/components/mobile-components/mobile-side-menu.tsx +154 -154
  31. package/src/components/mobile-components/mobile-top-sys-icon.tsx +18 -18
  32. package/src/components/mobile-components/mobile-top-sys-menu.tsx +62 -62
  33. package/src/components/modal.tsx +33 -33
  34. package/src/components/notice-message.tsx +118 -118
  35. package/src/components/page-title.tsx +6 -6
  36. package/src/components/paging-link.tsx +175 -175
  37. package/src/components/panel.tsx +21 -21
  38. package/src/components/popup-menu.tsx +289 -289
  39. package/src/components/progress.tsx +91 -91
  40. package/src/components/radio-label-component.tsx +36 -36
  41. package/src/components/redirect.tsx +19 -19
  42. package/src/components/resizable-splitter.tsx +128 -128
  43. package/src/components/select-angle-component.tsx +127 -127
  44. package/src/components/select-with-title.tsx +37 -37
  45. package/src/components/slide-tab-component.tsx +144 -149
  46. package/src/components/spinner.tsx +106 -100
  47. package/src/components/stars-component.tsx +66 -66
  48. package/src/components/svg.tsx +24 -24
  49. package/src/components/tabs.tsx +279 -279
  50. package/src/components/text-glow.tsx +37 -37
  51. package/src/components/text-scale.tsx +42 -42
  52. package/src/components/text-wave.tsx +55 -55
  53. package/src/components/theme-selector.tsx +28 -28
  54. package/src/components/toggle-base.tsx +269 -269
  55. package/src/components/toggle-switch.tsx +160 -160
  56. package/src/frames/index.ts +3 -3
  57. package/src/frames/responsive-frame.tsx +83 -83
  58. package/src/frames/slider-frame.tsx +111 -111
  59. package/src/frames/top-frame.tsx +30 -30
  60. package/src/index.ts +5 -5
  61. package/src/lib/back-action-helper.ts +54 -54
  62. package/src/lib/base62.ts +23 -23
  63. package/src/lib/blob-utils.ts +23 -23
  64. package/src/lib/calculate-text-width.ts +13 -13
  65. package/src/lib/date-utils.ts +317 -317
  66. package/src/lib/deep-merge.ts +37 -37
  67. package/src/lib/document-ready.ts +34 -34
  68. package/src/lib/dom-utils.ts +32 -32
  69. package/src/lib/download-file.ts +118 -118
  70. package/src/lib/download-link.ts +12 -12
  71. package/src/lib/download-stream.ts +19 -19
  72. package/src/lib/drag-util.ts +118 -118
  73. package/src/lib/dynamical-load.ts +134 -134
  74. package/src/lib/encode-html.ts +27 -27
  75. package/src/lib/find-parent-tag.ts +8 -8
  76. package/src/lib/format-bytes.ts +11 -11
  77. package/src/lib/index.ts +24 -24
  78. package/src/lib/lite-dom.ts +225 -225
  79. package/src/lib/message-hub.ts +103 -104
  80. package/src/lib/observable.ts +188 -188
  81. package/src/lib/path-utils.ts +42 -42
  82. package/src/lib/promise-timeout.ts +1 -1
  83. package/src/lib/simple-storage.ts +40 -40
  84. package/src/lib/stop-propagation.ts +7 -7
  85. package/src/lib/upload-file.ts +101 -101
  86. package/src/styles/base-themes.ts +17 -17
  87. package/src/styles/dark-themes.ts +99 -99
  88. package/src/styles/index.ts +5 -5
  89. package/src/styles/light-themes.ts +106 -106
  90. package/src/styles/media-query.ts +93 -93
  91. package/src/styles/shared-themes.ts +57 -57
  92. package/tsconfig.json +113 -113
@@ -1,317 +1,317 @@
1
- export class DateUtils {
2
- /*
3
- * returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
4
- */
5
- static now(): number {
6
- return Date.now();
7
- }
8
-
9
- // Date time string format: YYYY-MM-DDTHH:mm:ss.sssZ
10
- // The string that you want to parse into a Date should match this format or a portion of this format.
11
- // The “T” character separates the date from the time portion of the string. The “Z” character is the UTC offset representation.
12
- static toDate(str: string): Date {
13
- return new Date(Date.parse(str));
14
- }
15
-
16
- static clone(dt: Date): Date {
17
- return new Date(dt.valueOf());
18
- }
19
-
20
- static isLeapYear(year: number): boolean {
21
- return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
22
- }
23
-
24
- static daysInMonth(year: number, month: number) {
25
- return month === 1 ? (DateUtils.isLeapYear(year) ? 29 : 28) : 31 - ((month % 7) % 2);
26
- }
27
-
28
- static createDate(
29
- year: number,
30
- monthIndex: number,
31
- date?: number,
32
- hours?: number,
33
- minutes?: number,
34
- seconds?: number,
35
- ms?: number
36
- ): Date {
37
- const dt = new Date(year, monthIndex, date, hours, minutes, seconds, ms);
38
- return dt;
39
- }
40
-
41
- // It returns the number of milliseconds since January 1, 1970, 00:00:00 UTC instead of local (regardless of which time zone you are in).
42
- static createUTCDate(
43
- year: number,
44
- monthIndex?: number,
45
- date?: number,
46
- hours?: number,
47
- minutes?: number,
48
- seconds?: number,
49
- ms?: number
50
- ): Date {
51
- const dt = new Date(Date.UTC.apply(null, [year, monthIndex, date, hours, minutes, seconds, ms]));
52
- return dt;
53
- }
54
-
55
- static set(
56
- dt: Date,
57
- year?: number,
58
- monthIndex?: number,
59
- date?: number,
60
- hours?: number,
61
- minutes?: number,
62
- seconds?: number,
63
- ms?: number
64
- ): Date {
65
- if (!dt) {
66
- dt = new Date(DateUtils.now());
67
- }
68
- if (typeof year === 'number') {
69
- dt.setFullYear(year);
70
- }
71
- if (typeof monthIndex === 'number') {
72
- dt.setMonth(monthIndex);
73
- }
74
- if (typeof date === 'number') {
75
- dt.setDate(date);
76
- }
77
- if (typeof hours === 'number') {
78
- dt.setHours(hours);
79
- }
80
- if (typeof minutes === 'number') {
81
- dt.setMinutes(minutes);
82
- }
83
- if (typeof seconds === 'number') {
84
- dt.setSeconds(seconds);
85
- }
86
- if (typeof ms === 'number') {
87
- dt.setMilliseconds(ms);
88
- }
89
- return dt;
90
- }
91
-
92
- static add(
93
- dt: Date,
94
- year?: number,
95
- monthCount?: number,
96
- date?: number,
97
- hours?: number,
98
- minutes?: number,
99
- seconds?: number,
100
- ms?: number
101
- ): Date {
102
- if (!dt) {
103
- dt = new Date(DateUtils.now());
104
- }
105
- if (typeof year === 'number') {
106
- dt.setFullYear(dt.getFullYear() + year);
107
- }
108
- if (typeof monthCount === 'number') {
109
- dt.setMonth(dt.getMonth() + monthCount);
110
- }
111
- if (typeof date === 'number') {
112
- dt.setDate(dt.getDate() + date);
113
- }
114
- if (typeof hours === 'number') {
115
- dt.setHours(dt.getHours() + hours);
116
- }
117
- if (typeof minutes === 'number') {
118
- dt.setMinutes(dt.getMinutes() + minutes);
119
- }
120
- if (typeof seconds === 'number') {
121
- dt.setSeconds(dt.getSeconds() + seconds);
122
- }
123
- if (typeof ms === 'number') {
124
- dt.setMilliseconds(dt.getMilliseconds() + ms);
125
- }
126
- return dt;
127
- }
128
-
129
- // returns a difference object from two dates
130
- static diff(endDate: Date, startDate: Date): DiffDate {
131
- const startYear = startDate.getFullYear();
132
- let yearDiff = endDate.getFullYear() - startYear;
133
- let monthDiff = endDate.getMonth() - startDate.getMonth();
134
- if (monthDiff < 0) {
135
- yearDiff--;
136
- monthDiff += 12;
137
- }
138
- let dayDiff = endDate.getDate() - startDate.getDate();
139
- if (dayDiff < 0) {
140
- if (monthDiff > 0) {
141
- monthDiff--;
142
- } else {
143
- yearDiff--;
144
- monthDiff = 11;
145
- }
146
- dayDiff += DateUtils.daysInMonth(startYear, startDate.getMonth());
147
- }
148
- const msTotal = endDate.valueOf() - startDate.valueOf(); // milliseconds
149
- const secondTotal = Math.floor(msTotal / 1000); // milliseconds -> seconds
150
- const hourDiff = Math.floor(secondTotal / (60 * 60)) % 24;
151
- const minuteDiff = Math.floor(secondTotal / 60) % 60;
152
- const secondDiff = secondTotal % 60;
153
- const msDiff = msTotal % 1000;
154
- return new DiffDate(yearDiff, monthDiff, dayDiff, hourDiff, minuteDiff, secondDiff, msDiff);
155
- }
156
-
157
- // returns a time difference string from two dates
158
- static diffString(endDate: Date, startDate: Date, printMS = false): string {
159
- const diff = DateUtils.diff(endDate, startDate);
160
- let ret = '';
161
- if (diff.years !== 0) {
162
- ret = ret + diff.years + ' years(s), ';
163
- }
164
- if (diff.years !== 0 || diff.months !== 0) {
165
- ret = ret + diff.months + ' month(s), ';
166
- }
167
- if (diff.years !== 0 || diff.months !== 0 || diff.days !== 0) {
168
- ret = ret + diff.days + ' day(s), ';
169
- }
170
- if (diff.years !== 0 || diff.months !== 0 || diff.days !== 0 || diff.hours !== 0) {
171
- ret = ret + diff.hours + ' hour(s), ';
172
- }
173
- if (diff.years !== 0 || diff.months !== 0 || diff.days !== 0 || diff.hours !== 0 || diff.minutes !== 0) {
174
- ret = ret + diff.minutes + ' minute(s), ';
175
- }
176
- if (
177
- diff.years !== 0 ||
178
- diff.months !== 0 ||
179
- diff.days !== 0 ||
180
- diff.hours !== 0 ||
181
- diff.minutes !== 0 ||
182
- diff.seconds !== 0 ||
183
- !printMS
184
- ) {
185
- ret = ret + diff.seconds + ' second(s)';
186
- if (printMS) {
187
- ret += ', ';
188
- }
189
- }
190
- if (printMS) {
191
- ret = ret + diff.milliseconds + ' ms';
192
- }
193
- return ret;
194
- }
195
-
196
- // returns a YYYYMMDD format string
197
- static toYMD(dt: Date, separator: string) {
198
- separator = typeof separator === 'undefined' ? '-' : separator;
199
- return (
200
- dt.getFullYear() +
201
- separator +
202
- ('0' + (dt.getMonth() + 1)).toString().slice(-2) +
203
- separator +
204
- ('0' + dt.getDate()).toString().slice(-2)
205
- );
206
- }
207
- static toYmdHms(dt: Date, separator: string) {
208
- separator = typeof separator === 'undefined' ? '-' : separator;
209
- return (
210
- dt.getFullYear() +
211
- separator +
212
- ('0' + (dt.getMonth() + 1)).toString().slice(-2) +
213
- separator +
214
- ('0' + dt.getDate()).toString().slice(-2) +
215
- ' ' +
216
- ('0' + dt.getHours()).toString().slice(-2) +
217
- ':' +
218
- ('0' + dt.getMinutes()).toString().slice(-2) +
219
- ':' +
220
- ('0' + dt.getSeconds()).toString().slice(-2)
221
- );
222
- }
223
-
224
- static toJSONString(dt: Date) {
225
- // return dt.getUTCFullYear() + '-' + ('0' + (dt.getUTCMonth() + 1)).toString().slice(-2) +
226
- // '-' + ('0' + dt.getUTCDate()).toString().slice(-2) + ' ' + ('0' + dt.getUTCHours()).toString().slice(-2) +
227
- // ':' + ('0' + dt.getUTCMinutes()).toString().slice(-2) + ':' + ('0' + dt.getUTCSeconds()).toString().slice(-2) + 'Z';
228
- return dt.toJSON();
229
- }
230
-
231
- static showJSONString(dt: string, separator = '-') {
232
- return DateUtils.toYmdHms(DateUtils.toDate(dt), separator);
233
- }
234
-
235
- static fromJSONString(dt: string) {
236
- return DateUtils.toDate(dt);
237
- }
238
-
239
- static clearTime(dt: Date) {
240
- dt.setHours(0);
241
- dt.setMinutes(0);
242
- dt.setSeconds(0);
243
- dt.setMilliseconds(0);
244
- return dt;
245
- }
246
-
247
- static clearUTCTime(dt: Date) {
248
- dt.setUTCHours(0);
249
- dt.setUTCMinutes(0);
250
- dt.setUTCSeconds(0);
251
- dt.setUTCMilliseconds(0);
252
- return dt;
253
- }
254
-
255
- static format(dt: Date, fmt: string) {
256
- if (!fmt) {
257
- fmt = 'YYYY-MM-DD';
258
- }
259
- if (!dt) {
260
- dt = new Date();
261
- }
262
-
263
- const parts: { [key: string]: string } = {
264
- YYYY: dt.getFullYear().toString(),
265
- YY: ('00' + (dt.getFullYear() - 100)).toString().slice(-2),
266
- MM: ('0' + (dt.getMonth() + 1)).toString().slice(-2),
267
- M: (dt.getMonth() + 1).toString(),
268
- DD: ('0' + dt.getDate()).toString().slice(-2),
269
- D: dt.getDate().toString(),
270
- hh: ('0' + dt.getHours()).toString().slice(-2),
271
- h: dt.getHours().toString(),
272
- mm: ('0' + dt.getMinutes()).toString().slice(-2),
273
- ss: ('0' + dt.getSeconds()).toString().slice(-2),
274
- SSS: ('00' + dt.getMilliseconds()).toString().slice(-3),
275
- S: Math.floor(dt.getMilliseconds() / 100)
276
- .toString()
277
- .slice(-1),
278
- };
279
-
280
- const array = fmt.match(/(\[[^\[]*\])|(\\)?(YYYY|YY|MM?|DD?|hh?|mm?|ss?|SSS|S|.)/g) as string[];
281
- for (let i = 0, length = array.length; i < length; i++) {
282
- if (parts[array[i]]) {
283
- array[i] = parts[array[i]];
284
- }
285
- }
286
- const ret = array.join('');
287
- return ret;
288
- }
289
- }
290
-
291
- export class DiffDate {
292
- years: number;
293
- months: number;
294
- days: number;
295
- hours: number;
296
- minutes: number;
297
- seconds: number;
298
- milliseconds: number;
299
-
300
- constructor(
301
- years: number,
302
- months: number,
303
- days: number,
304
- hours: number,
305
- minutes: number,
306
- seconds: number,
307
- milliseconds: number
308
- ) {
309
- this.years = years;
310
- this.months = months;
311
- this.days = days;
312
- this.hours = hours;
313
- this.minutes = minutes;
314
- this.seconds = seconds;
315
- this.milliseconds = milliseconds;
316
- }
317
- }
1
+ export class DateUtils {
2
+ /*
3
+ * returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
4
+ */
5
+ static now(): number {
6
+ return Date.now();
7
+ }
8
+
9
+ // Date time string format: YYYY-MM-DDTHH:mm:ss.sssZ
10
+ // The string that you want to parse into a Date should match this format or a portion of this format.
11
+ // The “T” character separates the date from the time portion of the string. The “Z” character is the UTC offset representation.
12
+ static toDate(str: string): Date {
13
+ return new Date(Date.parse(str));
14
+ }
15
+
16
+ static clone(dt: Date): Date {
17
+ return new Date(dt.valueOf());
18
+ }
19
+
20
+ static isLeapYear(year: number): boolean {
21
+ return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
22
+ }
23
+
24
+ static daysInMonth(year: number, month: number) {
25
+ return month === 1 ? (DateUtils.isLeapYear(year) ? 29 : 28) : 31 - ((month % 7) % 2);
26
+ }
27
+
28
+ static createDate(
29
+ year: number,
30
+ monthIndex: number,
31
+ date?: number,
32
+ hours?: number,
33
+ minutes?: number,
34
+ seconds?: number,
35
+ ms?: number
36
+ ): Date {
37
+ const dt = new Date(year, monthIndex, date, hours, minutes, seconds, ms);
38
+ return dt;
39
+ }
40
+
41
+ // It returns the number of milliseconds since January 1, 1970, 00:00:00 UTC instead of local (regardless of which time zone you are in).
42
+ static createUTCDate(
43
+ year: number,
44
+ monthIndex?: number,
45
+ date?: number,
46
+ hours?: number,
47
+ minutes?: number,
48
+ seconds?: number,
49
+ ms?: number
50
+ ): Date {
51
+ const dt = new Date(Date.UTC.apply(null, [year, monthIndex, date, hours, minutes, seconds, ms]));
52
+ return dt;
53
+ }
54
+
55
+ static set(
56
+ dt: Date,
57
+ year?: number,
58
+ monthIndex?: number,
59
+ date?: number,
60
+ hours?: number,
61
+ minutes?: number,
62
+ seconds?: number,
63
+ ms?: number
64
+ ): Date {
65
+ if (!dt) {
66
+ dt = new Date(DateUtils.now());
67
+ }
68
+ if (typeof year === 'number') {
69
+ dt.setFullYear(year);
70
+ }
71
+ if (typeof monthIndex === 'number') {
72
+ dt.setMonth(monthIndex);
73
+ }
74
+ if (typeof date === 'number') {
75
+ dt.setDate(date);
76
+ }
77
+ if (typeof hours === 'number') {
78
+ dt.setHours(hours);
79
+ }
80
+ if (typeof minutes === 'number') {
81
+ dt.setMinutes(minutes);
82
+ }
83
+ if (typeof seconds === 'number') {
84
+ dt.setSeconds(seconds);
85
+ }
86
+ if (typeof ms === 'number') {
87
+ dt.setMilliseconds(ms);
88
+ }
89
+ return dt;
90
+ }
91
+
92
+ static add(
93
+ dt: Date,
94
+ year?: number,
95
+ monthCount?: number,
96
+ date?: number,
97
+ hours?: number,
98
+ minutes?: number,
99
+ seconds?: number,
100
+ ms?: number
101
+ ): Date {
102
+ if (!dt) {
103
+ dt = new Date(DateUtils.now());
104
+ }
105
+ if (typeof year === 'number') {
106
+ dt.setFullYear(dt.getFullYear() + year);
107
+ }
108
+ if (typeof monthCount === 'number') {
109
+ dt.setMonth(dt.getMonth() + monthCount);
110
+ }
111
+ if (typeof date === 'number') {
112
+ dt.setDate(dt.getDate() + date);
113
+ }
114
+ if (typeof hours === 'number') {
115
+ dt.setHours(dt.getHours() + hours);
116
+ }
117
+ if (typeof minutes === 'number') {
118
+ dt.setMinutes(dt.getMinutes() + minutes);
119
+ }
120
+ if (typeof seconds === 'number') {
121
+ dt.setSeconds(dt.getSeconds() + seconds);
122
+ }
123
+ if (typeof ms === 'number') {
124
+ dt.setMilliseconds(dt.getMilliseconds() + ms);
125
+ }
126
+ return dt;
127
+ }
128
+
129
+ // returns a difference object from two dates
130
+ static diff(endDate: Date, startDate: Date): DiffDate {
131
+ const startYear = startDate.getFullYear();
132
+ let yearDiff = endDate.getFullYear() - startYear;
133
+ let monthDiff = endDate.getMonth() - startDate.getMonth();
134
+ if (monthDiff < 0) {
135
+ yearDiff--;
136
+ monthDiff += 12;
137
+ }
138
+ let dayDiff = endDate.getDate() - startDate.getDate();
139
+ if (dayDiff < 0) {
140
+ if (monthDiff > 0) {
141
+ monthDiff--;
142
+ } else {
143
+ yearDiff--;
144
+ monthDiff = 11;
145
+ }
146
+ dayDiff += DateUtils.daysInMonth(startYear, startDate.getMonth());
147
+ }
148
+ const msTotal = endDate.valueOf() - startDate.valueOf(); // milliseconds
149
+ const secondTotal = Math.floor(msTotal / 1000); // milliseconds -> seconds
150
+ const hourDiff = Math.floor(secondTotal / (60 * 60)) % 24;
151
+ const minuteDiff = Math.floor(secondTotal / 60) % 60;
152
+ const secondDiff = secondTotal % 60;
153
+ const msDiff = msTotal % 1000;
154
+ return new DiffDate(yearDiff, monthDiff, dayDiff, hourDiff, minuteDiff, secondDiff, msDiff);
155
+ }
156
+
157
+ // returns a time difference string from two dates
158
+ static diffString(endDate: Date, startDate: Date, printMS = false): string {
159
+ const diff = DateUtils.diff(endDate, startDate);
160
+ let ret = '';
161
+ if (diff.years !== 0) {
162
+ ret = ret + diff.years + ' years(s), ';
163
+ }
164
+ if (diff.years !== 0 || diff.months !== 0) {
165
+ ret = ret + diff.months + ' month(s), ';
166
+ }
167
+ if (diff.years !== 0 || diff.months !== 0 || diff.days !== 0) {
168
+ ret = ret + diff.days + ' day(s), ';
169
+ }
170
+ if (diff.years !== 0 || diff.months !== 0 || diff.days !== 0 || diff.hours !== 0) {
171
+ ret = ret + diff.hours + ' hour(s), ';
172
+ }
173
+ if (diff.years !== 0 || diff.months !== 0 || diff.days !== 0 || diff.hours !== 0 || diff.minutes !== 0) {
174
+ ret = ret + diff.minutes + ' minute(s), ';
175
+ }
176
+ if (
177
+ diff.years !== 0 ||
178
+ diff.months !== 0 ||
179
+ diff.days !== 0 ||
180
+ diff.hours !== 0 ||
181
+ diff.minutes !== 0 ||
182
+ diff.seconds !== 0 ||
183
+ !printMS
184
+ ) {
185
+ ret = ret + diff.seconds + ' second(s)';
186
+ if (printMS) {
187
+ ret += ', ';
188
+ }
189
+ }
190
+ if (printMS) {
191
+ ret = ret + diff.milliseconds + ' ms';
192
+ }
193
+ return ret;
194
+ }
195
+
196
+ // returns a YYYYMMDD format string
197
+ static toYMD(dt: Date, separator: string) {
198
+ separator = typeof separator === 'undefined' ? '-' : separator;
199
+ return (
200
+ dt.getFullYear() +
201
+ separator +
202
+ ('0' + (dt.getMonth() + 1)).toString().slice(-2) +
203
+ separator +
204
+ ('0' + dt.getDate()).toString().slice(-2)
205
+ );
206
+ }
207
+ static toYmdHms(dt: Date, separator: string) {
208
+ separator = typeof separator === 'undefined' ? '-' : separator;
209
+ return (
210
+ dt.getFullYear() +
211
+ separator +
212
+ ('0' + (dt.getMonth() + 1)).toString().slice(-2) +
213
+ separator +
214
+ ('0' + dt.getDate()).toString().slice(-2) +
215
+ ' ' +
216
+ ('0' + dt.getHours()).toString().slice(-2) +
217
+ ':' +
218
+ ('0' + dt.getMinutes()).toString().slice(-2) +
219
+ ':' +
220
+ ('0' + dt.getSeconds()).toString().slice(-2)
221
+ );
222
+ }
223
+
224
+ static toJSONString(dt: Date) {
225
+ // return dt.getUTCFullYear() + '-' + ('0' + (dt.getUTCMonth() + 1)).toString().slice(-2) +
226
+ // '-' + ('0' + dt.getUTCDate()).toString().slice(-2) + ' ' + ('0' + dt.getUTCHours()).toString().slice(-2) +
227
+ // ':' + ('0' + dt.getUTCMinutes()).toString().slice(-2) + ':' + ('0' + dt.getUTCSeconds()).toString().slice(-2) + 'Z';
228
+ return dt.toJSON();
229
+ }
230
+
231
+ static showJSONString(dt: string, separator = '-') {
232
+ return DateUtils.toYmdHms(DateUtils.toDate(dt), separator);
233
+ }
234
+
235
+ static fromJSONString(dt: string) {
236
+ return DateUtils.toDate(dt);
237
+ }
238
+
239
+ static clearTime(dt: Date) {
240
+ dt.setHours(0);
241
+ dt.setMinutes(0);
242
+ dt.setSeconds(0);
243
+ dt.setMilliseconds(0);
244
+ return dt;
245
+ }
246
+
247
+ static clearUTCTime(dt: Date) {
248
+ dt.setUTCHours(0);
249
+ dt.setUTCMinutes(0);
250
+ dt.setUTCSeconds(0);
251
+ dt.setUTCMilliseconds(0);
252
+ return dt;
253
+ }
254
+
255
+ static format(dt: Date, fmt: string) {
256
+ if (!fmt) {
257
+ fmt = 'YYYY-MM-DD';
258
+ }
259
+ if (!dt) {
260
+ dt = new Date();
261
+ }
262
+
263
+ const parts: { [key: string]: string } = {
264
+ YYYY: dt.getFullYear().toString(),
265
+ YY: ('00' + (dt.getFullYear() - 100)).toString().slice(-2),
266
+ MM: ('0' + (dt.getMonth() + 1)).toString().slice(-2),
267
+ M: (dt.getMonth() + 1).toString(),
268
+ DD: ('0' + dt.getDate()).toString().slice(-2),
269
+ D: dt.getDate().toString(),
270
+ hh: ('0' + dt.getHours()).toString().slice(-2),
271
+ h: dt.getHours().toString(),
272
+ mm: ('0' + dt.getMinutes()).toString().slice(-2),
273
+ ss: ('0' + dt.getSeconds()).toString().slice(-2),
274
+ SSS: ('00' + dt.getMilliseconds()).toString().slice(-3),
275
+ S: Math.floor(dt.getMilliseconds() / 100)
276
+ .toString()
277
+ .slice(-1),
278
+ };
279
+
280
+ const array = fmt.match(/(\[[^\[]*\])|(\\)?(YYYY|YY|MM?|DD?|hh?|mm?|ss?|SSS|S|.)/g) as string[];
281
+ for (let i = 0, length = array.length; i < length; i++) {
282
+ if (parts[array[i]]) {
283
+ array[i] = parts[array[i]];
284
+ }
285
+ }
286
+ const ret = array.join('');
287
+ return ret;
288
+ }
289
+ }
290
+
291
+ export class DiffDate {
292
+ years: number;
293
+ months: number;
294
+ days: number;
295
+ hours: number;
296
+ minutes: number;
297
+ seconds: number;
298
+ milliseconds: number;
299
+
300
+ constructor(
301
+ years: number,
302
+ months: number,
303
+ days: number,
304
+ hours: number,
305
+ minutes: number,
306
+ seconds: number,
307
+ milliseconds: number
308
+ ) {
309
+ this.years = years;
310
+ this.months = months;
311
+ this.days = days;
312
+ this.hours = hours;
313
+ this.minutes = minutes;
314
+ this.seconds = seconds;
315
+ this.milliseconds = milliseconds;
316
+ }
317
+ }