The method isBefore from momentjs does not work
I want to check if one of the date is before taking into account the minute;
// 1610459035000 Tuesday, 12 January 2021 13:43:55
// 1642081435000 Thursday, 13 January 2022 13:43:55
const a = moment(1610459035000).isBefore(1642081435000, 'minute');
console.log(a) //get true but expect false
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
Making console.log(a)
i expect to get false
because the minutes are the same in both cases even if the years are difefrent.
Why i get true
if minutes are the same?
Solution 1:
See the docs.
The second argument limits precision.
This means that if your dates were 2001-01-01T00:00:10
and 2001-01-01T00:00:05
then normally the one that is five seconds after midnight would be before the one that is 10 seconds after midnight. If you specify 'minute'
precision then it would ignore the difference in seconds and treat them as the same time.
On the other hand, 2001-01-01T00:00:00
and 2002-01-01T00:00:00
are different years. If you have minute precision then the seconds are ignored but one is still clearly before the other.
Only the parts of the values that are smaller then the specified level are ignored, not the parts that are larger.