code: def _gen_business_days(
      start_date, end_date, holiday_calendar, backward=False
  ):
      """Generates business days between given dates, see BusinessDaySchedule."""
      # Handle the case when start_date or end_date fall on holidays.
      start_date = holiday_calendar.roll_to_business_day(
          start_date,
          roll_convention=constants.BusinessDayConvention.FOLLOWING,
      )
      end_date = holiday_calendar.roll_to_business_day(
          end_date,
          roll_convention=constants.BusinessDayConvention.PRECEDING,
      )
  
      # Validate inputs.
      control_deps = [
          tf.debugging.assert_greater_equal(
              end_date.ordinal(),
              start_date.ordinal(),
              message="End date must be >= Start date.",
          ),
      ]
      with tf.compat.v1.control_dependencies(control_deps):
          # Reshape the input Tensors.
          if backward:
              start_date = start_date.broadcast_to(
                  tf.shape(end_date.ordinal())
              )
          else:
              end_date = end_date.broadcast_to(
                  tf.shape(start_date.ordinal())
              )
          start_date = start_date.expand_dims(axis=-1)
          end_date = end_date.expand_dims(axis=-1)
  
          # Find the longest schedule in the batch.
          max_len = (
              tf.math.abs(
                  tf.math.reduce_max(
                      holiday_calendar.business_days_between(
                          start_date, end_date
                      )
                  )
              )
              + 1
          )
  
          if backward:
              # Subtract n days, where n = max_len-1, ..., 2, 1, 0.
              days = tf.range(-max_len + 1, 1, dtype=tf.int32)
              schedules = holiday_calendar.add_business_days(
                  end_date, days
              )
              in_bounds = schedules.ordinal() >= start_date.ordinal()
              # Pad with start_date.
              schedules = date_tensor.DateTensor.where(
                  in_bounds, schedules, start_date
              )
          else:
              # Add n days, where n = 0, 1, 2, ..., max_len-1.
              days = tf.range(max_len, dtype=tf.int32)
              schedules = holiday_calendar.add_business_days(
                  start_date, days
              )
              in_bounds = schedules.ordinal() <= end_date.ordinal()
              # Pad with end_date.
              schedules = date_tensor.DateTensor.where(
                  in_bounds, schedules, end_date
              )
  
          return schedules
  
imports: import tensorflow.compat.v2
  from tf_quant_finance.datetime import constants
  from tf_quant_finance.datetime import date_tensor
label_desc: Use image node_id 2 for calling a global function with example usage: _gen_business_days(start_date, end_date, holiday_calendar, backward) and returns: schedules