Salesforce Business Hours API计算无法正常运行?

时间:2018-02-15 20:08:23

标签: java apex

我使用salesforce BusinessHours API计算添加X天数时的目标日期。以下逻辑不正常?

注意:营业时间设置为上午8:00至下午5:00。

要求:当提交的案例今天上午10点(2/16/2018 10 AM)在营业时间内,预期目标日期为3天时,则目标日期应为2/22 / 2018年仅限上午10点。但是下面的逻辑显示错误的数据。我们如何解决这个问题?

global static Date getBusinessTargetDate(DateTime startDate, Integer businessDays){
    DateTime businessEndDateTime;
    DateTime startDateTime = DateTime.newInstance(startDate.year(), startDate.month(), startDate.day());

    BusinessHours bh = [SELECT Id,Name,IsActive,IsDefault,MondayEndTime,MondayStartTime 
                        FROM BusinessHours 
                        WHERE Name = 'US Business Hours'];
    businessEndDateTime = BusinessHours.add(bh.Id, startDateTime, businessDays*9*60*60*1000L);

    String strDateValue = businessEndDateTime.format().split('\\s+')[0];
    String[] strArray = strDateValue.split('/');

    return Date.newInstance(Integer.valueOf(strArray[1]), Integer.valueOf(strArray[0]), Integer.valueOf(strArray[2]));
}

0 个答案:

没有答案
相关问题