Comparing version 31.3.0 to 31.4.0
{ | ||
"name": "d2", | ||
"version": "31.3.0", | ||
"version": "31.4.0", | ||
"description": "Javascript library for DHIS2", | ||
@@ -5,0 +5,0 @@ "main": "d2.js", |
@@ -6,2 +6,3 @@ 'use strict'; | ||
}); | ||
exports.computeWeekBasedPeriod = undefined; | ||
exports.formatAsISODate = formatAsISODate; | ||
@@ -175,2 +176,85 @@ exports.filterFuturePeriods = filterFuturePeriods; | ||
} | ||
/** | ||
* This function takes some general instructions for a period and returns a precise period containing | ||
* a start date and end date. It corrects for week 1 starting in a previous year and for week 53 in a | ||
* 52 week year | ||
* It is used by the BiWeekly periodType and all flavors of Weekly PeriodTypes, | ||
* such as Weekly, weeklyWednessday, etc. | ||
* @param {Object} obj - An object | ||
* @param {Number} obj.year - Year | ||
* @param {Number} obj.week - Week number between 1-53 | ||
* @param {String} [obj.locale=en] - The current locale | ||
* @param {Number} [obj.weekTypeDiff=0] - The difference between the starting day of the week | ||
* in a given periodType and the first day of the week. This option is being used for different | ||
* flavors of weekly period types, such as WeeklyWednesday, WeeklyThursday, etc. | ||
* @param {Number} [obj.periodLength=6] - The amount of days until the end date: 6 for weekly | ||
* and 13 for Bikweekly | ||
* @returns {Object} - An object containing various properties that can be used to contruct | ||
* the final parsed period | ||
* @example for default scenario | ||
* computeWeekBasedPeriod({ year: 2019, week: 12}) | ||
* // returns: | ||
* // { | ||
* // week: 12, | ||
* // year: 2019, | ||
* // startMonthName: 'June', | ||
* // startDayNumber: 3, | ||
* // endDayNumber: 9, | ||
* // startDate: '2019-06-03', | ||
* // endDate: '2019-06-09', | ||
* // } | ||
* @example for week 53 in 52 week year edge case | ||
* computeWeekBasedPeriod({ year: 2016, week: 53}) | ||
* // returns: | ||
* // { | ||
* // week: 1, | ||
* // year: 2017, | ||
* // startMonthName: 'January', | ||
* // startDayNumber: 2, | ||
* // endDayNumber: 8, | ||
* // startDate: '2017-01-02', | ||
* // endDate: '2017-01-08', | ||
* // } | ||
*/ | ||
var computeWeekBasedPeriod = exports.computeWeekBasedPeriod = function computeWeekBasedPeriod(_ref) { | ||
var year = _ref.year, | ||
week = _ref.week, | ||
_ref$locale = _ref.locale, | ||
locale = _ref$locale === undefined ? 'en' : _ref$locale, | ||
_ref$weekTypeDiff = _ref.weekTypeDiff, | ||
weekTypeDiff = _ref$weekTypeDiff === undefined ? 0 : _ref$weekTypeDiff, | ||
_ref$periodLength = _ref.periodLength, | ||
periodLength = _ref$periodLength === undefined ? 6 : _ref$periodLength; | ||
var startDate = addDays(weekTypeDiff, getFirstDateOfWeek(year, week)); | ||
var monthNames = getMonthNamesForLocale(locale); | ||
var startMonth = startDate.getMonth(); | ||
var startYear = startDate.getFullYear(); | ||
var startMonthName = monthNames[startMonth]; | ||
var startDayNum = startDate.getDate(); | ||
if (week === 53 && startYear !== year) { | ||
/* eslint-disable no-param-reassign */ | ||
week = 1; | ||
year = startYear; | ||
/* eslint-enable */ | ||
} | ||
var endDate = addDays(periodLength, startDate); | ||
var endMonth = endDate.getMonth(); | ||
var endDayNum = endDate.getDate(); | ||
var endMonthName = monthNames[endMonth]; | ||
return { | ||
week: week, | ||
year: year, | ||
startMonthName: startMonthName, | ||
startDayNum: startDayNum, | ||
endMonthName: endMonthName, | ||
endDayNum: endDayNum, | ||
startDate: formatAsISODate(startDate), | ||
endDate: formatAsISODate(endDate) | ||
}; | ||
}; | ||
//# sourceMappingURL=helpers.js.map |
@@ -19,2 +19,3 @@ 'use strict'; | ||
WeeklySunday: /^([0-9]{4})(Sun)W([0-9]{1,2})$/, // YYYY"SunW"[1-53] | ||
BiWeekly: /^([0-9]{4})BiW([0-9]{1,2})$/, // YYYY"BiW"[1-27] | ||
Monthly: /^([0-9]{4})([0-9]{2})$/, // YYYYMM | ||
@@ -38,2 +39,3 @@ BiMonthly: /^([0-9]{4})([0-9]{2})B$/, // YYYY0[1-6]"B" | ||
var week = parseInt(match[3], 10); | ||
if (week < 1 || week > 53) { | ||
@@ -43,4 +45,2 @@ throw new Error('Invalid week number'); | ||
var monthNames = (0, _helpers.getMonthNamesForLocale)(locale); | ||
var weekTypeDiff = 0; | ||
@@ -60,26 +60,11 @@ switch (weekType) { | ||
var startDate = (0, _helpers.addDays)(weekTypeDiff, (0, _helpers.getFirstDateOfWeek)(year, week)); | ||
var startMonth = startDate.getMonth(); | ||
var startYear = startDate.getFullYear(); | ||
var startMonthName = monthNames[startMonth]; | ||
var startDayNum = startDate.getDate(); | ||
var p = (0, _helpers.computeWeekBasedPeriod)({ year: year, week: week, locale: locale, weekTypeDiff: weekTypeDiff }); | ||
if (week === 53 && startYear !== year) { | ||
week = 1; | ||
year = startYear; | ||
} | ||
var id = '' + year + weekType + 'W' + week; | ||
var name = p.startMonthName === p.endMonthName ? p.year + ' W' + p.week + ' ' + p.startMonthName + ' ' + p.startDayNum + ' - ' + p.endDayNum : p.year + ' W' + p.week + ' ' + p.startMonthName + ' ' + p.startDayNum + ' - ' + p.endMonthName + ' ' + p.endDayNum; | ||
var endDate = (0, _helpers.addDays)(6, startDate); | ||
var endMonth = endDate.getMonth(); | ||
var endDayNum = endDate.getDate(); | ||
var endMonthName = monthNames[endMonth]; | ||
var name = startMonth === endMonth ? year + ' W' + week + ' ' + startMonthName + ' ' + startDayNum + ' - ' + endDayNum : year + ' W' + week + ' ' + startMonthName + ' ' + startDayNum + ' - ' + endMonthName + ' ' + endDayNum; | ||
return { | ||
id: id, | ||
id: '' + p.year + weekType + 'W' + p.week, | ||
name: name, | ||
startDate: (0, _helpers.formatAsISODate)(startDate), | ||
endDate: (0, _helpers.formatAsISODate)(endDate) | ||
startDate: p.startDate, | ||
endDate: p.endDate | ||
}; | ||
@@ -116,2 +101,25 @@ }; | ||
WeeklySunday: weeklyMatcherParser, | ||
BiWeekly: function BiWeekly(match) { | ||
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en'; | ||
var year = parseInt(match[1], 10); | ||
var biWeek = parseInt(match[2], 10); | ||
if (biWeek < 1 || biWeek > 27) { | ||
throw new Error('Invalid BiWeek number'); | ||
} | ||
var week = biWeek * 2 - 1; | ||
var p = (0, _helpers.computeWeekBasedPeriod)({ year: year, week: week, locale: locale, periodLength: 13 }); | ||
biWeek = (p.week + 1) / 2; | ||
var name = p.startMonthName === p.endMonthName ? p.year + ' BiWeek ' + biWeek + ' ' + p.startMonthName + ' ' + p.startDayNum + ' - ' + p.endDayNum : p.year + ' BiWeek ' + biWeek + ' ' + p.startMonthName + ' ' + p.startDayNum + ' - ' + p.endMonthName + ' ' + p.endDayNum; | ||
return { | ||
id: p.year + 'BiW' + biWeek, | ||
name: name, | ||
startDate: p.startDate, | ||
endDate: p.endDate | ||
}; | ||
}, | ||
Monthly: function Monthly(match) { | ||
@@ -118,0 +126,0 @@ var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3940324
243
9565