DateUtils getMin/MaxDate is not working
-
Hello!
I tried to use the date utils from quasar and was trying the example of “Minimum/Maximum” from the docs. Copied it to my code and watched the result on the console. But the result is, for getMinDate: “Invalid Date” and for getMaxDate: “NaN”. I only copied the example code from the online docs and that is the result.
Can anybody help me with this topic?
Regards
Chris -
Can you try making a codepen? https://codepen.quasar.dev
Scott
-
Hi Scott!
Thanks for your reply. I have tried making the codepen but it seems so that it is not working as expected. I’m new to codepen and so I’m not sure what the problem is.
I’ve used the following code in my project (it is directly from the quasar homepage):
import { date } from ‘quasar’let dates = [ new Date(2017, 6, 24), new Date(2017, 5, 20), new Date(2017, 6, 26) ]
let min = date.getMinDate(dates) //min
is 2017-5-20
let max = date.getMaxDate(dates) //max
is 2017-6-26// Or simply use multiple parameters:
let min = date.getMinDate(new Date(2017, 6, 24), new Date(2017, 5, 20), new Date(2017, 6, 26))
//min
is 2017-5-20
let max = date.getMaxDate(new Date(2017, 6, 24), new Date(2017, 5, 20), new Date(2017, 6, 26))
//max
is 2017-6-26Regards
Chris -
Hi @ckoeste1,
I think there is a mistake on the documentation or on the function implementation on dateUtils getMinDate and getMaxDate methods.
If you pass “dates” parameter with spead (…) it works.
In your case:
let min = date.getMinDate(…dates) // min is 2017-5-20
let max = date.getMaxDate(…dates) // max is 2017-6-26You can check more detailed on https://codepen.io/mvelikoff/pen/pozBzOy
-
It was a typo in docs. Correct usage:
Minimum/Maximum
To get the minimum/maximum date of a date set (i.e. array) use:
import { date } from 'quasar' let min = date.getMinDate(new Date(2017, 6, 24), new Date(2017, 5, 20), new Date(2017, 6, 26)) // `min` is 2017-5-20 let max = date.getMaxDate(new Date(2017, 6, 24), new Date(2017, 5, 20), new Date(2017, 6, 26)) // `max` is 2017-6-26 // Or use an array: let dates = [ new Date(2017, 6, 24), new Date(2017, 5, 20), new Date(2017, 6, 26) ] let min = date.getMinDate(...dates) // `min` is 2017-5-20 let max = date.getMaxDate(...dates) // `max` is 2017-6-26
Note that the returning value is a timestamp.
console.log(max) // 1497906000000 console.log(new Date(max)) // Wed Jul 26 2017 00:00:00 GMT+0300 (Eastern European Summer Time)
-
Here is a codepen to hopefully help understand. And thanks for asking here!
https://codepen.io/smolinari/pen/bGbZXqL?editors=1010
The docs will be corrected with the next update.
Scott