Commits

Antoni Aloy committed ae17649

añadida generación de fecha a partir de una fecha dada

  • Participants
  • Parent commits dd737e8

Comments (0)

Files changed (1)

File fakeutils/core.py

     slug = random_words(num).replace(" ", "-")
     return ''.join(ch for ch in slug if ch.isalnum() or ch == '-')
 
-    
+
 def random_slugs(num):
     return [random_slug() for x in range(num)]
-    
+
 
 def random_url(sufix=".com", params=0):
     data = (random_slug(),sufix, random_slug())
         return "%s?%s" % (simple_url, param_url)
     else:
         return simple_url
-        
-def random_domain_url(sufix=".com"):        
+
+def random_domain_url(sufix=".com"):
     data = (random_slug(),sufix)
     return "http://%s%s/" % data
 
     return decimal.Decimal(str(random.random() + random.randint(1, 20)))
 
 
-def random_posint():
-    return random.randint(0, 10000)
+def random_posint(max=10000):
+    return random.randint(0, max)
 
 def random_datetime():
     """
     random_minutes = random.randint(-43200, 43200)
     return datetime.datetime.now() + datetime.timedelta(minutes=random_minutes)
 
+def random_date(start_date=None, min=0, max=5*365):
+    """
+    Return a random date that is n days after the
+    initial day where n is a number of days between
+    zero and aprox. 5 years
+    """
+    if not start_date:
+        from datetime import date
+        start_date = date.today()
+    days = random.randint(min, max)
+    return today - datetime.timedelta(days)
+
+
 def random_adult_birthdate():
     """
     Returns a random adult birth day.
     For this purposes we consider adult a person with a
     age greater than 21y
     """
-    
+
     from datetime import date
     today = date.today()
     days_age = random.randint(21, 98)*365 + random.randint(1, 365)
     For this purposes we consider child a person with a
     age lower than 12y and greater than 2
     """
-    
+
     from datetime import date
     today = date.today()
     days_age = random.randint(2, 11)*365 + random.randint(1, 365)
     return today - datetime.timedelta(days_age)
-    
+
 def random_baby_birthdate():
     """
     Returns a random baby birth day.
     For this purposes we consider baby a person with a
     age lower than 2y
     """
-    
+
     from datetime import date
     today = date.today()
     days_age = random.randint(0, 2)*365 + random.randint(1, 365)
-    return today - datetime.timedelta(days_age)    
-    
+    return today - datetime.timedelta(days_age)
+
 def random_color():
     """
     Returns a color code format
     in hex
     """
-    
+
     colors = []
     for i in range(3):
         color = hex(random.randrange(0, 255))[2:]
         if len(color)<2:
             color = "0%s" % color
         colors.append(color)
-        
+
     return "".join(colors).upper()
 
 def random_text_file(n=10):