@dhis2/analytics 26.10.2 → 26.11.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 (33) hide show
  1. package/build/cjs/components/PeriodDimension/PeriodDimension.js +5 -2
  2. package/build/cjs/components/PeriodDimension/PeriodTransfer.js +4 -2
  3. package/build/cjs/components/PeriodDimension/__tests__/__snapshots__/relativePeriods.spec.js.snap +347 -0
  4. package/build/cjs/components/PeriodDimension/__tests__/relativePeriods.spec.js +13 -0
  5. package/build/cjs/components/PeriodDimension/utils/fixedPeriods.js +2 -2
  6. package/build/cjs/components/PeriodDimension/utils/relativePeriods.js +158 -44
  7. package/build/cjs/index.js +21 -0
  8. package/build/cjs/locales/ar/translations.json +4 -4
  9. package/build/cjs/locales/id/translations.json +1 -1
  10. package/build/cjs/locales/ro/translations.json +1 -1
  11. package/build/cjs/locales/ru/translations.json +4 -4
  12. package/build/cjs/locales/uk/translations.json +3 -3
  13. package/build/cjs/locales/uz_UZ_Cyrl/translations.json +4 -4
  14. package/build/cjs/locales/uz_UZ_Latn/translations.json +3 -3
  15. package/build/cjs/locales/zh/translations.json +15 -15
  16. package/build/cjs/locales/zh_CN/translations.json +1 -1
  17. package/build/es/components/PeriodDimension/PeriodDimension.js +5 -2
  18. package/build/es/components/PeriodDimension/PeriodTransfer.js +4 -2
  19. package/build/es/components/PeriodDimension/__tests__/__snapshots__/relativePeriods.spec.js.snap +347 -0
  20. package/build/es/components/PeriodDimension/__tests__/relativePeriods.spec.js +11 -0
  21. package/build/es/components/PeriodDimension/utils/fixedPeriods.js +1 -1
  22. package/build/es/components/PeriodDimension/utils/relativePeriods.js +156 -43
  23. package/build/es/index.js +2 -2
  24. package/build/es/locales/ar/translations.json +4 -4
  25. package/build/es/locales/id/translations.json +1 -1
  26. package/build/es/locales/ro/translations.json +1 -1
  27. package/build/es/locales/ru/translations.json +4 -4
  28. package/build/es/locales/uk/translations.json +3 -3
  29. package/build/es/locales/uz_UZ_Cyrl/translations.json +4 -4
  30. package/build/es/locales/uz_UZ_Latn/translations.json +3 -3
  31. package/build/es/locales/zh/translations.json +15 -15
  32. package/build/es/locales/zh_CN/translations.json +1 -1
  33. package/package.json +1 -1
