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