@acorex/core 7.0.19 → 7.0.20
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/ax-preset.js +186 -0
- package/config/index.ts +1 -0
- package/config/ng-package.json +6 -0
- package/config/public-api.ts +1 -0
- package/config/src/configs.ts +37 -0
- package/dateTime/index.ts +1 -0
- package/dateTime/ng-package.json +6 -0
- package/dateTime/{public-api.d.ts → public-api.ts} +1 -1
- package/dateTime/src/datetime.class.ts +449 -0
- package/dateTime/src/datetime.module.ts +35 -0
- package/dateTime/src/datetime.pipe.ts +21 -0
- package/dateTime/src/georgian.calendar.ts +205 -0
- package/dateTime/src/jalali.calendar.ts +416 -0
- package/events/index.ts +1 -0
- package/events/ng-package.json +6 -0
- package/events/public-api.ts +1 -0
- package/events/src/event.service.ts +31 -0
- package/file/index.ts +1 -0
- package/file/ng-package.json +7 -0
- package/file/public-api.ts +4 -0
- package/file/src/file-download-ref.class.ts +16 -0
- package/file/src/file-download-result.class.ts +56 -0
- package/file/src/file-upload-ref.class.ts +14 -0
- package/file/src/file.service.ts +104 -0
- package/http/index.ts +1 -0
- package/http/ng-package.json +6 -0
- package/http/{public-api.d.ts → public-api.ts} +1 -1
- package/http/src/{http-error.class.d.ts → http-error.class.ts} +2 -2
- package/http/src/{http-events.interceptor.d.ts → http-events.interceptor.ts} +7 -3
- package/http/src/{http-request.class.d.ts → http-request.class.ts} +5 -5
- package/http/src/http-result.class.ts +34 -0
- package/http/src/http.module.ts +25 -0
- package/http/src/http.service.ts +161 -0
- package/image/index.ts +1 -0
- package/image/ng-package.json +7 -0
- package/image/public-api.ts +1 -0
- package/image/src/image.service.ts +42 -0
- package/index.ts +1 -0
- package/karma.conf.js +44 -0
- package/ng-package.json +7 -0
- package/package.json +16 -115
- package/pipes/index.ts +1 -0
- package/pipes/ng-package.json +6 -0
- package/pipes/public-api.ts +2 -0
- package/pipes/src/pipes.module.ts +11 -0
- package/pipes/src/safe.pipe.ts +24 -0
- package/platform/index.ts +1 -0
- package/platform/ng-package.json +6 -0
- package/platform/public-api.ts +1 -0
- package/platform/src/platform.service.ts +223 -0
- package/public-api.ts +4 -0
- package/test.ts +27 -0
- package/translation/index.ts +1 -0
- package/translation/ng-package.json +6 -0
- package/translation/{public-api.d.ts → public-api.ts} +1 -1
- package/translation/src/translation.module.ts +12 -0
- package/translation/src/translator.pipe.ts +9 -0
- package/translation/src/translator.ts +49 -0
- package/tsconfig.lib.json +15 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
- package/utils/index.ts +1 -0
- package/utils/ng-package.json +6 -0
- package/utils/{public-api.d.ts → public-api.ts} +1 -1
- package/utils/src/color-util.ts +83 -0
- package/utils/src/drawing-util.ts +43 -0
- package/utils/src/object-util.ts +82 -0
- package/utils/src/string-util.ts +25 -0
- package/config/index.d.ts +0 -5
- package/config/public-api.d.ts +0 -1
- package/config/src/configs.d.ts +0 -9
- package/dateTime/index.d.ts +0 -5
- package/dateTime/src/datetime.class.d.ts +0 -100
- package/dateTime/src/datetime.module.d.ts +0 -8
- package/dateTime/src/datetime.pipe.d.ts +0 -8
- package/dateTime/src/georgian.calendar.d.ts +0 -20
- package/dateTime/src/jalali.calendar.d.ts +0 -35
- package/esm2020/acorex-core.mjs +0 -5
- package/esm2020/config/acorex-core-config.mjs +0 -5
- package/esm2020/config/public-api.mjs +0 -2
- package/esm2020/config/src/configs.mjs +0 -32
- package/esm2020/dateTime/acorex-core-dateTime.mjs +0 -5
- package/esm2020/dateTime/public-api.mjs +0 -6
- 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/acorex-core-events.mjs +0 -5
- package/esm2020/events/public-api.mjs +0 -2
- package/esm2020/events/src/event.service.mjs +0 -36
- package/esm2020/file/acorex-core-file.mjs +0 -5
- package/esm2020/file/public-api.mjs +0 -5
- package/esm2020/file/src/file-download-ref.class.mjs +0 -12
- package/esm2020/file/src/file-download-result.class.mjs +0 -47
- package/esm2020/file/src/file-upload-ref.class.mjs +0 -12
- package/esm2020/file/src/file.service.mjs +0 -101
- package/esm2020/http/acorex-core-http.mjs +0 -5
- package/esm2020/http/public-api.mjs +0 -6
- package/esm2020/http/src/http-error.class.mjs +0 -2
- package/esm2020/http/src/http-events.interceptor.mjs +0 -3
- package/esm2020/http/src/http-request.class.mjs +0 -2
- 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/acorex-core-image.mjs +0 -5
- package/esm2020/image/public-api.mjs +0 -2
- package/esm2020/image/src/image.service.mjs +0 -43
- package/esm2020/pipes/acorex-core-pipes.mjs +0 -5
- package/esm2020/pipes/public-api.mjs +0 -3
- package/esm2020/pipes/src/pipes.module.mjs +0 -19
- package/esm2020/pipes/src/safe.pipe.mjs +0 -30
- package/esm2020/platform/acorex-core-platform.mjs +0 -5
- package/esm2020/platform/public-api.mjs +0 -2
- package/esm2020/platform/src/platform.service.mjs +0 -153
- package/esm2020/public-api.mjs +0 -5
- package/esm2020/translation/acorex-core-translation.mjs +0 -5
- package/esm2020/translation/public-api.mjs +0 -4
- 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/esm2020/utils/acorex-core-utils.mjs +0 -5
- package/esm2020/utils/public-api.mjs +0 -5
- package/esm2020/utils/src/color-util.mjs +0 -71
- package/esm2020/utils/src/drawing-util.mjs +0 -27
- package/esm2020/utils/src/object-util.mjs +0 -39
- package/esm2020/utils/src/string-util.mjs +0 -19
- package/events/index.d.ts +0 -5
- package/events/public-api.d.ts +0 -1
- package/events/src/event.service.d.ts +0 -9
- package/fesm2015/acorex-core-config.mjs +0 -40
- package/fesm2015/acorex-core-config.mjs.map +0 -1
- package/fesm2015/acorex-core-dateTime.mjs +0 -899
- 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 -177
- 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 +0 -54
- package/fesm2015/acorex-core-pipes.mjs.map +0 -1
- package/fesm2015/acorex-core-platform.mjs +0 -161
- 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 -164
- package/fesm2015/acorex-core-utils.mjs.map +0 -1
- package/fesm2015/acorex-core.mjs +0 -12
- package/fesm2015/acorex-core.mjs.map +0 -1
- package/fesm2020/acorex-core-config.mjs +0 -40
- package/fesm2020/acorex-core-config.mjs.map +0 -1
- package/fesm2020/acorex-core-dateTime.mjs +0 -899
- package/fesm2020/acorex-core-dateTime.mjs.map +0 -1
- package/fesm2020/acorex-core-events.mjs +0 -44
- package/fesm2020/acorex-core-events.mjs.map +0 -1
- package/fesm2020/acorex-core-file.mjs +0 -177
- package/fesm2020/acorex-core-file.mjs.map +0 -1
- package/fesm2020/acorex-core-http.mjs +0 -202
- package/fesm2020/acorex-core-http.mjs.map +0 -1
- package/fesm2020/acorex-core-image.mjs +0 -51
- package/fesm2020/acorex-core-image.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 +0 -161
- package/fesm2020/acorex-core-platform.mjs.map +0 -1
- package/fesm2020/acorex-core-translation.mjs +0 -80
- package/fesm2020/acorex-core-translation.mjs.map +0 -1
- package/fesm2020/acorex-core-utils.mjs +0 -164
- 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/file/index.d.ts +0 -5
- package/file/public-api.d.ts +0 -4
- package/file/src/file-download-ref.class.d.ts +0 -6
- package/file/src/file-download-result.class.d.ts +0 -8
- package/file/src/file-upload-ref.class.d.ts +0 -5
- package/file/src/file.service.d.ts +0 -18
- package/http/index.d.ts +0 -5
- package/http/src/http-result.class.d.ts +0 -11
- package/http/src/http.module.d.ts +0 -8
- package/http/src/http.service.d.ts +0 -23
- package/image/index.d.ts +0 -5
- package/image/public-api.d.ts +0 -1
- package/image/src/image.service.d.ts +0 -12
- package/index.d.ts +0 -5
- package/pipes/index.d.ts +0 -5
- package/pipes/public-api.d.ts +0 -2
- package/pipes/src/pipes.module.d.ts +0 -8
- package/pipes/src/safe.pipe.d.ts +0 -10
- package/platform/index.d.ts +0 -5
- package/platform/public-api.d.ts +0 -1
- package/platform/src/platform.service.d.ts +0 -26
- package/public-api.d.ts +0 -1
- package/translation/index.d.ts +0 -5
- package/translation/src/translation.module.d.ts +0 -7
- package/translation/src/translator.d.ts +0 -11
- package/translation/src/translator.pipe.d.ts +0 -7
- package/utils/index.d.ts +0 -5
- package/utils/src/color-util.d.ts +0 -20
- package/utils/src/drawing-util.d.ts +0 -17
- package/utils/src/object-util.d.ts +0 -4
- package/utils/src/string-util.d.ts +0 -6
@@ -0,0 +1,416 @@
|
|
1
|
+
import { AXCalendar, AXDateTime, AXDateValue, TimeUnit } from "./datetime.class";
|
2
|
+
|
3
|
+
export class JalaliCalendar implements AXCalendar {
|
4
|
+
|
5
|
+
monthNames = ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_");
|
6
|
+
|
7
|
+
monthShortNames = ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_");
|
8
|
+
|
9
|
+
dayNames = ("شنبه_یکشنبه_دوشنبه_سه شنبه_چهارشنبه_پنج شنبه_جمعه").split("_");
|
10
|
+
|
11
|
+
dayShortNames = "ش_ی_د_س_چ_پ_ج".split("_");
|
12
|
+
|
13
|
+
|
14
|
+
create(value: AXDateValue): AXDateTime {
|
15
|
+
const a = this.toGregorian(value.year, value.month, value.date);
|
16
|
+
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());
|
17
|
+
}
|
18
|
+
|
19
|
+
name(): string {
|
20
|
+
return 'jalali'
|
21
|
+
}
|
22
|
+
|
23
|
+
dayOfMonth(date: Date): number {
|
24
|
+
return this.toJalali(date).day;
|
25
|
+
}
|
26
|
+
|
27
|
+
dayOfYear(date: Date): number {
|
28
|
+
const j = this.toJalali(date);
|
29
|
+
return (j.month <= 6 ? ((j.month - 1) * 31) : ((6 * 31) + (j.month - 7) * 30)) + j.day;
|
30
|
+
}
|
31
|
+
|
32
|
+
dayOfWeek(date: Date): number {
|
33
|
+
return date.getDay() == 6 ? 1 : date.getDay() + 2;
|
34
|
+
}
|
35
|
+
|
36
|
+
weekOfYear(date: Date): number {
|
37
|
+
//TODO : apply jalali
|
38
|
+
const firstDay = new AXDateTime(date).startOf('year');
|
39
|
+
return Math.ceil((((date.getTime() - firstDay.date.getTime()) / 86400000) + firstDay.date.getDay() + 1) / 7);
|
40
|
+
}
|
41
|
+
|
42
|
+
year(date: Date): number {
|
43
|
+
return this.toJalali(date).year;
|
44
|
+
}
|
45
|
+
|
46
|
+
monthOfYear(date: Date): number {
|
47
|
+
return this.toJalali(date).month;
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
add(date: Date, unit: TimeUnit, amount: number): AXDateTime {
|
52
|
+
let value = date.valueOf();
|
53
|
+
switch (unit) {
|
54
|
+
case 'second':
|
55
|
+
value += 1000 * amount;
|
56
|
+
break
|
57
|
+
case 'minute':
|
58
|
+
value += 60000 * amount;
|
59
|
+
break
|
60
|
+
case 'hour':
|
61
|
+
value += 3600000 * amount;
|
62
|
+
break
|
63
|
+
case 'month':
|
64
|
+
{
|
65
|
+
const v = new Date(value);
|
66
|
+
let jd = this.dayOfMonth(date);
|
67
|
+
let jm = this.monthOfYear(date);
|
68
|
+
let jy = this.year(date);
|
69
|
+
const nm = (jm + amount);
|
70
|
+
const ny = (nm % 12) ? Math.floor(nm / 12) : 0;
|
71
|
+
jy += ny;
|
72
|
+
jm = nm - (ny * 12);
|
73
|
+
const vv = this.toGregorian(jy, jm, jd);
|
74
|
+
v.setFullYear(vv.getFullYear());
|
75
|
+
v.setMonth(vv.getMonth());
|
76
|
+
v.setDate(vv.getDate());
|
77
|
+
value = v.valueOf();
|
78
|
+
break
|
79
|
+
}
|
80
|
+
case 'week':
|
81
|
+
value += 7 * 86400000 * amount;
|
82
|
+
break
|
83
|
+
case 'year':
|
84
|
+
{
|
85
|
+
// const v = new Date(value);
|
86
|
+
// v.setFullYear(v.getFullYear() + amount);
|
87
|
+
// value = v.valueOf();
|
88
|
+
// break
|
89
|
+
const v = new Date(value);
|
90
|
+
let jd = this.dayOfMonth(date);
|
91
|
+
let jm = this.monthOfYear(date);
|
92
|
+
let jy = this.year(date);
|
93
|
+
const vv = this.toGregorian(jy + amount, jm, jd);
|
94
|
+
v.setFullYear(vv.getFullYear());
|
95
|
+
v.setMonth(vv.getMonth());
|
96
|
+
v.setDate(vv.getDate());
|
97
|
+
value = v.valueOf();
|
98
|
+
break
|
99
|
+
}
|
100
|
+
case 'day':
|
101
|
+
default:
|
102
|
+
value += 86400000 * amount;
|
103
|
+
}
|
104
|
+
return new AXDateTime(new Date(value), this.name());
|
105
|
+
}
|
106
|
+
|
107
|
+
set(date: Date, unit: TimeUnit, value: number): AXDateTime {
|
108
|
+
const clone = new Date(date.valueOf());
|
109
|
+
const jDate = this.toJalali(clone);
|
110
|
+
switch (unit) {
|
111
|
+
case 'second':
|
112
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), value, clone.getMilliseconds());
|
113
|
+
break;
|
114
|
+
case 'minute':
|
115
|
+
clone.setHours(clone.getHours(), value, clone.getSeconds(), clone.getMilliseconds());
|
116
|
+
break;
|
117
|
+
case 'hour':
|
118
|
+
clone.setHours(value, clone.getMinutes(), clone.getSeconds(), clone.getMilliseconds());
|
119
|
+
break;
|
120
|
+
default:
|
121
|
+
case 'day':
|
122
|
+
const gDate = this.toGregorian(jDate.year, jDate.month, value);
|
123
|
+
clone.setDate(gDate.getDate());
|
124
|
+
break;
|
125
|
+
case "week":
|
126
|
+
break;
|
127
|
+
case "month":
|
128
|
+
const gDate2 = this.toGregorian(jDate.year, value, jDate.day);
|
129
|
+
clone.setMonth(gDate2.getMonth());
|
130
|
+
break;
|
131
|
+
case "year":
|
132
|
+
const gDate3 = this.toGregorian(value, jDate.month, jDate.day);
|
133
|
+
clone.setFullYear(gDate3.getFullYear());
|
134
|
+
break;
|
135
|
+
}
|
136
|
+
return new AXDateTime(clone, this.name());
|
137
|
+
}
|
138
|
+
|
139
|
+
startOf(date: Date, unit: TimeUnit): AXDateTime {
|
140
|
+
const clone = new Date(date.valueOf());
|
141
|
+
switch (unit) {
|
142
|
+
case 'second':
|
143
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 0);
|
144
|
+
return new AXDateTime(clone, this.name());
|
145
|
+
case 'minute':
|
146
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), 0, 0);
|
147
|
+
return new AXDateTime(clone, this.name());
|
148
|
+
case 'hour':
|
149
|
+
clone.setHours(clone.getHours(), 0, 0, 0);
|
150
|
+
return new AXDateTime(clone, this.name());
|
151
|
+
default:
|
152
|
+
case 'day':
|
153
|
+
clone.setHours(0, 0, 0, 0);
|
154
|
+
return new AXDateTime(clone, this.name());
|
155
|
+
case "week":
|
156
|
+
return new AXDateTime(clone, this.name()).add('day', -this.dayOfWeek(clone) + 1).startOf('day');
|
157
|
+
case "month":
|
158
|
+
{
|
159
|
+
const jy = this.year(date);
|
160
|
+
const jm = this.monthOfYear(date);
|
161
|
+
const gDate = this.toGregorian(jy, jm, 1);
|
162
|
+
return new AXDateTime(gDate, this.name()).startOf('day');
|
163
|
+
}
|
164
|
+
case "year":
|
165
|
+
{
|
166
|
+
const jy = this.year(date);
|
167
|
+
const gDate = this.toGregorian(jy, 1, 1);
|
168
|
+
return new AXDateTime(gDate, this.name()).startOf('day');
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
endOf(date: Date, unit: TimeUnit): AXDateTime {
|
174
|
+
const clone = new Date(date.valueOf());
|
175
|
+
switch (unit) {
|
176
|
+
case 'second':
|
177
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 999);
|
178
|
+
return new AXDateTime(clone, this.name());
|
179
|
+
case 'minute':
|
180
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), 59, 999);
|
181
|
+
return new AXDateTime(clone, this.name());
|
182
|
+
case 'hour':
|
183
|
+
clone.setHours(clone.getHours(), 59, 59, 999);
|
184
|
+
return new AXDateTime(clone, this.name());
|
185
|
+
default:
|
186
|
+
case 'day':
|
187
|
+
clone.setHours(23, 59, 59, 999);
|
188
|
+
return new AXDateTime(clone, this.name());
|
189
|
+
case 'week':
|
190
|
+
{
|
191
|
+
return this.startOf(date, 'week').add('day', 6).endOf('day');
|
192
|
+
}
|
193
|
+
case 'month':
|
194
|
+
{
|
195
|
+
const jy = this.year(date);
|
196
|
+
const jm = this.monthOfYear(date);
|
197
|
+
const jd = this.monthLength(jy, jm);
|
198
|
+
const gDate = this.toGregorian(jy, jm, jd);
|
199
|
+
return new AXDateTime(gDate, this.name()).endOf('day');
|
200
|
+
}
|
201
|
+
case "year":
|
202
|
+
let jy = this.year(date);
|
203
|
+
const gDate = this.toGregorian(jy, 12, this.monthLength(jy, 12));
|
204
|
+
return new AXDateTime(gDate, this.name()).endOf('day');
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
toJalali(date: Date): { year: number, month: number, day: number } {
|
211
|
+
const gy = date.getFullYear();
|
212
|
+
const gm = date.getMonth() + 1;
|
213
|
+
const gd = date.getDate();
|
214
|
+
const r = this.d2j(this.g2d(gy, gm, gd))
|
215
|
+
return {
|
216
|
+
year: r.jy,
|
217
|
+
month: r.jm,
|
218
|
+
day: r.jd,
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
/*
|
223
|
+
Converts a Jalaali date to Gregorian.
|
224
|
+
*/
|
225
|
+
toGregorian(jy, jm, jd) {
|
226
|
+
const g = this.d2g(this.j2d(jy, jm, jd))
|
227
|
+
return new Date(g.gy, g.gm - 1, g.gd);
|
228
|
+
}
|
229
|
+
|
230
|
+
/*
|
231
|
+
Checks whether a Jalaali date is valid or not.
|
232
|
+
*/
|
233
|
+
isValid(jy, jm, jd) {
|
234
|
+
return jy >= -61 && jy <= 3177 &&
|
235
|
+
jm >= 1 && jm <= 12 &&
|
236
|
+
jd >= 1 && jd <= this.monthLength(jy, jm)
|
237
|
+
}
|
238
|
+
|
239
|
+
/*
|
240
|
+
Is this a leap year or not?
|
241
|
+
*/
|
242
|
+
isLeapYear(jy) {
|
243
|
+
return this.jalCal(jy).leap === 0
|
244
|
+
}
|
245
|
+
|
246
|
+
/*
|
247
|
+
Number of days in a given month in a Jalaali year.
|
248
|
+
*/
|
249
|
+
monthLength(jy, jm) {
|
250
|
+
if (jm <= 6) return 31
|
251
|
+
if (jm <= 11) return 30
|
252
|
+
if (this.isLeapYear(jy)) return 30
|
253
|
+
return 29
|
254
|
+
}
|
255
|
+
|
256
|
+
|
257
|
+
private jalCal(jy) {
|
258
|
+
// Jalaali years starting the 33-year rule.
|
259
|
+
let breaks = [-61, 9, 38, 199, 426, 686, 756, 818, 1111, 1181, 1210
|
260
|
+
, 1635, 2060, 2097, 2192, 2262, 2324, 2394, 2456, 3178
|
261
|
+
]
|
262
|
+
, bl = breaks.length
|
263
|
+
, gy = jy + 621
|
264
|
+
, leapJ = -14
|
265
|
+
, jp = breaks[0]
|
266
|
+
, jm
|
267
|
+
, jump
|
268
|
+
, leap
|
269
|
+
, leapG
|
270
|
+
, march
|
271
|
+
, n
|
272
|
+
, i
|
273
|
+
|
274
|
+
if (jy < jp || jy >= breaks[bl - 1])
|
275
|
+
throw new Error('Invalid Jalaali year ' + jy)
|
276
|
+
|
277
|
+
// Find the limiting years for the Jalaali year jy.
|
278
|
+
for (i = 1; i < bl; i += 1) {
|
279
|
+
jm = breaks[i]
|
280
|
+
jump = jm - jp
|
281
|
+
if (jy < jm)
|
282
|
+
break
|
283
|
+
leapJ = leapJ + this.div(jump, 33) * 8 + this.div(this.mod(jump, 33), 4)
|
284
|
+
jp = jm
|
285
|
+
}
|
286
|
+
n = jy - jp
|
287
|
+
|
288
|
+
// Find the number of leap years from AD 621 to the beginning
|
289
|
+
// of the current Jalaali year in the Persian calendar.
|
290
|
+
leapJ = leapJ + this.div(n, 33) * 8 + this.div(this.mod(n, 33) + 3, 4)
|
291
|
+
if (this.mod(jump, 33) === 4 && jump - n === 4)
|
292
|
+
leapJ += 1
|
293
|
+
|
294
|
+
// And the same in the Gregorian calendar (until the year gy).
|
295
|
+
leapG = this.div(gy, 4) - this.div((this.div(gy, 100) + 1) * 3, 4) - 150
|
296
|
+
|
297
|
+
// Determine the Gregorian date of Farvardin the 1st.
|
298
|
+
march = 20 + leapJ - leapG
|
299
|
+
|
300
|
+
// Find how many years have passed since the last leap year.
|
301
|
+
if (jump - n < 6)
|
302
|
+
n = n - jump + this.div(jump + 4, 33) * 33
|
303
|
+
leap = this.mod(this.mod(n + 1, 33) - 1, 4)
|
304
|
+
if (leap === -1) {
|
305
|
+
leap = 4
|
306
|
+
}
|
307
|
+
|
308
|
+
return {
|
309
|
+
leap: leap
|
310
|
+
, gy: gy
|
311
|
+
, march: march
|
312
|
+
}
|
313
|
+
}
|
314
|
+
|
315
|
+
/*
|
316
|
+
Converts a date of the Jalaali calendar to the Julian Day number.
|
317
|
+
@param jy Jalaali year (1 to 3100)
|
318
|
+
@param jm Jalaali month (1 to 12)
|
319
|
+
@param jd Jalaali day (1 to 29/31)
|
320
|
+
@return Julian Day number
|
321
|
+
*/
|
322
|
+
private j2d(jy, jm, jd) {
|
323
|
+
let r = this.jalCal(jy)
|
324
|
+
return this.g2d(r.gy, 3, r.march) + (jm - 1) * 31 - this.div(jm, 7) * (jm - 7) + jd - 1
|
325
|
+
}
|
326
|
+
|
327
|
+
/*
|
328
|
+
Converts the Julian Day number to a date in the Jalaali calendar.
|
329
|
+
@param jdn Julian Day number
|
330
|
+
@return
|
331
|
+
jy: Jalaali year (1 to 3100)
|
332
|
+
jm: Jalaali month (1 to 12)
|
333
|
+
jd: Jalaali day (1 to 29/31)
|
334
|
+
*/
|
335
|
+
private d2j(jdn) {
|
336
|
+
let gy = this.d2g(jdn).gy // Calculate Gregorian year (gy).
|
337
|
+
, jy = gy - 621
|
338
|
+
, r = this.jalCal(jy)
|
339
|
+
, jdn1f = this.g2d(gy, 3, r.march)
|
340
|
+
, jd
|
341
|
+
, jm
|
342
|
+
, k
|
343
|
+
|
344
|
+
// Find number of days that passed since 1 Farvardin.
|
345
|
+
k = jdn - jdn1f
|
346
|
+
if (k >= 0) {
|
347
|
+
if (k <= 185) {
|
348
|
+
// The first 6 months.
|
349
|
+
jm = 1 + this.div(k, 31)
|
350
|
+
jd = this.mod(k, 31) + 1
|
351
|
+
return {
|
352
|
+
jy: jy
|
353
|
+
, jm: jm
|
354
|
+
, jd: jd
|
355
|
+
}
|
356
|
+
} else {
|
357
|
+
// The remaining months.
|
358
|
+
k -= 186
|
359
|
+
}
|
360
|
+
} else {
|
361
|
+
// Previous Jalaali year.
|
362
|
+
jy -= 1
|
363
|
+
k += 179
|
364
|
+
if (r.leap === 1)
|
365
|
+
k += 1
|
366
|
+
}
|
367
|
+
jm = 7 + this.div(k, 30)
|
368
|
+
jd = this.mod(k, 30) + 1
|
369
|
+
return {
|
370
|
+
jy: jy
|
371
|
+
, jm: jm
|
372
|
+
, jd: jd
|
373
|
+
}
|
374
|
+
}
|
375
|
+
|
376
|
+
|
377
|
+
private g2d(gy, gm, gd) {
|
378
|
+
let d = this.div((gy + this.div(gm - 8, 6) + 100100) * 1461, 4)
|
379
|
+
+ this.div(153 * this.mod(gm + 9, 12) + 2, 5)
|
380
|
+
+ gd - 34840408
|
381
|
+
d = d - this.div(this.div(gy + 100100 + this.div(gm - 8, 6), 100) * 3, 4) + 752
|
382
|
+
return d
|
383
|
+
}
|
384
|
+
|
385
|
+
|
386
|
+
private d2g(jdn) {
|
387
|
+
let j
|
388
|
+
, i
|
389
|
+
, gd
|
390
|
+
, gm
|
391
|
+
, gy
|
392
|
+
j = 4 * jdn + 139361631
|
393
|
+
j = j + this.div(this.div(4 * jdn + 183187720, 146097) * 3, 4) * 4 - 3908
|
394
|
+
i = this.div(this.mod(j, 1461), 4) * 5 + 308
|
395
|
+
gd = this.div(this.mod(i, 153), 5) + 1
|
396
|
+
gm = this.mod(this.div(i, 153), 12) + 1
|
397
|
+
gy = this.div(j, 1461) - 100100 + this.div(8 - gm, 6)
|
398
|
+
return {
|
399
|
+
gy: gy
|
400
|
+
, gm: gm
|
401
|
+
, gd: gd
|
402
|
+
}
|
403
|
+
}
|
404
|
+
|
405
|
+
/*
|
406
|
+
Utility helper functions.
|
407
|
+
*/
|
408
|
+
private div(a, b) {
|
409
|
+
return ~~(a / b)
|
410
|
+
}
|
411
|
+
|
412
|
+
private mod(a, b) {
|
413
|
+
return a - ~~(a / b) * b
|
414
|
+
}
|
415
|
+
|
416
|
+
}
|
package/events/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './public-api'
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './src/event.service';
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { Injectable } from '@angular/core';
|
2
|
+
|
3
|
+
@Injectable({ providedIn: 'root' })
|
4
|
+
export class AXEventService {
|
5
|
+
private list: any[] = [];
|
6
|
+
|
7
|
+
public broadcast(key: string, options?: any): void {
|
8
|
+
const d = this.list.find(c => c.key === key);
|
9
|
+
if (d) {
|
10
|
+
d.events.forEach((c:any) => {
|
11
|
+
c(options);
|
12
|
+
});
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
public on(key: string, callback: (options?: any) => void) {
|
17
|
+
let d = this.list.find(c => c.key === key);
|
18
|
+
if (!d) {
|
19
|
+
d = { key, events: [] };
|
20
|
+
this.list.push(d);
|
21
|
+
}
|
22
|
+
d.events.push(callback);
|
23
|
+
}
|
24
|
+
|
25
|
+
public destroy(key: string, callback: (options?: any) => void): void {
|
26
|
+
const d = this.list.find(c => c.key === key);
|
27
|
+
if (d) {
|
28
|
+
d.events = [];
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
package/file/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './public-api';
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { AXFileDownloadResult } from "./file-download-result.class";
|
2
|
+
|
3
|
+
export class AXFileDownloadRef extends Promise<AXFileDownloadResult>
|
4
|
+
{
|
5
|
+
public abortMethod: () => void;
|
6
|
+
constructor(executor: (resolve: (value?: PromiseLike<AXFileDownloadResult>) => void, reject: (reason?: any) => void) => void) {
|
7
|
+
super(executor);
|
8
|
+
|
9
|
+
}
|
10
|
+
//abort the operation
|
11
|
+
public abort() {
|
12
|
+
if (this.abortMethod) {
|
13
|
+
this.abortMethod();
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
export class AXFileDownloadResult {
|
2
|
+
|
3
|
+
_response: Blob;
|
4
|
+
|
5
|
+
constructor(response: Blob) {
|
6
|
+
this._response = response;
|
7
|
+
}
|
8
|
+
|
9
|
+
save(filename?: string): Promise<void> {
|
10
|
+
this._defaultBrowserDownload(filename);
|
11
|
+
return Promise.resolve();
|
12
|
+
// else {
|
13
|
+
// return new Promise((resolve, reject) => {
|
14
|
+
// const button = document.createElement("button");
|
15
|
+
// button.addEventListener('click', async () => {
|
16
|
+
// debugger
|
17
|
+
// button.remove();
|
18
|
+
// const opts = {
|
19
|
+
// types: [{
|
20
|
+
// description: 'Save File',
|
21
|
+
// suggestedName: filename
|
22
|
+
// // accept: {'text/plain': ['.txt']},
|
23
|
+
// }],
|
24
|
+
// };
|
25
|
+
// const result = await window['showSaveFilePicker'](opts);
|
26
|
+
// console.log(result);
|
27
|
+
|
28
|
+
// resolve();
|
29
|
+
// });
|
30
|
+
// button.click();
|
31
|
+
// });
|
32
|
+
|
33
|
+
// }
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
blob() {
|
38
|
+
return this._response;
|
39
|
+
}
|
40
|
+
|
41
|
+
base64(): Promise<string> {
|
42
|
+
return new Promise((resolve, reject) => {
|
43
|
+
var reader = new window.FileReader();
|
44
|
+
reader.onloadend = () => resolve(reader.result as string);
|
45
|
+
reader.onerror = (e) => reject(e);
|
46
|
+
reader.readAsDataURL(this._response);
|
47
|
+
})
|
48
|
+
}
|
49
|
+
|
50
|
+
private _defaultBrowserDownload(filename: string = 'download') {
|
51
|
+
const link = document.createElement("a");
|
52
|
+
link.href = URL.createObjectURL(this._response);
|
53
|
+
link.download = filename;
|
54
|
+
link.click();
|
55
|
+
}
|
56
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
export class AXFileUploadRef<T = any> extends Promise<T>
|
2
|
+
{
|
3
|
+
public abortMethod: () => void;
|
4
|
+
constructor(executor: (resolve: (value?: PromiseLike<T>) => void, reject: (reason?: any) => void) => void) {
|
5
|
+
super(executor);
|
6
|
+
|
7
|
+
}
|
8
|
+
//abort the operation
|
9
|
+
public abort() {
|
10
|
+
if (this.abortMethod) {
|
11
|
+
this.abortMethod();
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,104 @@
|
|
1
|
+
import { HttpClient, HttpContext, HttpHeaders, HttpParams } from '@angular/common/http';
|
2
|
+
import { Injectable } from '@angular/core';
|
3
|
+
import { Observable, Subscription } from 'rxjs';
|
4
|
+
import { AXFileDownloadRef } from './file-download-ref.class';
|
5
|
+
import { AXFileDownloadResult } from './file-download-result.class';
|
6
|
+
import { AXFileUploadRef } from './file-upload-ref.class';
|
7
|
+
|
8
|
+
|
9
|
+
@Injectable({ providedIn: 'root' })
|
10
|
+
export class AXFileService {
|
11
|
+
constructor(private _httpClient: HttpClient) { }
|
12
|
+
|
13
|
+
public download(request: string | Observable<Blob>): AXFileDownloadRef {
|
14
|
+
let s: Subscription;
|
15
|
+
const promiseFunc = (resolve, reject) => {
|
16
|
+
//TODO: add custome http request
|
17
|
+
//const headers = new HttpHeaders().set('authorization','Bearer '+token);
|
18
|
+
let b: Observable<Blob>;
|
19
|
+
if (typeof request === 'string') {
|
20
|
+
b = this._httpClient.get(request, { responseType: 'blob' });
|
21
|
+
}
|
22
|
+
else if (b instanceof Observable<Blob>) {
|
23
|
+
b = request;
|
24
|
+
}
|
25
|
+
s = b?.subscribe({
|
26
|
+
next: (v) => resolve(new AXFileDownloadResult(v)),
|
27
|
+
error: (e) => reject(e)
|
28
|
+
})
|
29
|
+
};
|
30
|
+
|
31
|
+
const a = new AXFileDownloadRef(promiseFunc);
|
32
|
+
a.abort = () => {
|
33
|
+
s?.unsubscribe();
|
34
|
+
};
|
35
|
+
|
36
|
+
return a;
|
37
|
+
}
|
38
|
+
|
39
|
+
public upload<T = any>(url: string, files: File[]): AXFileUploadRef<T> {
|
40
|
+
let s: Subscription;
|
41
|
+
let formData = new FormData();
|
42
|
+
files.forEach(f => {
|
43
|
+
formData.append("files", f);
|
44
|
+
})
|
45
|
+
const promiseFunc = (resolve, reject) => {
|
46
|
+
let b: Observable<T>;
|
47
|
+
b = this._httpClient.post<T>(url, formData);
|
48
|
+
|
49
|
+
s = b?.subscribe({
|
50
|
+
next: (v) => resolve(v),
|
51
|
+
error: (e) => reject(e)
|
52
|
+
})
|
53
|
+
};
|
54
|
+
|
55
|
+
const a = new AXFileUploadRef(promiseFunc);
|
56
|
+
a.abort = () => {
|
57
|
+
s?.unsubscribe();
|
58
|
+
};
|
59
|
+
return a;
|
60
|
+
}
|
61
|
+
|
62
|
+
public choose(options?: { accept?: string, multiple?: boolean }): Promise<File[]> {
|
63
|
+
return new Promise<File[]>((resolve, reject) => {
|
64
|
+
options = Object.assign({ multiple: false }, options);
|
65
|
+
const input = document.createElement("input");
|
66
|
+
input.style.display = 'none';
|
67
|
+
document.body.appendChild(input);
|
68
|
+
input.type = 'file';
|
69
|
+
input.accept = options.accept;
|
70
|
+
input.multiple = options.multiple;
|
71
|
+
//
|
72
|
+
const onError = (e) => {
|
73
|
+
reject(e);
|
74
|
+
document.body.removeChild(input)
|
75
|
+
input.remove();
|
76
|
+
input.removeEventListener('change', onChange);
|
77
|
+
input.removeEventListener('error', onError);
|
78
|
+
}
|
79
|
+
//
|
80
|
+
const onChange = () => {
|
81
|
+
resolve(Array.from(input.files));
|
82
|
+
document.body.removeChild(input)
|
83
|
+
input.remove();
|
84
|
+
input.removeEventListener('change', onChange);
|
85
|
+
input.removeEventListener('error', onError);
|
86
|
+
}
|
87
|
+
//
|
88
|
+
input.addEventListener('change', onChange);
|
89
|
+
input.addEventListener('error', onError);
|
90
|
+
input.click();
|
91
|
+
});
|
92
|
+
}
|
93
|
+
|
94
|
+
blobToBase64 = (blob: Blob) => new Promise<string>((resolve, reject) => {
|
95
|
+
const reader = new FileReader;
|
96
|
+
reader.onerror = reject;
|
97
|
+
reader.onload = () => {
|
98
|
+
resolve(reader.result as string);
|
99
|
+
};
|
100
|
+
reader.readAsDataURL(blob);
|
101
|
+
});
|
102
|
+
}
|
103
|
+
|
104
|
+
|
package/http/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './public-api'
|