code: def cast_to_time_qualifier(time_qualifier, timeperiod):
      
  
      if time_qualifier == QUALIFIER_HOURLY:
          date_format = SYNERGY_HOURLY_PATTERN
      elif time_qualifier == QUALIFIER_DAILY:
          date_format = SYNERGY_DAILY_PATTERN
      elif time_qualifier == QUALIFIER_MONTHLY:
          date_format = SYNERGY_MONTHLY_PATTERN
      elif time_qualifier == QUALIFIER_YEARLY:
          date_format = SYNERGY_YEARLY_PATTERN
      else:
          raise ValueError('unknown time qualifier: {0}'.format(time_qualifier))
  
      pattern = define_pattern(timeperiod)
      t = datetime.strptime(timeperiod, pattern)
      return t.strftime(date_format)
docs: method casts given timeperiod accordingly to time qualifier.
      For example, will cast session time format of 20100101193412 to 2010010119 with QUALIFIER_HOURLY