Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validRange is wrong #434

Closed
DerBasler opened this issue Dec 10, 2024 · 1 comment
Closed

validRange is wrong #434

DerBasler opened this issue Dec 10, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@DerBasler
Copy link
Contributor

DerBasler commented Dec 10, 2024

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()

@DerBasler DerBasler added the bug Something isn't working label Dec 10, 2024
DerBasler added a commit to DerBasler/react-native-paper-dates that referenced this issue Dec 11, 2024
trunc the ms instead of round to avoid edge cases where the date would be changed example: 
Math.round((new Date('2024-12-10T23:59:59.999Z')).getTime() / 1000)
vs
Math.trunc((new Date('2024-12-10T23:59:59.999Z')).getTime() / 1000)
iM-GeeKy added a commit that referenced this issue Dec 11, 2024
fix: dateToUnix to preserve the date #434
@iM-GeeKy
Copy link
Collaborator

Closed by #435

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants