def parse_datetime_component(name, obj):
  """Parse datetime accessor arrays.

  The `datetime accessors`_ of :obj:`xarray.DataArray` objects are treated in
  semantique as a component of the temporal dimension. Parsing them includes
  adding :attr:`value_type <semantique.processor.structures.Cube.value_type>`
  and :attr:`value_label <semantique.processor.structures.Cube.value_labels>`
  properties as well as in some cases re-organize the values in the array.

  Parameters
  -----------
    name : :obj:`str`
      Name of the datetime component.
    obj : :obj:`xarray.DataArray`
      Xarray datetime accessor.

  Returns
  --------
    :obj:`xarray.DataArray`
      Parsed datetime accessor.

  .. _datetime accessors:
    https://xarray.pydata.org/en/stable/user-guide/time-series.html#datetime-components

  """
  if name in ["dayofweek", "weekday"]:
    obj.sq.value_type = "ordinal"
    obj.sq.value_labels = {
      0: "Monday",
      1: "Tuesday",
      2: "Wednesday",
      3: "Thursday",
      4: "Friday",
      5: "Saturday",
      6: "Sunday"
    }
  elif name == "month":
    obj.sq.value_type = "ordinal"
    obj.sq.value_labels = {
      1: "January",
      2: "February",
      3: "March",
      4: "April",
      5: "May",
      6: "June",
      7: "July",
      8: "August",
      9: "September",
      10: "October",
      11: "November",
      12: "December"
    }
  elif name == "quarter":
    obj.sq.value_type = "ordinal"
    obj.sq.value_labels = {
      1: "January, February, March",
      2: "May, April, June",
      3: "July, August, September",
      4: "October, November, December"
    }
  elif name == "season":
    # In xarray seasons get stored as strings.
    # We want to store them as integers instead.
    for k, v in zip(["MAM", "JJA", "SON", "DJF"], [1, 2, 3, 4]):
      obj = obj.str.replace(k, str(v))
    obj = obj.astype(int)
    obj.sq.value_type = "ordinal"
    obj.sq.value_labels = {
      1: "March, April, May",
      2: "June, July, August",
      3: "September, October, November",
      4: "December, January, February"
    }
  else:
    obj.sq.value_type = "numerical"
  return obj