quasar icon indicating copy to clipboard operation
quasar copied to clipboard

[Request] custom format-model string for datetime input

Open KnowZero opened this issue 8 years ago • 11 comments

format lets us pick any display mode, but we have no way of formating the date in the format-model.

When I create a datetime input that is type="date", the results are:

auto = 2018-05-21T20:00:00.000-04:00 date = Mon May 21 2018 20:00:00 GMT-0400 (EDT) string = 2018-05-21T20:00:00.000-04:00 number = 1526947200000

(not sure why it ends up 8pm my time or may 22nd gmt instead of may 21st 12am)

But this is not a type="datetime", this is a type="date" so I am looking for:

2018-05-21

So an option to format the string type would be nice. Or maybe have "auto" format type="date" as YYYY-MM-DD and type="datetime" format it as YYYY-MM-DDTHH:mm:ss.SSSZ

KnowZero avatar May 22 '18 13:05 KnowZero

It is implemented using prop formatModel="string" and you can use a custom format="YYYY/MM/DD"

pdanpdan avatar Aug 28 '18 08:08 pdanpdan

I stiill have problems with q-datetime For: <q-datetime format="YYYY-MM-DD" formatModel="string" type="date"/> Result is: string = 2018/09/07 00:00:00" It should be string = 2018-09-07

The same issue for type="datetime": <q-datetime format="YYYY-MM-DD HH:mm:ss" formatModel="string" type="datetime"/> Result is: string = 2018-09-07T05:24:00.000+02:00" It should be string = 2018-09-07 05:24:00

krugerpl avatar Sep 04 '18 10:09 krugerpl

The model must be a valid, parse-able date-time, so you cannot just store the date part. What the control is taking care of is to provide a cross-browser valid date without time zone, so you can extract later the part you need.

pdanpdan avatar Sep 05 '18 05:09 pdanpdan

Thank you for the explanation. I've thought about this and you're right. I found a way around this issue with my backend.

krugerpl avatar Sep 05 '18 08:09 krugerpl

OK, so this is a problem. Mainly with this specific statement written above.

What the control is taking care of is to provide a cross-browser valid date without time zone, so you can extract later the part you need.

Here is a single example:

if the value we pass to the datepicker component is '2003-10-21T00:00:00.000+00:00' and the user's timezone is set to any timezone with a negative offset (I did this example having set my system time to New York) then the displayed value will be 2003/10/20 when the format is set to YYYY/MM/DD.

It looks like the component internals are taking this date string, running it through new Date(), that's getting passed through the quasar formatDate function and we end up with the date being displayed as a day earlier having taken the users system timezone offset has been subtracted.

dontwork avatar Oct 25 '18 14:10 dontwork

If you want only the date part, timezone agnostic then use as input the data as string in this format: "2003/10/21". If you pass a ISO compliant string you'll get timezone conversion.

pdanpdan avatar Oct 25 '18 15:10 pdanpdan

The same thing will happen because when that string gets passed to new Date() the time will be set to 00:00 and if the user is in a negative offset timezone the date will be wrong

dontwork avatar Oct 25 '18 15:10 dontwork

Can you please try?

pdanpdan avatar Oct 25 '18 15:10 pdanpdan

Yes I see it does work... We were originally doing this but not in the exact format you have stated

Can you tell me why this one works: 2019/08/27 and this one doesnt: 2019-08-27

dontwork avatar Oct 25 '18 15:10 dontwork

Because of some quirk/feature in the specification of js that specifies that the parsing of datetime values from string is done using local timezone when separated with / and as UTC or specified timezone else.

pdanpdan avatar Oct 25 '18 15:10 pdanpdan

how to add second in text input time ?

dike321 avatar May 28 '19 08:05 dike321