@acorex/core 6.0.1 → 6.0.2

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 (169) 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 +295 -0
  18. package/esm2020/dateTime/src/datetime.module.mjs +33 -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/http/acorex-core-http.mjs +5 -0
  26. package/esm2020/http/public-api.mjs +6 -0
  27. package/esm2020/http/src/http-error.class.mjs +2 -0
  28. package/esm2020/http/src/http-events.interceptor.mjs +3 -0
  29. package/esm2020/http/src/http-request.class.mjs +2 -0
  30. package/esm2020/http/src/http-result.class.mjs +21 -0
  31. package/esm2020/http/src/http.module.mjs +29 -0
  32. package/esm2020/http/src/http.service.mjs +147 -0
  33. package/esm2020/pipes/acorex-core-pipes.mjs +5 -0
  34. package/esm2020/pipes/public-api.mjs +3 -0
  35. package/esm2020/pipes/src/pipes.module.mjs +19 -0
  36. package/esm2020/pipes/src/safe.pipe.mjs +30 -0
  37. package/esm2020/platform/acorex-core-platform.mjs +5 -0
  38. package/esm2020/platform/public-api.mjs +2 -0
  39. package/esm2020/platform/src/platform.service.mjs +141 -0
  40. package/esm2020/public-api.mjs +5 -0
  41. package/esm2020/translation/acorex-core-translation.mjs +5 -0
  42. package/esm2020/translation/public-api.mjs +4 -0
  43. package/esm2020/translation/src/translation.module.mjs +18 -0
  44. package/esm2020/translation/src/translator.mjs +43 -0
  45. package/esm2020/translation/src/translator.pipe.mjs +15 -0
  46. package/esm2020/utils/acorex-core-utils.mjs +5 -0
  47. package/esm2020/utils/public-api.mjs +5 -0
  48. package/esm2020/utils/src/color-util.mjs +71 -0
  49. package/esm2020/utils/src/drawing-util.mjs +27 -0
  50. package/esm2020/utils/src/object-util.mjs +39 -0
  51. package/esm2020/utils/src/string-util.mjs +19 -0
  52. package/events/index.d.ts +5 -0
  53. package/events/public-api.d.ts +1 -0
  54. package/events/src/event.service.d.ts +9 -0
  55. package/fesm2015/acorex-core-config.mjs +39 -0
  56. package/fesm2015/acorex-core-config.mjs.map +1 -0
  57. package/fesm2015/acorex-core-dateTime.mjs +899 -0
  58. package/fesm2015/acorex-core-dateTime.mjs.map +1 -0
  59. package/fesm2015/acorex-core-events.mjs +43 -0
  60. package/fesm2015/acorex-core-events.mjs.map +1 -0
  61. package/fesm2015/acorex-core-http.mjs +201 -0
  62. package/fesm2015/acorex-core-http.mjs.map +1 -0
  63. package/fesm2015/acorex-core-pipes.mjs +53 -0
  64. package/fesm2015/acorex-core-pipes.mjs.map +1 -0
  65. package/fesm2015/acorex-core-platform.mjs +148 -0
  66. package/fesm2015/acorex-core-platform.mjs.map +1 -0
  67. package/fesm2015/acorex-core-translation.mjs +80 -0
  68. package/fesm2015/acorex-core-translation.mjs.map +1 -0
  69. package/fesm2015/acorex-core-utils.mjs +163 -0
  70. package/fesm2015/acorex-core-utils.mjs.map +1 -0
  71. package/fesm2015/acorex-core.mjs +11 -0
  72. package/fesm2015/acorex-core.mjs.map +1 -0
  73. package/fesm2020/acorex-core-config.mjs +39 -0
  74. package/fesm2020/acorex-core-config.mjs.map +1 -0
  75. package/fesm2020/acorex-core-dateTime.mjs +899 -0
  76. package/fesm2020/acorex-core-dateTime.mjs.map +1 -0
  77. package/fesm2020/acorex-core-events.mjs +43 -0
  78. package/fesm2020/acorex-core-events.mjs.map +1 -0
  79. package/fesm2020/acorex-core-http.mjs +200 -0
  80. package/fesm2020/acorex-core-http.mjs.map +1 -0
  81. package/fesm2020/acorex-core-pipes.mjs +53 -0
  82. package/fesm2020/acorex-core-pipes.mjs.map +1 -0
  83. package/fesm2020/acorex-core-platform.mjs +148 -0
  84. package/fesm2020/acorex-core-platform.mjs.map +1 -0
  85. package/fesm2020/acorex-core-translation.mjs +79 -0
  86. package/fesm2020/acorex-core-translation.mjs.map +1 -0
  87. package/fesm2020/acorex-core-utils.mjs +163 -0
  88. package/fesm2020/acorex-core-utils.mjs.map +1 -0
  89. package/fesm2020/acorex-core.mjs +11 -0
  90. package/fesm2020/acorex-core.mjs.map +1 -0
  91. package/http/index.d.ts +5 -0
  92. package/http/{public-api.ts → public-api.d.ts} +1 -1
  93. package/http/src/{http-error.class.ts → http-error.class.d.ts} +2 -2
  94. package/http/src/{http-events.interceptor.ts → http-events.interceptor.d.ts} +3 -7
  95. package/http/src/{http-request.class.ts → http-request.class.d.ts} +5 -5
  96. package/http/src/http-result.class.d.ts +11 -0
  97. package/http/src/http.module.d.ts +8 -0
  98. package/http/src/http.service.d.ts +23 -0
  99. package/index.d.ts +5 -0
  100. package/package.json +106 -23
  101. package/pipes/index.d.ts +5 -0
  102. package/pipes/public-api.d.ts +2 -0
  103. package/pipes/src/pipes.module.d.ts +8 -0
  104. package/pipes/src/safe.pipe.d.ts +10 -0
  105. package/platform/index.d.ts +5 -0
  106. package/platform/public-api.d.ts +1 -0
  107. package/platform/src/platform.service.d.ts +25 -0
  108. package/public-api.d.ts +1 -0
  109. package/translation/index.d.ts +5 -0
  110. package/translation/{public-api.ts → public-api.d.ts} +1 -1
  111. package/translation/src/translation.module.d.ts +7 -0
  112. package/translation/src/translator.d.ts +11 -0
  113. package/translation/src/translator.pipe.d.ts +7 -0
  114. package/utils/index.d.ts +5 -0
  115. package/utils/{public-api.ts → public-api.d.ts} +1 -1
  116. package/utils/src/color-util.d.ts +20 -0
  117. package/utils/src/drawing-util.d.ts +17 -0
  118. package/utils/src/object-util.d.ts +4 -0
  119. package/utils/src/string-util.d.ts +6 -0
  120. package/.browserslistrc +0 -16
  121. package/config/ax-preset.js +0 -186
  122. package/config/index.ts +0 -1
  123. package/config/ng-package.json +0 -6
  124. package/config/public-api.ts +0 -1
  125. package/config/src/configs.ts +0 -37
  126. package/dateTime/index.ts +0 -1
  127. package/dateTime/ng-package.json +0 -6
  128. package/dateTime/src/datetime.class.ts +0 -452
  129. package/dateTime/src/datetime.module.ts +0 -29
  130. package/dateTime/src/datetime.pipe.ts +0 -21
  131. package/dateTime/src/georgian.calendar.ts +0 -205
  132. package/dateTime/src/jalali.calendar.ts +0 -416
  133. package/events/index.ts +0 -1
  134. package/events/ng-package.json +0 -6
  135. package/events/public-api.ts +0 -1
  136. package/events/src/event.service.ts +0 -31
  137. package/http/index.ts +0 -1
  138. package/http/ng-package.json +0 -6
  139. package/http/src/http-result.class.ts +0 -34
  140. package/http/src/http.module.ts +0 -25
  141. package/http/src/http.service.ts +0 -161
  142. package/index.ts +0 -1
  143. package/karma.conf.js +0 -44
  144. package/ng-package.json +0 -7
  145. package/pipes/index.ts +0 -1
  146. package/pipes/ng-package.json +0 -6
  147. package/pipes/public-api.ts +0 -2
  148. package/pipes/src/pipes.module.ts +0 -11
  149. package/pipes/src/safe.pipe.ts +0 -24
  150. package/platform/index.ts +0 -1
  151. package/platform/ng-package.json +0 -6
  152. package/platform/public-api.ts +0 -1
  153. package/platform/src/platform.service.ts +0 -207
  154. package/public-api.ts +0 -4
  155. package/test.ts +0 -27
  156. package/translation/index.ts +0 -1
  157. package/translation/ng-package.json +0 -6
  158. package/translation/src/translation.module.ts +0 -12
  159. package/translation/src/translator.pipe.ts +0 -9
  160. package/translation/src/translator.ts +0 -49
  161. package/tsconfig.lib.json +0 -15
  162. package/tsconfig.lib.prod.json +0 -10
  163. package/tsconfig.spec.json +0 -17
  164. package/utils/index.ts +0 -1
  165. package/utils/ng-package.json +0 -6
  166. package/utils/src/color-util.ts +0 -83
  167. package/utils/src/drawing-util.ts +0 -43
  168. package/utils/src/object-util.ts +0 -82
  169. package/utils/src/string-util.ts +0 -25
