Condition fails in react native production, but works in development

不羁的心 提交于 2021-02-10 06:43:11

问题


I have created a react native app, by which I need compare from and to date. And if it's true, execution will be done.

The problem is, the condition works in react native development mode and not working in react native production release. I am using firebase for the database, also using redux.

Here is my code:

  var d = new Date();
  const fromDate = extract.validFrom.split("-").reverse(); //"01-02-2019"
  const tillDate = extract.validTill.split("-").reverse(); //"10-03-2019"
  var k = new Date(fromDate)
  var j = new Date(tillDate)

The condition need to verified is :

if(d.getDate() >= k.getDate() === true && d.getDate() <= j.getDate() === true){...some code}else{this.props.error("Code Expired")}

This works, absolutely fine while in development, but the condition is failing and moving to else. I don't know why. The form and till date is retired from firebase.

Please help me to solve.


回答1:


Actually this, happens because of different javascript core. As , chrome has latest version of core, but react native doesnt. So you need to give date as per ES6, change the date "01-02-2019" to

"Fri Feb 02 2018 00:00:00 GMT+0530 (India Standard Time)". 

And after that, remove

.split("-").reverse(); on both dates.

Hope Fully it will work.




回答2:


Once I come across the same issue with date. Then I have tried to enclose the value with new Date() and that helped me. I thought your problem is also similar to that. Try to compare as

if((new Date(d) >= new Date(k)) && (new Date(d) <= new Date(j))){
   ...some code
}


来源:https://stackoverflow.com/questions/54998402/condition-fails-in-react-native-production-but-works-in-development

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!