code: def calc_next_date(schedule_str, base_date: dt.datetime):
      schedule_str = schedule_str.lower().strip()
  
      repeat_prefix = "every "
      if schedule_str.startswith(repeat_prefix):
          repeat_str = schedule_str[len(repeat_prefix) :]
      else:
          # TODO cron format
          raise NotImplementedError(f"Schedule: {schedule_str}")
  
      items = repeat_str.split()
  
      if len(items) == 1:
          value = "1"
          period = items[0]
      elif len(items) == 2:
          value, period = items
      else:
          raise Exception(f"Can't parse repeat string: {repeat_str}")
  
      if not value.isdigit():
          raise Exception(f"Number expected: {value}")
      value = int(value)
      if period in ("minute", "minutes", "min"):
          delta = dt.timedelta(minutes=value)
      elif period in ("hour", "hours"):
          delta = dt.timedelta(hours=value)
      elif period in ("day", "days"):
          delta = dt.timedelta(days=value)
      elif period in ("week", "weeks"):
          delta = dt.timedelta(days=value * 7)  # 1 week = 7 days
      elif period in ("month", "months"):
          delta = relativedelta(months=value)
      else:
          raise Exception(f"Unknown period: {period}")
  
      # period limitation disabled for now
      # config = Config()
      # is_cloud = config.get('cloud', False)
      # if is_cloud and ctx.user_class == 0:
      #     if delta < dt.timedelta(days=1):
      #         raise Exception("Minimal allowed period can't be less than one day")
  
      next_date = base_date + delta
  
      return next_date
  
imports: import re
  import datetime
  from dateutil.relativedelta import relativedelta
  import sqlalchemy
  from mindsdb_sql import parse_sql, ParsingException
  from mindsdb.utilities.context import context
  from mindsdb.utilities.exception import EntityNotExistsError, EntityExistsError
  from mindsdb.interfaces.storage import db
  from mindsdb.interfaces.database.projects import ProjectController
  from mindsdb.interfaces.query_context.context_controller import query_context_controller
  from mindsdb.utilities import log
label_desc: Use image node_id 2 for calling a global function with example usage: calc_next_date(schedule_str, base_date) and returns: next_date