Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Date format dd/MM/yyyy is not handled properly in datepicker #1939

Closed
yukiachen opened this issue Mar 17, 2014 · 3 comments
Closed

Date format dd/MM/yyyy is not handled properly in datepicker #1939

yukiachen opened this issue Mar 17, 2014 · 3 comments

Comments

@yukiachen
Copy link

hello there,

I'm having a problem using the datepicker plugin with the format dd/MM/yyyy , I have my datepicker initialized as below.

<input type="text" datepicker-popup="dd/MM/yyyy" ng-model="fromDate" min="mindate" max="maxdate" />

It works fine if I select the date from the calendar popup. but if I type in the date in the input box in the format 'dd/MM/yyyy', it will recognize the 'day' as the 'month'. eg. if type in '16/03/2014', datepicker will treat 16 as the month, and generate an undefined result.

When reading the code in ui-bootstrap-tpls.js, I found the following code in the function parseDate of directive 'datepickerPopup', the viewValue is in the format 'dd/MM/yyyy', but when the Javascript Date object takes it in, it will assume the format to be 'MM/dd/yyyy' ,

var date = new Date(viewValue);

So I have made my temporary fix to replace the above line with the following, and it's now working for me, could you please fix this problem in your repo, so we dont keep this custom code in your file.

var date = null;
            if(dateFormat === 'dd/MM/yyyy' || dateFormat === 'dd/MM/yy') {
                var dateParts = viewValue.split("/");
                date = new Date(dateParts[2], dateParts[1]-1, dateParts[0]);
            } else if(dateFormat === 'dd-MM-yyyy' || dateFormat === 'dd-MM-yy') {
                var dateParts = viewValue.split("-");
                date = new Date(dateParts[2], dateParts[1]-1, dateParts[0]);
            } else {
                date = new Date(viewValue);
            }
@bbaia
Copy link

bbaia commented Mar 17, 2014

+1!
There is a TODO comment about this before the parseDate method:

// TODO: reverse from dateFilter string to Date object

@bekos
Copy link
Contributor

bekos commented Mar 17, 2014

Duplicate of #1289. There is already a date parser in progress #1874. You can test and leave your feedback.

@bekos bekos closed this as completed Mar 17, 2014
@abdalrahmannada
Copy link

i face this broblem and i dont get solution i have model date type when i pass json date MM/dd/yyyy
it chose the correct date but i make format dd/MM/yyyy on the datpicer html it show correct date with wrong format , if i pass json Date object in the format dd/MM/yyyy then it make month as a day and Day as a Month , how can i solve this Prblem ( correct Date , Correct Format )

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

No branches or pull requests

4 participants