code: def timesince(when):
      
      if not when:
          return ''
  
      now = datetime.datetime.utcnow()
      if now > when:
          diff = now - when
          suffix = 'ago'
      else:
          diff = when - now
          suffix = 'from now'
  
      periods = (
          (diff.days / 365, 'year', 'years'),
          (diff.days / 30, 'month', 'months'),
          (diff.days / 7, 'week', 'weeks'),
          (diff.days, 'day', 'days'),
          (diff.seconds / 3600, 'hour', 'hours'),
          (diff.seconds / 60, 'minute', 'minutes'),
          (diff.seconds, 'second', 'seconds'),
      )
  
      for period, singular, plural in periods:
          if period:
              return '%d %s %s' % (
                  period,
                  singular if period == 1 else plural,
                  suffix)
  
      return 'now'
docs: Returns string representing "time since" or "time until".
  
      Examples:
          3 days ago, 5 hours ago, 3 minutes from now, 5 hours from now, now.