AdvoLogix Help

Date Calculation API

Updated on

The DateCalculatorService API allows organizations high-level access to the AdvoLogix date calculation business rules. The following Apex method returns a date based on the parameters supplied.

1. DateCalculatorService

The following Apex method can be used to compute date via custom coding. Please note that it is always suggested to test your code in the Sandbox.

1.1. Syntax

DateCalculatorService.calculateDate(
    @selectedAction,
    @dayCalculatorFunction,
    @startDate,
    @endDate,
    @numCountDays,
    @numCountMonths,
    @numCountYears,
    @selectedBusinessHour,
    @moveDateWhenNonBusiness
);

1.2. Parameters

  • @selectedAction
    Required. Provide an action by which the date is to be computed.
    Accepted values are ADD, SUBTRACT or COUNT.
     
  • @dayCalculatorFunction 
    Required. Provide whether the date is to be computed using Business Days calculations or Calendar Days calculations.
    Accepted values are ‘Calendar Days’, or ‘Business Days’.
     
  • @startDate 
    Required: Provide the base date from which the target date will be computed. It should be passed as a string in following format YYYY-MM-DD.

  • @endDate 
    Required: Provide an end date upto which the date results are returned. If endDate can be empty string if @selectedAction is not COUNT.
     
  • @numCountDays
    Required: Provide number of days to be added or subtracted from the @startDate.
     
  • @numCountMonths
    Required: Provide number of months to be added or subtracted from the @startDate.
     
  • @numCountYears
    Required: Provide number of years to be added or subtracted from the @startDate.
     
  • @selectedBusinessHour
    Required: This would help determine how the business days are to be identified.
    Accepted values are ‘Weekdays’ or the Record ID of the desired BusinessHour from the organization.
     
  • @moveDateWhenNonBusiness
    Required: This would help determine the action to be taken when date falls on the non-business day. This option is only used when counting by Calendar Days. Accepted values are ‘ALLOW_NON_BUSINESS_DAY’, ‘SELECT_FOLLOWING_BUSINESS_DAY’, ‘SELECT_PRECEDING_BUSINESS_DAY’ 

1.3. Result

The function call will return a JSON formatted string in this format: 

{success:"",result:""} 
  • success
    Will be either TRUE or FALSE

  • result
    Contains the actual date computation results OR Error message if process is hauled with any unexpected error. The date results will include all the necessary information such as Target Date and number of days/months/years between dates etc.

1.4. Example

DateCalculatorService.calculateDate(
  'ADD',
  'Business Days',
  ‘2018-10-01’,
  ‘’,
  80,
  0,
  0,
  'Weekdays',
  SELECT_FOLLOWING_BUSINESS_DAY’
);
Previous Article Date Calculator ⚡Component
Next Article Introduction to Business Hours
Still need help? Click here!
AdvoLogix® is a registered trademark of AdvoLogix.com LLC a Texas Limited Liability Company. All references to other trademarks belonging to third parties that appear on this website, documentation, or other materials shall be understood to refer to those registered trademarks owned by others, and not to any trademark belonging to AdvoLogix. Otherwise, all material herein is the copyright of AdvoLogix.com LLC. All Rights Reserved.