Skip to content

Add Month Range Picker Feature #2380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hatimmakki
Copy link

This PR adds a month range picker feature to the daterangepicker library.

Changes:

  • Added isMonthRange option to enable month-only selection
  • Modified calendar rendering to show month/year selection when in month range mode
  • Updated month navigation logic for month range picker
  • Maintained backward compatibility with existing day picker functionality

Usage:

.daterangepicker({
    isMonthRange: true,
    locale: {
        format: 'MM/YYYY'
    }
});

This feature allows users to select month ranges instead of specific dates, which is useful for reporting, analytics, and other use cases where month-level granularity is preferred.

- Add isMonthRange option to enable month-only selection
- Implement renderMonthCalendar method for month grid display
- Update updateMonthsInView to handle month range mode
- Add month navigation and selection logic
- Enhance styling for month picker interface
@Copilot Copilot AI review requested due to automatic review settings July 10, 2025 22:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a month-range selection mode to the existing date range picker, enabling users to pick entire months instead of specific dates while maintaining all current day-picker functionality.

  • Introduces an isMonthRange option and demo checkbox to toggle month-only mode.
  • Extends calendar rendering and navigation methods to support month grids and year-based navigation.
  • Adds CSS styling for the month-picker table and range highlighting.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
demo.html Added isMonthRange checkbox and demo configuration handling.
daterangepicker.js Introduced isMonthRange flag, month-range rendering, navigation, and selection logic.
daterangepicker.css Defined styles for the month-picker table, hover, disabled, and range states.
Comments suppressed due to low confidence (2)

daterangepicker.js:57

  • New isMonthRange option and its calendar logic lack accompanying unit tests. Consider adding tests for month-range rendering, navigation, and selection behaviors to ensure coverage.
        this.isMonthRange = false;

demo.html:146

  • [nitpick] The label isMonthRange may not be user-friendly in the demo. Consider changing it to a more descriptive phrase like “Enable month-range selection.”
                  <input type="checkbox" id="isMonthRange"> isMonthRange

if (this.endDate || startOfMonth.isBefore(this.startDate, 'month')) { //picking start
this.endDate = null;
this.setStartDate(startOfMonth.clone());
} else if (!this.endDate && startOfMonth.isBefore(this.startDate, 'month')) {
Copy link
Preview

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The special-case branch for selecting the same month is unreachable because the previous if already handles startOfMonth.isBefore(this.startDate). Consider checking for equality (isSame) or reordering conditions to correctly detect clicking the same start/end month.

Suggested change
} else if (!this.endDate && startOfMonth.isBefore(this.startDate, 'month')) {
} else if (!this.endDate && startOfMonth.isSame(this.startDate, 'month')) {

Copilot uses AI. Check for mistakes.

Comment on lines +895 to +904
renderMonthCalendar: function(side) {

var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar;
var year = calendar.month.year();

var minDate = side == 'left' ? this.minDate : this.startDate;
var maxDate = this.maxDate;

var html = '<table class="table-condensed month-picker">';
html += '<thead>';
Copy link
Preview

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The renderMonthCalendar method is large and duplicates parts of renderCalendar. Refactor shared header and grid-generation logic into helper functions to reduce duplication and improve readability.

Suggested change
renderMonthCalendar: function(side) {
var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar;
var year = calendar.month.year();
var minDate = side == 'left' ? this.minDate : this.startDate;
var maxDate = this.maxDate;
var html = '<table class="table-condensed month-picker">';
html += '<thead>';
generateCalendarHeader: function(year, minDate, maxDate, side) {
var html = '<thead>';

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants