-
Notifications
You must be signed in to change notification settings - Fork 195
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Current behaviour
dateUtils.tsx --> dateToUnix takes the initial date and modifies it wrongly because of the Math.round
Expected behaviour
The year, month and day should still be the same
How to reproduce?
const getEndOfDay = (d) => {
const endOfDay = new Date(d)
endOfDay.setUTCHours(23, 59, 59, 999)
return endOfDay
}
const dateToUnix = (d) => {
return Math.round(d.getTime() / 1000)
}
const validEnd= new Date(); // 2024-12-10T23:59:59.999Z
const endUnix = validEnd instanceof Date ? dateToUnix(getEndOfDay(validEnd)) : undefined
console.log(getEndOfDay(validEnd.getTime()) / 1000); // 1733875199.999
console.log(endUnix) // 1733875200
console.log('Would be correct', new Date(17338751991000)); //2024-12-10T23:59:59.000Z
console.log('Current state', new Date(17338752001000)); //2024-12-11T00:00:00.000Z
What have you tried so far?
A workaround would be to make the input validEnd + 1 day
Your Environment
| software | version |
|---|---|
| react-native | ~9.1.3 |
| react-native-paper | 5.12.5 |
| node | v18.20.2 |
| npm or yarn | 10.5.0 |
input
can we use Math.trunc()
emmaB93
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working