@@ -1,452 +0,0 @@
1
- import * as _ from 'lodash';
2
- import { AXConfig } from '@acorex/core/config';
3
-
4
- export type TimeUnit =
5
- | 'ms'
6
- | 'second'
7
- | 'minute'
8
- | 'hour'
9
- | 'day'
10
- | 'month'
11
- | 'year'
12
- | 'week';
13
-
14
- export interface AXDateValue {
15
- year: number,
16
- month: number,
17
- date: number,
18
- hours?: number,
19
- minutes?: number,
20
- seconds?: number,
21
- ms?: number
22
- calendar: string;
23
- }
24
-
25
-
26
- export interface AXCalendar {
27
- monthNames: string[];
28
-
29
- monthShortNames: string[];
30
-
31
- dayNames: string[];
32
-
33
- dayShortNames: string[];
34
-
35
- name(): string;
36
-
37
- dayOfMonth(date: Date): number;
38
-
39
- dayOfYear(date: Date): number;
40
-
41
- dayOfWeek(date: Date): number;
42
-
43
- monthOfYear(date: Date): number;
44
-
45
- weekOfYear(date: Date): number;
46
-
47
- year(date: Date): number;
48
-
49
- add(date: Date, unit: TimeUnit, amount: number): AXDateTime;
50
-
51
- set(date: Date, unit: TimeUnit, value: number): AXDateTime;
52
-
53
- startOf(date: Date, unit: TimeUnit): AXDateTime;
54
-
55
- endOf(date: Date, unit: TimeUnit): AXDateTime;
56
-
57
- create(value: AXDateValue): AXDateTime;
58
- }
59
-
60
-
61
-
62
-
63
- // @dynamic
64
- export class AXDateTime {
65
- static convert(
66
- value: Date | AXDateTime | string,
67
- calendar: string = AXConfig.get('dateTime.calendar')
68
- ): AXDateTime {
69
- let date: AXDateTime;
70
- if (typeof value === 'string' || value instanceof String) {
71
- date = new AXDateTime(value as string, calendar);
72
- } else if (value instanceof Date) {
73
- date = new AXDateTime(value as Date, calendar);
74
- } else if (value instanceof AXDateTime) {
75
- date = new AXDateTime(value.date, calendar);
76
- }
77
- return date!;
78
- }
79
-
80
- static from(value: AXDateValue = {
81
- calendar: AXConfig.get('dateTime.calendar'),
82
- year: 1,
83
- month: 1,
84
- date: 1,
85
- hours: 0,
86
- minutes: 0,
87
- seconds: 0,
88
- ms: 0
89
- }): AXDateTime {
90
- // let date: AXDateTime = new AXDateTime(new Date(), value.calendar);
91
- // date.set('year', value.year);
92
- // date.set('month', value.month);
93
- // date.set('day', value.date);
94
- // date.set('hour', value.hours);
95
- // date.set('minute', value.minutes);
96
- // date.set('second', value.seconds);
97
- // date.set('ms', value.ms);
98
-
99
- return AXDateTime.resolveCalendar(value.calendar).create(value);
100
- }
101
-
102
-
103
- static resolveCalendar(calendar: string | AXCalendar): AXCalendar {
104
- return typeof calendar == 'string'
105
- ? AXConfig.get(`dateTime.calendars.${calendar}`)
106
- : calendar;
107
- }
108
-
109
-
110
- private _date: Date;
111
-
112
- get date(): Date {
113
- return this._date;
114
- }
115
-
116
- private _calendar: AXCalendar;
117
- get calendar(): AXCalendar {
118
- return this._calendar;
119
- }
120
-
121
-
122
-
123
- constructor(
124
- value: Date | string = new Date(),
125
- calendar: string | AXCalendar = AXConfig.get(`dateTime.calendar`)
126
- ) {
127
- this._calendar = AXDateTime.resolveCalendar(calendar);
128
- if (value instanceof Date) {
129
- this._date = value as Date;
130
- } else {
131
- //TODO: parse jalali
132
- this._date = new Date(value);
133
- }
134
- }
135
-
136
- clone(): AXDateTime {
137
- return new AXDateTime(this.date, this.calendar);
138
- }
139
-
140
- get dayOfMonth(): number {
141
- return this._calendar.dayOfMonth(this.date);
142
- }
143
-
144
- get dayOfYear(): number {
145
- return this._calendar.dayOfYear(this.date);
146
- }
147
-
148
- get dayOfWeek(): number {
149
- return this._calendar.dayOfWeek(this.date);
150
- }
151
-
152
- get hour(): number {
153
- return this._date.getHours();
154
- }
155
-
156
- get minute(): number {
157
- return this._date.getMinutes();
158
- }
159
-
160
- get second(): number {
161
- return this._date.getSeconds();
162
- }
163
-
164
- get year(): number {
165
- return this._calendar.year(this.date);
166
- }
167
-
168
- get monthOfYear(): number {
169
- return this._calendar.monthOfYear(this.date);
170
- }
171
-
172
- get weekOfYear(): number {
173
- return this._calendar.weekOfYear(this.date);
174
- }
175
-
176
- get month(): AXCalendarMonth {
177
- return new AXCalendarMonth(this);
178
- }
179
-
180
- add(unit: TimeUnit, amount: number): AXDateTime {
181
- return this._calendar.add(this.date, unit, amount);
182
- }
183
-
184
- set(unit: TimeUnit = 'day', value: number): AXDateTime {
185
- return this._calendar.set(this.date, unit, value);
186
- }
187
-
188
- duration(
189
- end: Date | AXDateTime,
190
- unit: TimeUnit = 'day'
191
- ): AXTimeSpan {
192
- const range = new AXDateTimeRange(
193
- this,
194
- AXDateTime.convert(end, this.calendar.name())
195
- );
196
- return range.duration();
197
- }
198
-
199
- startOf(unit: TimeUnit = 'day'): AXDateTime {
200
- return this._calendar.startOf(this.date, unit);
201
- }
202
-
203
- endOf(unit: TimeUnit = 'day'): AXDateTime {
204
- return this._calendar.endOf(this.date, unit);
205
- }
206
-
207
- private _formatKeys = {
208
- ss: () => this.pad(this.date.getSeconds(), 2),
209
- s: () => this.date.getSeconds().toString(),
210
- //
211
- dd: () => this.pad(this.calendar.dayOfMonth(this.date), 2),
212
- d: () => this.calendar.dayOfMonth(this.date).toString(),
213
- //
214
- mm: () => this.pad(this.date.getMinutes(), 2),
215
- m: () => this.date.getMinutes().toString(),
216
- //
217
- MMMM: () => this.calendar.monthNames[this.calendar.monthOfYear(this.date) - 1],
218
- MMM: () => this.calendar.monthShortNames[this.calendar.monthOfYear(this.date) - 1],
219
- MM: () => this.pad(this.calendar.monthOfYear(this.date), 2),
220
- //
221
- DDDD: () => this.calendar.dayNames[this.calendar.dayOfWeek(this.date) - 1],
222
- DDD: () => this.calendar.dayShortNames[this.calendar.dayOfWeek(this.date) - 1],
223
- //
224
- yyyy: () => this.calendar.year(this.date).toString(),
225
- YYYY: () => this.calendar.year(this.date).toString(),
226
- yy: () => this.calendar.year(this.date).toString().substring(2),
227
- YY: () => this.calendar.year(this.date).toString().substring(2),
228
- //
229
- HH: () => this.pad(this.date.getHours(), 2),
230
- H: () => this.date.getHours().toString(),
231
- //
232
- hh: () => this.pad((this.date.getHours() % 12 || 12), 2),
233
- h: () => (this.date.getHours() % 12 || 12).toString(),
234
- //
235
- A: () => (this.date.getHours() < 12) ? 'am' : 'pm',
236
- a: () => (this.date.getHours() < 12) ? 'am' : 'pm',
237
- };
238
-
239
- format(
240
- format: string = AXConfig.get('dateTime.shortDateFormat')
241
- ): string {
242
- const re = new RegExp(_.orderBy(Object.keys(this._formatKeys), c => c.length, ['desc']).join("|"), "gi");
243
- return format.replace(re, (matched) => {
244
- return this._formatKeys[matched]();
245
- });
246
- }
247
-
248
- private pad(n, width, z = '0') {
249
- n = n + '';
250
- return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
251
- }
252
-
253
- toString(format: string = AXConfig.get('dateTime.shortDateFormat')): string {
254
- return this.format(format);
255
- }
256
-
257
- equal(value: Date | AXDateTime, unit: TimeUnit = 'day') {
258
- return this.compare(value, unit) == 0;
259
- }
260
-
261
- compare(value: Date | AXDateTime, unit: TimeUnit = 'day') {
262
- const val = AXDateTime.convert(value, this.calendar.name());
263
- const func = (v1: number, v2: number) => {
264
- if (v1 == v2) {
265
- return 0;
266
- } else if (v1 > v2) {
267
- return 1;
268
- } else {
269
- return -1;
270
- }
271
- }
272
- let p = 0;
273
- switch (unit) {
274
- case 'year':
275
- return func(this.year, val.year);
276
- case 'week':
277
- p = this.compare(val, 'year');
278
- return p == 0 ? func(this.weekOfYear, val.weekOfYear) : p;
279
- case 'month':
280
- p = this.compare(val, 'year');
281
- return p == 0 ? func(this.monthOfYear, val.monthOfYear) : p;
282
- case 'day':
283
- p = this.compare(val, 'year');
284
- return p == 0 ? func(this.dayOfYear, val.dayOfYear) : p;
285
- case 'hour':
286
- p = this.compare(val, 'day');
287
- return p == 0 ? func(this.hour, val.hour) : p;
288
- case 'minute':
289
- p = this.compare(val, 'hour');
290
- return p == 0 ? func(this.minute, val.minute) : p;
291
- case 'second':
292
- p = this.compare(val, 'minute');
293
- return p == 0 ? func(this.second, val.second) : p;
294
- default:
295
- return func(this.date.getTime(), val.date.getTime());
296
- }
297
-
298
- }
299
-
300
- convert(calendar: string) {
301
- return AXDateTime.convert(this, calendar);
302
- }
303
- }
304
-
305
- export class AXCalendarMonth {
306
- private _range: AXDateTimeRange;
307
- public get range(): AXDateTimeRange {
308
- return this._range;
309
- }
310
- public set range(v: AXDateTimeRange) {
311
- this._range = v;
312
- }
313
-
314
- constructor(date: AXDateTime) {
315
- this.index = date.date.getMonth();
316
- this.name = date.format('MMMM');
317
- this.range = new AXDateTimeRange(
318
- new AXDateTime(date.startOf('month').date, date.calendar),
319
- new AXDateTime(date.endOf('month').date, date.calendar)
320
- );
321
- }
322
-
323
- private readonly index: number;
324
- private readonly name: string;
325
- }
326
-
327
- export interface AXTimeSpanTotal {
328
- miliseconds: number;
329
- seconds: number;
330
- minutes: number;
331
- hours: number;
332
- days: number;
333
- weeks: number;
334
- months: number;
335
- years: number;
336
- }
337
-
338
- export interface AXTimeSpan {
339
- miliseconds: number;
340
- seconds: number;
341
- minutes: number;
342
- hours: number;
343
- days: number;
344
- months: number;
345
- years: number;
346
- total: AXTimeSpanTotal;
347
- }
348
-
349
- export class AXDateTimeRange {
350
- private _startTime: AXDateTime;
351
- private _endTime: AXDateTime;
352
-
353
- public get startTime(): AXDateTime {
354
- return this._startTime;
355
- }
356
-
357
- public get endTime(): AXDateTime {
358
- return this._endTime;
359
- }
360
-
361
- constructor(startTime: AXDateTime, endTime: AXDateTime) {
362
- this._startTime = startTime;
363
- this._endTime = endTime;
364
- }
365
-
366
- duration(): AXTimeSpan {
367
- const result: AXTimeSpan = {
368
- miliseconds: 0,
369
- seconds: 0,
370
- minutes: 0,
371
- hours: 0,
372
- days: 0,
373
- months: 0,
374
- years: 0,
375
- total: {
376
- miliseconds: 0,
377
- seconds: 0,
378
- minutes: 0,
379
- hours: 0,
380
- days: 0,
381
- weeks: 0,
382
- months: 0,
383
- years: 0,
384
- },
385
- };
386
-
387
- const one_second = 1000;
388
- const one_min = one_second * 60;
389
- const one_hour = one_min * 60;
390
- const one_day = one_hour * 24;
391
- const one_week = one_day * 7;
392
- const one_year = 365.25 * one_day;
393
- const one_month = one_year / 12;
394
- const startTime = this._startTime.date.getTime();
395
- const endTime = this._endTime.date.getTime();
396
- const diff = Math.abs(endTime - startTime);
397
- //
398
- result.total.miliseconds = diff;
399
- result.total.seconds = Number((diff / one_second).toFixed(2));
400
- result.total.minutes = Number((diff / one_min).toFixed(2));
401
- result.total.hours = Number((diff / one_hour).toFixed(2));
402
- result.total.days = Number((diff / one_day).toFixed(2));
403
- result.total.weeks = Number((diff / one_week).toFixed(2));
404
- //
405
- // let months = (this.endTime.year - this.startTime.year) * 12;
406
- // months += this.endTime.monthOfYear - this.startTime.monthOfYear + 1;
407
- // if (this.endTime.dayOfYear < this.startTime.dayOfYear) {
408
- // months--;
409
- // }
410
- // result.total.months = Math.abs(months);
411
- // TODO: review
412
- result.total.months = Number((diff / one_month).toFixed(2));
413
- result.total.years = Number((diff / one_year).toFixed(2));
414
- //
415
- result.miliseconds = result.total.miliseconds % 1000;
416
- result.seconds = Number((result.total.seconds % 60).toFixed(0));
417
- result.minutes = Number((result.total.minutes % 60).toFixed(0));
418
- result.hours = Number((result.total.hours % 24).toFixed(0));
419
- // TODO: review
420
- result.days = Number((result.total.days % 30.4).toFixed(0));
421
- result.months = Number((result.total.months % 12).toFixed(0));
422
- result.years = Number(result.total.years.toFixed(0));
423
- return result;
424
- }
425
-
426
- enumurate(unit: TimeUnit = 'day', amount: number = 1): AXDateTime[] {
427
- // TODO: setptemper savingtime issue
428
- const result: AXDateTime[] = [];
429
- let item = this._startTime.clone();
430
- while (item.compare(this._endTime, unit) < 1) {
431
- result.push(item);
432
- item = item.add(unit, amount)
433
- }
434
- return result;
435
- }
436
-
437
- includes(value: AXDateTime, unit: TimeUnit = 'day'): boolean {
438
- // TODO: ??
439
- return true;
440
- }
441
-
442
- // getViewCompaire(view) {
443
- // switch (view) {
444
- // case 'day':
445
- // return 'YMD';
446
- // case 'month':
447
- // return 'YM';
448
- // case 'year':
449
- // return 'Y';
450
- // }
451
- // }
452
- }
@@ -1,29 +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: new JalaliCalendar(),
21
- gregorian: new GeorgianCalendar()
22
- },
23
- calendar:'gregorian',
24
- shortDateFormat:'DDDD, d MMM yyyy'
25
- }
26
- });
27
-
28
- }
29
- }
@@ -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
- }