def granular_now(n=None, default_tz=None):
 if (n is None):
  n = timezone.now()
 if (default_tz is None):
  default_tz = n.tzinfo
 rounded_minute = ((n.minute // 5) * 5)
 d = datetime(n.year, n.month, n.day, n.hour, rounded_minute)
 try:
  retval = timezone.make_aware(d, default_tz)
 except AmbiguousTimeError:
  try:
   retval = timezone.make_aware(d, default_tz, is_dst=False)
  except TypeError:
   retval = timezone.make_aware(datetime(n.year, n.month, n.day, (n.hour + 1), rounded_minute), default_tz)
 return retval

def granular_now ( n = None , default_tz = None ) : if ( n is None ) : n = timezone . now ( ) if ( default_tz is None ) : default_tz = n . tzinfo rounded_minute = ( ( n . minute // 5 ) * 5 ) d = datetime ( n . year , n . month , n . day , n . hour , rounded_minute ) try : retval = timezone . make_aware ( d , default_tz ) except AmbiguousTimeError : try : retval = timezone . make_aware ( d , default_tz , is_dst = False ) except TypeError : retval = timezone . make_aware ( datetime ( n . year , n . month , n . day , ( n . hour + 1 ) , rounded_minute ) , default_tz ) return retval
a datetime .