ng2-ui / datetime-picker

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

string conversion #125

Closed vknaveenkumar closed 7 years ago

vknaveenkumar commented 7 years ago

when i use json.stringify it shows both date and time . i want only date

allenhwkim commented 7 years ago

Please be more specific with an example, or else this will be closed

vknaveenkumar commented 7 years ago

when using this directives it return in the form of date format in the [(ngModel)] . what i want is it should return the only date as string .

vinagreti commented 7 years ago

I'm having the same issue. I'm passing a string to ngModel and after any change, the ngModel value become a Date object instead string. The same does not occur if we not change the date. In 0.12.x does not happen. The problem is related to 0.13.x version...

allenhwkim commented 7 years ago

Please use date-only="true" as specified in README.md

image

vinagreti commented 7 years ago

I am doing this but did not work.... Still getting the same problem. See the plunker that shows the problem.

https://plnkr.co/edit/2mTkb6b0btmR33EkV0r3?p=preview

allenhwkim commented 7 years ago

This is datetime picker, it should and must return a Date, not string because it's not a string picker. If you want string, you can make use ot toString() function. Therefore, just add ''+, e.g., ''+myVar`

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

vinagreti commented 7 years ago

Your plunker does not solve my problem. I need to make an ajax call after form changes and I dont want to have to manipulate the dates fields to represent the format that I've passed to ngModel. None form component should change a type, only manipulates a variable, not changing it's type.

I think you are wrong saying this is a datepicker not a string picker. In my point of view (and angular point too), there are many ways to represent a Date, and string is one of them. If you just ignore this, you will end up loosing some users because they have JSON with ISO String dates and don't want to parse it before or after manipulate. If you accept a string as date, you should also delivery a date as string.

I've made another component to handle this, parsing the date after picking one in the datepicker but it is not what we suppose to do when using a component that was built to do this. It is like you are doing half work...

Besides my point of view, you did a great work with this and helped me a lot. I would not try another datepicker if string was supported, but this static DATE output is going to force me go find another datepicker. As I dont want to do this, I ask you if it is possible for you to change it and return date in the same format the input were. If string, return a string as you did in previous releases. Just in ISO format, not any other format that require a strong logic, so you can only to a toString() before returning the value... Thanks a lot for your attention.

allenhwkim commented 7 years ago

@vinagreti The main point of this module is to get date and output format from user, and return the date as formatted. If no formatting is required, it's not the design of this module although it can be easily done.

Although it can be easily done, I am not sure number of users who want this feature; date without formatting as string.

FYI, this conversation is out of topic from it shows both date and time . i want only date. Please create another issue if you want to discuss output as string or output without formatting

vinagreti commented 7 years ago

Thanks @allenhwkim . I'll improve the question with more arguments and start a new issue.

vknaveenkumar commented 7 years ago

can u fix the issue that make the datepicker output as string without any formattting