@acorex/core 7.0.20 → 7.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/config/index.d.ts +5 -0
  2. package/config/public-api.d.ts +1 -0
  3. package/config/src/configs.d.ts +9 -0
  4. package/dateTime/index.d.ts +5 -0
  5. package/dateTime/{public-api.ts → public-api.d.ts} +1 -1
  6. package/dateTime/src/datetime.class.d.ts +100 -0
  7. package/dateTime/src/datetime.module.d.ts +8 -0
  8. package/dateTime/src/datetime.pipe.d.ts +8 -0
  9. package/dateTime/src/georgian.calendar.d.ts +20 -0
  10. package/dateTime/src/jalali.calendar.d.ts +35 -0
  11. package/esm2020/acorex-core.mjs +5 -0
  12. package/esm2020/config/acorex-core-config.mjs +5 -0
  13. package/esm2020/config/public-api.mjs +2 -0
  14. package/esm2020/config/src/configs.mjs +32 -0
  15. package/esm2020/dateTime/acorex-core-dateTime.mjs +5 -0
  16. package/esm2020/dateTime/public-api.mjs +6 -0
  17. package/esm2020/dateTime/src/datetime.class.mjs +288 -0
  18. package/esm2020/dateTime/src/datetime.module.mjs +39 -0
  19. package/esm2020/dateTime/src/datetime.pipe.mjs +26 -0
  20. package/esm2020/dateTime/src/georgian.calendar.mjs +189 -0
  21. package/esm2020/dateTime/src/jalali.calendar.mjs +359 -0
  22. package/esm2020/events/acorex-core-events.mjs +5 -0
  23. package/esm2020/events/public-api.mjs +2 -0
  24. package/esm2020/events/src/event.service.mjs +36 -0
  25. package/esm2020/file/acorex-core-file.mjs +5 -0
  26. package/esm2020/file/public-api.mjs +5 -0
  27. package/esm2020/file/src/file-download-ref.class.mjs +12 -0
  28. package/esm2020/file/src/file-download-result.class.mjs +47 -0
  29. package/esm2020/file/src/file-upload-ref.class.mjs +12 -0
  30. package/esm2020/file/src/file.service.mjs +101 -0
  31. package/esm2020/http/acorex-core-http.mjs +5 -0
  32. package/esm2020/http/public-api.mjs +6 -0
  33. package/esm2020/http/src/http-error.class.mjs +2 -0
  34. package/esm2020/http/src/http-events.interceptor.mjs +3 -0
  35. package/esm2020/http/src/http-request.class.mjs +2 -0
  36. package/esm2020/http/src/http-result.class.mjs +21 -0
  37. package/esm2020/http/src/http.module.mjs +29 -0
  38. package/esm2020/http/src/http.service.mjs +148 -0
  39. package/esm2020/image/acorex-core-image.mjs +5 -0
  40. package/esm2020/image/public-api.mjs +2 -0
  41. package/esm2020/image/src/image.service.mjs +43 -0
  42. package/esm2020/pipes/acorex-core-pipes.mjs +5 -0
  43. package/esm2020/pipes/public-api.mjs +3 -0
  44. package/esm2020/pipes/src/pipes.module.mjs +19 -0
  45. package/esm2020/pipes/src/safe.pipe.mjs +30 -0
  46. package/esm2020/platform/acorex-core-platform.mjs +5 -0
  47. package/esm2020/platform/public-api.mjs +2 -0
  48. package/esm2020/platform/src/platform.service.mjs +153 -0
  49. package/esm2020/public-api.mjs +5 -0
  50. package/esm2020/translation/acorex-core-translation.mjs +5 -0
  51. package/esm2020/translation/public-api.mjs +4 -0
  52. package/esm2020/translation/src/translation.module.mjs +18 -0
  53. package/esm2020/translation/src/translator.mjs +43 -0
  54. package/esm2020/translation/src/translator.pipe.mjs +15 -0
  55. package/esm2020/utils/acorex-core-utils.mjs +5 -0
  56. package/esm2020/utils/public-api.mjs +5 -0
  57. package/esm2020/utils/src/color-util.mjs +71 -0
  58. package/esm2020/utils/src/drawing-util.mjs +27 -0
  59. package/esm2020/utils/src/object-util.mjs +39 -0
  60. package/esm2020/utils/src/string-util.mjs +19 -0
  61. package/events/index.d.ts +5 -0
  62. package/events/public-api.d.ts +1 -0
  63. package/events/src/event.service.d.ts +9 -0
  64. package/fesm2015/acorex-core-config.mjs +40 -0
  65. package/fesm2015/acorex-core-config.mjs.map +1 -0
  66. package/fesm2015/acorex-core-dateTime.mjs +899 -0
  67. package/fesm2015/acorex-core-dateTime.mjs.map +1 -0
  68. package/fesm2015/acorex-core-events.mjs +44 -0
  69. package/fesm2015/acorex-core-events.mjs.map +1 -0
  70. package/fesm2015/acorex-core-file.mjs +177 -0
  71. package/fesm2015/acorex-core-file.mjs.map +1 -0
  72. package/fesm2015/acorex-core-http.mjs +203 -0
  73. package/fesm2015/acorex-core-http.mjs.map +1 -0
  74. package/fesm2015/acorex-core-image.mjs +54 -0
  75. package/fesm2015/acorex-core-image.mjs.map +1 -0
  76. package/fesm2015/acorex-core-pipes.mjs +54 -0
  77. package/fesm2015/acorex-core-pipes.mjs.map +1 -0
  78. package/fesm2015/acorex-core-platform.mjs +161 -0
  79. package/fesm2015/acorex-core-platform.mjs.map +1 -0
  80. package/fesm2015/acorex-core-translation.mjs +81 -0
  81. package/fesm2015/acorex-core-translation.mjs.map +1 -0
  82. package/fesm2015/acorex-core-utils.mjs +164 -0
  83. package/fesm2015/acorex-core-utils.mjs.map +1 -0
  84. package/fesm2015/acorex-core.mjs +12 -0
  85. package/fesm2015/acorex-core.mjs.map +1 -0
  86. package/fesm2020/acorex-core-config.mjs +40 -0
  87. package/fesm2020/acorex-core-config.mjs.map +1 -0
  88. package/fesm2020/acorex-core-dateTime.mjs +899 -0
  89. package/fesm2020/acorex-core-dateTime.mjs.map +1 -0
  90. package/fesm2020/acorex-core-events.mjs +44 -0
  91. package/fesm2020/acorex-core-events.mjs.map +1 -0
  92. package/fesm2020/acorex-core-file.mjs +177 -0
  93. package/fesm2020/acorex-core-file.mjs.map +1 -0
  94. package/fesm2020/acorex-core-http.mjs +202 -0
  95. package/fesm2020/acorex-core-http.mjs.map +1 -0
  96. package/fesm2020/acorex-core-image.mjs +51 -0
  97. package/fesm2020/acorex-core-image.mjs.map +1 -0
  98. package/fesm2020/acorex-core-pipes.mjs +54 -0
  99. package/fesm2020/acorex-core-pipes.mjs.map +1 -0
  100. package/fesm2020/acorex-core-platform.mjs +161 -0
  101. package/fesm2020/acorex-core-platform.mjs.map +1 -0
  102. package/fesm2020/acorex-core-translation.mjs +80 -0
  103. package/fesm2020/acorex-core-translation.mjs.map +1 -0
  104. package/fesm2020/acorex-core-utils.mjs +164 -0
  105. package/fesm2020/acorex-core-utils.mjs.map +1 -0
  106. package/fesm2020/acorex-core.mjs +12 -0
  107. package/fesm2020/acorex-core.mjs.map +1 -0
  108. package/file/index.d.ts +5 -0
  109. package/file/public-api.d.ts +4 -0
  110. package/file/src/file-download-ref.class.d.ts +6 -0
  111. package/file/src/file-download-result.class.d.ts +8 -0
  112. package/file/src/file-upload-ref.class.d.ts +5 -0
  113. package/file/src/file.service.d.ts +18 -0
  114. package/http/index.d.ts +5 -0
  115. package/http/{public-api.ts → public-api.d.ts} +1 -1
  116. package/http/src/{http-error.class.ts → http-error.class.d.ts} +2 -2
  117. package/http/src/{http-events.interceptor.ts → http-events.interceptor.d.ts} +3 -7
  118. package/http/src/{http-request.class.ts → http-request.class.d.ts} +5 -5
  119. package/http/src/http-result.class.d.ts +11 -0
  120. package/http/src/http.module.d.ts +8 -0
  121. package/http/src/http.service.d.ts +23 -0
  122. package/image/index.d.ts +5 -0
  123. package/image/public-api.d.ts +1 -0
  124. package/image/src/image.service.d.ts +12 -0
  125. package/index.d.ts +5 -0
  126. package/package.json +115 -16
  127. package/pipes/index.d.ts +5 -0
  128. package/pipes/public-api.d.ts +2 -0
  129. package/pipes/src/pipes.module.d.ts +8 -0
  130. package/pipes/src/safe.pipe.d.ts +10 -0
  131. package/platform/index.d.ts +5 -0
  132. package/platform/public-api.d.ts +1 -0
  133. package/platform/src/platform.service.d.ts +26 -0
  134. package/public-api.d.ts +1 -0
  135. package/translation/index.d.ts +5 -0
  136. package/translation/{public-api.ts → public-api.d.ts} +1 -1
  137. package/translation/src/translation.module.d.ts +7 -0
  138. package/translation/src/translator.d.ts +11 -0
  139. package/translation/src/translator.pipe.d.ts +7 -0
  140. package/utils/index.d.ts +5 -0
  141. package/utils/{public-api.ts → public-api.d.ts} +1 -1
  142. package/utils/src/color-util.d.ts +20 -0
  143. package/utils/src/drawing-util.d.ts +17 -0
  144. package/utils/src/object-util.d.ts +4 -0
  145. package/utils/src/string-util.d.ts +6 -0
  146. package/config/ax-preset.js +0 -186
  147. package/config/index.ts +0 -1
  148. package/config/ng-package.json +0 -6
  149. package/config/public-api.ts +0 -1
  150. package/config/src/configs.ts +0 -37
  151. package/dateTime/index.ts +0 -1
  152. package/dateTime/ng-package.json +0 -6
  153. package/dateTime/src/datetime.class.ts +0 -449
  154. package/dateTime/src/datetime.module.ts +0 -35
  155. package/dateTime/src/datetime.pipe.ts +0 -21
  156. package/dateTime/src/georgian.calendar.ts +0 -205
  157. package/dateTime/src/jalali.calendar.ts +0 -416
  158. package/events/index.ts +0 -1
  159. package/events/ng-package.json +0 -6
  160. package/events/public-api.ts +0 -1
  161. package/events/src/event.service.ts +0 -31
  162. package/file/index.ts +0 -1
  163. package/file/ng-package.json +0 -7
  164. package/file/public-api.ts +0 -4
  165. package/file/src/file-download-ref.class.ts +0 -16
  166. package/file/src/file-download-result.class.ts +0 -56
  167. package/file/src/file-upload-ref.class.ts +0 -14
  168. package/file/src/file.service.ts +0 -104
  169. package/http/index.ts +0 -1
  170. package/http/ng-package.json +0 -6
  171. package/http/src/http-result.class.ts +0 -34
  172. package/http/src/http.module.ts +0 -25
  173. package/http/src/http.service.ts +0 -161
  174. package/image/index.ts +0 -1
  175. package/image/ng-package.json +0 -7
  176. package/image/public-api.ts +0 -1
  177. package/image/src/image.service.ts +0 -42
  178. package/index.ts +0 -1
  179. package/karma.conf.js +0 -44
  180. package/ng-package.json +0 -7
  181. package/pipes/index.ts +0 -1
  182. package/pipes/ng-package.json +0 -6
  183. package/pipes/public-api.ts +0 -2
  184. package/pipes/src/pipes.module.ts +0 -11
  185. package/pipes/src/safe.pipe.ts +0 -24
  186. package/platform/index.ts +0 -1
  187. package/platform/ng-package.json +0 -6
  188. package/platform/public-api.ts +0 -1
  189. package/platform/src/platform.service.ts +0 -223
  190. package/public-api.ts +0 -4
  191. package/test.ts +0 -27
  192. package/translation/index.ts +0 -1
  193. package/translation/ng-package.json +0 -6
  194. package/translation/src/translation.module.ts +0 -12
  195. package/translation/src/translator.pipe.ts +0 -9
  196. package/translation/src/translator.ts +0 -49
  197. package/tsconfig.lib.json +0 -15
  198. package/tsconfig.lib.prod.json +0 -10
  199. package/tsconfig.spec.json +0 -17
  200. package/utils/index.ts +0 -1
  201. package/utils/ng-package.json +0 -6
  202. package/utils/src/color-util.ts +0 -83
  203. package/utils/src/drawing-util.ts +0 -43
  204. package/utils/src/object-util.ts +0 -82
  205. package/utils/src/string-util.ts +0 -25
