diff --git a/daterangepicker.js b/daterangepicker.js index 5f7d304b..735583e7 100644 --- a/daterangepicker.js +++ b/daterangepicker.js @@ -81,6 +81,8 @@ firstDay: moment.localeData().firstDayOfWeek() }; + this.showCustomWeekNumbers = {}; + this.callback = function() { }; //some state information @@ -224,6 +226,12 @@ if (typeof options.showISOWeekNumbers === 'boolean') this.showISOWeekNumbers = options.showISOWeekNumbers; + if (typeof options.showCustomWeekNumbers === 'object') { + this.showCustomWeekNumbers = options.showCustomWeekNumbers; + } else { + this.showCustomWeekNumbers = false; + } + if (typeof options.buttonClasses === 'string') this.buttonClasses = options.buttonClasses; @@ -616,6 +624,17 @@ this.calculateChosenLabel(); }, + getCustomWeek: function (date) { + for (customWeeks in this.showCustomWeekNumbers) { + var startFirstWeek = moment(this.showCustomWeekNumbers[customWeeks][0]).startOf('week'); + var endLastWeek = moment(this.showCustomWeekNumbers[customWeeks][1]).endOf('week'); + if (date.isBetween(startFirstWeek, endLastWeek)) {; + return customWeeks + (date.diff(startFirstWeek, 'week') + 1); + } + } + return ''; + }, + renderCalendar: function(side) { // @@ -695,7 +714,7 @@ html += ''; // add empty cell for week number - if (this.showWeekNumbers || this.showISOWeekNumbers) + if (this.showWeekNumbers || this.showISOWeekNumbers || this.showCustomWeekNumbers) html += ''; if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) { @@ -750,7 +769,7 @@ html += ''; // add week number label - if (this.showWeekNumbers || this.showISOWeekNumbers) + if (this.showWeekNumbers || this.showISOWeekNumbers || this.showCustomWeekNumbers) html += '' + this.locale.weekLabel + ''; $.each(this.locale.daysOfWeek, function(index, dayOfWeek) { @@ -778,6 +797,9 @@ html += '' + calendar[row][0].week() + ''; else if (this.showISOWeekNumbers) html += '' + calendar[row][0].isoWeek() + ''; + else if (this.showCustomWeekNumbers) { + html += '' + this.getCustomWeek(calendar[row][0]) + '' + } for (var col = 0; col < 7; col++) { diff --git a/demo.html b/demo.html index 3157e8a1..f975e042 100644 --- a/demo.html +++ b/demo.html @@ -93,7 +93,13 @@

Configuration Builder

+
+ +
+
@@ -268,6 +274,15 @@

Configuration

if ($('#showWeekNumbers').is(':checked')) options.showWeekNumbers = true; + if ($('#showCustomWeekNumbers').is(':checked')) { + options.showCustomWeekNumbers = { + 'T1W': ['01/27/2021', '04/01/2021'], + 'T2W': ['04/19/2021', '06/25/2021'], + 'T3W': ['07/12/2021', '09/17/2021'], + 'T4W': ['10/04/2021', '12/17/2021'] + } + } + if ($('#showISOWeekNumbers').is(':checked')) options.showISOWeekNumbers = true;