code: def add_datetime_features(
      ts: TimeSeries,
      add_month_of_year: bool = False,
      add_week_of_year: bool = False,
      add_day_of_year: bool = False,
      add_day_of_month: bool = False,
      add_day_of_week: bool = False,
      add_hour_of_day: bool = False,
      add_minute_of_hour: bool = False,
      normalized: bool = True,
  ) -> TimeSeries:
      def _month_of_year(time_index: pd.DatetimeIndex) -> np.ndarray:
          vals = time_index.month.values - 1
          if normalized:
              vals = vals.astype(np.float32)
              vals = vals / 11.0 - 0.5
              vals = vals.reshape(-1, 1)
              return vals
          else:
              return vals.astype(np.int64)
  
      def _week_of_year(time_index: pd.DatetimeIndex) -> np.ndarray:
          vals = time_index.weekofyear.values - 1
          if normalized:
              vals = vals.astype(np.float32)
              vals = vals / 51.0 - 0.5
              vals = vals.reshape(-1, 1)
              return vals
          else:
              return vals.astype(np.int64)
  
      def _day_of_year(time_index: pd.DatetimeIndex) -> np.ndarray:
          vals = time_index.dayofyear.values - 1
          if normalized:
              vals = vals.astype(np.float32)
              vals = vals / 364.0 - 0.5
              vals = vals.reshape(-1, 1)
              return vals
          else:
              return vals.astype(np.int64)
  
      def _day_of_month(time_index: pd.DatetimeIndex) -> np.ndarray:
          vals = time_index.day.values - 1
          if normalized:
              vals = vals.astype(np.float32)
              vals = vals / 30.0 - 0.5
              vals = vals.reshape(-1, 1)
              return vals
          else:
              return vals.astype(np.int64)
  
      def _day_of_week(time_index: pd.DatetimeIndex) -> np.ndarray:
          vals = time_index.dayofweek.values
          if normalized:
              vals = vals.astype(np.float32)
              vals = vals / 6.0 - 0.5
              vals = vals.reshape(-1, 1)
              return vals
          else:
              return vals.astype(np.int64)
  
      def _hour_of_day(time_index: pd.DatetimeIndex) -> np.ndarray:
          vals = time_index.hour.values - 1
          if normalized:
              vals = vals.astype(np.float32)
              vals = vals / 23.0 - 0.5
              vals = vals.reshape(-1, 1)
              return vals
          else:
              return vals.astype(np.int64)
  
      def _minute_of_hour(time_index: pd.DatetimeIndex) -> np.ndarray:
          vals = time_index.minute.values - 1
          if normalized:
              vals = vals.astype(np.float32)
              vals = vals / 59.0 - 0.5
              vals = vals.reshape(-1, 1)
              return vals
          else:
              return vals.astype(np.int64)
  
      time_index = ts.time_index
      feature_type = "revealed"
      data_type = "numerical" if normalized else "categorical"
      if add_month_of_year:
          ts.add_features(
              "month_of_year",
              _month_of_year(time_index),
              data_type,
              feature_type,
          )
      if add_week_of_year:
          ts.add_features(
              "week_of_year",
              _week_of_year(time_index),
              data_type,
              feature_type,
          )
      if add_day_of_year:
          ts.add_features(
              "day_of_year",
              _day_of_year(time_index),
              data_type,
              feature_type,
          )
      if add_day_of_month:
          ts.add_features(
              "day_of_month",
              _day_of_month(time_index),
              data_type,
              feature_type,
          )
      if add_day_of_week:
          ts.add_features(
              "day_of_week",
              _day_of_week(time_index),
              data_type,
              feature_type,
          )
      if add_hour_of_day:
          ts.add_features(
              "hour_of_day",
              _hour_of_day(time_index),
              data_type,
              feature_type,
          )
      if add_minute_of_hour:
          ts.add_features(
              "minute_of_hour",
              _minute_of_hour(time_index),
              data_type,
              feature_type,
          )
      return ts
  
imports: from typing import Optional
  from copy import copy, deepcopy
  import numpy
  import pandas
  from .timeseries import TimeSeries
label_desc: Use image node_id 1 for calling a global function with example usage: add_datetime_features(ts, add_month_of_year, add_week_of_year, add_day_of_year, add_day_of_month, add_day_of_week, add_hour_of_day, add_minute_of_hour, normalized) and returns: ts, vals, vals, vals, vals, vals, vals, vals, vals, vals, vals, vals, vals, vals, vals