Skip to content
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

Add month and year format option #2270

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions daterangepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
this.locale = {
direction: 'ltr',
format: moment.localeData().longDateFormat('L'),
monthFormat: null,
separator: ' - ',
applyLabel: 'Apply',
cancelLabel: 'Cancel',
Expand Down Expand Up @@ -131,6 +132,9 @@
if (typeof options.locale.format === 'string')
this.locale.format = options.locale.format;

if (typeof options.locale.monthFormat === 'string')
this.locale.monthFormat = options.locale.monthFormat;

if (typeof options.locale.separator === 'string')
this.locale.separator = options.locale.separator;

Expand Down Expand Up @@ -705,6 +709,8 @@
}

var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY");
if(this.locale.monthFormat !== null)
dateHtml = calendar[1][1].format(this.monthFormat);

if (this.showDropdowns) {
var currentMonth = calendar[1][1].month();
Expand Down
1 change: 1 addition & 0 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ <h4>Configuration</h4>
options.locale = {
direction: $('#rtl').is(':checked') ? 'rtl' : 'ltr',
format: 'MM/DD/YYYY HH:mm',
monthFormat: 'MMMM YYYY',
separator: ' - ',
applyLabel: 'Apply',
cancelLabel: 'Cancel',
Expand Down
1 change: 1 addition & 0 deletions example/amd/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ $(document).ready(function() {
if ($('#locale').is(':checked')) {
options.locale = {
format: 'MM/DD/YYYY HH:mm',
monthFormat: 'MMMM YYYY',
separator: ' - ',
applyLabel: 'Apply',
cancelLabel: 'Cancel',
Expand Down
1 change: 1 addition & 0 deletions example/browserify/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ $(document).ready(function() {
if ($('#locale').is(':checked')) {
options.locale = {
format: 'MM/DD/YYYY HH:mm',
monthFormat: 'MMMM YYYY',
separator: ' - ',
applyLabel: 'Apply',
cancelLabel: 'Cancel',
Expand Down
1 change: 1 addition & 0 deletions website/website.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ $(document).ready(function() {
if ($('#locale').is(':checked')) {
options.locale = {
format: 'MM/DD/YYYY',
monthFormat: 'MMMM YYYY',
separator: ' - ',
applyLabel: 'Apply',
cancelLabel: 'Cancel',
Expand Down