@@ -0,0 +1,347 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`relativePeriods utils should correctly return relative periods details 1`] = `
4
+ Object {
5
+ "BIMONTHS_THIS_YEAR": Object {
6
+ "duration": 6,
7
+ "id": "BIMONTHS_THIS_YEAR",
8
+ "name": "Bi-months this year",
9
+ "offset": 5,
10
+ "type": "BIMONTHLY",
11
+ },
12
+ "LAST_10_YEARS": Object {
13
+ "duration": 10,
14
+ "id": "LAST_10_YEARS",
15
+ "name": "Last 10 years",
16
+ "offset": -1,
17
+ "type": "YEARLY",
18
+ },
19
+ "LAST_12_MONTHS": Object {
20
+ "duration": 12,
21
+ "id": "LAST_12_MONTHS",
22
+ "name": "Last 12 months",
23
+ "offset": -1,
24
+ "type": "MONTHLY",
25
+ },
26
+ "LAST_12_WEEKS": Object {
27
+ "duration": 12,
28
+ "id": "LAST_12_WEEKS",
29
+ "name": "Last 12 weeks",
30
+ "offset": -1,
31
+ "type": "WEEKLY",
32
+ },
33
+ "LAST_14_DAYS": Object {
34
+ "duration": 14,
35
+ "id": "LAST_14_DAYS",
36
+ "name": "Last 14 days",
37
+ "offset": -1,
38
+ "type": "DAILY",
39
+ },
40
+ "LAST_180_DAYS": Object {
41
+ "duration": 180,
42
+ "id": "LAST_180_DAYS",
43
+ "name": "Last 180 days",
44
+ "offset": -1,
45
+ "type": "DAILY",
46
+ },
47
+ "LAST_2_SIXMONTHS": Object {
48
+ "duration": 2,
49
+ "id": "LAST_2_SIXMONTHS",
50
+ "name": "Last 2 six-month",
51
+ "offset": -1,
52
+ "type": "SIXMONTHLY",
53
+ },
54
+ "LAST_30_DAYS": Object {
55
+ "duration": 30,
56
+ "id": "LAST_30_DAYS",
57
+ "name": "Last 30 days",
58
+ "offset": -1,
59
+ "type": "DAILY",
60
+ },
61
+ "LAST_3_DAYS": Object {
62
+ "duration": 3,
63
+ "id": "LAST_3_DAYS",
64
+ "name": "Last 3 days",
65
+ "offset": -1,
66
+ "type": "DAILY",
67
+ },
68
+ "LAST_3_MONTHS": Object {
69
+ "duration": 3,
70
+ "id": "LAST_3_MONTHS",
71
+ "name": "Last 3 months",
72
+ "offset": -1,
73
+ "type": "MONTHLY",
74
+ },
75
+ "LAST_4_BIWEEKS": Object {
76
+ "duration": 4,
77
+ "id": "LAST_4_BIWEEKS",
78
+ "name": "Last 4 bi-weeks",
79
+ "offset": -1,
80
+ "type": "BIWEEKLY",
81
+ },
82
+ "LAST_4_QUARTERS": Object {
83
+ "duration": 4,
84
+ "id": "LAST_4_QUARTERS",
85
+ "name": "Last 4 quarters",
86
+ "offset": -1,
87
+ "type": "QUARTERLY",
88
+ },
89
+ "LAST_4_WEEKS": Object {
90
+ "duration": 4,
91
+ "id": "LAST_4_WEEKS",
92
+ "name": "Last 4 weeks",
93
+ "offset": -1,
94
+ "type": "WEEKLY",
95
+ },
96
+ "LAST_52_WEEKS": Object {
97
+ "duration": 52,
98
+ "id": "LAST_52_WEEKS",
99
+ "name": "Last 52 weeks",
100
+ "offset": -1,
101
+ "type": "WEEKLY",
102
+ },
103
+ "LAST_5_FINANCIAL_YEARS": Object {
104
+ "duration": 5,
105
+ "id": "LAST_5_FINANCIAL_YEARS",
106
+ "name": "Last 5 financial years",
107
+ "offset": -1,
108
+ "type": "FINANCIAL",
109
+ },
110
+ "LAST_5_YEARS": Object {
111
+ "duration": 5,
112
+ "id": "LAST_5_YEARS",
113
+ "name": "Last 5 years",
114
+ "offset": -1,
115
+ "type": "YEARLY",
116
+ },
117
+ "LAST_60_DAYS": Object {
118
+ "duration": 60,
119
+ "id": "LAST_60_DAYS",
120
+ "name": "Last 60 days",
121
+ "offset": -1,
122
+ "type": "DAILY",
123
+ },
124
+ "LAST_6_BIMONTHS": Object {
125
+ "duration": 6,
126
+ "id": "LAST_6_BIMONTHS",
127
+ "name": "Last 6 bi-months",
128
+ "offset": -1,
129
+ "type": "BIMONTHLY",
130
+ },
131
+ "LAST_6_MONTHS": Object {
132
+ "duration": 6,
133
+ "id": "LAST_6_MONTHS",
134
+ "name": "Last 6 months",
135
+ "offset": -1,
136
+ "type": "MONTHLY",
137
+ },
138
+ "LAST_7_DAYS": Object {
139
+ "duration": 7,
140
+ "id": "LAST_7_DAYS",
141
+ "name": "Last 7 days",
142
+ "offset": -1,
143
+ "type": "DAILY",
144
+ },
145
+ "LAST_90_DAYS": Object {
146
+ "duration": 90,
147
+ "id": "LAST_90_DAYS",
148
+ "name": "Last 90 days",
149
+ "offset": -1,
150
+ "type": "DAILY",
151
+ },
152
+ "LAST_BIMONTH": Object {
153
+ "duration": 1,
154
+ "id": "LAST_BIMONTH",
155
+ "name": "Last bi-month",
156
+ "offset": -1,
157
+ "type": "BIMONTHLY",
158
+ },
159
+ "LAST_BIWEEK": Object {
160
+ "duration": 1,
161
+ "id": "LAST_BIWEEK",
162
+ "name": "Last bi-week",
163
+ "offset": -1,
164
+ "type": "BIWEEKLY",
165
+ },
166
+ "LAST_FINANCIAL_YEAR": Object {
167
+ "duration": 1,
168
+ "id": "LAST_FINANCIAL_YEAR",
169
+ "name": "Last financial year",
170
+ "offset": -1,
171
+ "type": "FINANCIAL",
172
+ },
173
+ "LAST_MONTH": Object {
174
+ "duration": 1,
175
+ "id": "LAST_MONTH",
176
+ "name": "Last month",
177
+ "offset": -1,
178
+ "type": "MONTHLY",
179
+ },
180
+ "LAST_QUARTER": Object {
181
+ "duration": 1,
182
+ "id": "LAST_QUARTER",
183
+ "name": "Last quarter",
184
+ "offset": -1,
185
+ "type": "QUARTERLY",
186
+ },
187
+ "LAST_SIX_MONTH": Object {
188
+ "duration": 1,
189
+ "id": "LAST_SIX_MONTH",
190
+ "name": "Last six-month",
191
+ "offset": -1,
192
+ "type": "SIXMONTHLY",
193
+ },
194
+ "LAST_WEEK": Object {
195
+ "duration": 1,
196
+ "id": "LAST_WEEK",
197
+ "name": "Last week",
198
+ "offset": -1,
199
+ "type": "WEEKLY",
200
+ },
201
+ "LAST_YEAR": Object {
202
+ "duration": 1,
203
+ "id": "LAST_YEAR",
204
+ "name": "Last year",
205
+ "offset": -1,
206
+ "type": "YEARLY",
207
+ },
208
+ "MONTHS_THIS_YEAR": Object {
209
+ "duration": 12,
210
+ "id": "MONTHS_THIS_YEAR",
211
+ "name": "Months this year",
212
+ "offset": 11,
213
+ "type": "MONTHLY",
214
+ },
215
+ "QUARTERS_THIS_YEAR": Object {
216
+ "duration": 4,
217
+ "id": "QUARTERS_THIS_YEAR",
218
+ "name": "Quarters this year",
219
+ "offset": 3,
220
+ "type": "QUARTERLY",
221
+ },
222
+ "THIS_BIMONTH": Object {
223
+ "duration": 1,
224
+ "id": "THIS_BIMONTH",
225
+ "name": "This bi-month",
226
+ "offset": 0,
227
+ "type": "BIMONTHLY",
228
+ },
229
+ "THIS_BIWEEK": Object {
230
+ "duration": 1,
231
+ "id": "THIS_BIWEEK",
232
+ "name": "This bi-week",
233
+ "offset": 0,
234
+ "type": "BIWEEKLY",
235
+ },
236
+ "THIS_FINANCIAL_YEAR": Object {
237
+ "duration": 1,
238
+ "id": "THIS_FINANCIAL_YEAR",
239
+ "name": "This financial year",
240
+ "offset": 0,
241
+ "type": "FINANCIAL",
242
+ },
243
+ "THIS_MONTH": Object {
244
+ "duration": 1,
245
+ "id": "THIS_MONTH",
246
+ "name": "This month",
247
+ "offset": 0,
248
+ "type": "MONTHLY",
249
+ },
250
+ "THIS_QUARTER": Object {
251
+ "duration": 1,
252
+ "id": "THIS_QUARTER",
253
+ "name": "This quarter",
254
+ "offset": 0,
255
+ "type": "QUARTERLY",
256
+ },
257
+ "THIS_SIX_MONTH": Object {
258
+ "duration": 1,
259
+ "id": "THIS_SIX_MONTH",
260
+ "name": "This six-month",
261
+ "offset": 0,
262
+ "type": "SIXMONTHLY",
263
+ },
264
+ "THIS_WEEK": Object {
265
+ "duration": 1,
266
+ "id": "THIS_WEEK",
267
+ "name": "This week",
268
+ "offset": 0,
269
+ "type": "WEEKLY",
270
+ },
271
+ "THIS_YEAR": Object {
272
+ "duration": 1,
273
+ "id": "THIS_YEAR",
274
+ "name": "This year",
275
+ "offset": 0,
276
+ "type": "YEARLY",
277
+ },
278
+ "TODAY": Object {
279
+ "duration": 1,
280
+ "id": "TODAY",
281
+ "name": "Today",
282
+ "offset": 0,
283
+ "type": "DAILY",
284
+ },
285
+ "WEEKS_THIS_YEAR": Object {
286
+ "duration": 52,
287
+ "id": "WEEKS_THIS_YEAR",
288
+ "name": "Weeks this year",
289
+ "offset": 51,
290
+ "type": "WEEKLY",
291
+ },
292
+ "YESTERDAY": Object {
293
+ "duration": 1,
294
+ "id": "YESTERDAY",
295
+ "name": "Yesterday",
296
+ "offset": -1,
297
+ "type": "DAILY",
298
+ },
299
+ }
300
+ `;
301
+
302
+ exports[`relativePeriods utils should correctly return relative periods names 1`] = `
303
+ Object {
304
+ "BIMONTHS_THIS_YEAR": "Bi-months this year",
305
+ "LAST_10_YEARS": "Last 10 years",
306
+ "LAST_12_MONTHS": "Last 12 months",
307
+ "LAST_12_WEEKS": "Last 12 weeks",
308
+ "LAST_14_DAYS": "Last 14 days",
309
+ "LAST_180_DAYS": "Last 180 days",
310
+ "LAST_2_SIXMONTHS": "Last 2 six-month",
311
+ "LAST_30_DAYS": "Last 30 days",
312
+ "LAST_3_DAYS": "Last 3 days",
313
+ "LAST_3_MONTHS": "Last 3 months",
314
+ "LAST_4_BIWEEKS": "Last 4 bi-weeks",
315
+ "LAST_4_QUARTERS": "Last 4 quarters",
316
+ "LAST_4_WEEKS": "Last 4 weeks",
317
+ "LAST_52_WEEKS": "Last 52 weeks",
318
+ "LAST_5_FINANCIAL_YEARS": "Last 5 financial years",
319
+ "LAST_5_YEARS": "Last 5 years",
320
+ "LAST_60_DAYS": "Last 60 days",
321
+ "LAST_6_BIMONTHS": "Last 6 bi-months",
322
+ "LAST_6_MONTHS": "Last 6 months",
323
+ "LAST_7_DAYS": "Last 7 days",
324
+ "LAST_90_DAYS": "Last 90 days",
325
+ "LAST_BIMONTH": "Last bi-month",
326
+ "LAST_BIWEEK": "Last bi-week",
327
+ "LAST_FINANCIAL_YEAR": "Last financial year",
328
+ "LAST_MONTH": "Last month",
329
+ "LAST_QUARTER": "Last quarter",
330
+ "LAST_SIX_MONTH": "Last six-month",
331
+ "LAST_WEEK": "Last week",
332
+ "LAST_YEAR": "Last year",
333
+ "MONTHS_THIS_YEAR": "Months this year",
334
+ "QUARTERS_THIS_YEAR": "Quarters this year",
335
+ "THIS_BIMONTH": "This bi-month",
336
+ "THIS_BIWEEK": "This bi-week",
337
+ "THIS_FINANCIAL_YEAR": "This financial year",
338
+ "THIS_MONTH": "This month",
339
+ "THIS_QUARTER": "This quarter",
340
+ "THIS_SIX_MONTH": "This six-month",
341
+ "THIS_WEEK": "This week",
342
+ "THIS_YEAR": "This year",
343
+ "TODAY": "Today",
344
+ "WEEKS_THIS_YEAR": "Weeks this year",
345
+ "YESTERDAY": "Yesterday",
346
+ }
347
+ `;
@@ -0,0 +1,11 @@
1
+ import { getRelativePeriodsDetails, getRelativePeriodsName } from '../utils/relativePeriods.js';
2
+ describe('relativePeriods utils', () => {
3
+ it('should correctly return relative periods details', () => {
4
+ const details = getRelativePeriodsDetails();
5
+ expect(details).toMatchSnapshot();
6
+ });
7
+ it('should correctly return relative periods names', () => {
8
+ const names = getRelativePeriodsName();
9
+ expect(names).toMatchSnapshot();
10
+ });
11
+ });
@@ -1,7 +1,7 @@
1
1
  import { generateFixedPeriods, getNowInCalendar } from '@dhis2/multi-calendar-dates';
