0

I have a LWC component that is a calendar, he verify the begin and end time of the company to put the interval of this hours, the problem is, when the hour is 00 or 01 or 02.. because of the way that was made. He considered only the hour ignoring the minutes and the method is like this:

 getFirstHour(milliBegin) {
            let hour = milliBegin / 1000 / 60 / 60;
            return (Number.isInteger(hour) ? milliBegin : (parseInt(hour) * 60 * 60 * 1000));
        }

At first, he send the milliseconds value so imagine:

  • 23h = 82800000 (RIGHT!! It works) (CORRECT: 23 * 60 * 60 * 1000)
  • 00h = 0 (the right value should be: 86400000) (WRONG: 00 * 60 * 60 * 1000/CORRECT: 24 * 60 * 60 * 1000)
  • 01h = 3600000 (the right value should be: 90000000) (WRONG: 01 * 60 * 60 * 1000/CORRECT: 25 * 60 * 60 * 1000)

When I put this right values, before the getFirstHour method be called, it works, because I put this ifs statements:

if(this.dealer.BusinessHourEnd__c == 0){
            this.dealer.BusinessHourEnd__c = 86400000; 
        }
        else if(this.dealer.BusinessHourEnd__c == 1){
            this.dealer.BusinessHourEnd__c = 90000000;
        }

But I don't wanna do several ifs to achieve the right solution.. How can I solved this? I need to used the milliseconds unfortunately because it's only this small bug and I don't have time to correct all this component, and it was built in that way

2
  • Welcome to SFSE! Please take a moment to read How to Ask and take the tour. Including a Minimal, Complete and Reproducible Example would be helpful. Your snippets of code and your statements about avoiding ifs are unclear as to what you're trying to achieve.
    – identigral
    Commented Feb 21, 2023 at 17:12
  • We can't help you with this level of detail. Where is the date component of the value you are trying to figure out? It is exceptionally trivial to calculate the number of hours between two dates. I daresay your problem isn't in getFirstHour, but rather it's in whatever code is calling this method.
    – sfdcfox
    Commented Feb 21, 2023 at 17:13

0

You must log in to answer this question.

Browse other questions tagged .