@acorex/core 5.0.0 → 5.0.5
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/karma.conf.js +44 -0
- package/ng-package.json +11 -0
- package/package.json +14 -18
- package/src/lib/config/configs.ts +36 -0
- package/src/lib/core.module.ts +10 -0
- package/src/lib/dateTime/datetime.class.ts +395 -0
- package/src/lib/dateTime/datetime.module.ts +11 -0
- package/src/lib/dateTime/datetime.pipe.ts +20 -0
- package/src/lib/dateTime/georgian.calendar.ts +157 -0
- package/{lib/dateTime/index.d.ts → src/lib/dateTime/index.ts} +1 -1
- package/src/lib/dateTime/jalali.calendar.ts +376 -0
- package/src/lib/http/http-error.class.ts +7 -0
- package/src/lib/http/http-events.interceptor.ts +14 -0
- package/src/lib/http/http-request.class.ts +14 -0
- package/src/lib/http/http-result.class.ts +34 -0
- package/src/lib/http/http.module.ts +25 -0
- package/src/lib/http/http.service.ts +159 -0
- package/src/lib/platform/index.ts +1 -0
- package/src/lib/platform/platform.service.ts +185 -0
- package/{lib/translation/index.d.ts → src/lib/translation/index.ts} +1 -1
- package/src/lib/translation/translation.module.ts +12 -0
- package/src/lib/translation/translator.pipe.ts +9 -0
- package/src/lib/translation/translator.ts +31 -0
- package/src/lib/utils/drawing-util.ts +43 -0
- package/src/lib/utils/index.ts +3 -0
- package/src/lib/utils/object-util.ts +82 -0
- package/src/lib/utils/safe.pipe.ts +24 -0
- package/src/public-api.ts +11 -0
- package/src/test.ts +26 -0
- package/tsconfig.lib.json +20 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
- package/acorex-core.d.ts +0 -5
- package/bundles/acorex-core.umd.js +0 -822
- package/bundles/acorex-core.umd.js.map +0 -1
- package/esm2015/acorex-core.js +0 -5
- package/esm2015/lib/config/configs.js +0 -29
- package/esm2015/lib/dateTime/datetime.class.js +0 -226
- package/esm2015/lib/dateTime/datetime.module.js +0 -18
- package/esm2015/lib/dateTime/datetime.pipe.js +0 -25
- package/esm2015/lib/dateTime/georgian.calendar.js +0 -145
- package/esm2015/lib/dateTime/index.js +0 -5
- package/esm2015/lib/platform/index.js +0 -2
- package/esm2015/lib/platform/platform.service.js +0 -105
- package/esm2015/lib/translation/index.js +0 -4
- package/esm2015/lib/translation/translation.module.js +0 -18
- package/esm2015/lib/translation/translator.js +0 -26
- package/esm2015/lib/translation/translator.pipe.js +0 -15
- package/esm2015/lib/utils/object-util.js +0 -83
- package/esm2015/public-api.js +0 -6
- package/fesm2015/acorex-core.js +0 -679
- package/fesm2015/acorex-core.js.map +0 -1
- package/lib/config/configs.d.ts +0 -9
- package/lib/dateTime/datetime.class.d.ts +0 -83
- package/lib/dateTime/datetime.module.d.ts +0 -7
- package/lib/dateTime/datetime.pipe.d.ts +0 -8
- package/lib/dateTime/georgian.calendar.d.ts +0 -17
- package/lib/platform/index.d.ts +0 -1
- package/lib/platform/platform.service.d.ts +0 -20
- package/lib/translation/translation.module.d.ts +0 -7
- package/lib/translation/translator.d.ts +0 -9
- package/lib/translation/translator.pipe.d.ts +0 -7
- package/lib/utils/object-util.d.ts +0 -7
- package/public-api.d.ts +0 -5
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { AXCalendar, AXDateTime, TimeUnit } from "./datetime.class";
|
|
2
|
+
|
|
3
|
+
export class GeorgianCalendar implements AXCalendar {
|
|
4
|
+
|
|
5
|
+
monthNames = [
|
|
6
|
+
"January", "February", "March",
|
|
7
|
+
"April", "May", "June", "July",
|
|
8
|
+
"August", "September", "October",
|
|
9
|
+
"November", "December"
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
monthShortNames = [
|
|
13
|
+
"Jan", "Feb", "Mar",
|
|
14
|
+
"Apr", "May", "Jun", "Jul",
|
|
15
|
+
"Aug", "Sep", "Oct",
|
|
16
|
+
"Nov", "Dec"
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
dayNames = [
|
|
20
|
+
"Sunday", "Monday", "Tuesday", "Wednesday",
|
|
21
|
+
"Thursday", "Friday", "Saturday"
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
dayShortNames = [
|
|
25
|
+
"Sun", "Mon", "Tue", "Wed",
|
|
26
|
+
"Thu", "Fri", "Sat"
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
name(): string {
|
|
30
|
+
return 'gregorian'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
dayInMonth(date: Date): number {
|
|
34
|
+
return date.getDate();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
dayOfYear(date: Date): number {
|
|
38
|
+
const start = +new Date(date.getFullYear(), 0, 0);
|
|
39
|
+
const diff = +date - start;
|
|
40
|
+
const oneDay = 1000 * 60 * 60 * 24;
|
|
41
|
+
return Math.floor(diff / oneDay);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
dayInWeek(date: Date): number {
|
|
45
|
+
return date.getDay() + 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
year(date: Date): number {
|
|
49
|
+
return date.getFullYear();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
monthOfYear(date: Date): number {
|
|
53
|
+
return date.getMonth() + 1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
add(date: Date, unit: TimeUnit, amount: number): AXDateTime {
|
|
57
|
+
let value = date.valueOf();
|
|
58
|
+
switch (unit) {
|
|
59
|
+
case 'second':
|
|
60
|
+
value += 1000 * amount;
|
|
61
|
+
break
|
|
62
|
+
case 'minute':
|
|
63
|
+
value += 60000 * amount;
|
|
64
|
+
break
|
|
65
|
+
case 'hour':
|
|
66
|
+
value += 3600000 * amount;
|
|
67
|
+
break
|
|
68
|
+
case 'month':
|
|
69
|
+
const v = new Date(value);
|
|
70
|
+
var mo = date.getMonth();
|
|
71
|
+
var yr = date.getFullYear();
|
|
72
|
+
mo = (mo + amount) % 12;
|
|
73
|
+
if (0 > mo) {
|
|
74
|
+
yr += (date.getMonth() + amount - mo - 12) / 12;
|
|
75
|
+
mo += 12;
|
|
76
|
+
}
|
|
77
|
+
else
|
|
78
|
+
yr += ((date.getMonth() + amount - mo) / 12);
|
|
79
|
+
v.setMonth(mo);
|
|
80
|
+
v.setFullYear(yr);
|
|
81
|
+
value = v.valueOf();
|
|
82
|
+
break
|
|
83
|
+
case 'week':
|
|
84
|
+
value += 7 * 86400000 * amount;
|
|
85
|
+
break
|
|
86
|
+
case 'year':
|
|
87
|
+
const yv = new Date(value);
|
|
88
|
+
yv.setFullYear(yv.getFullYear() + amount);
|
|
89
|
+
value = v.valueOf();
|
|
90
|
+
break
|
|
91
|
+
case 'day':
|
|
92
|
+
default:
|
|
93
|
+
value += 86400000 * amount;
|
|
94
|
+
}
|
|
95
|
+
return new AXDateTime(new Date(value), this.name());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
set(date: Date, unit: TimeUnit, value: number): AXDateTime {
|
|
99
|
+
throw new Error("Method not implemented.");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
startOf(date: Date, unit: TimeUnit): AXDateTime {
|
|
103
|
+
const clone = new Date(date.valueOf());
|
|
104
|
+
switch (unit) {
|
|
105
|
+
case 'second':
|
|
106
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 0);
|
|
107
|
+
return new AXDateTime(clone, this.name());
|
|
108
|
+
case 'minute':
|
|
109
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), 0, 0);
|
|
110
|
+
return new AXDateTime(clone, this.name());
|
|
111
|
+
case 'hour':
|
|
112
|
+
clone.setHours(clone.getHours(), 0, 0, 0);
|
|
113
|
+
return new AXDateTime(clone, this.name());
|
|
114
|
+
default:
|
|
115
|
+
case 'day':
|
|
116
|
+
clone.setHours(0, 0, 0, 0);
|
|
117
|
+
return new AXDateTime(clone, this.name());
|
|
118
|
+
case "week":
|
|
119
|
+
const diff = clone.getDate() - clone.getDay() + (clone.getDay() === 0 ? -6 : 1);
|
|
120
|
+
clone.setDate(diff)
|
|
121
|
+
return new AXDateTime(clone, this.name()).startOf('day');
|
|
122
|
+
case "month":
|
|
123
|
+
clone.setDate(1)
|
|
124
|
+
return new AXDateTime(clone, this.name()).startOf('day');
|
|
125
|
+
case "year":
|
|
126
|
+
clone.setMonth(0);
|
|
127
|
+
clone.setDate(1);
|
|
128
|
+
return new AXDateTime(clone, this.name()).startOf('day');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
endOf(date: Date, unit: TimeUnit): AXDateTime {
|
|
133
|
+
const clone = new Date(date.valueOf());
|
|
134
|
+
switch (unit) {
|
|
135
|
+
case 'second':
|
|
136
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 999);
|
|
137
|
+
return new AXDateTime(clone, this.name());
|
|
138
|
+
case 'minute':
|
|
139
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), 59, 999);
|
|
140
|
+
return new AXDateTime(clone, this.name());
|
|
141
|
+
case 'hour':
|
|
142
|
+
clone.setHours(clone.getHours(), 59, 59, 999);
|
|
143
|
+
return new AXDateTime(clone, this.name());
|
|
144
|
+
default:
|
|
145
|
+
case 'day':
|
|
146
|
+
clone.setHours(23, 59, 59, 999);
|
|
147
|
+
return new AXDateTime(clone, this.name());
|
|
148
|
+
case 'week':
|
|
149
|
+
return this.startOf(date, 'week').add('day', 6).endOf('day');
|
|
150
|
+
case 'month':
|
|
151
|
+
return new AXDateTime(new Date(date.getFullYear(), date.getMonth() + 1, 0), this.name()).endOf('day');
|
|
152
|
+
case "year":
|
|
153
|
+
clone.setMonth(11);
|
|
154
|
+
return new AXDateTime(clone, this.name()).endOf('month');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { AXCalendar, AXDateTime, 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
|
+
name(): string {
|
|
14
|
+
return 'jalali'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
dayInMonth(date: Date): number {
|
|
18
|
+
return this.toJalali(date).day;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
dayOfYear(date: Date): number {
|
|
22
|
+
const j = this.toJalali(date);
|
|
23
|
+
return (j.month <= 6 ? ((j.month - 1) * 31) : ((6 * 31) + (j.month - 7) * 30)) + j.day;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
dayInWeek(date: Date): number {
|
|
27
|
+
return date.getDay() == 6 ? 1 : date.getDay() + 2;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
year(date: Date): number {
|
|
31
|
+
return this.toJalali(date).year;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
monthOfYear(date: Date): number {
|
|
35
|
+
return this.toJalali(date).month;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
add(date: Date, unit: TimeUnit, amount: number): AXDateTime {
|
|
40
|
+
let value = date.valueOf();
|
|
41
|
+
switch (unit) {
|
|
42
|
+
case 'second':
|
|
43
|
+
value += 1000 * amount;
|
|
44
|
+
break
|
|
45
|
+
case 'minute':
|
|
46
|
+
value += 60000 * amount;
|
|
47
|
+
break
|
|
48
|
+
case 'hour':
|
|
49
|
+
value += 3600000 * amount;
|
|
50
|
+
break
|
|
51
|
+
case 'month':
|
|
52
|
+
{
|
|
53
|
+
const v = new Date(value);
|
|
54
|
+
let jd = this.dayInMonth(date);
|
|
55
|
+
let jm = this.monthOfYear(date);
|
|
56
|
+
let jy = this.year(date);
|
|
57
|
+
jm = (jm + amount) % 12;
|
|
58
|
+
if (0 > jm) {
|
|
59
|
+
jy += (this.monthOfYear(date) + amount - jm - 12) / 12;
|
|
60
|
+
jm += 12;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
jy += ((this.monthOfYear(date) + amount - jm) / 12);
|
|
64
|
+
}
|
|
65
|
+
const vv = this.toGregorian(jy, jm, jd);
|
|
66
|
+
v.setFullYear(vv.getFullYear());
|
|
67
|
+
v.setMonth(vv.getMonth());
|
|
68
|
+
v.setDate(vv.getDate());
|
|
69
|
+
value = v.valueOf();
|
|
70
|
+
break
|
|
71
|
+
}
|
|
72
|
+
case 'week':
|
|
73
|
+
value += 7 * 86400000 * amount;
|
|
74
|
+
break
|
|
75
|
+
case 'year':
|
|
76
|
+
{
|
|
77
|
+
const v = new Date(value);
|
|
78
|
+
let jd = this.dayInMonth(date);
|
|
79
|
+
let jm = this.monthOfYear(date);
|
|
80
|
+
let jy = this.year(date);
|
|
81
|
+
const vv = this.toGregorian(jy + amount, jm, jd);
|
|
82
|
+
v.setFullYear(vv.getFullYear());
|
|
83
|
+
v.setMonth(vv.getMonth());
|
|
84
|
+
v.setDate(vv.getDate());
|
|
85
|
+
value = v.valueOf();
|
|
86
|
+
}
|
|
87
|
+
break
|
|
88
|
+
case 'day':
|
|
89
|
+
default:
|
|
90
|
+
value += 86400000 * amount;
|
|
91
|
+
}
|
|
92
|
+
return new AXDateTime(new Date(value), this.name());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
set(date: Date, unit: TimeUnit, value: number): AXDateTime {
|
|
96
|
+
throw new Error("Method not implemented.");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
startOf(date: Date, unit: TimeUnit): AXDateTime {
|
|
100
|
+
const clone = new Date(date.valueOf());
|
|
101
|
+
switch (unit) {
|
|
102
|
+
case 'second':
|
|
103
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 0);
|
|
104
|
+
return new AXDateTime(clone, this.name());
|
|
105
|
+
case 'minute':
|
|
106
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), 0, 0);
|
|
107
|
+
return new AXDateTime(clone, this.name());
|
|
108
|
+
case 'hour':
|
|
109
|
+
clone.setHours(clone.getHours(), 0, 0, 0);
|
|
110
|
+
return new AXDateTime(clone, this.name());
|
|
111
|
+
default:
|
|
112
|
+
case 'day':
|
|
113
|
+
clone.setHours(0, 0, 0, 0);
|
|
114
|
+
return new AXDateTime(clone, this.name());
|
|
115
|
+
case "week":
|
|
116
|
+
return new AXDateTime(clone, this.name()).add('day', -this.dayInWeek(clone) + 1).startOf('day');
|
|
117
|
+
case "month":
|
|
118
|
+
{
|
|
119
|
+
const jy = this.year(date);
|
|
120
|
+
const jm = this.monthOfYear(date);
|
|
121
|
+
const gDate = this.toGregorian(jy, jm, 1);
|
|
122
|
+
return new AXDateTime(gDate, this.name()).startOf('day');
|
|
123
|
+
}
|
|
124
|
+
case "year":
|
|
125
|
+
{
|
|
126
|
+
const jy = this.year(date);
|
|
127
|
+
const gDate = this.toGregorian(jy, 1, 1);
|
|
128
|
+
return new AXDateTime(gDate, this.name()).startOf('day');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
endOf(date: Date, unit: TimeUnit): AXDateTime {
|
|
134
|
+
const clone = new Date(date.valueOf());
|
|
135
|
+
switch (unit) {
|
|
136
|
+
case 'second':
|
|
137
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 999);
|
|
138
|
+
return new AXDateTime(clone, this.name());
|
|
139
|
+
case 'minute':
|
|
140
|
+
clone.setHours(clone.getHours(), clone.getMinutes(), 59, 999);
|
|
141
|
+
return new AXDateTime(clone, this.name());
|
|
142
|
+
case 'hour':
|
|
143
|
+
clone.setHours(clone.getHours(), 59, 59, 999);
|
|
144
|
+
return new AXDateTime(clone, this.name());
|
|
145
|
+
default:
|
|
146
|
+
case 'day':
|
|
147
|
+
clone.setHours(23, 59, 59, 999);
|
|
148
|
+
return new AXDateTime(clone, this.name());
|
|
149
|
+
case 'week':
|
|
150
|
+
{
|
|
151
|
+
return this.startOf(date, 'week').add('day', 6).endOf('day');
|
|
152
|
+
}
|
|
153
|
+
case 'month':
|
|
154
|
+
{
|
|
155
|
+
const jy = this.year(date);
|
|
156
|
+
const jm = this.monthOfYear(date);
|
|
157
|
+
const jd = this.monthLength(jy, jm);
|
|
158
|
+
const gDate = this.toGregorian(jy, jm, jd);
|
|
159
|
+
return new AXDateTime(gDate, this.name()).endOf('day');
|
|
160
|
+
}
|
|
161
|
+
case "year":
|
|
162
|
+
let jy = this.year(date);
|
|
163
|
+
const gDate = this.toGregorian(jy, 12, this.monthLength(jy, 12));
|
|
164
|
+
return new AXDateTime(gDate, this.name()).endOf('day');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
toJalali(date: Date): { year: number, month: number, day: number } {
|
|
171
|
+
const gy = date.getFullYear();
|
|
172
|
+
const gm = date.getMonth() + 1;
|
|
173
|
+
const gd = date.getDate();
|
|
174
|
+
const r = this.d2j(this.g2d(gy, gm, gd))
|
|
175
|
+
return {
|
|
176
|
+
year: r.jy,
|
|
177
|
+
month: r.jm,
|
|
178
|
+
day: r.jd,
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/*
|
|
183
|
+
Converts a Jalaali date to Gregorian.
|
|
184
|
+
*/
|
|
185
|
+
toGregorian(jy, jm, jd) {
|
|
186
|
+
const g = this.d2g(this.j2d(jy, jm, jd))
|
|
187
|
+
return new Date(g.gy, g.gm - 1, g.gd);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/*
|
|
191
|
+
Checks whether a Jalaali date is valid or not.
|
|
192
|
+
*/
|
|
193
|
+
isValid(jy, jm, jd) {
|
|
194
|
+
return jy >= -61 && jy <= 3177 &&
|
|
195
|
+
jm >= 1 && jm <= 12 &&
|
|
196
|
+
jd >= 1 && jd <= this.monthLength(jy, jm)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/*
|
|
200
|
+
Is this a leap year or not?
|
|
201
|
+
*/
|
|
202
|
+
isLeapYear(jy) {
|
|
203
|
+
return this.jalCal(jy).leap === 0
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/*
|
|
207
|
+
Number of days in a given month in a Jalaali year.
|
|
208
|
+
*/
|
|
209
|
+
monthLength(jy, jm) {
|
|
210
|
+
if (jm <= 6) return 31
|
|
211
|
+
if (jm <= 11) return 30
|
|
212
|
+
if (this.isLeapYear(jy)) return 30
|
|
213
|
+
return 29
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
private jalCal(jy) {
|
|
218
|
+
// Jalaali years starting the 33-year rule.
|
|
219
|
+
let breaks = [-61, 9, 38, 199, 426, 686, 756, 818, 1111, 1181, 1210
|
|
220
|
+
, 1635, 2060, 2097, 2192, 2262, 2324, 2394, 2456, 3178
|
|
221
|
+
]
|
|
222
|
+
, bl = breaks.length
|
|
223
|
+
, gy = jy + 621
|
|
224
|
+
, leapJ = -14
|
|
225
|
+
, jp = breaks[0]
|
|
226
|
+
, jm
|
|
227
|
+
, jump
|
|
228
|
+
, leap
|
|
229
|
+
, leapG
|
|
230
|
+
, march
|
|
231
|
+
, n
|
|
232
|
+
, i
|
|
233
|
+
|
|
234
|
+
if (jy < jp || jy >= breaks[bl - 1])
|
|
235
|
+
throw new Error('Invalid Jalaali year ' + jy)
|
|
236
|
+
|
|
237
|
+
// Find the limiting years for the Jalaali year jy.
|
|
238
|
+
for (i = 1; i < bl; i += 1) {
|
|
239
|
+
jm = breaks[i]
|
|
240
|
+
jump = jm - jp
|
|
241
|
+
if (jy < jm)
|
|
242
|
+
break
|
|
243
|
+
leapJ = leapJ + this.div(jump, 33) * 8 + this.div(this.mod(jump, 33), 4)
|
|
244
|
+
jp = jm
|
|
245
|
+
}
|
|
246
|
+
n = jy - jp
|
|
247
|
+
|
|
248
|
+
// Find the number of leap years from AD 621 to the beginning
|
|
249
|
+
// of the current Jalaali year in the Persian calendar.
|
|
250
|
+
leapJ = leapJ + this.div(n, 33) * 8 + this.div(this.mod(n, 33) + 3, 4)
|
|
251
|
+
if (this.mod(jump, 33) === 4 && jump - n === 4)
|
|
252
|
+
leapJ += 1
|
|
253
|
+
|
|
254
|
+
// And the same in the Gregorian calendar (until the year gy).
|
|
255
|
+
leapG = this.div(gy, 4) - this.div((this.div(gy, 100) + 1) * 3, 4) - 150
|
|
256
|
+
|
|
257
|
+
// Determine the Gregorian date of Farvardin the 1st.
|
|
258
|
+
march = 20 + leapJ - leapG
|
|
259
|
+
|
|
260
|
+
// Find how many years have passed since the last leap year.
|
|
261
|
+
if (jump - n < 6)
|
|
262
|
+
n = n - jump + this.div(jump + 4, 33) * 33
|
|
263
|
+
leap = this.mod(this.mod(n + 1, 33) - 1, 4)
|
|
264
|
+
if (leap === -1) {
|
|
265
|
+
leap = 4
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
leap: leap
|
|
270
|
+
, gy: gy
|
|
271
|
+
, march: march
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/*
|
|
276
|
+
Converts a date of the Jalaali calendar to the Julian Day number.
|
|
277
|
+
@param jy Jalaali year (1 to 3100)
|
|
278
|
+
@param jm Jalaali month (1 to 12)
|
|
279
|
+
@param jd Jalaali day (1 to 29/31)
|
|
280
|
+
@return Julian Day number
|
|
281
|
+
*/
|
|
282
|
+
private j2d(jy, jm, jd) {
|
|
283
|
+
let r = this.jalCal(jy)
|
|
284
|
+
return this.g2d(r.gy, 3, r.march) + (jm - 1) * 31 - this.div(jm, 7) * (jm - 7) + jd - 1
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/*
|
|
288
|
+
Converts the Julian Day number to a date in the Jalaali calendar.
|
|
289
|
+
@param jdn Julian Day number
|
|
290
|
+
@return
|
|
291
|
+
jy: Jalaali year (1 to 3100)
|
|
292
|
+
jm: Jalaali month (1 to 12)
|
|
293
|
+
jd: Jalaali day (1 to 29/31)
|
|
294
|
+
*/
|
|
295
|
+
private d2j(jdn) {
|
|
296
|
+
let gy = this.d2g(jdn).gy // Calculate Gregorian year (gy).
|
|
297
|
+
, jy = gy - 621
|
|
298
|
+
, r = this.jalCal(jy)
|
|
299
|
+
, jdn1f = this.g2d(gy, 3, r.march)
|
|
300
|
+
, jd
|
|
301
|
+
, jm
|
|
302
|
+
, k
|
|
303
|
+
|
|
304
|
+
// Find number of days that passed since 1 Farvardin.
|
|
305
|
+
k = jdn - jdn1f
|
|
306
|
+
if (k >= 0) {
|
|
307
|
+
if (k <= 185) {
|
|
308
|
+
// The first 6 months.
|
|
309
|
+
jm = 1 + this.div(k, 31)
|
|
310
|
+
jd = this.mod(k, 31) + 1
|
|
311
|
+
return {
|
|
312
|
+
jy: jy
|
|
313
|
+
, jm: jm
|
|
314
|
+
, jd: jd
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
// The remaining months.
|
|
318
|
+
k -= 186
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
// Previous Jalaali year.
|
|
322
|
+
jy -= 1
|
|
323
|
+
k += 179
|
|
324
|
+
if (r.leap === 1)
|
|
325
|
+
k += 1
|
|
326
|
+
}
|
|
327
|
+
jm = 7 + this.div(k, 30)
|
|
328
|
+
jd = this.mod(k, 30) + 1
|
|
329
|
+
return {
|
|
330
|
+
jy: jy
|
|
331
|
+
, jm: jm
|
|
332
|
+
, jd: jd
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
private g2d(gy, gm, gd) {
|
|
338
|
+
let d = this.div((gy + this.div(gm - 8, 6) + 100100) * 1461, 4)
|
|
339
|
+
+ this.div(153 * this.mod(gm + 9, 12) + 2, 5)
|
|
340
|
+
+ gd - 34840408
|
|
341
|
+
d = d - this.div(this.div(gy + 100100 + this.div(gm - 8, 6), 100) * 3, 4) + 752
|
|
342
|
+
return d
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
private d2g(jdn) {
|
|
347
|
+
let j
|
|
348
|
+
, i
|
|
349
|
+
, gd
|
|
350
|
+
, gm
|
|
351
|
+
, gy
|
|
352
|
+
j = 4 * jdn + 139361631
|
|
353
|
+
j = j + this.div(this.div(4 * jdn + 183187720, 146097) * 3, 4) * 4 - 3908
|
|
354
|
+
i = this.div(this.mod(j, 1461), 4) * 5 + 308
|
|
355
|
+
gd = this.div(this.mod(i, 153), 5) + 1
|
|
356
|
+
gm = this.mod(this.div(i, 153), 12) + 1
|
|
357
|
+
gy = this.div(j, 1461) - 100100 + this.div(8 - gm, 6)
|
|
358
|
+
return {
|
|
359
|
+
gy: gy
|
|
360
|
+
, gm: gm
|
|
361
|
+
, gd: gd
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/*
|
|
366
|
+
Utility helper functions.
|
|
367
|
+
*/
|
|
368
|
+
private div(a, b) {
|
|
369
|
+
return ~~(a / b)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
private mod(a, b) {
|
|
373
|
+
return a - ~~(a / b) * b
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IHttpError } from './http-error.class';
|
|
2
|
+
import { InjectionToken } from '@angular/core';
|
|
3
|
+
import { AXHttpRequestOptions } from './http-request.class';
|
|
4
|
+
|
|
5
|
+
export const AX_HTTP_EVENT_INTERCEPTOR = new InjectionToken<AXHttpEventInterceptor>('ax.http.events');
|
|
6
|
+
|
|
7
|
+
export interface AXHttpEventInterceptor {
|
|
8
|
+
begin(request: AXHttpRequestOptions): Promise<AXHttpRequestOptions>;
|
|
9
|
+
success(request: AXHttpRequestOptions, result: any): Promise<any>;
|
|
10
|
+
complete(request: AXHttpRequestOptions);
|
|
11
|
+
error(request: AXHttpRequestOptions, error: IHttpError);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface AXHttpRequestOptions {
|
|
2
|
+
url?: any,
|
|
3
|
+
params?: {
|
|
4
|
+
[param: string]: any;
|
|
5
|
+
},
|
|
6
|
+
body?: {
|
|
7
|
+
[param: string]: any;
|
|
8
|
+
},
|
|
9
|
+
headers?: {
|
|
10
|
+
[header: string]: any;
|
|
11
|
+
},
|
|
12
|
+
method?: 'get' | 'post' | 'put' | 'delete';
|
|
13
|
+
responseType?: any;
|
|
14
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IHttpError } from './http-error.class';
|
|
2
|
+
|
|
3
|
+
export class HttpResult<T> {
|
|
4
|
+
private _executor: (result: (e?: T) => void, error: (e?: IHttpError) => void, complete: () => void) => void;
|
|
5
|
+
constructor(
|
|
6
|
+
executor: (
|
|
7
|
+
result: (e?: T) => void,
|
|
8
|
+
error: (e?: IHttpError) => void,
|
|
9
|
+
complete: () => void
|
|
10
|
+
) => void
|
|
11
|
+
) {
|
|
12
|
+
this._executor = executor;
|
|
13
|
+
setTimeout(() => {
|
|
14
|
+
this._executor(this.resultAction, this.errorAction, this.completeAction);
|
|
15
|
+
}, 50);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private resultAction: (e?: T) => void;
|
|
19
|
+
private errorAction: (e?: IHttpError) => void;
|
|
20
|
+
private completeAction: () => void;
|
|
21
|
+
|
|
22
|
+
result(action: (e?: T) => void): HttpResult<T> {
|
|
23
|
+
this.resultAction = action;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
error(action: (e?: IHttpError) => void): HttpResult<T> {
|
|
27
|
+
this.errorAction = action;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
complete(action: () => void): HttpResult<T> {
|
|
31
|
+
this.completeAction = action;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { NgModule, ModuleWithProviders } from '@angular/core';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { HttpClientModule } from '@angular/common/http';
|
|
4
|
+
import { AXHttpService } from './http.service';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@NgModule({
|
|
8
|
+
declarations: [],
|
|
9
|
+
imports: [
|
|
10
|
+
CommonModule,
|
|
11
|
+
HttpClientModule
|
|
12
|
+
],
|
|
13
|
+
exports: [HttpClientModule],
|
|
14
|
+
providers: [
|
|
15
|
+
AXHttpService
|
|
16
|
+
]
|
|
17
|
+
})
|
|
18
|
+
export class AXHttpModule {
|
|
19
|
+
static forRoot(): ModuleWithProviders {
|
|
20
|
+
return {
|
|
21
|
+
ngModule: AXHttpModule,
|
|
22
|
+
providers: [AXHttpService]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|