@ajf/calendars 13.0.0-next.2 → 13.0.0-rc.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 (44) hide show
  1. package/esm2020/ethiopian/calendar-module.mjs +40 -0
  2. package/{esm2015/ethiopian/calendar-service.js → esm2020/ethiopian/calendar-service.mjs} +10 -8
  3. package/esm2020/ethiopian/converter.mjs +154 -0
  4. package/esm2020/ethiopian/ethiopian-date-pipe.mjs +47 -0
  5. package/esm2020/ethiopian/ethiopian-date.mjs +204 -0
  6. package/esm2020/ethiopian/ethiopian_public_index.mjs +5 -0
  7. package/esm2020/ethiopian/index.mjs +23 -0
  8. package/{esm2015/ethiopian/public-api.js → esm2020/ethiopian/public-api.mjs} +0 -0
  9. package/esm2020/ethiopian/utils.mjs +53 -0
  10. package/{esm2015/index.js → esm2020/index.mjs} +0 -0
  11. package/{esm2015/public-api.js → esm2020/public-api.mjs} +0 -0
  12. package/{esm2015/version.js → esm2020/version.mjs} +1 -1
  13. package/ethiopian/calendar-module.d.ts +5 -21
  14. package/ethiopian/calendar-service.d.ts +3 -0
  15. package/ethiopian/converter.d.ts +1 -5
  16. package/ethiopian/ethiopian-date-pipe.d.ts +4 -0
  17. package/ethiopian/ethiopian-date.d.ts +11 -1
  18. package/ethiopian/ethiopian_public_index.d.ts +4 -0
  19. package/ethiopian/index.d.ts +19 -1
  20. package/ethiopian/package.json +6 -6
  21. package/fesm2015/{calendars.js → calendars.mjs} +2 -2
  22. package/fesm2015/calendars.mjs.map +1 -0
  23. package/fesm2015/{ethiopian.js → ethiopian.mjs} +137 -54
  24. package/fesm2015/ethiopian.mjs.map +1 -0
  25. package/fesm2020/calendars.mjs +72 -0
  26. package/fesm2020/calendars.mjs.map +1 -0
  27. package/fesm2020/ethiopian.mjs +750 -0
  28. package/fesm2020/ethiopian.mjs.map +1 -0
  29. package/package.json +30 -8
  30. package/bundles/calendars-ethiopian.umd.js +0 -984
  31. package/bundles/calendars-ethiopian.umd.js.map +0 -1
  32. package/bundles/calendars.umd.js +0 -80
  33. package/bundles/calendars.umd.js.map +0 -1
  34. package/esm2015/calendars.externs.js +0 -0
  35. package/esm2015/ethiopian/calendar-module.js +0 -41
  36. package/esm2015/ethiopian/converter.js +0 -140
  37. package/esm2015/ethiopian/ethiopian-date-pipe.js +0 -41
  38. package/esm2015/ethiopian/ethiopian-date.js +0 -188
  39. package/esm2015/ethiopian/ethiopian.externs.js +0 -6
  40. package/esm2015/ethiopian/index.js +0 -5
  41. package/esm2015/ethiopian/utils.js +0 -27
  42. package/ethiopian/index.metadata.json +0 -1
  43. package/fesm2015/calendars.js.map +0 -1
  44. package/fesm2015/ethiopian.js.map +0 -1
