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