@dhis2/analytics 24.5.0 → 24.6.0
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.
- package/CHANGELOG.md +9 -2
- package/build/cjs/components/PeriodDimension/PeriodTransfer.js +4 -16
- package/build/cjs/components/PeriodDimension/utils/fixedPeriods.js +478 -204
- package/build/cjs/locales/en/translations.json +14 -0
- package/build/cjs/visualizations/config/generators/dhis/singleValue.js +76 -23
- package/build/cjs/visualizations/config/index.js +2 -1
- package/build/es/components/PeriodDimension/PeriodTransfer.js +4 -14
- package/build/es/components/PeriodDimension/utils/fixedPeriods.js +477 -202
- package/build/es/locales/en/translations.json +14 -0
- package/build/es/visualizations/config/generators/dhis/singleValue.js +79 -26
- package/build/es/visualizations/config/index.js +2 -1
- package/package.json +1 -7
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { generateFixedPeriods, getNowInCalendar } from '@dhis2/multi-calendar-dates';
|
|
2
1
|
import i18n from '../../../locales/index.js';
|
|
3
2
|
import { DAILY, WEEKLY, WEEKLYWED, WEEKLYTHU, WEEKLYSAT, WEEKLYSUN, BIWEEKLY, MONTHLY, BIMONTHLY, QUARTERLY, SIXMONTHLY, SIXMONTHLYAPR, YEARLY, FYNOV, FYOCT, FYJUL, FYAPR } from './index.js';
|
|
4
3
|
const PERIOD_TYPE_REGEX = {
|
|
@@ -39,175 +38,452 @@ const PERIOD_TYPE_REGEX = {
|
|
|
39
38
|
|
|
40
39
|
};
|
|
41
40
|
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
config,
|
|
46
|
-
fnFilter,
|
|
47
|
-
calendar
|
|
48
|
-
} = _ref;
|
|
49
|
-
const offset = parseInt(config.offset, 10);
|
|
50
|
-
const isFilter = config.filterFuturePeriods;
|
|
51
|
-
const isReverse = periodType.match(/^FY|YEARLY/) ? true : config.reversePeriods;
|
|
52
|
-
const year = getNowInCalendar(calendar).eraYear + offset;
|
|
53
|
-
const params = {
|
|
54
|
-
periodType,
|
|
55
|
-
year,
|
|
56
|
-
calendar,
|
|
57
|
-
locale: 'en',
|
|
58
|
-
startingDay: config.startDay
|
|
59
|
-
};
|
|
60
|
-
let periods = generateFixedPeriods(params);
|
|
61
|
-
periods = isFilter ? fnFilter(periods) : periods;
|
|
62
|
-
periods = !isReverse ? periods : periods.reverse();
|
|
63
|
-
return periods;
|
|
41
|
+
const getMonthName = key => {
|
|
42
|
+
const monthNames = [i18n.t('January'), i18n.t('February'), i18n.t('March'), i18n.t('April'), i18n.t('May'), i18n.t('June'), i18n.t('July'), i18n.t('August'), i18n.t('September'), i18n.t('October'), i18n.t('November'), i18n.t('December')];
|
|
43
|
+
return monthNames[key];
|
|
64
44
|
};
|
|
65
45
|
|
|
66
|
-
const getDailyPeriodType = (
|
|
46
|
+
const getDailyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
67
47
|
return config => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
48
|
+
let periods = [];
|
|
49
|
+
const offset = parseInt(config.offset, 10);
|
|
50
|
+
const isFilter = config.filterFuturePeriods;
|
|
51
|
+
const isReverse = config.reversePeriods;
|
|
52
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
53
|
+
const date = new Date("01 Jan ".concat(year));
|
|
54
|
+
|
|
55
|
+
while (date.getFullYear() === year) {
|
|
56
|
+
const period = {};
|
|
57
|
+
period.startDate = formatYyyyMmDd(date);
|
|
58
|
+
period.endDate = period.startDate;
|
|
59
|
+
period.name = period.startDate;
|
|
60
|
+
period.iso = period.startDate.replace(/-/g, '');
|
|
61
|
+
period.id = period.iso;
|
|
62
|
+
periods.push(period);
|
|
63
|
+
date.setDate(date.getDate() + 1);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
67
|
+
periods = isReverse ? periods.reverse() : periods;
|
|
68
|
+
return periods;
|
|
74
69
|
};
|
|
75
70
|
};
|
|
76
71
|
|
|
77
|
-
const getWeeklyPeriodType = (weekObj, fnFilter
|
|
72
|
+
const getWeeklyPeriodType = (formatYyyyMmDd, weekObj, fnFilter) => {
|
|
73
|
+
// Calculate the first date of an EPI year base on ISO standard ( first week always contains 4th Jan )
|
|
74
|
+
const getEpiWeekStartDay = (year, startDayOfWeek) => {
|
|
75
|
+
const jan4 = new Date(year, 0, 4);
|
|
76
|
+
const jan4DayOfWeek = jan4.getDay();
|
|
77
|
+
const startDate = jan4;
|
|
78
|
+
const dayDiff = jan4DayOfWeek - startDayOfWeek;
|
|
79
|
+
|
|
80
|
+
if (dayDiff > 0) {
|
|
81
|
+
startDate.setDate(jan4.getDate() - dayDiff);
|
|
82
|
+
} else if (dayDiff < 0) {
|
|
83
|
+
startDate.setDate(jan4.getDate() - dayDiff);
|
|
84
|
+
startDate.setDate(startDate.getDate() - 7);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return startDate;
|
|
88
|
+
};
|
|
89
|
+
|
|
78
90
|
return config => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
let periods = [];
|
|
92
|
+
const offset = parseInt(config.offset, 10);
|
|
93
|
+
const isFilter = config.filterFuturePeriods;
|
|
94
|
+
const isReverse = config.reversePeriods;
|
|
95
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
96
|
+
const date = getEpiWeekStartDay(year, weekObj.startDay);
|
|
97
|
+
let week = 1;
|
|
98
|
+
|
|
99
|
+
while (date.getFullYear() <= year) {
|
|
100
|
+
const period = {};
|
|
101
|
+
period.startDate = formatYyyyMmDd(date);
|
|
102
|
+
period.iso = "".concat(year).concat(weekObj.shortName, "W").concat(week);
|
|
103
|
+
period.id = period.iso;
|
|
104
|
+
date.setDate(date.getDate() + 6);
|
|
105
|
+
period.endDate = formatYyyyMmDd(date);
|
|
106
|
+
const weekNumber = week;
|
|
107
|
+
period.name = "".concat(i18n.t('Week {{weekNumber}}', {
|
|
108
|
+
weekNumber
|
|
109
|
+
}), " - ").concat(period.startDate, " - ").concat(period.endDate); // if end date is Jan 4th or later, week belongs to next year
|
|
110
|
+
|
|
111
|
+
if (date.getFullYear() > year && date.getDate() >= 4) {
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
periods.push(period);
|
|
116
|
+
date.setDate(date.getDate() + 1);
|
|
117
|
+
week += 1;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
121
|
+
periods = isReverse ? periods.reverse() : periods;
|
|
122
|
+
return periods;
|
|
87
123
|
};
|
|
88
124
|
};
|
|
89
125
|
|
|
90
|
-
const getBiWeeklyPeriodType = (
|
|
126
|
+
const getBiWeeklyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
91
127
|
return config => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
128
|
+
let periods = [];
|
|
129
|
+
const offset = parseInt(config.offset, 10);
|
|
130
|
+
const isFilter = config.filterFuturePeriods;
|
|
131
|
+
const isReverse = config.reversePeriods;
|
|
132
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
133
|
+
const date = new Date("01 Jan ".concat(year));
|
|
134
|
+
const day = date.getDay();
|
|
135
|
+
let biWeek = 1;
|
|
136
|
+
|
|
137
|
+
if (day <= 4) {
|
|
138
|
+
date.setDate(date.getDate() - (day - 1));
|
|
139
|
+
} else {
|
|
140
|
+
date.setDate(date.getDate() + (8 - day));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
while (date.getFullYear() <= year) {
|
|
144
|
+
const period = {};
|
|
145
|
+
period.iso = "".concat(year, "BiW").concat(biWeek);
|
|
146
|
+
period.id = period.iso;
|
|
147
|
+
period.startDate = formatYyyyMmDd(date);
|
|
148
|
+
date.setDate(date.getDate() + 13);
|
|
149
|
+
period.endDate = formatYyyyMmDd(date);
|
|
150
|
+
const biWeekNumber = biWeek;
|
|
151
|
+
period.name = "".concat(i18n.t('Bi-Week {{biWeekNumber}}', {
|
|
152
|
+
biWeekNumber
|
|
153
|
+
}), " - ").concat(period.startDate, " - ").concat(period.endDate); // if end date is Jan 4th or later, biweek belongs to next year
|
|
154
|
+
|
|
155
|
+
if (date.getFullYear() > year && date.getDate() >= 4) {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
periods.push(period);
|
|
160
|
+
date.setDate(date.getDate() + 1);
|
|
161
|
+
biWeek += 1;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
165
|
+
periods = isReverse ? periods.reverse() : periods;
|
|
166
|
+
return periods;
|
|
98
167
|
};
|
|
99
168
|
};
|
|
100
169
|
|
|
101
|
-
const getMonthlyPeriodType = (
|
|
170
|
+
const getMonthlyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
171
|
+
const formatIso = date => {
|
|
172
|
+
const y = date.getFullYear();
|
|
173
|
+
let m = String(date.getMonth() + 1);
|
|
174
|
+
m = m.length < 2 ? "0".concat(m) : m;
|
|
175
|
+
return y + m;
|
|
176
|
+
};
|
|
177
|
+
|
|
102
178
|
return config => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
179
|
+
let periods = [];
|
|
180
|
+
const offset = parseInt(config.offset, 10);
|
|
181
|
+
const isFilter = config.filterFuturePeriods;
|
|
182
|
+
const isReverse = config.reversePeriods;
|
|
183
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
184
|
+
const date = new Date("31 Dec ".concat(year));
|
|
185
|
+
|
|
186
|
+
while (date.getFullYear() === year) {
|
|
187
|
+
const period = {};
|
|
188
|
+
period.endDate = formatYyyyMmDd(date);
|
|
189
|
+
date.setDate(1);
|
|
190
|
+
period.startDate = formatYyyyMmDd(date);
|
|
191
|
+
const monthName = getMonthName(date.getMonth());
|
|
192
|
+
period.name = "".concat(monthName, " ").concat(year);
|
|
193
|
+
period.iso = formatIso(date);
|
|
194
|
+
period.id = period.iso;
|
|
195
|
+
periods.push(period);
|
|
196
|
+
date.setDate(0);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
200
|
+
periods = isReverse ? periods : periods.reverse(); // Months are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
201
|
+
|
|
202
|
+
return periods;
|
|
109
203
|
};
|
|
110
204
|
};
|
|
111
205
|
|
|
112
|
-
const getBiMonthlyPeriodType = (
|
|
206
|
+
const getBiMonthlyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
113
207
|
return config => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
208
|
+
let periods = [];
|
|
209
|
+
const offset = parseInt(config.offset, 10);
|
|
210
|
+
const isFilter = config.filterFuturePeriods;
|
|
211
|
+
const isReverse = config.reversePeriods;
|
|
212
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
213
|
+
const date = new Date("31 Dec ".concat(year));
|
|
214
|
+
let index = 6;
|
|
215
|
+
|
|
216
|
+
while (date.getFullYear() === year) {
|
|
217
|
+
const period = {};
|
|
218
|
+
period.endDate = formatYyyyMmDd(date);
|
|
219
|
+
date.setDate(0);
|
|
220
|
+
date.setDate(1);
|
|
221
|
+
period.startDate = formatYyyyMmDd(date);
|
|
222
|
+
const monthStart = getMonthName(date.getMonth());
|
|
223
|
+
const monthEnd = getMonthName(date.getMonth() + 1);
|
|
224
|
+
const fullYear = date.getFullYear();
|
|
225
|
+
period.name = "".concat(monthStart, " - ").concat(monthEnd, " ").concat(fullYear);
|
|
226
|
+
period.iso = "".concat(year, "0").concat(index, "B");
|
|
227
|
+
period.id = period.iso;
|
|
228
|
+
periods.push(period);
|
|
229
|
+
date.setDate(0);
|
|
230
|
+
index--;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
234
|
+
periods = isReverse ? periods : periods.reverse(); // Bi-months are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
235
|
+
|
|
236
|
+
return periods;
|
|
120
237
|
};
|
|
121
238
|
};
|
|
122
239
|
|
|
123
|
-
const getQuarterlyPeriodType = (
|
|
240
|
+
const getQuarterlyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
124
241
|
return config => {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
242
|
+
let periods = [];
|
|
243
|
+
const offset = parseInt(config.offset, 10);
|
|
244
|
+
const isFilter = config.filterFuturePeriods;
|
|
245
|
+
const isReverse = config.reversePeriods;
|
|
246
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
247
|
+
const date = new Date("31 Dec ".concat(year));
|
|
248
|
+
let quarter = 4;
|
|
249
|
+
|
|
250
|
+
while (date.getFullYear() === year) {
|
|
251
|
+
const period = {};
|
|
252
|
+
period.endDate = formatYyyyMmDd(date);
|
|
253
|
+
date.setDate(0);
|
|
254
|
+
date.setDate(0);
|
|
255
|
+
date.setDate(1);
|
|
256
|
+
period.startDate = formatYyyyMmDd(date);
|
|
257
|
+
const monthStart = getMonthName(date.getMonth());
|
|
258
|
+
const monthEnd = getMonthName(date.getMonth() + 2);
|
|
259
|
+
const fullYear = date.getFullYear();
|
|
260
|
+
period.name = "".concat(monthStart, " - ").concat(monthEnd, " ").concat(fullYear);
|
|
261
|
+
period.iso = "".concat(year, "Q").concat(quarter);
|
|
262
|
+
period.id = period.iso;
|
|
263
|
+
periods.push(period);
|
|
264
|
+
date.setDate(0);
|
|
265
|
+
quarter -= 1;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
269
|
+
periods = isReverse ? periods : periods.reverse(); // Quarters are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
270
|
+
|
|
271
|
+
return periods;
|
|
131
272
|
};
|
|
132
273
|
};
|
|
133
274
|
|
|
134
|
-
const getSixMonthlyPeriodType =
|
|
275
|
+
const getSixMonthlyPeriodType = fnFilter => {
|
|
135
276
|
return config => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
277
|
+
let periods = [];
|
|
278
|
+
const offset = parseInt(config.offset, 10);
|
|
279
|
+
const isFilter = config.filterFuturePeriods;
|
|
280
|
+
const isReverse = config.reversePeriods;
|
|
281
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
282
|
+
let period = {};
|
|
283
|
+
period.startDate = "".concat(year, "-01-01");
|
|
284
|
+
period.endDate = "".concat(year, "-06-30");
|
|
285
|
+
period.name = "".concat(getMonthName(0), " - ").concat(getMonthName(5), " ").concat(year);
|
|
286
|
+
period.iso = "".concat(year, "S1");
|
|
287
|
+
period.id = period.iso;
|
|
288
|
+
periods.push(period);
|
|
289
|
+
period = {};
|
|
290
|
+
period.startDate = "".concat(year, "-07-01");
|
|
291
|
+
period.endDate = "".concat(year, "-12-31");
|
|
292
|
+
period.name = "".concat(getMonthName(6), " - ").concat(getMonthName(11), " ").concat(year);
|
|
293
|
+
period.iso = "".concat(year, "S2");
|
|
294
|
+
period.id = period.iso;
|
|
295
|
+
periods.push(period);
|
|
296
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
297
|
+
periods = isReverse ? periods.reverse() : periods;
|
|
298
|
+
return periods;
|
|
142
299
|
};
|
|
143
300
|
};
|
|
144
301
|
|
|
145
|
-
const getSixMonthlyAprilPeriodType =
|
|
302
|
+
const getSixMonthlyAprilPeriodType = fnFilter => {
|
|
146
303
|
return config => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
304
|
+
let periods = [];
|
|
305
|
+
const offset = parseInt(config.offset, 10);
|
|
306
|
+
const isFilter = config.filterFuturePeriods;
|
|
307
|
+
const isReverse = config.reversePeriods;
|
|
308
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
309
|
+
let period = {};
|
|
310
|
+
period.startDate = "".concat(year, "-04-01");
|
|
311
|
+
period.endDate = "".concat(year, "-09-30");
|
|
312
|
+
period.name = "".concat(getMonthName(3), " - ").concat(getMonthName(8), " ").concat(year);
|
|
313
|
+
period.iso = "".concat(year, "AprilS1");
|
|
314
|
+
period.id = period.iso;
|
|
315
|
+
periods.push(period);
|
|
316
|
+
period = {};
|
|
317
|
+
period.startDate = "".concat(year, "-10-01");
|
|
318
|
+
period.endDate = "".concat(year + 1, "-03-31");
|
|
319
|
+
period.name = "".concat(getMonthName(9), " ").concat(year, " - ").concat(getMonthName(2), " ").concat(year + 1);
|
|
320
|
+
period.iso = "".concat(year, "AprilS2");
|
|
321
|
+
period.id = period.iso;
|
|
322
|
+
periods.push(period);
|
|
323
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
324
|
+
periods = isReverse ? periods.reverse() : periods;
|
|
325
|
+
return periods;
|
|
153
326
|
};
|
|
154
327
|
};
|
|
155
328
|
|
|
156
|
-
const getYearlyPeriodType = (
|
|
329
|
+
const getYearlyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
157
330
|
return config => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
331
|
+
let periods = [];
|
|
332
|
+
const offset = parseInt(config.offset, 10);
|
|
333
|
+
const isFilter = config.filterFuturePeriods;
|
|
334
|
+
const isReverse = config.reversePeriods;
|
|
335
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
336
|
+
const date = new Date("31 Dec ".concat(year));
|
|
337
|
+
|
|
338
|
+
while (year - date.getFullYear() < 10) {
|
|
339
|
+
const period = {};
|
|
340
|
+
period.endDate = formatYyyyMmDd(date);
|
|
341
|
+
date.setMonth(0, 1);
|
|
342
|
+
period.startDate = formatYyyyMmDd(date);
|
|
343
|
+
const dateString = date.getFullYear().toString();
|
|
344
|
+
period.name = dateString;
|
|
345
|
+
period.iso = date.getFullYear().toString();
|
|
346
|
+
period.id = period.iso.toString();
|
|
347
|
+
periods.push(period);
|
|
348
|
+
date.setDate(0);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
352
|
+
periods = isReverse ? periods : periods.reverse(); // Years are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
353
|
+
|
|
354
|
+
return periods;
|
|
164
355
|
};
|
|
165
356
|
};
|
|
166
357
|
|
|
167
|
-
const getFinancialOctoberPeriodType = (
|
|
358
|
+
const getFinancialOctoberPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
168
359
|
return config => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
360
|
+
let periods = [];
|
|
361
|
+
const offset = parseInt(config.offset, 10);
|
|
362
|
+
const isFilter = config.filterFuturePeriods;
|
|
363
|
+
const isReverse = config.reversePeriods;
|
|
364
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
365
|
+
const date = new Date("30 Sep ".concat(year + 1));
|
|
366
|
+
|
|
367
|
+
for (let i = 0; i < 10; i++) {
|
|
368
|
+
const period = {};
|
|
369
|
+
period.endDate = formatYyyyMmDd(date);
|
|
370
|
+
date.setYear(date.getFullYear() - 1);
|
|
371
|
+
date.setDate(date.getDate() + 1);
|
|
372
|
+
period.startDate = formatYyyyMmDd(date);
|
|
373
|
+
const yearStart = date.getFullYear();
|
|
374
|
+
const yearEnd = date.getFullYear() + 1;
|
|
375
|
+
period.name = "".concat(getMonthName(9), " ").concat(yearStart, " - ").concat(getMonthName(8), " ").concat(yearEnd);
|
|
376
|
+
period.id = "".concat(date.getFullYear(), "Oct");
|
|
377
|
+
periods.push(period);
|
|
378
|
+
date.setDate(date.getDate() - 1);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
382
|
+
periods = isReverse ? periods : periods.reverse(); // FinancialOctober periods are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
383
|
+
|
|
384
|
+
return periods;
|
|
175
385
|
};
|
|
176
386
|
};
|
|
177
387
|
|
|
178
|
-
const getFinancialNovemberPeriodType = (
|
|
388
|
+
const getFinancialNovemberPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
179
389
|
return config => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
390
|
+
let periods = [];
|
|
391
|
+
const offset = parseInt(config.offset, 10);
|
|
392
|
+
const isFilter = config.filterFuturePeriods;
|
|
393
|
+
const isReverse = config.reversePeriods;
|
|
394
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
395
|
+
const date = new Date("31 Oct ".concat(year + 1));
|
|
396
|
+
|
|
397
|
+
for (let i = 0; i < 10; i++) {
|
|
398
|
+
const period = {};
|
|
399
|
+
period.endDate = formatYyyyMmDd(date);
|
|
400
|
+
date.setYear(date.getFullYear() - 1);
|
|
401
|
+
date.setDate(date.getDate() + 1);
|
|
402
|
+
period.startDate = formatYyyyMmDd(date);
|
|
403
|
+
const yearStart = date.getFullYear();
|
|
404
|
+
const yearEnd = date.getFullYear() + 1;
|
|
405
|
+
period.name = "".concat(getMonthName(10), " ").concat(yearStart, " - ").concat(getMonthName(9), " ").concat(yearEnd);
|
|
406
|
+
period.id = "".concat(date.getFullYear(), "Nov");
|
|
407
|
+
periods.push(period);
|
|
408
|
+
date.setDate(date.getDate() - 1);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
412
|
+
periods = isReverse ? periods : periods.reverse(); // FinancialNovember periods are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
413
|
+
|
|
414
|
+
return periods;
|
|
186
415
|
};
|
|
187
416
|
};
|
|
188
417
|
|
|
189
|
-
const getFinancialJulyPeriodType = (
|
|
418
|
+
const getFinancialJulyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
190
419
|
return config => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
420
|
+
let periods = [];
|
|
421
|
+
const offset = parseInt(config.offset, 10);
|
|
422
|
+
const isFilter = config.filterFuturePeriods;
|
|
423
|
+
const isReverse = config.reversePeriods;
|
|
424
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
425
|
+
const date = new Date("30 Jun ".concat(year + 1));
|
|
426
|
+
|
|
427
|
+
for (let i = 0; i < 10; i++) {
|
|
428
|
+
const period = {};
|
|
429
|
+
period.endDate = formatYyyyMmDd(date);
|
|
430
|
+
date.setYear(date.getFullYear() - 1);
|
|
431
|
+
date.setDate(date.getDate() + 1);
|
|
432
|
+
period.startDate = formatYyyyMmDd(date);
|
|
433
|
+
const yearStart = date.getFullYear();
|
|
434
|
+
const yearEnd = date.getFullYear() + 1;
|
|
435
|
+
period.name = "".concat(getMonthName(6), " ").concat(yearStart, " - ").concat(getMonthName(5), " ").concat(yearEnd);
|
|
436
|
+
period.id = "".concat(date.getFullYear(), "July");
|
|
437
|
+
periods.push(period);
|
|
438
|
+
date.setDate(date.getDate() - 1);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
442
|
+
periods = isReverse ? periods : periods.reverse(); // FinancialJuly periods are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
443
|
+
|
|
444
|
+
return periods;
|
|
197
445
|
};
|
|
198
446
|
};
|
|
199
447
|
|
|
200
|
-
const getFinancialAprilPeriodType = (
|
|
448
|
+
const getFinancialAprilPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
201
449
|
return config => {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
450
|
+
let periods = [];
|
|
451
|
+
const offset = parseInt(config.offset, 10);
|
|
452
|
+
const isFilter = config.filterFuturePeriods;
|
|
453
|
+
const isReverse = config.reversePeriods;
|
|
454
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
455
|
+
const date = new Date("31 Mar ".concat(year + 1));
|
|
456
|
+
|
|
457
|
+
for (let i = 0; i < 10; i++) {
|
|
458
|
+
const period = {};
|
|
459
|
+
period.endDate = formatYyyyMmDd(date);
|
|
460
|
+
date.setYear(date.getFullYear() - 1);
|
|
461
|
+
date.setDate(date.getDate() + 1);
|
|
462
|
+
period.startDate = formatYyyyMmDd(date);
|
|
463
|
+
const yearStart = date.getFullYear();
|
|
464
|
+
const yearEnd = date.getFullYear() + 1;
|
|
465
|
+
period.name = "".concat(getMonthName(3), " ").concat(yearStart, " - ").concat(getMonthName(2), " ").concat(yearEnd);
|
|
466
|
+
period.id = "".concat(date.getFullYear(), "April");
|
|
467
|
+
periods.push(period);
|
|
468
|
+
date.setDate(date.getDate() - 1);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
472
|
+
periods = isReverse ? periods : periods.reverse(); // FinancialApril periods are collected backwards. If isReverse is true, then do nothing. Else reverse to correct order and return.
|
|
473
|
+
|
|
474
|
+
return periods;
|
|
208
475
|
};
|
|
209
476
|
};
|
|
210
477
|
|
|
478
|
+
const formatYyyyMmDd = date => {
|
|
479
|
+
const y = date.getFullYear();
|
|
480
|
+
let m = String(date.getMonth() + 1);
|
|
481
|
+
let d = String(date.getDate());
|
|
482
|
+
m = m.length < 2 ? "0".concat(m) : m;
|
|
483
|
+
d = d.length < 2 ? "0".concat(d) : d;
|
|
484
|
+
return "".concat(y, "-").concat(m, "-").concat(d);
|
|
485
|
+
};
|
|
486
|
+
|
|
211
487
|
const filterFuturePeriods = periods => {
|
|
212
488
|
const array = [];
|
|
213
489
|
const now = new Date(Date.now());
|
|
@@ -221,93 +497,92 @@ const filterFuturePeriods = periods => {
|
|
|
221
497
|
return array;
|
|
222
498
|
};
|
|
223
499
|
|
|
224
|
-
const getOptions =
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
},
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
500
|
+
const getOptions = () => [{
|
|
501
|
+
id: DAILY,
|
|
502
|
+
getPeriods: getDailyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
503
|
+
name: i18n.t('Daily')
|
|
504
|
+
}, {
|
|
505
|
+
id: WEEKLY,
|
|
506
|
+
getPeriods: getWeeklyPeriodType(formatYyyyMmDd, {
|
|
507
|
+
shortName: '',
|
|
508
|
+
startDay: 1
|
|
509
|
+
}, filterFuturePeriods),
|
|
510
|
+
name: i18n.t('Weekly')
|
|
511
|
+
}, {
|
|
512
|
+
id: WEEKLYWED,
|
|
513
|
+
getPeriods: getWeeklyPeriodType(formatYyyyMmDd, {
|
|
514
|
+
shortName: 'Wed',
|
|
515
|
+
startDay: 3
|
|
516
|
+
}, filterFuturePeriods),
|
|
517
|
+
name: i18n.t('Weekly (Start Wednesday)')
|
|
518
|
+
}, {
|
|
519
|
+
id: WEEKLYTHU,
|
|
520
|
+
getPeriods: getWeeklyPeriodType(formatYyyyMmDd, {
|
|
521
|
+
shortName: 'Thu',
|
|
522
|
+
startDay: 4
|
|
523
|
+
}, filterFuturePeriods),
|
|
524
|
+
name: i18n.t('Weekly (Start Thursday)')
|
|
525
|
+
}, {
|
|
526
|
+
id: WEEKLYSAT,
|
|
527
|
+
getPeriods: getWeeklyPeriodType(formatYyyyMmDd, {
|
|
528
|
+
shortName: 'Sat',
|
|
529
|
+
startDay: 6
|
|
530
|
+
}, filterFuturePeriods),
|
|
531
|
+
name: i18n.t('Weekly (Start Saturday)')
|
|
532
|
+
}, {
|
|
533
|
+
id: WEEKLYSUN,
|
|
534
|
+
getPeriods: getWeeklyPeriodType(formatYyyyMmDd, {
|
|
535
|
+
shortName: 'Sun',
|
|
536
|
+
startDay: 7
|
|
537
|
+
}, filterFuturePeriods),
|
|
538
|
+
name: i18n.t('Weekly (Start Sunday)')
|
|
539
|
+
}, {
|
|
540
|
+
id: BIWEEKLY,
|
|
541
|
+
getPeriods: getBiWeeklyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
542
|
+
name: i18n.t('Bi-weekly')
|
|
543
|
+
}, {
|
|
544
|
+
id: MONTHLY,
|
|
545
|
+
getPeriods: getMonthlyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
546
|
+
name: i18n.t('Monthly')
|
|
547
|
+
}, {
|
|
548
|
+
id: BIMONTHLY,
|
|
549
|
+
getPeriods: getBiMonthlyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
550
|
+
name: i18n.t('Bi-monthly')
|
|
551
|
+
}, {
|
|
552
|
+
id: QUARTERLY,
|
|
553
|
+
getPeriods: getQuarterlyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
554
|
+
name: i18n.t('Quarterly')
|
|
555
|
+
}, {
|
|
556
|
+
id: SIXMONTHLY,
|
|
557
|
+
getPeriods: getSixMonthlyPeriodType(filterFuturePeriods),
|
|
558
|
+
name: i18n.t('Six-monthly')
|
|
559
|
+
}, {
|
|
560
|
+
id: SIXMONTHLYAPR,
|
|
561
|
+
getPeriods: getSixMonthlyAprilPeriodType(filterFuturePeriods),
|
|
562
|
+
name: i18n.t('Six-monthly April')
|
|
563
|
+
}, {
|
|
564
|
+
id: YEARLY,
|
|
565
|
+
getPeriods: getYearlyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
566
|
+
name: i18n.t('Yearly')
|
|
567
|
+
}, {
|
|
568
|
+
id: FYNOV,
|
|
569
|
+
getPeriods: getFinancialNovemberPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
570
|
+
name: i18n.t('Financial year (Start November)')
|
|
571
|
+
}, {
|
|
572
|
+
id: FYOCT,
|
|
573
|
+
getPeriods: getFinancialOctoberPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
574
|
+
name: i18n.t('Financial year (Start October)')
|
|
575
|
+
}, {
|
|
576
|
+
id: FYJUL,
|
|
577
|
+
getPeriods: getFinancialJulyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
578
|
+
name: i18n.t('Financial year (Start July)')
|
|
579
|
+
}, {
|
|
580
|
+
id: FYAPR,
|
|
581
|
+
getPeriods: getFinancialAprilPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
582
|
+
name: i18n.t('Financial year (Start April)')
|
|
583
|
+
}];
|
|
306
584
|
|
|
307
|
-
export const getFixedPeriodsOptionsById =
|
|
308
|
-
let calendar = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'gregory';
|
|
309
|
-
return getOptions(calendar).find(option => option.id === id);
|
|
310
|
-
};
|
|
585
|
+
export const getFixedPeriodsOptionsById = id => getOptions().find(option => option.id === id);
|
|
311
586
|
export const getFixedPeriodsOptions = () => getOptions();
|
|
312
587
|
export const getYearOffsetFromNow = yearStr => parseInt(yearStr) - new Date(Date.now()).getFullYear();
|
|
313
588
|
export const parsePeriodCode = (code, allowedTypes) => {
|