2017-09-18 5 views
0

SLAとOLA計算の2つの営業時間が設定されています。BusinessHours.diffは、異なる営業時間の理由で値を取得します。なぜですか?

SLA時間 enter image description here

OLAの時間の両方の営業時間は9時間のために設定されているが、それでもコードが正しく値を計算されていないが enter image description here

。最初の営業時間は106時間、それ以外の時間は108時間です。理由は?私はその後、私の営業下記のような時間、その後 enter image description here

とした場合、別の出力

再び

enter image description here

です。ここ参照のために以下

Date startDate = Date.today(); // 9/18/2017 
Date endDate = Date.today().addDays(16); // 10/4/2017 

BusinessHours bh = [SELECT Id,Name,IsActive,IsDefault,MondayEndTime,MondayStartTime 
             FROM BusinessHours 
             WHERE Name = 'SLA Hours']; 

Datetime startTime = Datetime.newInstance(startDate.year(), startDate.month(), startDate.day()); 
Datetime endTime = Datetime.newInstance(endDate.year(), endDate.month(), endDate.day()); 
System.debug('START_TIME :: '+startTime); 
System.debug('END_TIME :: '+endTime); 

// API to calculate the business hours difference   
Long difference = BusinessHours.diff(bh.Id, startDate, endDate); 

// calculate the minutes from Milisecond value 
Integer diffInminutes = Integer.valueOf(difference/(1000*60)); 
System.debug('DIFF IN HOURS :: '+diffInminutes/60); 

enter image description here

を、コードを共有しています

enter image description here

答えて

0

まず、営業時間のスクリーンショットのタイムゾーンが異なります。 第2に、ユーザーのレコードに設定されているローカルタイムゾーンでDateTimesを構築していますが、それが何であるかはわかりません。

Apex DevガイドのSupport Classesページをご覧ください。営業時間の使用方法に関する例があります。

+0

ありがとうございます!これにはどのような方法が推奨されますか?どのタイムゾーンを作成する必要がありますか? 108時間の違いをどうやって得ることができますか?ガイドをお願いしますか? –

関連する問題