@dhis2/analytics 24.5.0-alpha.1 → 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 +6 -4
- package/build/cjs/components/PeriodDimension/PeriodTransfer.js +4 -17
- package/build/cjs/components/PeriodDimension/__tests__/PeriodSelector.spec.js +0 -5
- package/build/cjs/components/PeriodDimension/utils/fixedPeriods.js +478 -205
- 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 -15
- package/build/es/components/PeriodDimension/__tests__/PeriodSelector.spec.js +0 -5
- package/build/es/components/PeriodDimension/utils/fixedPeriods.js +477 -203
- 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
|
@@ -5,8 +5,6 @@ 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
|
-
|
|
10
8
|
var _index = _interopRequireDefault(require("../../../locales/index.js"));
|
|
11
9
|
|
|
12
10
|
var _index2 = require("./index.js");
|
|
@@ -51,176 +49,452 @@ const PERIOD_TYPE_REGEX = {
|
|
|
51
49
|
|
|
52
50
|
};
|
|
53
51
|
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
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;
|
|
52
|
+
const getMonthName = key => {
|
|
53
|
+
const monthNames = [_index.default.t('January'), _index.default.t('February'), _index.default.t('March'), _index.default.t('April'), _index.default.t('May'), _index.default.t('June'), _index.default.t('July'), _index.default.t('August'), _index.default.t('September'), _index.default.t('October'), _index.default.t('November'), _index.default.t('December')];
|
|
54
|
+
return monthNames[key];
|
|
77
55
|
};
|
|
78
56
|
|
|
79
|
-
const getDailyPeriodType = (
|
|
57
|
+
const getDailyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
80
58
|
return config => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
59
|
+
let periods = [];
|
|
60
|
+
const offset = parseInt(config.offset, 10);
|
|
61
|
+
const isFilter = config.filterFuturePeriods;
|
|
62
|
+
const isReverse = config.reversePeriods;
|
|
63
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
64
|
+
const date = new Date("01 Jan ".concat(year));
|
|
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;
|
|
87
80
|
};
|
|
88
81
|
};
|
|
89
82
|
|
|
90
|
-
const getWeeklyPeriodType = (weekObj, fnFilter
|
|
83
|
+
const getWeeklyPeriodType = (formatYyyyMmDd, weekObj, fnFilter) => {
|
|
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
|
+
|
|
91
101
|
return config => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
let periods = [];
|
|
103
|
+
const offset = parseInt(config.offset, 10);
|
|
104
|
+
const isFilter = config.filterFuturePeriods;
|
|
105
|
+
const isReverse = config.reversePeriods;
|
|
106
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
107
|
+
const date = getEpiWeekStartDay(year, weekObj.startDay);
|
|
108
|
+
let week = 1;
|
|
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;
|
|
100
134
|
};
|
|
101
135
|
};
|
|
102
136
|
|
|
103
|
-
const getBiWeeklyPeriodType = (
|
|
137
|
+
const getBiWeeklyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
104
138
|
return config => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
139
|
+
let periods = [];
|
|
140
|
+
const offset = parseInt(config.offset, 10);
|
|
141
|
+
const isFilter = config.filterFuturePeriods;
|
|
142
|
+
const isReverse = config.reversePeriods;
|
|
143
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
144
|
+
const date = new Date("01 Jan ".concat(year));
|
|
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;
|
|
111
178
|
};
|
|
112
179
|
};
|
|
113
180
|
|
|
114
|
-
const getMonthlyPeriodType = (
|
|
181
|
+
const getMonthlyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
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
|
+
|
|
115
189
|
return config => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
190
|
+
let periods = [];
|
|
191
|
+
const offset = parseInt(config.offset, 10);
|
|
192
|
+
const isFilter = config.filterFuturePeriods;
|
|
193
|
+
const isReverse = config.reversePeriods;
|
|
194
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
195
|
+
const date = new Date("31 Dec ".concat(year));
|
|
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;
|
|
122
214
|
};
|
|
123
215
|
};
|
|
124
216
|
|
|
125
|
-
const getBiMonthlyPeriodType = (
|
|
217
|
+
const getBiMonthlyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
126
218
|
return config => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
219
|
+
let periods = [];
|
|
220
|
+
const offset = parseInt(config.offset, 10);
|
|
221
|
+
const isFilter = config.filterFuturePeriods;
|
|
222
|
+
const isReverse = config.reversePeriods;
|
|
223
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
224
|
+
const date = new Date("31 Dec ".concat(year));
|
|
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;
|
|
133
248
|
};
|
|
134
249
|
};
|
|
135
250
|
|
|
136
|
-
const getQuarterlyPeriodType = (
|
|
251
|
+
const getQuarterlyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
137
252
|
return config => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
253
|
+
let periods = [];
|
|
254
|
+
const offset = parseInt(config.offset, 10);
|
|
255
|
+
const isFilter = config.filterFuturePeriods;
|
|
256
|
+
const isReverse = config.reversePeriods;
|
|
257
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
258
|
+
const date = new Date("31 Dec ".concat(year));
|
|
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;
|
|
144
283
|
};
|
|
145
284
|
};
|
|
146
285
|
|
|
147
|
-
const getSixMonthlyPeriodType =
|
|
286
|
+
const getSixMonthlyPeriodType = fnFilter => {
|
|
148
287
|
return config => {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
288
|
+
let periods = [];
|
|
289
|
+
const offset = parseInt(config.offset, 10);
|
|
290
|
+
const isFilter = config.filterFuturePeriods;
|
|
291
|
+
const isReverse = config.reversePeriods;
|
|
292
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
293
|
+
let period = {};
|
|
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;
|
|
155
310
|
};
|
|
156
311
|
};
|
|
157
312
|
|
|
158
|
-
const getSixMonthlyAprilPeriodType =
|
|
313
|
+
const getSixMonthlyAprilPeriodType = fnFilter => {
|
|
159
314
|
return config => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
315
|
+
let periods = [];
|
|
316
|
+
const offset = parseInt(config.offset, 10);
|
|
317
|
+
const isFilter = config.filterFuturePeriods;
|
|
318
|
+
const isReverse = config.reversePeriods;
|
|
319
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
320
|
+
let period = {};
|
|
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;
|
|
166
337
|
};
|
|
167
338
|
};
|
|
168
339
|
|
|
169
|
-
const getYearlyPeriodType = (
|
|
340
|
+
const getYearlyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
170
341
|
return config => {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
342
|
+
let periods = [];
|
|
343
|
+
const offset = parseInt(config.offset, 10);
|
|
344
|
+
const isFilter = config.filterFuturePeriods;
|
|
345
|
+
const isReverse = config.reversePeriods;
|
|
346
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
347
|
+
const date = new Date("31 Dec ".concat(year));
|
|
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;
|
|
177
366
|
};
|
|
178
367
|
};
|
|
179
368
|
|
|
180
|
-
const getFinancialOctoberPeriodType = (
|
|
369
|
+
const getFinancialOctoberPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
181
370
|
return config => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
371
|
+
let periods = [];
|
|
372
|
+
const offset = parseInt(config.offset, 10);
|
|
373
|
+
const isFilter = config.filterFuturePeriods;
|
|
374
|
+
const isReverse = config.reversePeriods;
|
|
375
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
376
|
+
const date = new Date("30 Sep ".concat(year + 1));
|
|
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;
|
|
188
396
|
};
|
|
189
397
|
};
|
|
190
398
|
|
|
191
|
-
const getFinancialNovemberPeriodType = (
|
|
399
|
+
const getFinancialNovemberPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
192
400
|
return config => {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
401
|
+
let periods = [];
|
|
402
|
+
const offset = parseInt(config.offset, 10);
|
|
403
|
+
const isFilter = config.filterFuturePeriods;
|
|
404
|
+
const isReverse = config.reversePeriods;
|
|
405
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
406
|
+
const date = new Date("31 Oct ".concat(year + 1));
|
|
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;
|
|
199
426
|
};
|
|
200
427
|
};
|
|
201
428
|
|
|
202
|
-
const getFinancialJulyPeriodType = (
|
|
429
|
+
const getFinancialJulyPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
203
430
|
return config => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
431
|
+
let periods = [];
|
|
432
|
+
const offset = parseInt(config.offset, 10);
|
|
433
|
+
const isFilter = config.filterFuturePeriods;
|
|
434
|
+
const isReverse = config.reversePeriods;
|
|
435
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
436
|
+
const date = new Date("30 Jun ".concat(year + 1));
|
|
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;
|
|
210
456
|
};
|
|
211
457
|
};
|
|
212
458
|
|
|
213
|
-
const getFinancialAprilPeriodType = (
|
|
459
|
+
const getFinancialAprilPeriodType = (formatYyyyMmDd, fnFilter) => {
|
|
214
460
|
return config => {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
461
|
+
let periods = [];
|
|
462
|
+
const offset = parseInt(config.offset, 10);
|
|
463
|
+
const isFilter = config.filterFuturePeriods;
|
|
464
|
+
const isReverse = config.reversePeriods;
|
|
465
|
+
const year = new Date(Date.now()).getFullYear() + offset;
|
|
466
|
+
const date = new Date("31 Mar ".concat(year + 1));
|
|
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;
|
|
221
486
|
};
|
|
222
487
|
};
|
|
223
488
|
|
|
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
|
+
|
|
224
498
|
const filterFuturePeriods = periods => {
|
|
225
499
|
const array = [];
|
|
226
500
|
const now = new Date(Date.now());
|
|
@@ -234,93 +508,92 @@ const filterFuturePeriods = periods => {
|
|
|
234
508
|
return array;
|
|
235
509
|
};
|
|
236
510
|
|
|
237
|
-
const getOptions =
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
};
|
|
511
|
+
const getOptions = () => [{
|
|
512
|
+
id: _index2.DAILY,
|
|
513
|
+
getPeriods: getDailyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
514
|
+
name: _index.default.t('Daily')
|
|
515
|
+
}, {
|
|
516
|
+
id: _index2.WEEKLY,
|
|
517
|
+
getPeriods: getWeeklyPeriodType(formatYyyyMmDd, {
|
|
518
|
+
shortName: '',
|
|
519
|
+
startDay: 1
|
|
520
|
+
}, filterFuturePeriods),
|
|
521
|
+
name: _index.default.t('Weekly')
|
|
522
|
+
}, {
|
|
523
|
+
id: _index2.WEEKLYWED,
|
|
524
|
+
getPeriods: getWeeklyPeriodType(formatYyyyMmDd, {
|
|
525
|
+
shortName: 'Wed',
|
|
526
|
+
startDay: 3
|
|
527
|
+
}, filterFuturePeriods),
|
|
528
|
+
name: _index.default.t('Weekly (Start Wednesday)')
|
|
529
|
+
}, {
|
|
530
|
+
id: _index2.WEEKLYTHU,
|
|
531
|
+
getPeriods: getWeeklyPeriodType(formatYyyyMmDd, {
|
|
532
|
+
shortName: 'Thu',
|
|
533
|
+
startDay: 4
|
|
534
|
+
}, filterFuturePeriods),
|
|
535
|
+
name: _index.default.t('Weekly (Start Thursday)')
|
|
536
|
+
}, {
|
|
537
|
+
id: _index2.WEEKLYSAT,
|
|
538
|
+
getPeriods: getWeeklyPeriodType(formatYyyyMmDd, {
|
|
539
|
+
shortName: 'Sat',
|
|
540
|
+
startDay: 6
|
|
541
|
+
}, filterFuturePeriods),
|
|
542
|
+
name: _index.default.t('Weekly (Start Saturday)')
|
|
543
|
+
}, {
|
|
544
|
+
id: _index2.WEEKLYSUN,
|
|
545
|
+
getPeriods: getWeeklyPeriodType(formatYyyyMmDd, {
|
|
546
|
+
shortName: 'Sun',
|
|
547
|
+
startDay: 7
|
|
548
|
+
}, filterFuturePeriods),
|
|
549
|
+
name: _index.default.t('Weekly (Start Sunday)')
|
|
550
|
+
}, {
|
|
551
|
+
id: _index2.BIWEEKLY,
|
|
552
|
+
getPeriods: getBiWeeklyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
553
|
+
name: _index.default.t('Bi-weekly')
|
|
554
|
+
}, {
|
|
555
|
+
id: _index2.MONTHLY,
|
|
556
|
+
getPeriods: getMonthlyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
557
|
+
name: _index.default.t('Monthly')
|
|
558
|
+
}, {
|
|
559
|
+
id: _index2.BIMONTHLY,
|
|
560
|
+
getPeriods: getBiMonthlyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
561
|
+
name: _index.default.t('Bi-monthly')
|
|
562
|
+
}, {
|
|
563
|
+
id: _index2.QUARTERLY,
|
|
564
|
+
getPeriods: getQuarterlyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
565
|
+
name: _index.default.t('Quarterly')
|
|
566
|
+
}, {
|
|
567
|
+
id: _index2.SIXMONTHLY,
|
|
568
|
+
getPeriods: getSixMonthlyPeriodType(filterFuturePeriods),
|
|
569
|
+
name: _index.default.t('Six-monthly')
|
|
570
|
+
}, {
|
|
571
|
+
id: _index2.SIXMONTHLYAPR,
|
|
572
|
+
getPeriods: getSixMonthlyAprilPeriodType(filterFuturePeriods),
|
|
573
|
+
name: _index.default.t('Six-monthly April')
|
|
574
|
+
}, {
|
|
575
|
+
id: _index2.YEARLY,
|
|
576
|
+
getPeriods: getYearlyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
577
|
+
name: _index.default.t('Yearly')
|
|
578
|
+
}, {
|
|
579
|
+
id: _index2.FYNOV,
|
|
580
|
+
getPeriods: getFinancialNovemberPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
581
|
+
name: _index.default.t('Financial year (Start November)')
|
|
582
|
+
}, {
|
|
583
|
+
id: _index2.FYOCT,
|
|
584
|
+
getPeriods: getFinancialOctoberPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
585
|
+
name: _index.default.t('Financial year (Start October)')
|
|
586
|
+
}, {
|
|
587
|
+
id: _index2.FYJUL,
|
|
588
|
+
getPeriods: getFinancialJulyPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
589
|
+
name: _index.default.t('Financial year (Start July)')
|
|
590
|
+
}, {
|
|
591
|
+
id: _index2.FYAPR,
|
|
592
|
+
getPeriods: getFinancialAprilPeriodType(formatYyyyMmDd, filterFuturePeriods),
|
|
593
|
+
name: _index.default.t('Financial year (Start April)')
|
|
594
|
+
}];
|
|
595
|
+
|
|
596
|
+
const getFixedPeriodsOptionsById = id => getOptions().find(option => option.id === id);
|
|
324
597
|
|
|
325
598
|
exports.getFixedPeriodsOptionsById = getFixedPeriodsOptionsById;
|
|
326
599
|
|