code: def datetime2yeardec(time: Union[str, datetime.datetime, datetime.date]) -> float:
      
      if isinstance(time, str):
          t = parse(time)
      elif isinstance(time, datetime.datetime):
          t = time
      elif isinstance(time, datetime.date):
          t = datetime.datetime.combine(time, datetime.datetime.min.time())
      elif isinstance(time, (tuple, list, np.ndarray)):
          return np.asarray([datetime2yeardec(t) for t in time])
      else:
          raise TypeError('unknown input type {}'.format(type(time)))
  
      year = t.year
  
      boy = datetime.datetime(year, 1, 1)
      eoy = datetime.datetime(year + 1, 1, 1)
  
      return year + ((t - boy).total_seconds() / ((eoy - boy).total_seconds()))
docs: Convert a datetime into a float. The integer part of the float should
      represent the year.
      Order should be preserved. If adate<bdate, then d2t(adate)<d2t(bdate)
      time distances should be preserved: If bdate-adate=ddate-cdate then
      dt2t(bdate)-dt2t(adate) = dt2t(ddate)-dt2t(cdate)