I have a unix timestamp property in my database propertyName is closeDeal.
closeDeal value in database - 1624699800 (unix timestamp). What I'm required to do is have two validations on the above timestamps
- the closeDeal timestamp is greater than the current timestamp
- the closeDeal timestamp should be >= currentDate_StartTime and <= currentDate_EndTime
Here the currentDate_StartTime would be the start time of the current date i.e (0,0,0,0)
Here the currentDate_EndTime would be the start time of the current date i.e (23, 59, 59, 999)
What I tried.
Below is my code of converting the currentDate to unixtimestamp and comparing.
Helper functions
getStartDateTimeStamp() {
let currentTime = new Date();
currentTime.setHours(0, 0, 0, 0);
return Math.round((currentTime).getTime() / 1000);
}
getEndDateTimeStamp() {
let currentTime = new Date();
currentTime.setHours(23, 59, 59, 999);
return Math.round((currentTime).getTime() / 1000);
}
getCurrentDateTimeStamp() {
let currentTime = new Date();
return Math.round((currentTime).getTime() / 1000);
}
Date comparison in business logic
if(
closeDeal > this.helper.getCurrentDateTimeStamp() // check if close deal is greater than current date
&& closeDeal >= this.helper.getStartDateTimeStamp() // closeDeal greater = than current Datetime
&& closeDeal <= this.helper.getEndDateTimeStamp() // closeDeal less = than current Datetime
) {
//some logic here.
}
But the above code always fails