Skip to content

validRange is wrong #434

@DerBasler

Description

@DerBasler

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(1733875200
1000)); //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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions