@dhis2/analytics 24.4.1 → 24.5.0-alpha.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.
- package/CHANGELOG.md +19 -0
- package/build/cjs/components/OpenFileDialog/OpenFileDialog.js +7 -2
- package/build/cjs/components/PeriodDimension/PeriodTransfer.js +17 -4
- package/build/cjs/components/PeriodDimension/__tests__/PeriodSelector.spec.js +5 -0
- package/build/cjs/components/PeriodDimension/utils/fixedPeriods.js +205 -478
- package/build/cjs/locales/en/translations.json +0 -14
- package/build/es/components/OpenFileDialog/OpenFileDialog.js +7 -2
- package/build/es/components/PeriodDimension/PeriodTransfer.js +15 -4
- package/build/es/components/PeriodDimension/__tests__/PeriodSelector.spec.js +5 -0
- package/build/es/components/PeriodDimension/utils/fixedPeriods.js +203 -477
- package/build/es/locales/en/translations.json +0 -14
- package/package.json +7 -1
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.parsePeriodCode = exports.getYearOffsetFromNow = exports.getFixedPeriodsOptionsById = exports.getFixedPeriodsOptions = 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,176 @@ const PERIOD_TYPE_REGEX = {
|
|
|
49
51
|
|
|
50
52
|
};
|
|
51
53
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
const getPeriods = _ref => {
|
|
55
|
+
let {
|
|
56
|
+
periodType,
|
|
57
|
+
config,
|
|
58
|
+
fnFilter,
|
|
59
|
+
calendar
|
|
60
|
+
} = _ref;
|
|
61
|
+
const offset = parseInt(config.offset, 10);
|
|
62
|
+
const isFilter = config.filterFuturePeriods;
|
|
63
|
+
const isReverse = periodType.match(/^FY|YEARLY/) ? true : config.reversePeriods;
|
|
64
|
+
const now = (0, _multiCalendarDates.getNowInCalendar)(calendar);
|
|
65
|
+
const year = (now.eraYear || now.year) + offset;
|
|
66
|
+
const params = {
|
|
67
|
+
periodType,
|
|
68
|
+
year,
|
|
69
|
+
calendar,
|
|
70
|
+
locale: 'en',
|
|
71
|
+
startingDay: config.startDay
|
|
72
|
+
};
|
|
73
|
+
let periods = (0, _multiCalendarDates.generateFixedPeriods)(params);
|
|
74
|
+
periods = isFilter ? fnFilter(periods) : periods;
|
|
75
|
+
periods = !isReverse ? periods : periods.reverse();
|
|
76
|
+
return periods;
|
|
55
77
|
};
|
|
56
78
|
|
|
57
|
-
const getDailyPeriodType = (
|
|
79
|
+
const getDailyPeriodType = (fnFilter, calendar) => {
|
|
58
80
|
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;
|
|
81
|
+
return getPeriods({
|
|
82
|
+
periodType: 'DAILY',
|
|
83
|
+
config,
|
|
84
|
+
fnFilter,
|
|
85
|
+
calendar
|
|
86
|
+
});
|
|
80
87
|
};
|
|
81
88
|
};
|
|
82
89
|
|
|
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
|
-
|
|
90
|
+
const getWeeklyPeriodType = (weekObj, fnFilter, calendar) => {
|
|
101
91
|
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;
|
|
92
|
+
return getPeriods({
|
|
93
|
+
periodType: 'WEEKLY',
|
|
94
|
+
config: { ...config,
|
|
95
|
+
startDay: weekObj.startDay
|
|
96
|
+
},
|
|
97
|
+
fnFilter,
|
|
98
|
+
calendar
|
|
99
|
+
});
|
|
134
100
|
};
|
|
135
101
|
};
|
|
136
102
|
|
|
137
|
-
const getBiWeeklyPeriodType = (
|
|
103
|
+
const getBiWeeklyPeriodType = (fnFilter, calendar) => {
|
|
138
104
|
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;
|
|
105
|
+
return getPeriods({
|
|
106
|
+
periodType: 'BIWEEKLY',
|
|
107
|
+
config,
|
|
108
|
+
fnFilter,
|
|
109
|
+
calendar
|
|
110
|
+
});
|
|
178
111
|
};
|
|
179
112
|
};
|
|
180
113
|
|
|
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
|
-
|
|
114
|
+
const getMonthlyPeriodType = (fnFilter, calendar) => {
|
|
189
115
|
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;
|
|
116
|
+
return getPeriods({
|
|
117
|
+
periodType: 'MONTHLY',
|
|
118
|
+
config,
|
|
119
|
+
fnFilter,
|
|
120
|
+
calendar
|
|
121
|
+
});
|
|
214
122
|
};
|
|
215
123
|
};
|
|
216
124
|
|
|
217
|
-
const getBiMonthlyPeriodType = (
|
|
125
|
+
const getBiMonthlyPeriodType = (fnFilter, calendar) => {
|
|
218
126
|
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;
|
|
127
|
+
return getPeriods({
|
|
128
|
+
periodType: 'BIMONTHLY',
|
|
129
|
+
config,
|
|
130
|
+
fnFilter,
|
|
131
|
+
calendar
|
|
132
|
+
});
|
|
248
133
|
};
|
|
249
134
|
};
|
|
250
135
|
|
|
251
|
-
const getQuarterlyPeriodType = (
|
|
136
|
+
const getQuarterlyPeriodType = (fnFilter, calendar) => {
|
|
252
137
|
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;
|
|
138
|
+
return getPeriods({
|
|
139
|
+
periodType: 'QUARTERLY',
|
|
140
|
+
config,
|
|
141
|
+
fnFilter,
|
|
142
|
+
calendar
|
|
143
|
+
});
|
|
283
144
|
};
|
|
284
145
|
};
|
|
285
146
|
|
|
286
|
-
const getSixMonthlyPeriodType = fnFilter => {
|
|
147
|
+
const getSixMonthlyPeriodType = (fnFilter, calendar) => {
|
|
287
148
|
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;
|
|
149
|
+
return getPeriods({
|
|
150
|
+
periodType: 'SIXMONTHLY',
|
|
151
|
+
config,
|
|
152
|
+
fnFilter,
|
|
153
|
+
calendar
|
|
154
|
+
});
|
|
310
155
|
};
|
|
311
156
|
};
|
|
312
157
|
|
|
313
|
-
const getSixMonthlyAprilPeriodType = fnFilter => {
|
|
158
|
+
const getSixMonthlyAprilPeriodType = (fnFilter, calendar) => {
|
|
314
159
|
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;
|
|
160
|
+
return getPeriods({
|
|
161
|
+
periodType: 'SIXMONTHLYAPR',
|
|
162
|
+
config,
|
|
163
|
+
fnFilter,
|
|
164
|
+
calendar
|
|
165
|
+
});
|
|
337
166
|
};
|
|
338
167
|
};
|
|
339
168
|
|
|
340
|
-
const getYearlyPeriodType = (
|
|
169
|
+
const getYearlyPeriodType = (fnFilter, calendar) => {
|
|
341
170
|
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;
|
|
171
|
+
return getPeriods({
|
|
172
|
+
periodType: 'YEARLY',
|
|
173
|
+
config,
|
|
174
|
+
fnFilter,
|
|
175
|
+
calendar
|
|
176
|
+
});
|
|
366
177
|
};
|
|
367
178
|
};
|
|
368
179
|
|
|
369
|
-
const getFinancialOctoberPeriodType = (
|
|
180
|
+
const getFinancialOctoberPeriodType = (fnFilter, calendar) => {
|
|
370
181
|
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;
|
|
182
|
+
return getPeriods({
|
|
183
|
+
periodType: 'FYOCT',
|
|
184
|
+
config,
|
|
185
|
+
fnFilter,
|
|
186
|
+
calendar
|
|
187
|
+
});
|
|
396
188
|
};
|
|
397
189
|
};
|
|
398
190
|
|
|
399
|
-
const getFinancialNovemberPeriodType = (
|
|
191
|
+
const getFinancialNovemberPeriodType = (fnFilter, calendar) => {
|
|
400
192
|
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;
|
|
193
|
+
return getPeriods({
|
|
194
|
+
periodType: 'FYNOV',
|
|
195
|
+
config,
|
|
196
|
+
fnFilter,
|
|
197
|
+
calendar
|
|
198
|
+
});
|
|
426
199
|
};
|
|
427
200
|
};
|
|
428
201
|
|
|
429
|
-
const getFinancialJulyPeriodType = (
|
|
202
|
+
const getFinancialJulyPeriodType = (fnFilter, calendar) => {
|
|
430
203
|
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;
|
|
204
|
+
return getPeriods({
|
|
205
|
+
periodType: 'FYJUL',
|
|
206
|
+
config,
|
|
207
|
+
fnFilter,
|
|
208
|
+
calendar
|
|
209
|
+
});
|
|
456
210
|
};
|
|
457
211
|
};
|
|
458
212
|
|
|
459
|
-
const getFinancialAprilPeriodType = (
|
|
213
|
+
const getFinancialAprilPeriodType = (fnFilter, calendar) => {
|
|
460
214
|
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;
|
|
215
|
+
return getPeriods({
|
|
216
|
+
periodType: 'FYAPR',
|
|
217
|
+
config,
|
|
218
|
+
fnFilter,
|
|
219
|
+
calendar
|
|
220
|
+
});
|
|
486
221
|
};
|
|
487
222
|
};
|
|
488
223
|
|
|
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
224
|
const filterFuturePeriods = periods => {
|
|
499
225
|
const array = [];
|
|
500
226
|
const now = new Date(Date.now());
|
|
@@ -508,92 +234,93 @@ const filterFuturePeriods = periods => {
|
|
|
508
234
|
return array;
|
|
509
235
|
};
|
|
510
236
|
|
|
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
|
-
|
|
237
|
+
const getOptions = function () {
|
|
238
|
+
let calendar = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'gregory';
|
|
239
|
+
return [{
|
|
240
|
+
id: _index2.DAILY,
|
|
241
|
+
getPeriods: getDailyPeriodType(filterFuturePeriods, calendar),
|
|
242
|
+
name: _index.default.t('Daily')
|
|
243
|
+
}, {
|
|
244
|
+
id: _index2.WEEKLY,
|
|
245
|
+
getPeriods: getWeeklyPeriodType({
|
|
246
|
+
startDay: 1
|
|
247
|
+
}, filterFuturePeriods, calendar),
|
|
248
|
+
name: _index.default.t('Weekly')
|
|
249
|
+
}, {
|
|
250
|
+
id: _index2.WEEKLYWED,
|
|
251
|
+
getPeriods: getWeeklyPeriodType({
|
|
252
|
+
startDay: 3
|
|
253
|
+
}, filterFuturePeriods, calendar),
|
|
254
|
+
name: _index.default.t('Weekly (Start Wednesday)')
|
|
255
|
+
}, {
|
|
256
|
+
id: _index2.WEEKLYTHU,
|
|
257
|
+
getPeriods: getWeeklyPeriodType({
|
|
258
|
+
startDay: 4
|
|
259
|
+
}, filterFuturePeriods, calendar),
|
|
260
|
+
name: _index.default.t('Weekly (Start Thursday)')
|
|
261
|
+
}, {
|
|
262
|
+
id: _index2.WEEKLYSAT,
|
|
263
|
+
getPeriods: getWeeklyPeriodType({
|
|
264
|
+
startDay: 6
|
|
265
|
+
}, filterFuturePeriods, calendar),
|
|
266
|
+
name: _index.default.t('Weekly (Start Saturday)')
|
|
267
|
+
}, {
|
|
268
|
+
id: _index2.WEEKLYSUN,
|
|
269
|
+
getPeriods: getWeeklyPeriodType({
|
|
270
|
+
startDay: 7
|
|
271
|
+
}, filterFuturePeriods, calendar),
|
|
272
|
+
name: _index.default.t('Weekly (Start Sunday)')
|
|
273
|
+
}, {
|
|
274
|
+
id: _index2.BIWEEKLY,
|
|
275
|
+
getPeriods: getBiWeeklyPeriodType(filterFuturePeriods, calendar),
|
|
276
|
+
name: _index.default.t('Bi-weekly')
|
|
277
|
+
}, {
|
|
278
|
+
id: _index2.MONTHLY,
|
|
279
|
+
getPeriods: getMonthlyPeriodType(filterFuturePeriods, calendar),
|
|
280
|
+
name: _index.default.t('Monthly')
|
|
281
|
+
}, {
|
|
282
|
+
id: _index2.BIMONTHLY,
|
|
283
|
+
getPeriods: getBiMonthlyPeriodType(filterFuturePeriods, calendar),
|
|
284
|
+
name: _index.default.t('Bi-monthly')
|
|
285
|
+
}, {
|
|
286
|
+
id: _index2.QUARTERLY,
|
|
287
|
+
getPeriods: getQuarterlyPeriodType(filterFuturePeriods, calendar),
|
|
288
|
+
name: _index.default.t('Quarterly')
|
|
289
|
+
}, {
|
|
290
|
+
id: _index2.SIXMONTHLY,
|
|
291
|
+
getPeriods: getSixMonthlyPeriodType(filterFuturePeriods, calendar),
|
|
292
|
+
name: _index.default.t('Six-monthly')
|
|
293
|
+
}, {
|
|
294
|
+
id: _index2.SIXMONTHLYAPR,
|
|
295
|
+
getPeriods: getSixMonthlyAprilPeriodType(filterFuturePeriods, calendar),
|
|
296
|
+
name: _index.default.t('Six-monthly April')
|
|
297
|
+
}, {
|
|
298
|
+
id: _index2.YEARLY,
|
|
299
|
+
getPeriods: getYearlyPeriodType(filterFuturePeriods, calendar),
|
|
300
|
+
name: _index.default.t('Yearly')
|
|
301
|
+
}, {
|
|
302
|
+
id: _index2.FYNOV,
|
|
303
|
+
getPeriods: getFinancialNovemberPeriodType(filterFuturePeriods, calendar),
|
|
304
|
+
name: _index.default.t('Financial year (Start November)')
|
|
305
|
+
}, {
|
|
306
|
+
id: _index2.FYOCT,
|
|
307
|
+
getPeriods: getFinancialOctoberPeriodType(filterFuturePeriods, calendar),
|
|
308
|
+
name: _index.default.t('Financial year (Start October)')
|
|
309
|
+
}, {
|
|
310
|
+
id: _index2.FYJUL,
|
|
311
|
+
getPeriods: getFinancialJulyPeriodType(filterFuturePeriods, calendar),
|
|
312
|
+
name: _index.default.t('Financial year (Start July)')
|
|
313
|
+
}, {
|
|
314
|
+
id: _index2.FYAPR,
|
|
315
|
+
getPeriods: getFinancialAprilPeriodType(filterFuturePeriods, calendar),
|
|
316
|
+
name: _index.default.t('Financial year (Start April)')
|
|
317
|
+
}];
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const getFixedPeriodsOptionsById = function (id) {
|
|
321
|
+
let calendar = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'gregory';
|
|
322
|
+
return getOptions(calendar).find(option => option.id === id);
|
|
323
|
+
};
|
|
597
324
|
|
|
598
325
|
exports.getFixedPeriodsOptionsById = getFixedPeriodsOptionsById;
|
|
599
326
|
|