code: def datetime_to_hamsterday(civil_date_time):
      
  
      # work around cyclic imports
      from hamster.lib.configuration import conf
  
      if civil_date_time.time() < conf.day_start:
          # early morning, between midnight and day_start
          # => the hamster day is the previous civil day
          hamster_date_time = civil_date_time - dt.timedelta(days=1)
      else:
          hamster_date_time = civil_date_time
      # return only the date
      return hamster_date_time.date()
docs: Return the hamster day corresponding to a given civil datetime.
  
      The hamster day start is taken into account.