ng2-ui / datetime-picker

Angular2 DateTime Picker
https://ng2-ui.github.io/#/datetime-picker
MIT License
121 stars 62 forks source link

Date value not the displayed value #45

Closed luizfbicalho closed 7 years ago

luizfbicalho commented 7 years ago

I set the date to 01/01/2010, using the DD/MM/YYYY format and I got another value in my datepicker

image

https://plnkr.co/edit/onkXaUSVycm9Ds3iOsoo?p=preview

allenhwkim commented 7 years ago

This issue seems duplicate to #44

luizfbicalho commented 7 years ago

I think that his problem is when he type the date in the input with datepicker.

my problem is when it's displaying the date.

luizfbicalho commented 7 years ago

the problem is in the datetime.ts line 119 let date = moment(dateStr, dateFormat).toDate();

the component shouldn't use the dateformat to read any date that looks like "2010-01-01T00:00:00"

allenhwkim commented 7 years ago

The problem is that you use date-format DD/MM/YYYY and the value is a 'GMT format' If you use date-format, the value must follow the date-format you give. If not, use Date object. e.g. var myDate = new Date("2010-01-01T00:00:00")

https://plnkr.co/edit/RgNHeL?p=preview

luizfbicalho commented 7 years ago

but the value return from a webapi formatted that way

allenhwkim commented 7 years ago

Sorry, but this module should not care about different web api returns.

If you want to format in that way, you should provide the exact format or a date object as an input.

I know the server RESTful api returns date as a string with an ISO format, but not all of them doe s that. That's why I recommend you to build a date object from the given string, and use it for this. This module cannot follow all valid date format of all web api server returns.

This modules accepts only two possible value as an input for simplicity;

  1. string(with the exact format if you use date-format)
  2. or, a date object
luizfbicalho commented 7 years ago

I made this plunkr https://plnkr.co/edit/yOoXEdAeVqUvlElVN32Q?p=preview if I put a Date object, it shoudn't return the date object back?

the displayed value should be the formatted and the internal value should be the date correct?