@@ -1,35 +0,0 @@
1
- import { NgModule } from '@angular/core';
2
- import { AXConfig } from '@acorex/core/config';
3
- import { AXDateTimePipe } from './datetime.pipe';
4
- import { GeorgianCalendar } from './georgian.calendar';
5
- import { JalaliCalendar } from './jalali.calendar';
6
-
7
-
8
- @NgModule({
9
- imports: [],
10
- exports: [AXDateTimePipe],
11
- declarations: [AXDateTimePipe],
12
- providers: [],
13
- })
14
- export class AXDateTimeModule {
15
-
16
- constructor() {
17
- AXConfig.set({
18
- dateTime: {
19
- calendars: {
20
- jalali: {
21
- "class": new JalaliCalendar(),
22
- weekend: [6, 7]
23
- },
24
- gregorian: {
25
- "class": new GeorgianCalendar(),
26
- weekend: [7, 1]
27
- }
28
- },
29
- calendar: 'gregorian',
30
- shortDateFormat: 'DDDD, d MMM yyyy'
31
- }
32
- });
33
-
34
- }
35
- }
@@ -1,21 +0,0 @@
1
- import { PipeTransform, Pipe } from '@angular/core';
2
- import { AXConfig } from '@acorex/core/config';
3
- import { AXDateTime } from './datetime.class';
4
-
5
- @Pipe({ name: 'axDate' })
6
- export class AXDateTimePipe implements PipeTransform {
7
- constructor() { }
8
-
9
- transform(value: any, format?: string, calendar?: string): string {
10
- if (value == null) {
11
- return '';
12
- }
13
- const date: AXDateTime = value instanceof AXDateTime ? value.clone() : AXDateTime.convert(value, calendar);
14
- if (!format) {
15
- return date.format(AXConfig.get('dateTime.shortDateFormat'));
16
- }
17
- else {
18
- return date.format(format);
19
- }
20
- }
21
- }
@@ -1,205 +0,0 @@
1
- import { AXCalendar, AXDateTime, AXDateValue, 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
-
30
- create(value: AXDateValue): AXDateTime {
31
- 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());
32
- }
33
-
34
- name(): string {
35
- return 'gregorian'
36
- }
37
-
38
- dayOfMonth(date: Date): number {
39
- return date.getDate();
40
- }
41
-
42
- dayOfYear(date: Date): number {
43
- let result = 0;
44
- let m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
45
- if (this.isLeap(date)) {
46
- m[1] = 29;
47
- }
48
- for (let i = 0; i < date.getMonth(); i++) {
49
- result = result + m[i];
50
- }
51
- result += date.getDate();
52
- return result;
53
- }
54
-
55
- dayOfWeek(date: Date): number {
56
- return date.getDay() + 1;
57
- }
58
-
59
- weekOfYear(date: Date): number {
60
- const firstDay = new AXDateTime(date).startOf('year');
61
- return Math.ceil((((date.getTime() - firstDay.date.getTime()) / 86400000) + firstDay.date.getDay() + 1) / 7);
62
- }
63
-
64
- year(date: Date): number {
65
- return date.getFullYear();
66
- }
67
-
68
- monthOfYear(date: Date): number {
69
- return date.getMonth() + 1;
70
- }
71
-
72
- add(date: Date, unit: TimeUnit, amount: number): AXDateTime {
73
- let value = date.valueOf();
74
- switch (unit) {
75
- case 'second':
76
- value += 1000 * amount;
77
- break
78
- case 'minute':
79
- value += 60000 * amount;
80
- break
81
- case 'hour':
82
- value += 3600000 * amount;
83
- break
84
- case 'month':
85
- const v = new Date(value);
86
- var mo = date.getMonth();
87
- var yr = date.getFullYear();
88
- mo = (mo + amount) % 12;
89
- if (0 > mo) {
90
- yr += (date.getMonth() + amount - mo - 12) / 12;
91
- mo += 12;
92
- }
93
- else
94
- yr += ((date.getMonth() + amount - mo) / 12);
95
- v.setMonth(mo);
96
- v.setFullYear(yr);
97
- value = v.valueOf();
98
- break
99
- case 'week':
100
- value += 7 * 86400000 * amount;
101
- break
102
- case 'year':
103
- const yv = new Date(value);
104
- yv.setFullYear(yv.getFullYear() + amount);
105
- value = yv.valueOf();
106
- break
107
- case 'day':
108
- default:
109
- value += 86400000 * amount;
110
- }
111
- return new AXDateTime(new Date(value), this.name());
112
- }
113
-
114
- set(date: Date, unit: TimeUnit, value: number): AXDateTime {
115
- const clone = new Date(date.valueOf());
116
- switch (unit) {
117
- case 'second':
118
- clone.setHours(clone.getHours(), clone.getMinutes(), value, clone.getMilliseconds());
119
- break;
120
- case 'minute':
121
- clone.setHours(clone.getHours(), value, clone.getSeconds(), clone.getMilliseconds());
122
- break;
123
- case 'hour':
124
- clone.setHours(value, clone.getMinutes(), clone.getSeconds(), clone.getMilliseconds());
125
- break;
126
- default:
127
- case 'day':
128
- clone.setDate(value);
129
- break;
130
- case "week":
131
- break;
132
- case "month":
133
- clone.setMonth(Math.max(0, value - 1));
134
- break;
135
- case "year":
136
- clone.setFullYear(value);
137
- break;
138
- }
139
- return new AXDateTime(clone, this.name());
140
- }
141
-
142
- startOf(date: Date, unit: TimeUnit): AXDateTime {
143
- const clone = new Date(date.valueOf());
144
- switch (unit) {
145
- case 'second':
146
- clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 0);
147
- return new AXDateTime(clone, this.name());
148
- case 'minute':
149
- clone.setHours(clone.getHours(), clone.getMinutes(), 0, 0);
150
- return new AXDateTime(clone, this.name());
151
- case 'hour':
152
- clone.setHours(clone.getHours(), 0, 0, 0);
153
- return new AXDateTime(clone, this.name());
154
- default:
155
- case 'day':
156
- clone.setHours(0, 0, 0, 0);
157
- return new AXDateTime(clone, this.name());
158
- case "week":
159
- const index = 0;
160
- const start = index >= 0 ? index : 0;
161
- const day = clone.getDay();
162
- const diff = clone.getDate() - day + (start > day ? start - 7 : start);
163
- clone.setDate(diff);
164
- return new AXDateTime(clone, this.name()).startOf('day');
165
- case "month":
166
- clone.setDate(1)
167
- return new AXDateTime(clone, this.name()).startOf('day');
168
- case "year":
169
- clone.setMonth(0);
170
- clone.setDate(1);
171
- return new AXDateTime(clone, this.name()).startOf('day');
172
- }
173
- }
174
-
175
- endOf(date: Date, unit: TimeUnit): AXDateTime {
176
- const clone = new Date(date.valueOf());
177
- switch (unit) {
178
- case 'second':
179
- clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 999);
180
- return new AXDateTime(clone, this.name());
181
- case 'minute':
182
- clone.setHours(clone.getHours(), clone.getMinutes(), 59, 999);
183
- return new AXDateTime(clone, this.name());
184
- case 'hour':
185
- clone.setHours(clone.getHours(), 59, 59, 999);
186
- return new AXDateTime(clone, this.name());
187
- default:
188
- case 'day':
189
- clone.setHours(23, 59, 59, 999);
190
- return new AXDateTime(clone, this.name());
191
- case 'week':
192
- return this.startOf(date, 'week').add('day', 6).endOf('day');
193
- case 'month':
194
- return new AXDateTime(new Date(date.getFullYear(), date.getMonth() + 1, 0), this.name()).endOf('day');
195
- case "year":
196
- clone.setMonth(11);
197
- return new AXDateTime(clone, this.name()).endOf('month');
198
- }
199
- }
200
-
201
- isLeap(date: Date) {
202
- let leapYear = new Date(date.getFullYear(), 1, 29);
203
- return leapYear.getDate() == 29;
204
- }
205
- }
@@ -1,416 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
1
- export * from './public-api'
@@ -1,6 +0,0 @@
1
- {
2
- "$schema": "../../../../node_modules/ng-packagr/ng-package.schema.json",
3
- "lib": {
4
- "entryFile": "public-api.ts"
5
- }
6
- }
@@ -1 +0,0 @@
1
- export * from './src/event.service';