@@ -0,0 +1,750 @@
1
+ import { AjfCalendarService } from '@ajf/core/calendar';
2
+ import * as i0 from '@angular/core';
3
+ import { Injectable, Pipe, NgModule } from '@angular/core';
4
+ import { getISODay, startOfISOWeek, endOfISOWeek, addWeeks, subWeeks, setISODay, startOfWeek, addDays, addYears } from 'date-fns';
5
+
6
+ /**
7
+ * @license
8
+ * Copyright (C) Gnucoop soc. coop.
9
+ *
10
+ * This file is part of the Advanced JSON forms (ajf).
11
+ *
12
+ * Advanced JSON forms (ajf) is free software: you can redistribute it and/or
13
+ * modify it under the terms of the GNU Affero General Public License as
14
+ * published by the Free Software Foundation, either version 3 of the License,
15
+ * or (at your option) any later version.
16
+ *
17
+ * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
20
+ * General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU Affero General Public License
23
+ * along with Advanced JSON forms (ajf).
24
+ * If not, see http://www.gnu.org/licenses/.
25
+ *
26
+ */
27
+ const JD_EPOCH_OFFSET_AMETE_ALEM = -285019; // ዓ/ዓ
28
+ const JD_EPOCH_OFFSET_AMETE_MIHRET = 1723856; // ዓ/ም
29
+ const JD_EPOCH_OFFSET_GREGORIAN = 1721426;
30
+ const JD_EPOCH_OFFSET_UNSET = -1;
31
+ let JDN_OFFSET = JD_EPOCH_OFFSET_UNSET;
32
+ const GREGORIAN_NUMBER_OF_MONTHS = 12;
33
+ const monthDays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
34
+ function quotient(i, j) {
35
+ return Math.floor(i / j);
36
+ }
37
+ function isGregorianLeap(year) {
38
+ return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
39
+ }
40
+ function setEra(era) {
41
+ if (era === JD_EPOCH_OFFSET_AMETE_ALEM || era === JD_EPOCH_OFFSET_AMETE_MIHRET) {
42
+ JDN_OFFSET = era;
43
+ }
44
+ else {
45
+ throw new Error(`Unknown Era: ${era}`);
46
+ }
47
+ }
48
+ function isEraSet() {
49
+ return JD_EPOCH_OFFSET_UNSET !== JDN_OFFSET;
50
+ }
51
+ function unsetEra() {
52
+ JDN_OFFSET = JD_EPOCH_OFFSET_UNSET;
53
+ }
54
+ function guessEraFromJDN(jdn) {
55
+ return jdn >= JD_EPOCH_OFFSET_AMETE_MIHRET + 365
56
+ ? JD_EPOCH_OFFSET_AMETE_MIHRET
57
+ : JD_EPOCH_OFFSET_AMETE_ALEM;
58
+ }
59
+ function ethiopicToJDN(day, month, year) {
60
+ const ERA = isEraSet() ? JDN_OFFSET : JD_EPOCH_OFFSET_AMETE_MIHRET;
61
+ const jdn = ERA + 365 + 365 * (year - 1) + quotient(year, 4) + 30 * month + day - 31;
62
+ return jdn;
63
+ }
64
+ function jdnToEthiopic(jdn) {
65
+ const ERA = isEraSet() ? JDN_OFFSET : guessEraFromJDN(jdn);
66
+ const r = (jdn - ERA) % 1461;
67
+ const n = (r % 365) + 365 * quotient(r, 1460);
68
+ const year = 4 * quotient(jdn - ERA, 1461) + quotient(r, 365) - quotient(r, 1460);
69
+ const month = quotient(n, 30) + 1;
70
+ const day = (n % 30) + 1;
71
+ return [year, month, day];
72
+ }
73
+ function gregorianToJDN(day, month, year) {
74
+ const s = quotient(year, 4) -
75
+ quotient(year - 1, 4) -
76
+ quotient(year, 100) +
77
+ quotient(year - 1, 100) +
78
+ quotient(year, 400) -
79
+ quotient(year - 1, 400);
80
+ const t = quotient(14 - month, 12);
81
+ const n = 31 * t * (month - 1) +
82
+ (1 - t) * (59 + s + 30 * (month - 3) + quotient(3 * month - 7, 5)) +
83
+ day -
84
+ 1;
85
+ const j = JD_EPOCH_OFFSET_GREGORIAN +
86
+ 365 * (year - 1) +
87
+ quotient(year - 1, 4) -
88
+ quotient(year - 1, 100) +
89
+ quotient(year - 1, 400) +
90
+ n;
91
+ return j;
92
+ }
93
+ function jdnToGregorian(jdn) {
94
+ const r2000 = (jdn - JD_EPOCH_OFFSET_GREGORIAN) % 730485;
95
+ const r400 = (jdn - JD_EPOCH_OFFSET_GREGORIAN) % 146097;
96
+ const r100 = r400 % 36524;
97
+ const r4 = r100 % 1461;
98
+ let n = (r4 % 365) + 365 * quotient(r4, 1460);
99
+ const s = quotient(r4, 1095);
100
+ const aprime = 400 * quotient(jdn - JD_EPOCH_OFFSET_GREGORIAN, 146097) +
101
+ 100 * quotient(r400, 36524) +
102
+ 4 * quotient(r100, 1461) +
103
+ quotient(r4, 365) -
104
+ quotient(r4, 1460) -
105
+ quotient(r2000, 730484);
106
+ const year = aprime + 1;
107
+ const t = quotient(364 + s - n, 306);
108
+ let month = t * (quotient(n, 31) + 1) + (1 - t) * (quotient(5 * (n - s) + 13, 153) + 1);
109
+ n += 1 - quotient(r2000, 730484);
110
+ let day = n;
111
+ if (r100 === 0 && n === 0 && r400 !== 0) {
112
+ month = 12;
113
+ day = 31;
114
+ }
115
+ else {
116
+ monthDays[2] = isGregorianLeap(year) ? 29 : 28;
117
+ for (let i = 1; i <= GREGORIAN_NUMBER_OF_MONTHS; i += 1) {
118
+ if (n <= monthDays[i]) {
119
+ day = n;
120
+ break;
121
+ }
122
+ n -= monthDays[i];
123
+ }
124
+ }
125
+ return [year, month, day];
126
+ }
127
+ function gregorianToEthiopic(day, month, year) {
128
+ const jdn = gregorianToJDN(day, month, year);
129
+ return jdnToEthiopic(jdn);
130
+ }
131
+ function ethioipicToGreg(day, month, year) {
132
+ const jdn = ethiopicToJDN(day, month, year);
133
+ return jdnToGregorian(jdn);
134
+ }
135
+ function ethioipicToGregorian(day, month, year, era) {
136
+ setEra(era);
137
+ const result = ethioipicToGreg(day, month, year);
138
+ unsetEra();
139
+ return result;
140
+ }
141
+ /** API * */
142
+ /** ethiopian to gregorian */
143
+ function toGC(dateArray) {
144
+ const [y, m, d] = dateArray;
145
+ let era = dateArray.length === 4 ? dateArray[3] : JD_EPOCH_OFFSET_AMETE_MIHRET;
146
+ if (d < 0 || d > 30 || m < 0 || m > 13) {
147
+ throw new Error('Invalid Ethiopian Date');
148
+ }
149
+ return ethioipicToGregorian(d, m, y, era);
150
+ }
151
+ /** gregorian to ethiopian */
152
+ function toEC(dateArray) {
153
+ const [y, m, d] = dateArray;
154
+ if (d < 0 || d > 31 || m < 0 || m > 12) {
155
+ throw new Error('Invalid Gregorian Date');
156
+ }
157
+ return gregorianToEthiopic(d, m, y);
158
+ }
159
+
160
+ /**
161
+ * @license
162
+ * Copyright (C) Gnucoop soc. coop.
163
+ *
164
+ * This file is part of the Advanced JSON forms (ajf).
165
+ *
166
+ * Advanced JSON forms (ajf) is free software: you can redistribute it and/or
167
+ * modify it under the terms of the GNU Affero General Public License as
168
+ * published by the Free Software Foundation, either version 3 of the License,
169
+ * or (at your option) any later version.
170
+ *
171
+ * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,
172
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
173
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
174
+ * General Public License for more details.
175
+ *
176
+ * You should have received a copy of the GNU Affero General Public License
177
+ * along with Advanced JSON forms (ajf).
178
+ * If not, see http://www.gnu.org/licenses/.
179
+ *
180
+ */
181
+ const WEEK_NAMES = ['እሑድ', 'ሰኞ', 'ማክሰኞ', 'ረቡዕ', 'ሓሙስ', 'ዓርብ', 'ቅዳሜ'];
182
+ const MONTHS_NAMES = [
183
+ 'መስከረም',
184
+ 'ጥቅምት',
185
+ 'ኅዳር',
186
+ 'ታኅሣሥ',
187
+ 'ጥር',
188
+ 'የካቲት',
189
+ 'መጋቢት',
190
+ 'ሚያዝያ',
191
+ 'ግንቦት',
192
+ 'ሰኔ',
193
+ 'ሐምሌ',
194
+ 'ነሐሴ',
195
+ 'ጳጉሜን',
196
+ ];
197
+ const SHORT_MONTHS_NAMES = [
198
+ 'መስከ',
199
+ 'ጥቅም',
200
+ 'ኅዳር',
201
+ 'ታኅሣ',
202
+ 'ጥር',
203
+ 'የካቲ',
204
+ 'መጋቢ',
205
+ 'ሚያዝ',
206
+ 'ግንቦ',
207
+ 'ሰኔ',
208
+ 'ሐምሌ',
209
+ 'ነሐሴ',
210
+ 'ጳጉሜ',
211
+ ];
212
+
213
+ /**
214
+ * @license
215
+ * Copyright (C) Gnucoop soc. coop.
216
+ *
217
+ * This file is part of the Advanced JSON forms (ajf).
218
+ *
219
+ * Advanced JSON forms (ajf) is free software: you can redistribute it and/or
220
+ * modify it under the terms of the GNU Affero General Public License as
221
+ * published by the Free Software Foundation, either version 3 of the License,
222
+ * or (at your option) any later version.
223
+ *
224
+ * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,
225
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
226
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
227
+ * General Public License for more details.
228
+ *
229
+ * You should have received a copy of the GNU Affero General Public License
230
+ * along with Advanced JSON forms (ajf).
231
+ * If not, see http://www.gnu.org/licenses/.
232
+ *
233
+ */
234
+ class EthiopianDate {
235
+ /**
236
+ * @param val - A numeric year value if the second and third parameters ar provided,
237
+ * It should be a date string if not
238
+ * @param month A zero-based numeric value for the month (0 for መስከረም, 12 for ጳጉሜን)
239
+ * @param day A numeric value equal for the day of the month.
240
+ */
241
+ constructor(val, month, day) {
242
+ if (val == null && month == null && day == null) {
243
+ const ahun = EthiopianDate.gregorianToEthiopian(new Date());
244
+ [this._year, this._month, this._date] = [ahun.getFullYear(), ahun.getMonth(), ahun.getDate()];
245
+ this._gc = EthiopianDate.ethiopianToGregorian(this._year, this._month, this._date);
246
+ }
247
+ else if (val != null && month == null && day == null && typeof val !== 'number') {
248
+ if (typeof val === 'string') {
249
+ const result = EthiopianDate.parse(val);
250
+ if (result == null) {
251
+ throw new Error('Invalid Argument Exception');
252
+ }
253
+ [this._year, this._month, this._date] = [
254
+ result.getFullYear(),
255
+ result.getMonth(),
256
+ result.getDate(),
257
+ ];
258
+ this._gc = EthiopianDate.ethiopianToGregorian(this._year, this._month, this._date);
259
+ }
260
+ else if (typeof val === 'object' && val instanceof Date) {
261
+ const result = EthiopianDate.gregorianToEthiopian(val);
262
+ [this._year, this._month, this._date] = [
263
+ result.getFullYear(),
264
+ result.getMonth(),
265
+ result.getDate(),
266
+ ];
267
+ this._gc = EthiopianDate.ethiopianToGregorian(this._year, this._month, this._date);
268
+ }
269
+ else {
270
+ throw new Error('Invalid Argument Exception');
271
+ }
272
+ }
273
+ else if (val != null && month != null && day != null && typeof val === 'number') {
274
+ this._year = val;
275
+ this._month = month;
276
+ this._date = day;
277
+ this._gc = EthiopianDate.ethiopianToGregorian(this._year, this._month, this._date);
278
+ }
279
+ }
280
+ getDate() {
281
+ return this._date;
282
+ }
283
+ getDay() {
284
+ return this._gc.getDay();
285
+ }
286
+ getDayOfWeek() {
287
+ const weekDay = this.getGCWeekDay();
288
+ return WEEK_NAMES[weekDay];
289
+ }
290
+ getFullYear() {
291
+ return this._year;
292
+ }
293
+ getGregorianDate() {
294
+ return this._gc;
295
+ }
296
+ getGCWeekDay() {
297
+ return this._gc.getDay();
298
+ }
299
+ getMonth() {
300
+ return this._month;
301
+ }
302
+ getMonthName() {
303
+ return this._month >= 0 && this._month < MONTHS_NAMES.length ? MONTHS_NAMES[this._month] : null;
304
+ }
305
+ getShortMonthName() {
306
+ return this._month >= 0 && this._month < SHORT_MONTHS_NAMES.length
307
+ ? SHORT_MONTHS_NAMES[this._month]
308
+ : null;
309
+ }
310
+ getHours() {
311
+ return 0;
312
+ }
313
+ getMinutes() {
314
+ return 0;
315
+ }
316
+ getSeconds() {
317
+ return 0;
318
+ }
319
+ getMilliseconds() {
320
+ return 0;
321
+ }
322
+ toString() {
323
+ return `${this._year}-${this._month + 1}-${this._date}`;
324
+ }
325
+ /**
326
+ * Converts a Ethiopian date to Gregorian and returns Date instance representing Gregorian Date.
327
+ *
328
+ * @param val - A numeric year value if the second and third parameters are
329
+ * provided, it should be a date string if not
330
+ * @param month A zero-based numeric value for the month
331
+ * (0 for መስከረም, 12 for ጳጉሜን)
332
+ * @param day A numeric value equal for the day of the month.
333
+ *
334
+ * @api public
335
+ */
336
+ static ethiopianToGregorian(val, month, day) {
337
+ let ec;
338
+ if (val != null && month == null && day == null && typeof val !== 'number') {
339
+ if (typeof val === 'string') {
340
+ const etDate = new EthiopianDate(val);
341
+ ec = [etDate.getFullYear(), etDate.getMonth() + 1, etDate.getDate()];
342
+ }
343
+ else if (typeof val === 'object' && val instanceof EthiopianDate) {
344
+ const [y, m, d] = [val.getFullYear(), val.getMonth() + 1, val.getDate()];
345
+ ec = [y, m, d];
346
+ }
347
+ else {
348
+ throw new Error('Invalid Argument Exception');
349
+ }
350
+ }
351
+ else if (val != null && month != null && day != null && typeof val === 'number') {
352
+ ec = [val, month + 1, day];
353
+ }
354
+ else {
355
+ throw new Error('Invalid Argument Exception');
356
+ }
357
+ const gc = toGC(ec);
358
+ return new Date(gc[0], gc[1] - 1, gc[2]);
359
+ }
360
+ /**
361
+ *
362
+ * @param val - A numeric year value if the second and third parameters are
363
+ * provided, it should be a date string if not
364
+ * @param month A zero-based numeric value for the month
365
+ * (0 for January, 11 for December)
366
+ * @param day A numeric value equal for the day of the month.
367
+ *
368
+ * @api public
369
+ */
370
+ static gregorianToEthiopian(val, month, day) {
371
+ let gc;
372
+ if (val != null && month == null && day == null && typeof val !== 'number') {
373
+ if (typeof val === 'string') {
374
+ const gcDate = new Date(val);
375
+ gc = [gcDate.getFullYear(), gcDate.getMonth() + 1, gcDate.getDate()];
376
+ }
377
+ else if (typeof val === 'object' && val instanceof Date) {
378
+ const [y, m, d] = [val.getFullYear(), val.getMonth() + 1, val.getDate()];
379
+ gc = [y, m, d];
380
+ }
381
+ else {
382
+ throw new Error('Invalid Argument Exception');
383
+ }
384
+ }
385
+ else if (val != null && month != null && day != null && typeof val === 'number') {
386
+ gc = [val, month + 1, day];
387
+ }
388
+ else {
389
+ throw new Error('Invalid Argument Exception');
390
+ }
391
+ const ec = toEC(gc);
392
+ return new EthiopianDate(ec[0], ec[1] - 1, ec[2]);
393
+ }
394
+ /**
395
+ * Parse Ethiopian date from string
396
+ *
397
+ * @param dateString a date string to parse
398
+ * @param pattern a parsing pattern
399
+ *
400
+ * @returns EthiopianDate
401
+ */
402
+ static parse(dateString) {
403
+ if (!dateString) {
404
+ return null;
405
+ }
406
+ const result = dateString.split('-');
407
+ if (result.length === 3) {
408
+ const [y, m, d] = result;
409
+ return new EthiopianDate(parseInt(y, 10), parseInt(m, 10) - 1, parseInt(d, 10));
410
+ }
411
+ throw new Error(`ParsingError: Can't parse ${dateString}`);
412
+ }
413
+ }
414
+
415
+ /**
416
+ * @license
417
+ * Copyright (C) Gnucoop soc. coop.
418
+ *
419
+ * This file is part of the Advanced JSON forms (ajf).
420
+ *
421
+ * Advanced JSON forms (ajf) is free software: you can redistribute it and/or
422
+ * modify it under the terms of the GNU Affero General Public License as
423
+ * published by the Free Software Foundation, either version 3 of the License,
424
+ * or (at your option) any later version.
425
+ *
426
+ * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,
427
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
428
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
429
+ * General Public License for more details.
430
+ *
431
+ * You should have received a copy of the GNU Affero General Public License
432
+ * along with Advanced JSON forms (ajf).
433
+ * If not, see http://www.gnu.org/licenses/.
434
+ *
435
+ */
436
+ function getMonthDays(month, year) {
437
+ if (month < 12) {
438
+ return 30;
439
+ }
440
+ return year % 4 === 3 ? 6 : 5;
441
+ }
442
+ function getMonthBounds(date) {
443
+ const year = date.getFullYear();
444
+ const month = date.getMonth();
445
+ const start = new EthiopianDate(year, month, 1);
446
+ const endDay = getMonthDays(month, year);
447
+ const end = new EthiopianDate(year, month, endDay);
448
+ return { start, end };
449
+ }
450
+ class AjfEthiopianCalendarService extends AjfCalendarService {
451
+ buildView(params) {
452
+ const { viewMode } = params;
453
+ const viewDate = EthiopianDate.gregorianToEthiopian(params.viewDate);
454
+ switch (viewMode) {
455
+ case 'decade':
456
+ let curYear = viewDate.getFullYear();
457
+ let firstYear = curYear - (curYear % 10) + 1;
458
+ let lastYear = firstYear + 11;
459
+ return {
460
+ header: `${firstYear} - ${lastYear}`,
461
+ headerRow: [],
462
+ rows: this._ecDecadeCalendarRows(params),
463
+ };
464
+ case 'year':
465
+ return {
466
+ header: `${viewDate.getFullYear()}`,
467
+ headerRow: [],
468
+ rows: this._ecYearCalendarRows(params),
469
+ };
470
+ case 'month':
471
+ const view = super.buildView(params);
472
+ return {
473
+ header: `${viewDate.getShortMonthName()} ${viewDate.getFullYear()}`,
474
+ headerRow: this._ecMonthHeaderRow(params),
475
+ rows: view.rows,
476
+ };
477
+ }
478
+ return super.buildView(params);
479
+ }
480
+ entryLabel(entry) {
481
+ const ecDate = EthiopianDate.gregorianToEthiopian(entry.date);
482
+ if (entry.type === 'day') {
483
+ return `${ecDate.getDate()}`;
484
+ }
485
+ if (entry.type === 'month') {
486
+ return `${ecDate.getMonthName()}`;
487
+ }
488
+ return `${ecDate.getFullYear()}`;
489
+ }
490
+ monthBounds(date, isoMode) {
491
+ if (!isoMode) {
492
+ const ecDate = EthiopianDate.gregorianToEthiopian(date);
493
+ const { start, end } = getMonthBounds(ecDate);
494
+ return {
495
+ start: EthiopianDate.ethiopianToGregorian(start),
496
+ end: EthiopianDate.ethiopianToGregorian(end),
497
+ };
498
+ }
499
+ else {
500
+ let isoDay = getISODay(date);
501
+ const ecDate = EthiopianDate.gregorianToEthiopian(date);
502
+ let { start, end } = getMonthBounds(ecDate);
503
+ if (ecDate.getMonth() === 12) {
504
+ start = EthiopianDate.gregorianToEthiopian(startOfISOWeek(start.getGregorianDate()));
505
+ end = EthiopianDate.gregorianToEthiopian(endOfISOWeek(end.getGregorianDate()));
506
+ }
507
+ else {
508
+ date = isoDay < 4 ? endOfISOWeek(date) : startOfISOWeek(date);
509
+ const startWeekDay = start.getDay();
510
+ const endWeekDay = end.getDay();
511
+ if (startWeekDay == 0 || startWeekDay > 4) {
512
+ start = EthiopianDate.gregorianToEthiopian(addWeeks(start.getGregorianDate(), 1));
513
+ }
514
+ if (endWeekDay > 0 && endWeekDay < 4) {
515
+ end = EthiopianDate.gregorianToEthiopian(subWeeks(end.getGregorianDate(), 1));
516
+ }
517
+ }
518
+ return {
519
+ start: startOfISOWeek(start.getGregorianDate()),
520
+ end: endOfISOWeek(end.getGregorianDate()),
521
+ };
522
+ }
523
+ }
524
+ nextView(viewDate, viewMode) {
525
+ if (viewMode === 'month') {
526
+ const ecDate = EthiopianDate.gregorianToEthiopian(viewDate);
527
+ let year = ecDate.getFullYear();
528
+ let month = ecDate.getMonth();
529
+ if (month === 12) {
530
+ month = 0;
531
+ year += 1;
532
+ }
533
+ else {
534
+ month += 1;
535
+ }
536
+ return EthiopianDate.ethiopianToGregorian(new EthiopianDate(year, month, 1));
537
+ }
538
+ return super.nextView(viewDate, viewMode);
539
+ }
540
+ previousView(viewDate, viewMode) {
541
+ if (viewMode === 'month') {
542
+ const ecDate = EthiopianDate.gregorianToEthiopian(viewDate);
543
+ let year = ecDate.getFullYear();
544
+ let month = ecDate.getMonth();
545
+ if (month === 0) {
546
+ month = 12;
547
+ year -= 1;
548
+ }
549
+ else {
550
+ month -= 1;
551
+ }
552
+ return EthiopianDate.ethiopianToGregorian(new EthiopianDate(year, month, 1));
553
+ }
554
+ return super.previousView(viewDate, viewMode);
555
+ }
556
+ _ecMonthHeaderRow(params) {
557
+ const { isoMode, viewDate } = params;
558
+ let curDate;
559
+ if (isoMode) {
560
+ curDate = setISODay(startOfWeek(viewDate), 1);
561
+ }
562
+ else {
563
+ curDate = startOfWeek(viewDate);
564
+ }
565
+ let weekDayNames = [];
566
+ for (let i = 0; i < 7; i++) {
567
+ const ecDate = EthiopianDate.gregorianToEthiopian(curDate);
568
+ weekDayNames.push(ecDate.getDayOfWeek());
569
+ curDate = addDays(curDate, 1);
570
+ }
571
+ return weekDayNames;
572
+ }
573
+ _ecYearCalendarRows(params) {
574
+ const { viewDate, selection } = params;
575
+ const year = EthiopianDate.gregorianToEthiopian(viewDate).getFullYear();
576
+ let curDate;
577
+ let rows = [];
578
+ for (let i = 0; i <= 4; i++) {
579
+ let row = [];
580
+ for (let j = 0; j < 3; j++) {
581
+ const curMonth = i * 3 + j;
582
+ if (curMonth < 13) {
583
+ curDate = new EthiopianDate(year, curMonth, 1);
584
+ let date = EthiopianDate.ethiopianToGregorian(curDate);
585
+ let newEntry = { type: 'month', date, selected: 'none' };
586
+ newEntry.selected = this.isEntrySelected(newEntry, selection);
587
+ row.push(newEntry);
588
+ }
589
+ }
590
+ rows.push(row);
591
+ }
592
+ return rows;
593
+ }
594
+ _ecDecadeCalendarRows(params) {
595
+ const { viewDate, selection } = params;
596
+ const ecDate = EthiopianDate.gregorianToEthiopian(viewDate);
597
+ let curYear = ecDate.getFullYear();
598
+ let firstYear = curYear - (curYear % 10) + 1;
599
+ let curDate = EthiopianDate.ethiopianToGregorian(firstYear, 0, 1);
600
+ let rows = [];
601
+ for (let i = 0; i < 4; i++) {
602
+ let row = [];
603
+ for (let j = 0; j < 3; j++) {
604
+ let date = new Date(curDate);
605
+ let newEntry = { type: 'year', date: date, selected: 'none' };
606
+ newEntry.selected = this.isEntrySelected(newEntry, selection);
607
+ row.push(newEntry);
608
+ curDate = addYears(curDate, 1);
609
+ }
610
+ rows.push(row);
611
+ }
612
+ return rows;
613
+ }
614
+ }
615
+ AjfEthiopianCalendarService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0-rc.3", ngImport: i0, type: AjfEthiopianCalendarService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
616
+ AjfEthiopianCalendarService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0-rc.3", ngImport: i0, type: AjfEthiopianCalendarService, providedIn: 'root' });
617
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0-rc.3", ngImport: i0, type: AjfEthiopianCalendarService, decorators: [{
618
+ type: Injectable,
619
+ args: [{ providedIn: 'root' }]
620
+ }] });
621
+
622
+ /**
623
+ * @license
624
+ * Copyright (C) Gnucoop soc. coop.
625
+ *
626
+ * This file is part of the Advanced JSON forms (ajf).
627
+ *
628
+ * Advanced JSON forms (ajf) is free software: you can redistribute it and/or
629
+ * modify it under the terms of the GNU Affero General Public License as
630
+ * published by the Free Software Foundation, either version 3 of the License,
631
+ * or (at your option) any later version.
632
+ *
633
+ * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,
634
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
635
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
636
+ * General Public License for more details.
637
+ *
638
+ * You should have received a copy of the GNU Affero General Public License
639
+ * along with Advanced JSON forms (ajf).
640
+ * If not, see http://www.gnu.org/licenses/.
641
+ *
642
+ */
643
+ class AjfEthiopianDatePipe {
644
+ transform(value) {
645
+ try {
646
+ const ed = EthiopianDate.gregorianToEthiopian(value);
647
+ const date = `0${ed.getDate()}`.slice(-2);
648
+ const month = `0${ed.getMonth() + 1}`.slice(-2);
649
+ return `${date}/${month}/${ed.getFullYear()}`;
650
+ }
651
+ catch (e) {
652
+ return null;
653
+ }
654
+ }
655
+ }
656
+ AjfEthiopianDatePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0-rc.3", ngImport: i0, type: AjfEthiopianDatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
657
+ AjfEthiopianDatePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.0.0-rc.3", ngImport: i0, type: AjfEthiopianDatePipe, name: "ajfEthiopianDate" });
658
+ AjfEthiopianDatePipe.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0-rc.3", ngImport: i0, type: AjfEthiopianDatePipe });
659
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0-rc.3", ngImport: i0, type: AjfEthiopianDatePipe, decorators: [{
660
+ type: Injectable
661
+ }, {
662
+ type: Pipe,
663
+ args: [{ name: 'ajfEthiopianDate' }]
664
+ }] });
665
+
666
+ /**
667
+ * @license
668
+ * Copyright (C) Gnucoop soc. coop.
669
+ *
670
+ * This file is part of the Advanced JSON forms (ajf).
671
+ *
672
+ * Advanced JSON forms (ajf) is free software: you can redistribute it and/or
673
+ * modify it under the terms of the GNU Affero General Public License as
674
+ * published by the Free Software Foundation, either version 3 of the License,
675
+ * or (at your option) any later version.
676
+ *
677
+ * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,
678
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
679
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
680
+ * General Public License for more details.
681
+ *
682
+ * You should have received a copy of the GNU Affero General Public License
683
+ * along with Advanced JSON forms (ajf).
684
+ * If not, see http://www.gnu.org/licenses/.
685
+ *
686
+ */
687
+ class AjfEthiopianCalendarModule {
688
+ }
689
+ AjfEthiopianCalendarModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0-rc.3", ngImport: i0, type: AjfEthiopianCalendarModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
690
+ AjfEthiopianCalendarModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0-rc.3", ngImport: i0, type: AjfEthiopianCalendarModule, declarations: [AjfEthiopianDatePipe], exports: [AjfEthiopianDatePipe] });
691
+ AjfEthiopianCalendarModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0-rc.3", ngImport: i0, type: AjfEthiopianCalendarModule, providers: [{ provide: AjfCalendarService, useClass: AjfEthiopianCalendarService }] });
692
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0-rc.3", ngImport: i0, type: AjfEthiopianCalendarModule, decorators: [{
693
+ type: NgModule,
694
+ args: [{
695
+ declarations: [AjfEthiopianDatePipe],
696
+ exports: [AjfEthiopianDatePipe],
697
+ providers: [{ provide: AjfCalendarService, useClass: AjfEthiopianCalendarService }],
698
+ }]
699
+ }] });
700
+
701
+ /**
702
+ * @license
703
+ * Copyright (C) Gnucoop soc. coop.
704
+ *
705
+ * This file is part of the Advanced JSON forms (ajf).
706
+ *
707
+ * Advanced JSON forms (ajf) is free software: you can redistribute it and/or
708
+ * modify it under the terms of the GNU Affero General Public License as
709
+ * published by the Free Software Foundation, either version 3 of the License,
710
+ * or (at your option) any later version.
711
+ *
712
+ * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,
713
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
714
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
715
+ * General Public License for more details.
716
+ *
717
+ * You should have received a copy of the GNU Affero General Public License
718
+ * along with Advanced JSON forms (ajf).
719
+ * If not, see http://www.gnu.org/licenses/.
720
+ *
721
+ */
722
+
723
+ /**
724
+ * @license
725
+ * Copyright (C) Gnucoop soc. coop.
726
+ *
727
+ * This file is part of the Advanced JSON forms (ajf).
728
+ *
729
+ * Advanced JSON forms (ajf) is free software: you can redistribute it and/or
730
+ * modify it under the terms of the GNU Affero General Public License as
731
+ * published by the Free Software Foundation, either version 3 of the License,
732
+ * or (at your option) any later version.
733
+ *
734
+ * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,
735
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
736
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
737
+ * General Public License for more details.
738
+ *
739
+ * You should have received a copy of the GNU Affero General Public License
740
+ * along with Advanced JSON forms (ajf).
741
+ * If not, see http://www.gnu.org/licenses/.
742
+ *
743
+ */
744
+
745
+ /**
746
+ * Generated bundle index. Do not edit.
747
+ */
748
+
749
+ export { AjfEthiopianCalendarModule, AjfEthiopianCalendarService, AjfEthiopianDatePipe, EthiopianDate };
750
+ //# sourceMappingURL=ethiopian.mjs.map