2
2
  import i18n from '../../../locales/index.js';
3
3
  import { DAILY, WEEKLY, WEEKLYWED, WEEKLYTHU, WEEKLYSAT, WEEKLYSUN, BIWEEKLY, MONTHLY, BIMONTHLY, QUARTERLY, SIXMONTHLY, SIXMONTHLYAPR, YEARLY, FYNOV, FYOCT, FYJUL, FYAPR } from './index.js';
4
- const PERIOD_TYPE_REGEX = {
4
+ export const PERIOD_TYPE_REGEX = {
5
5
  [DAILY]: /^([0-9]{4})([0-9]{2})([0-9]{2})$/,
6
6
  // YYYYMMDD
7
7
  [WEEKLY]: /^([0-9]{4})()W([0-9]{1,2})$/,
@@ -1,139 +1,238 @@
1
1
  import i18n from '../../../locales/index.js';
2
2
  import { DAILY, WEEKLY, BIWEEKLY, WEEKS_THIS_YEAR, MONTHLY, BIMONTHLY, QUARTERLY, SIXMONTHLY, FINANCIAL, YEARLY } from './index.js';
3
+
4
+ /*
5
+ In getDaysPeriodType, getWeeksPeriodType, getBiWeeksPeriodType,
6
+ getBiWeeksPeriodType, getMonthsPeriodType, getBiMonthsPeriodType,
7
+ getQuartersPeriodType, getSixMonthsPeriodType,
8
+ getFinancialYearsPeriodType, and getYearsPeriodType:
9
+ - duration: The number of individual periods in the preset
10
+ (the maximum when the duration is variable).
11
+ eg: LAST_14_DAYS duration is 14
12
+ - offset: The position of the most recent individual period
13
+ relative to THIS period in the preset, earlier periods are
14
+ negative (the maximum when the offset is variable).
15
+ eg: LAST_BIMONTH offset is -1
16
+ */
17
+
3
18
  const getDaysPeriodType = () => [{
4
19
  id: 'TODAY',
5
- name: i18n.t('Today')
20
+ name: i18n.t('Today'),
21
+ offset: 0,
22
+ duration: 1
6
23
  }, {
7
24
  id: 'YESTERDAY',
8
- name: i18n.t('Yesterday')
25
+ name: i18n.t('Yesterday'),
26
+ offset: -1,
27
+ duration: 1
9
28
  }, {
10
29
  id: 'LAST_3_DAYS',
11
- name: i18n.t('Last 3 days')
30
+ name: i18n.t('Last 3 days'),
31
+ offset: -1,
32
+ duration: 3
12
33
  }, {
13
34
  id: 'LAST_7_DAYS',
14
- name: i18n.t('Last 7 days')
35
+ name: i18n.t('Last 7 days'),
36
+ offset: -1,
37
+ duration: 7
15
38
  }, {
16
39
  id: 'LAST_14_DAYS',
17
- name: i18n.t('Last 14 days')
40
+ name: i18n.t('Last 14 days'),
41
+ offset: -1,
42
+ duration: 14
18
43
  }, {
19
44
  id: 'LAST_30_DAYS',
20
- name: i18n.t('Last 30 days')
45
+ name: i18n.t('Last 30 days'),
46
+ offset: -1,
47
+ duration: 30
21
48
  }, {
22
49
  id: 'LAST_60_DAYS',
23
- name: i18n.t('Last 60 days')
50
+ name: i18n.t('Last 60 days'),
51
+ offset: -1,
52
+ duration: 60
24
53
  }, {
25
54
  id: 'LAST_90_DAYS',
26
- name: i18n.t('Last 90 days')
55
+ name: i18n.t('Last 90 days'),
56
+ offset: -1,
57
+ duration: 90
27
58
  }, {
28
59
  id: 'LAST_180_DAYS',
29
- name: i18n.t('Last 180 days')
60
+ name: i18n.t('Last 180 days'),
61
+ offset: -1,
62
+ duration: 180
30
63
  }];
31
64
  const getWeeksPeriodType = () => [{
32
65
  id: 'THIS_WEEK',
33
- name: i18n.t('This week')
66
+ name: i18n.t('This week'),
67
+ offset: 0,
68
+ duration: 1
34
69
  }, {
35
70
  id: 'LAST_WEEK',
36
- name: i18n.t('Last week')
71
+ name: i18n.t('Last week'),
72
+ offset: -1,
73
+ duration: 1
37
74
  }, {
38
75
  id: 'LAST_4_WEEKS',
39
- name: i18n.t('Last 4 weeks')
76
+ name: i18n.t('Last 4 weeks'),
77
+ offset: -1,
78
+ duration: 4
40
79
  }, {
41
80
  id: 'LAST_12_WEEKS',
42
- name: i18n.t('Last 12 weeks')
81
+ name: i18n.t('Last 12 weeks'),
82
+ offset: -1,
83
+ duration: 12
43
84
  }, {
44
85
  id: 'LAST_52_WEEKS',
45
- name: i18n.t('Last 52 weeks')
86
+ name: i18n.t('Last 52 weeks'),
87
+ offset: -1,
88
+ duration: 52
46
89
  }, {
47
90
  id: WEEKS_THIS_YEAR,
48
- name: i18n.t('Weeks this year')
91
+ name: i18n.t('Weeks this year'),
92
+ offset: 51,
93
+ duration: 52
49
94
  }];
50
95
  const getBiWeeksPeriodType = () => [{
51
96
  id: 'THIS_BIWEEK',
52
- name: i18n.t('This bi-week')
97
+ name: i18n.t('This bi-week'),
98
+ offset: 0,
99
+ duration: 1
53
100
  }, {
54
101
  id: 'LAST_BIWEEK',
55
- name: i18n.t('Last bi-week')
102
+ name: i18n.t('Last bi-week'),
103
+ offset: -1,
104
+ duration: 1
56
105
  }, {
57
106
  id: 'LAST_4_BIWEEKS',
58
- name: i18n.t('Last 4 bi-weeks')
107
+ name: i18n.t('Last 4 bi-weeks'),
108
+ offset: -1,
109
+ duration: 4
59
110
  }];
60
111
  const getMonthsPeriodType = () => [{
61
112
  id: 'THIS_MONTH',
62
- name: i18n.t('This month')
113
+ name: i18n.t('This month'),
114
+ offset: 0,
115
+ duration: 1
63
116
  }, {
64
117
  id: 'LAST_MONTH',
65
- name: i18n.t('Last month')
118
+ name: i18n.t('Last month'),
119
+ offset: -1,
120
+ duration: 1
66
121
  }, {
67
122
  id: 'LAST_3_MONTHS',
68
- name: i18n.t('Last 3 months')
123
+ name: i18n.t('Last 3 months'),
124
+ offset: -1,
125
+ duration: 3
69
126
  }, {
70
127
  id: 'LAST_6_MONTHS',
71
- name: i18n.t('Last 6 months')
128
+ name: i18n.t('Last 6 months'),
129
+ offset: -1,
130
+ duration: 6
72
131
  }, {
73
132
  id: 'LAST_12_MONTHS',
74
- name: i18n.t('Last 12 months')
133
+ name: i18n.t('Last 12 months'),
134
+ offset: -1,
135
+ duration: 12
75
136
  }, {
76
137
  id: 'MONTHS_THIS_YEAR',
77
- name: i18n.t('Months this year')
138
+ name: i18n.t('Months this year'),
139
+ offset: 11,
140
+ duration: 12
78
141
  }];
79
142
  const getBiMonthsPeriodType = () => [{
80
143
  id: 'THIS_BIMONTH',
81
- name: i18n.t('This bi-month')
144
+ name: i18n.t('This bi-month'),
145
+ offset: 0,
146
+ duration: 1
82
147
  }, {
83
148
  id: 'LAST_BIMONTH',
84
- name: i18n.t('Last bi-month')
149
+ name: i18n.t('Last bi-month'),
150
+ offset: -1,
151
+ duration: 1
85
152
  }, {
86
153
  id: 'LAST_6_BIMONTHS',
87
- name: i18n.t('Last 6 bi-months')
154
+ name: i18n.t('Last 6 bi-months'),
155
+ offset: -1,
156
+ duration: 6
88
157
  }, {
89
158
  id: 'BIMONTHS_THIS_YEAR',
90
- name: i18n.t('Bi-months this year')
159
+ name: i18n.t('Bi-months this year'),
160
+ offset: 5,
161
+ duration: 6
91
162
  }];
92
163
  const getQuartersPeriodType = () => [{
93
164
  id: 'THIS_QUARTER',
94
- name: i18n.t('This quarter')
165
+ name: i18n.t('This quarter'),
166
+ offset: 0,
167
+ duration: 1
95
168
  }, {
96
169
  id: 'LAST_QUARTER',
97
- name: i18n.t('Last quarter')
170
+ name: i18n.t('Last quarter'),
171
+ offset: -1,
172
+ duration: 1
98
173
  }, {
99
174
  id: 'LAST_4_QUARTERS',
100
- name: i18n.t('Last 4 quarters')
175
+ name: i18n.t('Last 4 quarters'),
176
+ offset: -1,
177
+ duration: 4
101
178
  }, {
102
179
  id: 'QUARTERS_THIS_YEAR',
103
- name: i18n.t('Quarters this year')
180
+ name: i18n.t('Quarters this year'),
181
+ offset: 3,
182
+ duration: 4
104
183
  }];
105
184
  const getSixMonthsPeriodType = () => [{
106
185
  id: 'THIS_SIX_MONTH',
107
- name: i18n.t('This six-month')
186
+ name: i18n.t('This six-month'),
187
+ offset: 0,
188
+ duration: 1
108
189
  }, {
109
190
  id: 'LAST_SIX_MONTH',
110
- name: i18n.t('Last six-month')
191
+ name: i18n.t('Last six-month'),
192
+ offset: -1,
193
+ duration: 1
111
194
  }, {
112
195
  id: 'LAST_2_SIXMONTHS',
113
- name: i18n.t('Last 2 six-month')
196
+ name: i18n.t('Last 2 six-month'),
197
+ offset: -1,
198
+ duration: 2
114
199
  }];
115
200
  const getFinancialYearsPeriodType = () => [{
116
201
  id: 'THIS_FINANCIAL_YEAR',
117
- name: i18n.t('This financial year')
202
+ name: i18n.t('This financial year'),
203
+ offset: 0,
204
+ duration: 1
118
205
  }, {
119
206
  id: 'LAST_FINANCIAL_YEAR',
120
- name: i18n.t('Last financial year')
207
+ name: i18n.t('Last financial year'),
208
+ offset: -1,
209
+ duration: 1
121
210
  }, {
122
211
  id: 'LAST_5_FINANCIAL_YEARS',
123
- name: i18n.t('Last 5 financial years')
212
+ name: i18n.t('Last 5 financial years'),
213
+ offset: -1,
214
+ duration: 5
124
215
  }];
125
216
  const getYearsPeriodType = () => [{
126
217
  id: 'THIS_YEAR',
127
- name: i18n.t('This year')
218
+ name: i18n.t('This year'),
219
+ offset: 0,
220
+ duration: 1
128
221
  }, {
129
222
  id: 'LAST_YEAR',
130
- name: i18n.t('Last year')
223
+ name: i18n.t('Last year'),
224
+ offset: -1,
225
+ duration: 1
131
226
  }, {
132
227
  id: 'LAST_5_YEARS',
133
- name: i18n.t('Last 5 years')
228
+ name: i18n.t('Last 5 years'),
229
+ offset: -1,
230
+ duration: 5
134
231
  }, {
135
232
  id: 'LAST_10_YEARS',
136
- name: i18n.t('Last 10 years')
233
+ name: i18n.t('Last 10 years'),
234
+ offset: -1,
235
+ duration: 10
137
236
  }];
138
237
  const getOptions = () => [{
139
238
  id: DAILY,
@@ -174,4 +273,18 @@ const getOptions = () => [{
174
273
  }];
175
274
  export const getRelativePeriodsOptionsById = id => getOptions().find(option => option.id === id);
176
275
  export const getRelativePeriodsOptions = () => getOptions();
177
- export const getRelativePeriodIds = () => Object.values(getOptions()).map(option => option.getPeriods().map(period => period.id)).flat();
276
+ export const getRelativePeriodIds = () => Object.values(getOptions()).map(option => option.getPeriods().map(period => period.id)).flat();
277
+ export const getRelativePeriodsDetails = () => Object.values(getOptions()).map(option => option.getPeriods().map(period => ({
278
+ id: period.id,
279
+ name: period.name,
280
+ offset: period.offset,
281
+ duration: period.duration,
282
+ type: option.id
283
+ }))).flat().reduce((acc, period) => {
284
+ acc[period.id] = period;
285
+ return acc;
286
+ }, {});
287
+ export const getRelativePeriodsName = () => Object.values(getOptions()).map(option => option.getPeriods()).flat().reduce((acc, period) => {
288
+ acc[period.id] = period.name;
289
+ return acc;
290
+ }, {});
package/build/es/index.js CHANGED
@@ -129,7 +129,7 @@ export { COLOR_SET_DEFAULT, COLOR_SET_BASIC, COLOR_SET_EXTENDED, COLOR_SET_BRIGH
129
129
 
130
130
  // Utils: periods
131
131
  export { DAILY, WEEKLY, WEEKLYWED, WEEKLYTHU, WEEKLYSAT, WEEKLYSUN, WEEKS_THIS_YEAR, BIWEEKLY, MONTHLY, BIMONTHLY, QUARTERLY, SIXMONTHLY, SIXMONTHLYAPR, YEARLY, FINANCIAL, FYNOV, FYOCT, FYJUL, FYAPR } from './components/PeriodDimension/utils/index.js';
132
- export { getRelativePeriodsOptionsById } from './components/PeriodDimension/utils/relativePeriods.js';
133
- export { getFixedPeriodsOptionsById } from './components/PeriodDimension/utils/fixedPeriods.js';
132
+ export { getRelativePeriodsOptionsById, getRelativePeriodsName, getRelativePeriodsDetails } from './components/PeriodDimension/utils/relativePeriods.js';
133
+ export { getFixedPeriodsOptionsById, PERIOD_TYPE_REGEX } from './components/PeriodDimension/utils/fixedPeriods.js';
134
134
  export { default as VisualizationOptions } from './components/Options/VisualizationOptions.js';
135
135
  export { DIMENSION_TYPE_INDICATOR, DIMENSION_TYPE_DATA_ELEMENT, DIMENSION_TYPE_DATA_SET, DIMENSION_TYPE_EVENT_DATA_ITEM, DIMENSION_TYPE_PROGRAM_INDICATOR, DIMENSION_TYPE_PROGRAM_DATA_ELEMENT, DIMENSION_TYPE_PROGRAM_ATTRIBUTE, DIMENSION_TYPE_DATA_ELEMENT_OPERAND, DIMENSION_TYPE_CATEGORY, DIMENSION_TYPE_CATEGORY_OPTION_GROUP_SET, DIMENSION_TYPE_ALL, DIMENSION_TYPE_DATA, DIMENSION_TYPE_DATA_ELEMENT_GROUP_SET, DIMENSION_TYPE_ORGANISATION_UNIT, DIMENSION_TYPE_PERIOD, DIMENSION_TYPE_ORGANISATION_UNIT_GROUP_SET, DIMENSION_TYPE_EXPRESSION_DIMENSION_ITEM, dataTypeMap } from './modules/dataTypes.js';