@acorex/core 7.0.41 → 7.1.1
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/config/index.d.ts +5 -5
- package/config/public-api.d.ts +1 -1
- package/config/src/configs.d.ts +9 -9
- package/dateTime/index.d.ts +5 -5
- package/dateTime/public-api.d.ts +5 -5
- package/dateTime/src/datetime.class.d.ts +100 -100
- package/dateTime/src/datetime.module.d.ts +8 -8
- package/dateTime/src/datetime.pipe.d.ts +8 -8
- package/dateTime/src/georgian.calendar.d.ts +20 -20
- package/dateTime/src/jalali.calendar.d.ts +35 -35
- package/{esm2020 → esm2022}/acorex-core.mjs +4 -4
- package/{esm2020 → esm2022}/config/acorex-core-config.mjs +4 -4
- package/{esm2020 → esm2022}/config/public-api.mjs +1 -1
- package/esm2022/config/src/configs.mjs +25 -0
- package/{esm2020 → esm2022}/dateTime/acorex-core-dateTime.mjs +4 -4
- package/{esm2020 → esm2022}/dateTime/public-api.mjs +5 -5
- package/esm2022/dateTime/src/datetime.class.mjs +295 -0
- package/esm2022/dateTime/src/datetime.module.mjs +40 -0
- package/esm2022/dateTime/src/datetime.pipe.mjs +27 -0
- package/esm2022/dateTime/src/georgian.calendar.mjs +187 -0
- package/esm2022/dateTime/src/jalali.calendar.mjs +357 -0
- package/{esm2020 → esm2022}/events/acorex-core-events.mjs +4 -4
- package/{esm2020 → esm2022}/events/public-api.mjs +1 -1
- package/esm2022/events/src/event.service.mjs +35 -0
- package/{esm2020 → esm2022}/file/acorex-core-file.mjs +4 -4
- package/{esm2020 → esm2022}/file/public-api.mjs +4 -4
- package/esm2022/file/src/file-download-ref.class.mjs +13 -0
- package/esm2022/file/src/file-download-result.class.mjs +47 -0
- package/esm2022/file/src/file-upload-ref.class.mjs +13 -0
- package/esm2022/file/src/file.service.mjs +103 -0
- package/{esm2020 → esm2022}/http/acorex-core-http.mjs +4 -4
- package/{esm2020 → esm2022}/http/public-api.mjs +5 -5
- package/{esm2020 → esm2022}/http/src/http-error.class.mjs +1 -1
- package/{esm2020 → esm2022}/http/src/http-events.interceptor.mjs +2 -2
- package/{esm2020 → esm2022}/http/src/http-request.class.mjs +1 -1
- package/esm2022/http/src/http-result.class.mjs +25 -0
- package/esm2022/http/src/http.module.mjs +30 -0
- package/esm2022/http/src/http.service.mjs +152 -0
- package/{esm2020 → esm2022}/image/acorex-core-image.mjs +4 -4
- package/{esm2020 → esm2022}/image/public-api.mjs +1 -1
- package/esm2022/image/src/image.service.mjs +44 -0
- package/{esm2020 → esm2022}/pipes/acorex-core-pipes.mjs +4 -4
- package/{esm2020 → esm2022}/pipes/public-api.mjs +2 -2
- package/esm2022/pipes/src/pipes.module.mjs +20 -0
- package/{esm2020 → esm2022}/pipes/src/safe.pipe.mjs +32 -30
- package/{esm2020 → esm2022}/platform/acorex-core-platform.mjs +4 -4
- package/{esm2020 → esm2022}/platform/public-api.mjs +1 -1
- package/esm2022/platform/src/platform.service.mjs +152 -0
- package/{esm2020 → esm2022}/public-api.mjs +4 -4
- package/{esm2020 → esm2022}/translation/acorex-core-translation.mjs +4 -4
- package/{esm2020 → esm2022}/translation/public-api.mjs +3 -3
- package/esm2022/translation/src/translation.module.mjs +19 -0
- package/esm2022/translation/src/translator.mjs +44 -0
- package/esm2022/translation/src/translator.pipe.mjs +16 -0
- package/{esm2020 → esm2022}/utils/acorex-core-utils.mjs +4 -4
- package/{esm2020 → esm2022}/utils/public-api.mjs +5 -5
- package/{esm2020 → esm2022}/utils/src/color-util.mjs +114 -114
- package/{esm2020 → esm2022}/utils/src/drawing-util.mjs +29 -29
- package/{esm2020 → esm2022}/utils/src/html-util.mjs +15 -15
- package/{esm2020 → esm2022}/utils/src/object-util.mjs +38 -38
- package/{esm2020 → esm2022}/utils/src/string-util.mjs +18 -18
- package/events/index.d.ts +5 -5
- package/events/public-api.d.ts +1 -1
- package/events/src/event.service.d.ts +9 -9
- package/{fesm2015 → fesm2022}/acorex-core-config.mjs +23 -24
- package/{fesm2015 → fesm2022}/acorex-core-config.mjs.map +1 -1
- package/{fesm2015 → fesm2022}/acorex-core-dateTime.mjs +882 -880
- package/{fesm2020 → fesm2022}/acorex-core-dateTime.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/acorex-core-events.mjs +32 -35
- package/fesm2022/acorex-core-events.mjs.map +1 -0
- package/{fesm2020 → fesm2022}/acorex-core-file.mjs +162 -159
- package/{fesm2020 → fesm2022}/acorex-core-file.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/acorex-core-http.mjs +190 -184
- package/{fesm2020 → fesm2022}/acorex-core-http.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/acorex-core-image.mjs +41 -42
- package/{fesm2020 → fesm2022}/acorex-core-image.mjs.map +1 -1
- package/{fesm2015 → fesm2022}/acorex-core-pipes.mjs +41 -41
- package/fesm2022/acorex-core-pipes.mjs.map +1 -0
- package/{fesm2020 → fesm2022}/acorex-core-platform.mjs +147 -154
- package/fesm2022/acorex-core-platform.mjs.map +1 -0
- package/{fesm2020 → fesm2022}/acorex-core-translation.mjs +64 -65
- package/{fesm2020 → fesm2022}/acorex-core-translation.mjs.map +1 -1
- package/{fesm2020 → fesm2022}/acorex-core-utils.mjs +209 -210
- package/{fesm2015 → fesm2022}/acorex-core.mjs +5 -6
- package/file/index.d.ts +5 -5
- package/file/public-api.d.ts +4 -4
- package/file/src/file-download-ref.class.d.ts +6 -6
- package/file/src/file-download-result.class.d.ts +8 -8
- package/file/src/file-upload-ref.class.d.ts +5 -5
- package/file/src/file.service.d.ts +18 -18
- package/http/index.d.ts +5 -5
- package/http/public-api.d.ts +5 -5
- package/http/src/http-error.class.d.ts +7 -7
- package/http/src/http-events.interceptor.d.ts +10 -10
- package/http/src/http-request.class.d.ts +14 -14
- package/http/src/http-result.class.d.ts +11 -11
- package/http/src/http.module.d.ts +8 -8
- package/http/src/http.service.d.ts +23 -23
- package/image/index.d.ts +5 -5
- package/image/public-api.d.ts +1 -1
- package/image/src/image.service.d.ts +12 -12
- package/index.d.ts +5 -5
- package/package.json +39 -65
- package/pipes/index.d.ts +5 -5
- package/pipes/public-api.d.ts +2 -2
- package/pipes/src/pipes.module.d.ts +8 -8
- package/pipes/src/safe.pipe.d.ts +10 -10
- package/platform/index.d.ts +5 -5
- package/platform/public-api.d.ts +1 -1
- package/platform/src/platform.service.d.ts +26 -26
- package/public-api.d.ts +1 -1
- package/translation/index.d.ts +5 -5
- package/translation/public-api.d.ts +3 -3
- package/translation/src/translation.module.d.ts +7 -7
- package/translation/src/translator.d.ts +11 -11
- package/translation/src/translator.pipe.d.ts +7 -7
- package/utils/index.d.ts +5 -5
- package/utils/public-api.d.ts +5 -5
- package/utils/src/color-util.d.ts +23 -23
- package/utils/src/drawing-util.d.ts +18 -18
- package/utils/src/html-util.d.ts +4 -4
- package/utils/src/object-util.d.ts +4 -4
- package/utils/src/string-util.d.ts +6 -6
- package/esm2020/config/src/configs.mjs +0 -24
- package/esm2020/dateTime/src/datetime.class.mjs +0 -288
- package/esm2020/dateTime/src/datetime.module.mjs +0 -39
- package/esm2020/dateTime/src/datetime.pipe.mjs +0 -26
- package/esm2020/dateTime/src/georgian.calendar.mjs +0 -189
- package/esm2020/dateTime/src/jalali.calendar.mjs +0 -359
- package/esm2020/events/src/event.service.mjs +0 -36
- package/esm2020/file/src/file-download-ref.class.mjs +0 -12
- package/esm2020/file/src/file-download-result.class.mjs +0 -46
- package/esm2020/file/src/file-upload-ref.class.mjs +0 -12
- package/esm2020/file/src/file.service.mjs +0 -101
- package/esm2020/http/src/http-result.class.mjs +0 -21
- package/esm2020/http/src/http.module.mjs +0 -29
- package/esm2020/http/src/http.service.mjs +0 -148
- package/esm2020/image/src/image.service.mjs +0 -43
- package/esm2020/pipes/src/pipes.module.mjs +0 -19
- package/esm2020/platform/src/platform.service.mjs +0 -157
- package/esm2020/translation/src/translation.module.mjs +0 -18
- package/esm2020/translation/src/translator.mjs +0 -43
- package/esm2020/translation/src/translator.pipe.mjs +0 -15
- package/fesm2015/acorex-core-dateTime.mjs.map +0 -1
- package/fesm2015/acorex-core-events.mjs +0 -44
- package/fesm2015/acorex-core-events.mjs.map +0 -1
- package/fesm2015/acorex-core-file.mjs +0 -176
- package/fesm2015/acorex-core-file.mjs.map +0 -1
- package/fesm2015/acorex-core-http.mjs +0 -203
- package/fesm2015/acorex-core-http.mjs.map +0 -1
- package/fesm2015/acorex-core-image.mjs +0 -54
- package/fesm2015/acorex-core-image.mjs.map +0 -1
- package/fesm2015/acorex-core-pipes.mjs.map +0 -1
- package/fesm2015/acorex-core-platform.mjs +0 -165
- package/fesm2015/acorex-core-platform.mjs.map +0 -1
- package/fesm2015/acorex-core-translation.mjs +0 -81
- package/fesm2015/acorex-core-translation.mjs.map +0 -1
- package/fesm2015/acorex-core-utils.mjs +0 -227
- package/fesm2020/acorex-core-config.mjs +0 -32
- package/fesm2020/acorex-core-config.mjs.map +0 -1
- package/fesm2020/acorex-core-dateTime.mjs +0 -899
- package/fesm2020/acorex-core-events.mjs.map +0 -1
- package/fesm2020/acorex-core-pipes.mjs +0 -54
- package/fesm2020/acorex-core-pipes.mjs.map +0 -1
- package/fesm2020/acorex-core-platform.mjs.map +0 -1
- package/fesm2020/acorex-core-utils.mjs.map +0 -1
- package/fesm2020/acorex-core.mjs +0 -12
- package/fesm2020/acorex-core.mjs.map +0 -1
- /package/{fesm2015 → fesm2022}/acorex-core-utils.mjs.map +0 -0
- /package/{fesm2015 → fesm2022}/acorex-core.mjs.map +0 -0
|
@@ -3,897 +3,899 @@ import { AXConfig } from '@acorex/core/config';
|
|
|
3
3
|
import * as i0 from '@angular/core';
|
|
4
4
|
import { Pipe, NgModule } from '@angular/core';
|
|
5
5
|
|
|
6
|
-
// @dynamic
|
|
7
|
-
class AXDateTime {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return date;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
date
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
case '
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
p
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
p
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
p
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
p
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
p
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return func(this.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
get
|
|
215
|
-
return this.
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
const
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
//
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
//
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
//
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
result.
|
|
271
|
-
|
|
272
|
-
result.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
6
|
+
// @dynamic
|
|
7
|
+
class AXDateTime {
|
|
8
|
+
static convert(value, calendar = AXConfig.get('dateTime.calendar')) {
|
|
9
|
+
let date;
|
|
10
|
+
if (typeof value === 'string' || value instanceof String) {
|
|
11
|
+
date = new AXDateTime(value, calendar);
|
|
12
|
+
}
|
|
13
|
+
else if (value instanceof Date) {
|
|
14
|
+
date = new AXDateTime(value, calendar);
|
|
15
|
+
}
|
|
16
|
+
else if (value instanceof AXDateTime) {
|
|
17
|
+
date = new AXDateTime(value.date, calendar);
|
|
18
|
+
}
|
|
19
|
+
return date;
|
|
20
|
+
}
|
|
21
|
+
static from(value = {
|
|
22
|
+
calendar: AXConfig.get('dateTime.calendar'),
|
|
23
|
+
year: 1,
|
|
24
|
+
month: 1,
|
|
25
|
+
date: 1,
|
|
26
|
+
hours: 0,
|
|
27
|
+
minutes: 0,
|
|
28
|
+
seconds: 0,
|
|
29
|
+
ms: 0
|
|
30
|
+
}) {
|
|
31
|
+
return AXDateTime.resolveCalendar(value.calendar).create(value);
|
|
32
|
+
}
|
|
33
|
+
static resolveCalendar(calendar) {
|
|
34
|
+
return typeof calendar == 'string'
|
|
35
|
+
? AXConfig.get(`dateTime.calendars.${calendar}.class`)
|
|
36
|
+
: calendar;
|
|
37
|
+
}
|
|
38
|
+
_date;
|
|
39
|
+
get date() {
|
|
40
|
+
return this._date;
|
|
41
|
+
}
|
|
42
|
+
_calendar;
|
|
43
|
+
get calendar() {
|
|
44
|
+
return this._calendar;
|
|
45
|
+
}
|
|
46
|
+
constructor(value = new Date(), calendar = AXConfig.get(`dateTime.calendar`)) {
|
|
47
|
+
this._calendar = AXDateTime.resolveCalendar(calendar);
|
|
48
|
+
if (value instanceof Date) {
|
|
49
|
+
this._date = value;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
//TODO: parse jalali
|
|
53
|
+
this._date = new Date(value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
clone() {
|
|
57
|
+
return new AXDateTime(this.date, this.calendar);
|
|
58
|
+
}
|
|
59
|
+
get dayOfMonth() {
|
|
60
|
+
return this._calendar.dayOfMonth(this.date);
|
|
61
|
+
}
|
|
62
|
+
get dayOfYear() {
|
|
63
|
+
return this._calendar.dayOfYear(this.date);
|
|
64
|
+
}
|
|
65
|
+
get dayOfWeek() {
|
|
66
|
+
return this._calendar.dayOfWeek(this.date);
|
|
67
|
+
}
|
|
68
|
+
get hour() {
|
|
69
|
+
return this._date.getHours();
|
|
70
|
+
}
|
|
71
|
+
get minute() {
|
|
72
|
+
return this._date.getMinutes();
|
|
73
|
+
}
|
|
74
|
+
get second() {
|
|
75
|
+
return this._date.getSeconds();
|
|
76
|
+
}
|
|
77
|
+
get year() {
|
|
78
|
+
return this._calendar.year(this.date);
|
|
79
|
+
}
|
|
80
|
+
get monthOfYear() {
|
|
81
|
+
return this._calendar.monthOfYear(this.date);
|
|
82
|
+
}
|
|
83
|
+
get weekOfYear() {
|
|
84
|
+
return this._calendar.weekOfYear(this.date);
|
|
85
|
+
}
|
|
86
|
+
get month() {
|
|
87
|
+
return new AXCalendarMonth(this);
|
|
88
|
+
}
|
|
89
|
+
add(unit, amount) {
|
|
90
|
+
return this._calendar.add(this.date, unit, amount);
|
|
91
|
+
}
|
|
92
|
+
set(unit = 'day', value) {
|
|
93
|
+
return this._calendar.set(this.date, unit, value);
|
|
94
|
+
}
|
|
95
|
+
duration(end, unit = 'day') {
|
|
96
|
+
const range = new AXDateTimeRange(this, AXDateTime.convert(end, this.calendar.name()));
|
|
97
|
+
return range.duration();
|
|
98
|
+
}
|
|
99
|
+
startOf(unit = 'day') {
|
|
100
|
+
return this._calendar.startOf(this.date, unit);
|
|
101
|
+
}
|
|
102
|
+
endOf(unit = 'day') {
|
|
103
|
+
return this._calendar.endOf(this.date, unit);
|
|
104
|
+
}
|
|
105
|
+
_formatKeys = {
|
|
106
|
+
ss: () => this.pad(this.date.getSeconds(), 2),
|
|
107
|
+
s: () => this.date.getSeconds().toString(),
|
|
108
|
+
//
|
|
109
|
+
dd: () => this.pad(this.calendar.dayOfMonth(this.date), 2),
|
|
110
|
+
d: () => this.calendar.dayOfMonth(this.date).toString(),
|
|
111
|
+
//
|
|
112
|
+
mm: () => this.pad(this.date.getMinutes(), 2),
|
|
113
|
+
m: () => this.date.getMinutes().toString(),
|
|
114
|
+
//
|
|
115
|
+
MMMM: () => this.calendar.monthNames[this.calendar.monthOfYear(this.date) - 1],
|
|
116
|
+
MMM: () => this.calendar.monthShortNames[this.calendar.monthOfYear(this.date) - 1],
|
|
117
|
+
MM: () => this.pad(this.calendar.monthOfYear(this.date), 2),
|
|
118
|
+
//
|
|
119
|
+
DDDD: () => this.calendar.dayNames[this.calendar.dayOfWeek(this.date) - 1],
|
|
120
|
+
DDD: () => this.calendar.dayShortNames[this.calendar.dayOfWeek(this.date) - 1],
|
|
121
|
+
//
|
|
122
|
+
yyyy: () => this.calendar.year(this.date).toString(),
|
|
123
|
+
YYYY: () => this.calendar.year(this.date).toString(),
|
|
124
|
+
yy: () => this.calendar.year(this.date).toString().substring(2),
|
|
125
|
+
YY: () => this.calendar.year(this.date).toString().substring(2),
|
|
126
|
+
//
|
|
127
|
+
HH: () => this.pad(this.date.getHours(), 2),
|
|
128
|
+
H: () => this.date.getHours().toString(),
|
|
129
|
+
//
|
|
130
|
+
hh: () => this.pad((this.date.getHours() % 12 || 12), 2),
|
|
131
|
+
h: () => (this.date.getHours() % 12 || 12).toString(),
|
|
132
|
+
//
|
|
133
|
+
A: () => (this.date.getHours() < 12) ? 'am' : 'pm',
|
|
134
|
+
a: () => (this.date.getHours() < 12) ? 'am' : 'pm',
|
|
135
|
+
};
|
|
136
|
+
format(format = AXConfig.get('dateTime.shortDateFormat')) {
|
|
137
|
+
const re = new RegExp(_.orderBy(Object.keys(this._formatKeys), c => c.length, ['desc']).join("|"), "gi");
|
|
138
|
+
return format.replace(re, (matched) => {
|
|
139
|
+
return this._formatKeys[matched]();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
pad(n, width, z = '0') {
|
|
143
|
+
n = n + '';
|
|
144
|
+
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
|
145
|
+
}
|
|
146
|
+
toString(format = AXConfig.get('dateTime.shortDateFormat')) {
|
|
147
|
+
return this.format(format);
|
|
148
|
+
}
|
|
149
|
+
equal(value, unit = 'day') {
|
|
150
|
+
return this.compare(value, unit) == 0;
|
|
151
|
+
}
|
|
152
|
+
compare(value, unit = 'day') {
|
|
153
|
+
const val = AXDateTime.convert(value, this.calendar.name());
|
|
154
|
+
const func = (v1, v2) => {
|
|
155
|
+
if (v1 == v2) {
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
else if (v1 > v2) {
|
|
159
|
+
return 1;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return -1;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
let p = 0;
|
|
166
|
+
switch (unit) {
|
|
167
|
+
case 'year':
|
|
168
|
+
return func(this.year, val.year);
|
|
169
|
+
case 'week':
|
|
170
|
+
p = this.compare(val, 'year');
|
|
171
|
+
return p == 0 ? func(this.weekOfYear, val.weekOfYear) : p;
|
|
172
|
+
case 'month':
|
|
173
|
+
p = this.compare(val, 'year');
|
|
174
|
+
return p == 0 ? func(this.monthOfYear, val.monthOfYear) : p;
|
|
175
|
+
case 'day':
|
|
176
|
+
p = this.compare(val, 'year');
|
|
177
|
+
return p == 0 ? func(this.dayOfYear, val.dayOfYear) : p;
|
|
178
|
+
case 'hour':
|
|
179
|
+
p = this.compare(val, 'day');
|
|
180
|
+
return p == 0 ? func(this.hour, val.hour) : p;
|
|
181
|
+
case 'minute':
|
|
182
|
+
p = this.compare(val, 'hour');
|
|
183
|
+
return p == 0 ? func(this.minute, val.minute) : p;
|
|
184
|
+
case 'second':
|
|
185
|
+
p = this.compare(val, 'minute');
|
|
186
|
+
return p == 0 ? func(this.second, val.second) : p;
|
|
187
|
+
default:
|
|
188
|
+
return func(this.date.getTime(), val.date.getTime());
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
convert(calendar) {
|
|
192
|
+
return AXDateTime.convert(this, calendar);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
class AXCalendarMonth {
|
|
196
|
+
_range;
|
|
197
|
+
get range() {
|
|
198
|
+
return this._range;
|
|
199
|
+
}
|
|
200
|
+
set range(v) {
|
|
201
|
+
this._range = v;
|
|
202
|
+
}
|
|
203
|
+
constructor(date) {
|
|
204
|
+
this.index = date.date.getMonth();
|
|
205
|
+
this.name = date.format('MMMM');
|
|
206
|
+
this.range = new AXDateTimeRange(new AXDateTime(date.startOf('month').date, date.calendar), new AXDateTime(date.endOf('month').date, date.calendar));
|
|
207
|
+
}
|
|
208
|
+
index;
|
|
209
|
+
name;
|
|
210
|
+
}
|
|
211
|
+
class AXDateTimeRange {
|
|
212
|
+
_startTime;
|
|
213
|
+
_endTime;
|
|
214
|
+
get startTime() {
|
|
215
|
+
return this._startTime;
|
|
216
|
+
}
|
|
217
|
+
get endTime() {
|
|
218
|
+
return this._endTime;
|
|
219
|
+
}
|
|
220
|
+
constructor(startTime, endTime) {
|
|
221
|
+
this._startTime = startTime;
|
|
222
|
+
this._endTime = endTime;
|
|
223
|
+
}
|
|
224
|
+
duration() {
|
|
225
|
+
const result = {
|
|
226
|
+
miliseconds: 0,
|
|
227
|
+
seconds: 0,
|
|
228
|
+
minutes: 0,
|
|
229
|
+
hours: 0,
|
|
230
|
+
days: 0,
|
|
231
|
+
months: 0,
|
|
232
|
+
years: 0,
|
|
233
|
+
total: {
|
|
234
|
+
miliseconds: 0,
|
|
235
|
+
seconds: 0,
|
|
236
|
+
minutes: 0,
|
|
237
|
+
hours: 0,
|
|
238
|
+
days: 0,
|
|
239
|
+
weeks: 0,
|
|
240
|
+
months: 0,
|
|
241
|
+
years: 0,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
const one_second = 1000;
|
|
245
|
+
const one_min = one_second * 60;
|
|
246
|
+
const one_hour = one_min * 60;
|
|
247
|
+
const one_day = one_hour * 24;
|
|
248
|
+
const one_week = one_day * 7;
|
|
249
|
+
const one_year = 365.25 * one_day;
|
|
250
|
+
const one_month = one_year / 12;
|
|
251
|
+
const startTime = this._startTime.date.getTime();
|
|
252
|
+
const endTime = this._endTime.date.getTime();
|
|
253
|
+
const diff = Math.abs(endTime - startTime);
|
|
254
|
+
//
|
|
255
|
+
result.total.miliseconds = diff;
|
|
256
|
+
result.total.seconds = Number((diff / one_second).toFixed(2));
|
|
257
|
+
result.total.minutes = Number((diff / one_min).toFixed(2));
|
|
258
|
+
result.total.hours = Number((diff / one_hour).toFixed(2));
|
|
259
|
+
result.total.days = Number((diff / one_day).toFixed(2));
|
|
260
|
+
result.total.weeks = Number((diff / one_week).toFixed(2));
|
|
261
|
+
//
|
|
262
|
+
// let months = (this.endTime.year - this.startTime.year) * 12;
|
|
263
|
+
// months += this.endTime.monthOfYear - this.startTime.monthOfYear + 1;
|
|
264
|
+
// if (this.endTime.dayOfYear < this.startTime.dayOfYear) {
|
|
265
|
+
// months--;
|
|
266
|
+
// }
|
|
267
|
+
// result.total.months = Math.abs(months);
|
|
268
|
+
// TODO: review
|
|
269
|
+
result.total.months = Number((diff / one_month).toFixed(2));
|
|
270
|
+
result.total.years = Number((diff / one_year).toFixed(2));
|
|
271
|
+
//
|
|
272
|
+
result.miliseconds = result.total.miliseconds % 1000;
|
|
273
|
+
result.seconds = Number((result.total.seconds % 60).toFixed(0));
|
|
274
|
+
result.minutes = Number((result.total.minutes % 60).toFixed(0));
|
|
275
|
+
result.hours = Number((result.total.hours % 24).toFixed(0));
|
|
276
|
+
// TODO: review
|
|
277
|
+
result.days = Number((result.total.days % 30.4).toFixed(0));
|
|
278
|
+
result.months = Number((result.total.months % 12).toFixed(0));
|
|
279
|
+
result.years = Number(result.total.years.toFixed(0));
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
enumurate(unit = 'day', amount = 1) {
|
|
283
|
+
const result = [];
|
|
284
|
+
let item = this._startTime.clone();
|
|
285
|
+
while (item.compare(this._endTime, unit) < 1) {
|
|
286
|
+
if (!result.some(c => c.equal(item, unit))) {
|
|
287
|
+
result.push(item);
|
|
288
|
+
}
|
|
289
|
+
item = item.add(unit, amount);
|
|
290
|
+
}
|
|
291
|
+
return result;
|
|
292
|
+
}
|
|
293
|
+
includes(value, unit = 'day') {
|
|
294
|
+
// TODO: ??
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
290
297
|
}
|
|
291
298
|
|
|
292
|
-
class AXDateTimePipe {
|
|
293
|
-
constructor() { }
|
|
294
|
-
transform(value, format, calendar) {
|
|
295
|
-
if (value == null) {
|
|
296
|
-
return '';
|
|
297
|
-
}
|
|
298
|
-
const date = value instanceof AXDateTime ? value.clone() : AXDateTime.convert(value, calendar);
|
|
299
|
-
if (!format) {
|
|
300
|
-
return date.format(AXConfig.get('dateTime.shortDateFormat'));
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
return date.format(format);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
310
|
-
type: Pipe,
|
|
311
|
-
args: [{ name: 'axDate' }]
|
|
299
|
+
class AXDateTimePipe {
|
|
300
|
+
constructor() { }
|
|
301
|
+
transform(value, format, calendar) {
|
|
302
|
+
if (value == null) {
|
|
303
|
+
return '';
|
|
304
|
+
}
|
|
305
|
+
const date = value instanceof AXDateTime ? value.clone() : AXDateTime.convert(value, calendar);
|
|
306
|
+
if (!format) {
|
|
307
|
+
return date.format(AXConfig.get('dateTime.shortDateFormat'));
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
return date.format(format);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: AXDateTimePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
314
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.0.0", ngImport: i0, type: AXDateTimePipe, name: "axDate" });
|
|
315
|
+
}
|
|
316
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: AXDateTimePipe, decorators: [{
|
|
317
|
+
type: Pipe,
|
|
318
|
+
args: [{ name: 'axDate' }]
|
|
312
319
|
}], ctorParameters: function () { return []; } });
|
|
313
320
|
|
|
314
|
-
class GeorgianCalendar {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
v.
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
break;
|
|
428
|
-
case "
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
clone.
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
return
|
|
487
|
-
case '
|
|
488
|
-
return
|
|
489
|
-
case
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
return leapYear.getDate() == 29;
|
|
499
|
-
}
|
|
321
|
+
class GeorgianCalendar {
|
|
322
|
+
monthNames = [
|
|
323
|
+
"January", "February", "March",
|
|
324
|
+
"April", "May", "June", "July",
|
|
325
|
+
"August", "September", "October",
|
|
326
|
+
"November", "December"
|
|
327
|
+
];
|
|
328
|
+
monthShortNames = [
|
|
329
|
+
"Jan", "Feb", "Mar",
|
|
330
|
+
"Apr", "May", "Jun", "Jul",
|
|
331
|
+
"Aug", "Sep", "Oct",
|
|
332
|
+
"Nov", "Dec"
|
|
333
|
+
];
|
|
334
|
+
dayNames = [
|
|
335
|
+
"Sunday", "Monday", "Tuesday", "Wednesday",
|
|
336
|
+
"Thursday", "Friday", "Saturday"
|
|
337
|
+
];
|
|
338
|
+
dayShortNames = [
|
|
339
|
+
"Sun", "Mon", "Tue", "Wed",
|
|
340
|
+
"Thu", "Fri", "Sat"
|
|
341
|
+
];
|
|
342
|
+
create(value) {
|
|
343
|
+
return new AXDateTime(new Date(value.year, value.month - 1, value.date, value.hours || 0, value.minutes || 0, value.seconds || 0, value.ms || 0), this.name());
|
|
344
|
+
}
|
|
345
|
+
name() {
|
|
346
|
+
return 'gregorian';
|
|
347
|
+
}
|
|
348
|
+
dayOfMonth(date) {
|
|
349
|
+
return date.getDate();
|
|
350
|
+
}
|
|
351
|
+
dayOfYear(date) {
|
|
352
|
+
let result = 0;
|
|
353
|
+
let m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
354
|
+
if (this.isLeap(date)) {
|
|
355
|
+
m[1] = 29;
|
|
356
|
+
}
|
|
357
|
+
for (let i = 0; i < date.getMonth(); i++) {
|
|
358
|
+
result = result + m[i];
|
|
359
|
+
}
|
|
360
|
+
result += date.getDate();
|
|
361
|
+
return result;
|
|
362
|
+
}
|
|
363
|
+
dayOfWeek(date) {
|
|
364
|
+
return date.getDay() + 1;
|
|
365
|
+
}
|
|
366
|
+
weekOfYear(date) {
|
|
367
|
+
const firstDay = new AXDateTime(date).startOf('year');
|
|
368
|
+
return Math.ceil((((date.getTime() - firstDay.date.getTime()) / 86400000) + firstDay.date.getDay() + 1) / 7);
|
|
369
|
+
}
|
|
370
|
+
year(date) {
|
|
371
|
+
return date.getFullYear();
|
|
372
|
+
}
|
|
373
|
+
monthOfYear(date) {
|
|
374
|
+
return date.getMonth() + 1;
|
|
375
|
+
}
|
|
376
|
+
add(date, unit, amount) {
|
|
377
|
+
let value = date.valueOf();
|
|
378
|
+
switch (unit) {
|
|
379
|
+
case 'second':
|
|
380
|
+
value += 1000 * amount;
|
|
381
|
+
break;
|
|
382
|
+
case 'minute':
|
|
383
|
+
value += 60000 * amount;
|
|
384
|
+
break;
|
|
385
|
+
case 'hour':
|
|
386
|
+
value += 3600000 * amount;
|
|
387
|
+
break;
|
|
388
|
+
case 'month':
|
|
389
|
+
const v = new Date(value);
|
|
390
|
+
var mo = date.getMonth();
|
|
391
|
+
var yr = date.getFullYear();
|
|
392
|
+
mo = (mo + amount) % 12;
|
|
393
|
+
if (0 > mo) {
|
|
394
|
+
yr += (date.getMonth() + amount - mo - 12) / 12;
|
|
395
|
+
mo += 12;
|
|
396
|
+
}
|
|
397
|
+
else
|
|
398
|
+
yr += ((date.getMonth() + amount - mo) / 12);
|
|
399
|
+
v.setMonth(mo);
|
|
400
|
+
v.setFullYear(yr);
|
|
401
|
+
value = v.valueOf();
|
|
402
|
+
break;
|
|
403
|
+
case 'week':
|
|
404
|
+
value += 7 * 86400000 * amount;
|
|
405
|
+
break;
|
|
406
|
+
case 'year':
|
|
407
|
+
const yv = new Date(value);
|
|
408
|
+
yv.setFullYear(yv.getFullYear() + amount);
|
|
409
|
+
value = yv.valueOf();
|
|
410
|
+
break;
|
|
411
|
+
case 'day':
|
|
412
|
+
default:
|
|
413
|
+
value += 86400000 * amount;
|
|
414
|
+
}
|
|
415
|
+
return new AXDateTime(new Date(value), this.name());
|
|
416
|
+
}
|
|
417
|
+
set(date, unit, value) {
|
|
418
|
+
const clone = new Date(date.valueOf());
|
|
419
|
+
switch (unit) {
|
|
420
|
+
case 'second':
|
|
421
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), value, clone.getMilliseconds());
|
|
422
|
+
break;
|
|
423
|
+
case 'minute':
|
|
424
|
+
clone.setHours(clone.getHours(), value, clone.getSeconds(), clone.getMilliseconds());
|
|
425
|
+
break;
|
|
426
|
+
case 'hour':
|
|
427
|
+
clone.setHours(value, clone.getMinutes(), clone.getSeconds(), clone.getMilliseconds());
|
|
428
|
+
break;
|
|
429
|
+
default:
|
|
430
|
+
case 'day':
|
|
431
|
+
clone.setDate(value);
|
|
432
|
+
break;
|
|
433
|
+
case "week":
|
|
434
|
+
break;
|
|
435
|
+
case "month":
|
|
436
|
+
clone.setMonth(Math.max(0, value - 1));
|
|
437
|
+
break;
|
|
438
|
+
case "year":
|
|
439
|
+
clone.setFullYear(value);
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
return new AXDateTime(clone, this.name());
|
|
443
|
+
}
|
|
444
|
+
startOf(date, unit) {
|
|
445
|
+
const clone = new Date(date.valueOf());
|
|
446
|
+
switch (unit) {
|
|
447
|
+
case 'second':
|
|
448
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 0);
|
|
449
|
+
return new AXDateTime(clone, this.name());
|
|
450
|
+
case 'minute':
|
|
451
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), 0, 0);
|
|
452
|
+
return new AXDateTime(clone, this.name());
|
|
453
|
+
case 'hour':
|
|
454
|
+
clone.setHours(clone.getHours(), 0, 0, 0);
|
|
455
|
+
return new AXDateTime(clone, this.name());
|
|
456
|
+
default:
|
|
457
|
+
case 'day':
|
|
458
|
+
clone.setHours(0, 0, 0, 0);
|
|
459
|
+
return new AXDateTime(clone, this.name());
|
|
460
|
+
case "week":
|
|
461
|
+
const index = 0;
|
|
462
|
+
const start = index >= 0 ? index : 0;
|
|
463
|
+
const day = clone.getDay();
|
|
464
|
+
const diff = clone.getDate() - day + (start > day ? start - 7 : start);
|
|
465
|
+
clone.setDate(diff);
|
|
466
|
+
return new AXDateTime(clone, this.name()).startOf('day');
|
|
467
|
+
case "month":
|
|
468
|
+
clone.setDate(1);
|
|
469
|
+
return new AXDateTime(clone, this.name()).startOf('day');
|
|
470
|
+
case "year":
|
|
471
|
+
clone.setMonth(0);
|
|
472
|
+
clone.setDate(1);
|
|
473
|
+
return new AXDateTime(clone, this.name()).startOf('day');
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
endOf(date, unit) {
|
|
477
|
+
const clone = new Date(date.valueOf());
|
|
478
|
+
switch (unit) {
|
|
479
|
+
case 'second':
|
|
480
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 999);
|
|
481
|
+
return new AXDateTime(clone, this.name());
|
|
482
|
+
case 'minute':
|
|
483
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), 59, 999);
|
|
484
|
+
return new AXDateTime(clone, this.name());
|
|
485
|
+
case 'hour':
|
|
486
|
+
clone.setHours(clone.getHours(), 59, 59, 999);
|
|
487
|
+
return new AXDateTime(clone, this.name());
|
|
488
|
+
default:
|
|
489
|
+
case 'day':
|
|
490
|
+
clone.setHours(23, 59, 59, 999);
|
|
491
|
+
return new AXDateTime(clone, this.name());
|
|
492
|
+
case 'week':
|
|
493
|
+
return this.startOf(date, 'week').add('day', 6).endOf('day');
|
|
494
|
+
case 'month':
|
|
495
|
+
return new AXDateTime(new Date(date.getFullYear(), date.getMonth() + 1, 0), this.name()).endOf('day');
|
|
496
|
+
case "year":
|
|
497
|
+
clone.setMonth(11);
|
|
498
|
+
return new AXDateTime(clone, this.name()).endOf('month');
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
isLeap(date) {
|
|
502
|
+
let leapYear = new Date(date.getFullYear(), 1, 29);
|
|
503
|
+
return leapYear.getDate() == 29;
|
|
504
|
+
}
|
|
500
505
|
}
|
|
501
506
|
|
|
502
|
-
class JalaliCalendar {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
let
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
jy
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
v.
|
|
561
|
-
v.
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
//
|
|
572
|
-
//
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
let
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
v.
|
|
581
|
-
v.
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
break;
|
|
610
|
-
case "
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
return new AXDateTime(clone, this.name());
|
|
639
|
-
case "
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
const
|
|
679
|
-
const
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
const
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
if (jm <=
|
|
727
|
-
return
|
|
728
|
-
if (
|
|
729
|
-
return 30;
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
//
|
|
757
|
-
|
|
758
|
-
//
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
@param
|
|
776
|
-
@
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
return a - ~~(a / b) * b;
|
|
857
|
-
}
|
|
507
|
+
class JalaliCalendar {
|
|
508
|
+
monthNames = ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_");
|
|
509
|
+
monthShortNames = ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_");
|
|
510
|
+
dayNames = ("شنبه_یکشنبه_دوشنبه_سه شنبه_چهارشنبه_پنج شنبه_جمعه").split("_");
|
|
511
|
+
dayShortNames = "ش_ی_د_س_چ_پ_ج".split("_");
|
|
512
|
+
create(value) {
|
|
513
|
+
const a = this.toGregorian(value.year, value.month, value.date);
|
|
514
|
+
return new AXDateTime(new Date(a.getFullYear(), a.getMonth(), a.getDate(), value.hours || 0, value.minutes || 0, value.seconds || 0, value.ms || 0), this.name());
|
|
515
|
+
}
|
|
516
|
+
name() {
|
|
517
|
+
return 'jalali';
|
|
518
|
+
}
|
|
519
|
+
dayOfMonth(date) {
|
|
520
|
+
return this.toJalali(date).day;
|
|
521
|
+
}
|
|
522
|
+
dayOfYear(date) {
|
|
523
|
+
const j = this.toJalali(date);
|
|
524
|
+
return (j.month <= 6 ? ((j.month - 1) * 31) : ((6 * 31) + (j.month - 7) * 30)) + j.day;
|
|
525
|
+
}
|
|
526
|
+
dayOfWeek(date) {
|
|
527
|
+
return date.getDay() == 6 ? 1 : date.getDay() + 2;
|
|
528
|
+
}
|
|
529
|
+
weekOfYear(date) {
|
|
530
|
+
//TODO : apply jalali
|
|
531
|
+
const firstDay = new AXDateTime(date).startOf('year');
|
|
532
|
+
return Math.ceil((((date.getTime() - firstDay.date.getTime()) / 86400000) + firstDay.date.getDay() + 1) / 7);
|
|
533
|
+
}
|
|
534
|
+
year(date) {
|
|
535
|
+
return this.toJalali(date).year;
|
|
536
|
+
}
|
|
537
|
+
monthOfYear(date) {
|
|
538
|
+
return this.toJalali(date).month;
|
|
539
|
+
}
|
|
540
|
+
add(date, unit, amount) {
|
|
541
|
+
let value = date.valueOf();
|
|
542
|
+
switch (unit) {
|
|
543
|
+
case 'second':
|
|
544
|
+
value += 1000 * amount;
|
|
545
|
+
break;
|
|
546
|
+
case 'minute':
|
|
547
|
+
value += 60000 * amount;
|
|
548
|
+
break;
|
|
549
|
+
case 'hour':
|
|
550
|
+
value += 3600000 * amount;
|
|
551
|
+
break;
|
|
552
|
+
case 'month':
|
|
553
|
+
{
|
|
554
|
+
const v = new Date(value);
|
|
555
|
+
let jd = this.dayOfMonth(date);
|
|
556
|
+
let jm = this.monthOfYear(date);
|
|
557
|
+
let jy = this.year(date);
|
|
558
|
+
const nm = (jm + amount);
|
|
559
|
+
const ny = (nm % 12) ? Math.floor(nm / 12) : 0;
|
|
560
|
+
jy += ny;
|
|
561
|
+
jm = nm - (ny * 12);
|
|
562
|
+
const vv = this.toGregorian(jy, jm, jd);
|
|
563
|
+
v.setFullYear(vv.getFullYear());
|
|
564
|
+
v.setMonth(vv.getMonth());
|
|
565
|
+
v.setDate(vv.getDate());
|
|
566
|
+
value = v.valueOf();
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
case 'week':
|
|
570
|
+
value += 7 * 86400000 * amount;
|
|
571
|
+
break;
|
|
572
|
+
case 'year':
|
|
573
|
+
{
|
|
574
|
+
// const v = new Date(value);
|
|
575
|
+
// v.setFullYear(v.getFullYear() + amount);
|
|
576
|
+
// value = v.valueOf();
|
|
577
|
+
// break
|
|
578
|
+
const v = new Date(value);
|
|
579
|
+
let jd = this.dayOfMonth(date);
|
|
580
|
+
let jm = this.monthOfYear(date);
|
|
581
|
+
let jy = this.year(date);
|
|
582
|
+
const vv = this.toGregorian(jy + amount, jm, jd);
|
|
583
|
+
v.setFullYear(vv.getFullYear());
|
|
584
|
+
v.setMonth(vv.getMonth());
|
|
585
|
+
v.setDate(vv.getDate());
|
|
586
|
+
value = v.valueOf();
|
|
587
|
+
break;
|
|
588
|
+
}
|
|
589
|
+
case 'day':
|
|
590
|
+
default:
|
|
591
|
+
value += 86400000 * amount;
|
|
592
|
+
}
|
|
593
|
+
return new AXDateTime(new Date(value), this.name());
|
|
594
|
+
}
|
|
595
|
+
set(date, unit, value) {
|
|
596
|
+
const clone = new Date(date.valueOf());
|
|
597
|
+
const jDate = this.toJalali(clone);
|
|
598
|
+
switch (unit) {
|
|
599
|
+
case 'second':
|
|
600
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), value, clone.getMilliseconds());
|
|
601
|
+
break;
|
|
602
|
+
case 'minute':
|
|
603
|
+
clone.setHours(clone.getHours(), value, clone.getSeconds(), clone.getMilliseconds());
|
|
604
|
+
break;
|
|
605
|
+
case 'hour':
|
|
606
|
+
clone.setHours(value, clone.getMinutes(), clone.getSeconds(), clone.getMilliseconds());
|
|
607
|
+
break;
|
|
608
|
+
default:
|
|
609
|
+
case 'day':
|
|
610
|
+
const gDate = this.toGregorian(jDate.year, jDate.month, value);
|
|
611
|
+
clone.setDate(gDate.getDate());
|
|
612
|
+
break;
|
|
613
|
+
case "week":
|
|
614
|
+
break;
|
|
615
|
+
case "month":
|
|
616
|
+
const gDate2 = this.toGregorian(jDate.year, value, jDate.day);
|
|
617
|
+
clone.setMonth(gDate2.getMonth());
|
|
618
|
+
break;
|
|
619
|
+
case "year":
|
|
620
|
+
const gDate3 = this.toGregorian(value, jDate.month, jDate.day);
|
|
621
|
+
clone.setFullYear(gDate3.getFullYear());
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
return new AXDateTime(clone, this.name());
|
|
625
|
+
}
|
|
626
|
+
startOf(date, unit) {
|
|
627
|
+
const clone = new Date(date.valueOf());
|
|
628
|
+
switch (unit) {
|
|
629
|
+
case 'second':
|
|
630
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 0);
|
|
631
|
+
return new AXDateTime(clone, this.name());
|
|
632
|
+
case 'minute':
|
|
633
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), 0, 0);
|
|
634
|
+
return new AXDateTime(clone, this.name());
|
|
635
|
+
case 'hour':
|
|
636
|
+
clone.setHours(clone.getHours(), 0, 0, 0);
|
|
637
|
+
return new AXDateTime(clone, this.name());
|
|
638
|
+
default:
|
|
639
|
+
case 'day':
|
|
640
|
+
clone.setHours(0, 0, 0, 0);
|
|
641
|
+
return new AXDateTime(clone, this.name());
|
|
642
|
+
case "week":
|
|
643
|
+
return new AXDateTime(clone, this.name()).add('day', -this.dayOfWeek(clone) + 1).startOf('day');
|
|
644
|
+
case "month":
|
|
645
|
+
{
|
|
646
|
+
const jy = this.year(date);
|
|
647
|
+
const jm = this.monthOfYear(date);
|
|
648
|
+
const gDate = this.toGregorian(jy, jm, 1);
|
|
649
|
+
return new AXDateTime(gDate, this.name()).startOf('day');
|
|
650
|
+
}
|
|
651
|
+
case "year":
|
|
652
|
+
{
|
|
653
|
+
const jy = this.year(date);
|
|
654
|
+
const gDate = this.toGregorian(jy, 1, 1);
|
|
655
|
+
return new AXDateTime(gDate, this.name()).startOf('day');
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
endOf(date, unit) {
|
|
660
|
+
const clone = new Date(date.valueOf());
|
|
661
|
+
switch (unit) {
|
|
662
|
+
case 'second':
|
|
663
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 999);
|
|
664
|
+
return new AXDateTime(clone, this.name());
|
|
665
|
+
case 'minute':
|
|
666
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), 59, 999);
|
|
667
|
+
return new AXDateTime(clone, this.name());
|
|
668
|
+
case 'hour':
|
|
669
|
+
clone.setHours(clone.getHours(), 59, 59, 999);
|
|
670
|
+
return new AXDateTime(clone, this.name());
|
|
671
|
+
default:
|
|
672
|
+
case 'day':
|
|
673
|
+
clone.setHours(23, 59, 59, 999);
|
|
674
|
+
return new AXDateTime(clone, this.name());
|
|
675
|
+
case 'week':
|
|
676
|
+
{
|
|
677
|
+
return this.startOf(date, 'week').add('day', 6).endOf('day');
|
|
678
|
+
}
|
|
679
|
+
case 'month':
|
|
680
|
+
{
|
|
681
|
+
const jy = this.year(date);
|
|
682
|
+
const jm = this.monthOfYear(date);
|
|
683
|
+
const jd = this.monthLength(jy, jm);
|
|
684
|
+
const gDate = this.toGregorian(jy, jm, jd);
|
|
685
|
+
return new AXDateTime(gDate, this.name()).endOf('day');
|
|
686
|
+
}
|
|
687
|
+
case "year":
|
|
688
|
+
let jy = this.year(date);
|
|
689
|
+
const gDate = this.toGregorian(jy, 12, this.monthLength(jy, 12));
|
|
690
|
+
return new AXDateTime(gDate, this.name()).endOf('day');
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
toJalali(date) {
|
|
694
|
+
const gy = date.getFullYear();
|
|
695
|
+
const gm = date.getMonth() + 1;
|
|
696
|
+
const gd = date.getDate();
|
|
697
|
+
const r = this.d2j(this.g2d(gy, gm, gd));
|
|
698
|
+
return {
|
|
699
|
+
year: r.jy,
|
|
700
|
+
month: r.jm,
|
|
701
|
+
day: r.jd,
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
/*
|
|
705
|
+
Converts a Jalaali date to Gregorian.
|
|
706
|
+
*/
|
|
707
|
+
toGregorian(jy, jm, jd) {
|
|
708
|
+
const g = this.d2g(this.j2d(jy, jm, jd));
|
|
709
|
+
return new Date(g.gy, g.gm - 1, g.gd);
|
|
710
|
+
}
|
|
711
|
+
/*
|
|
712
|
+
Checks whether a Jalaali date is valid or not.
|
|
713
|
+
*/
|
|
714
|
+
isValid(jy, jm, jd) {
|
|
715
|
+
return jy >= -61 && jy <= 3177 &&
|
|
716
|
+
jm >= 1 && jm <= 12 &&
|
|
717
|
+
jd >= 1 && jd <= this.monthLength(jy, jm);
|
|
718
|
+
}
|
|
719
|
+
/*
|
|
720
|
+
Is this a leap year or not?
|
|
721
|
+
*/
|
|
722
|
+
isLeapYear(jy) {
|
|
723
|
+
return this.jalCal(jy).leap === 0;
|
|
724
|
+
}
|
|
725
|
+
/*
|
|
726
|
+
Number of days in a given month in a Jalaali year.
|
|
727
|
+
*/
|
|
728
|
+
monthLength(jy, jm) {
|
|
729
|
+
if (jm <= 6)
|
|
730
|
+
return 31;
|
|
731
|
+
if (jm <= 11)
|
|
732
|
+
return 30;
|
|
733
|
+
if (this.isLeapYear(jy))
|
|
734
|
+
return 30;
|
|
735
|
+
return 29;
|
|
736
|
+
}
|
|
737
|
+
jalCal(jy) {
|
|
738
|
+
// Jalaali years starting the 33-year rule.
|
|
739
|
+
let breaks = [-61, 9, 38, 199, 426, 686, 756, 818, 1111, 1181, 1210,
|
|
740
|
+
1635, 2060, 2097, 2192, 2262, 2324, 2394, 2456, 3178
|
|
741
|
+
], bl = breaks.length, gy = jy + 621, leapJ = -14, jp = breaks[0], jm, jump, leap, leapG, march, n, i;
|
|
742
|
+
if (jy < jp || jy >= breaks[bl - 1])
|
|
743
|
+
throw new Error('Invalid Jalaali year ' + jy);
|
|
744
|
+
// Find the limiting years for the Jalaali year jy.
|
|
745
|
+
for (i = 1; i < bl; i += 1) {
|
|
746
|
+
jm = breaks[i];
|
|
747
|
+
jump = jm - jp;
|
|
748
|
+
if (jy < jm)
|
|
749
|
+
break;
|
|
750
|
+
leapJ = leapJ + this.div(jump, 33) * 8 + this.div(this.mod(jump, 33), 4);
|
|
751
|
+
jp = jm;
|
|
752
|
+
}
|
|
753
|
+
n = jy - jp;
|
|
754
|
+
// Find the number of leap years from AD 621 to the beginning
|
|
755
|
+
// of the current Jalaali year in the Persian calendar.
|
|
756
|
+
leapJ = leapJ + this.div(n, 33) * 8 + this.div(this.mod(n, 33) + 3, 4);
|
|
757
|
+
if (this.mod(jump, 33) === 4 && jump - n === 4)
|
|
758
|
+
leapJ += 1;
|
|
759
|
+
// And the same in the Gregorian calendar (until the year gy).
|
|
760
|
+
leapG = this.div(gy, 4) - this.div((this.div(gy, 100) + 1) * 3, 4) - 150;
|
|
761
|
+
// Determine the Gregorian date of Farvardin the 1st.
|
|
762
|
+
march = 20 + leapJ - leapG;
|
|
763
|
+
// Find how many years have passed since the last leap year.
|
|
764
|
+
if (jump - n < 6)
|
|
765
|
+
n = n - jump + this.div(jump + 4, 33) * 33;
|
|
766
|
+
leap = this.mod(this.mod(n + 1, 33) - 1, 4);
|
|
767
|
+
if (leap === -1) {
|
|
768
|
+
leap = 4;
|
|
769
|
+
}
|
|
770
|
+
return {
|
|
771
|
+
leap: leap,
|
|
772
|
+
gy: gy,
|
|
773
|
+
march: march
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
/*
|
|
777
|
+
Converts a date of the Jalaali calendar to the Julian Day number.
|
|
778
|
+
@param jy Jalaali year (1 to 3100)
|
|
779
|
+
@param jm Jalaali month (1 to 12)
|
|
780
|
+
@param jd Jalaali day (1 to 29/31)
|
|
781
|
+
@return Julian Day number
|
|
782
|
+
*/
|
|
783
|
+
j2d(jy, jm, jd) {
|
|
784
|
+
let r = this.jalCal(jy);
|
|
785
|
+
return this.g2d(r.gy, 3, r.march) + (jm - 1) * 31 - this.div(jm, 7) * (jm - 7) + jd - 1;
|
|
786
|
+
}
|
|
787
|
+
/*
|
|
788
|
+
Converts the Julian Day number to a date in the Jalaali calendar.
|
|
789
|
+
@param jdn Julian Day number
|
|
790
|
+
@return
|
|
791
|
+
jy: Jalaali year (1 to 3100)
|
|
792
|
+
jm: Jalaali month (1 to 12)
|
|
793
|
+
jd: Jalaali day (1 to 29/31)
|
|
794
|
+
*/
|
|
795
|
+
d2j(jdn) {
|
|
796
|
+
let gy = this.d2g(jdn).gy // Calculate Gregorian year (gy).
|
|
797
|
+
, jy = gy - 621, r = this.jalCal(jy), jdn1f = this.g2d(gy, 3, r.march), jd, jm, k;
|
|
798
|
+
// Find number of days that passed since 1 Farvardin.
|
|
799
|
+
k = jdn - jdn1f;
|
|
800
|
+
if (k >= 0) {
|
|
801
|
+
if (k <= 185) {
|
|
802
|
+
// The first 6 months.
|
|
803
|
+
jm = 1 + this.div(k, 31);
|
|
804
|
+
jd = this.mod(k, 31) + 1;
|
|
805
|
+
return {
|
|
806
|
+
jy: jy,
|
|
807
|
+
jm: jm,
|
|
808
|
+
jd: jd
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
else {
|
|
812
|
+
// The remaining months.
|
|
813
|
+
k -= 186;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
else {
|
|
817
|
+
// Previous Jalaali year.
|
|
818
|
+
jy -= 1;
|
|
819
|
+
k += 179;
|
|
820
|
+
if (r.leap === 1)
|
|
821
|
+
k += 1;
|
|
822
|
+
}
|
|
823
|
+
jm = 7 + this.div(k, 30);
|
|
824
|
+
jd = this.mod(k, 30) + 1;
|
|
825
|
+
return {
|
|
826
|
+
jy: jy,
|
|
827
|
+
jm: jm,
|
|
828
|
+
jd: jd
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
g2d(gy, gm, gd) {
|
|
832
|
+
let d = this.div((gy + this.div(gm - 8, 6) + 100100) * 1461, 4)
|
|
833
|
+
+ this.div(153 * this.mod(gm + 9, 12) + 2, 5)
|
|
834
|
+
+ gd - 34840408;
|
|
835
|
+
d = d - this.div(this.div(gy + 100100 + this.div(gm - 8, 6), 100) * 3, 4) + 752;
|
|
836
|
+
return d;
|
|
837
|
+
}
|
|
838
|
+
d2g(jdn) {
|
|
839
|
+
let j, i, gd, gm, gy;
|
|
840
|
+
j = 4 * jdn + 139361631;
|
|
841
|
+
j = j + this.div(this.div(4 * jdn + 183187720, 146097) * 3, 4) * 4 - 3908;
|
|
842
|
+
i = this.div(this.mod(j, 1461), 4) * 5 + 308;
|
|
843
|
+
gd = this.div(this.mod(i, 153), 5) + 1;
|
|
844
|
+
gm = this.mod(this.div(i, 153), 12) + 1;
|
|
845
|
+
gy = this.div(j, 1461) - 100100 + this.div(8 - gm, 6);
|
|
846
|
+
return {
|
|
847
|
+
gy: gy,
|
|
848
|
+
gm: gm,
|
|
849
|
+
gd: gd
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
/*
|
|
853
|
+
Utility helper functions.
|
|
854
|
+
*/
|
|
855
|
+
div(a, b) {
|
|
856
|
+
return ~~(a / b);
|
|
857
|
+
}
|
|
858
|
+
mod(a, b) {
|
|
859
|
+
return a - ~~(a / b) * b;
|
|
860
|
+
}
|
|
858
861
|
}
|
|
859
862
|
|
|
860
|
-
class AXDateTimeModule {
|
|
861
|
-
constructor() {
|
|
862
|
-
AXConfig.set({
|
|
863
|
-
dateTime: {
|
|
864
|
-
calendars: {
|
|
865
|
-
jalali: {
|
|
866
|
-
"class": new JalaliCalendar(),
|
|
867
|
-
weekend: [6, 7]
|
|
868
|
-
},
|
|
869
|
-
gregorian: {
|
|
870
|
-
"class": new GeorgianCalendar(),
|
|
871
|
-
weekend: [7, 1]
|
|
872
|
-
}
|
|
873
|
-
},
|
|
874
|
-
calendar: 'gregorian',
|
|
875
|
-
shortDateFormat: 'DDDD, d MMM yyyy'
|
|
876
|
-
}
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
884
|
-
type: NgModule,
|
|
885
|
-
args: [{
|
|
886
|
-
imports: [],
|
|
887
|
-
exports: [AXDateTimePipe],
|
|
888
|
-
declarations: [AXDateTimePipe],
|
|
889
|
-
providers: [],
|
|
890
|
-
}]
|
|
863
|
+
class AXDateTimeModule {
|
|
864
|
+
constructor() {
|
|
865
|
+
AXConfig.set({
|
|
866
|
+
dateTime: {
|
|
867
|
+
calendars: {
|
|
868
|
+
jalali: {
|
|
869
|
+
"class": new JalaliCalendar(),
|
|
870
|
+
weekend: [6, 7]
|
|
871
|
+
},
|
|
872
|
+
gregorian: {
|
|
873
|
+
"class": new GeorgianCalendar(),
|
|
874
|
+
weekend: [7, 1]
|
|
875
|
+
}
|
|
876
|
+
},
|
|
877
|
+
calendar: 'gregorian',
|
|
878
|
+
shortDateFormat: 'DDDD, d MMM yyyy'
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: AXDateTimeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
883
|
+
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.0.0", ngImport: i0, type: AXDateTimeModule, declarations: [AXDateTimePipe], exports: [AXDateTimePipe] });
|
|
884
|
+
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: AXDateTimeModule });
|
|
885
|
+
}
|
|
886
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: AXDateTimeModule, decorators: [{
|
|
887
|
+
type: NgModule,
|
|
888
|
+
args: [{
|
|
889
|
+
imports: [],
|
|
890
|
+
exports: [AXDateTimePipe],
|
|
891
|
+
declarations: [AXDateTimePipe],
|
|
892
|
+
providers: [],
|
|
893
|
+
}]
|
|
891
894
|
}], ctorParameters: function () { return []; } });
|
|
892
895
|
|
|
893
|
-
/**
|
|
894
|
-
* Generated bundle index. Do not edit.
|
|
896
|
+
/**
|
|
897
|
+
* Generated bundle index. Do not edit.
|
|
895
898
|
*/
|
|
896
899
|
|
|
897
900
|
export { AXCalendarMonth, AXDateTime, AXDateTimeModule, AXDateTimePipe, AXDateTimeRange, GeorgianCalendar, JalaliCalendar };
|
|
898
901
|
//# sourceMappingURL=acorex-core-dateTime.mjs.map
|
|
899
|
-
//# sourceMappingURL=acorex-core-dateTime.mjs.map
|