I am very much confused by following behavior while comparing two dates:
moment(date).format('YYYY-MM-DD')
'2022-07-15'
moment(range.end).subtract(1, 'days').format('YYYY-MM-DD')
'2022-07-15'
why then:
moment(date) <= moment(range.end).subtract(1, 'days')
what should be the proper way compare this days for date being equal, gt, lt using momentjs?
UPDATE:
using isSameOrBefore
after having both dates wrapped in moment:
date.format('YYYY-MM-DD')
'2022-07-15'
range.end
'2022-07-16'
moment(date).format('YYYY-MM-DD')
'2022-07-15'
moment(range.end).subtract(1, 'days').format('YYYY-MM-DD')
'2022-07-15'
moment(date).isSameOrBefore(moment(range.end).subtract(1, 'days'))
false
I guess I got it:
moment(date).isSameOrBefore(moment(range.end).subtract(1, 'days'), 'day')
providing level of granularity of check to day seems to do the trick.
As the second parameter determines the precision, and not just a single value to check, using day will check for year, month and day.