utils.py
changeset 4478 442fd69ff13b
parent 4466 8b0ca7904820
child 4510 8dc44329f5c8
equal deleted inserted replaced
4477:c094101ba85d 4478:442fd69ff13b
    16 from md5 import md5
    16 from md5 import md5
    17 from time import time
    17 from time import time
    18 from random import randint, seed
    18 from random import randint, seed
    19 import decimal
    19 import decimal
    20 
    20 
    21 from logilab.common.date import strptime, todate, next_month
       
    22 
       
    23 # initialize random seed from current time
    21 # initialize random seed from current time
    24 seed()
    22 seed()
    25 
    23 
    26 # XXX should replace lgc.date.date_range implementation
       
    27 def date_range(begin, end, incday=None, incmonth=None):
       
    28     """yields each date between begin and end
       
    29     :param begin: the start date
       
    30     :param end: the end date
       
    31     :param incr: the step to use to iterate over dates. Default is
       
    32                  one day.
       
    33     :param include: None (means no exclusion) or a function taking a
       
    34                     date as parameter, and returning True if the date
       
    35                     should be included.
       
    36     """
       
    37     assert not (incday and incmonth)
       
    38     begin = todate(begin)
       
    39     end = todate(end)
       
    40     if incmonth:
       
    41         while begin < end:
       
    42             begin = next_month(begin, incmonth)
       
    43             yield begin
       
    44     else:
       
    45         if not incday:
       
    46             incr = ONEDAY
       
    47         else:
       
    48             incr = datetime.timedelta(incday)
       
    49         while begin <= end:
       
    50            yield begin
       
    51            begin += incr
       
    52 
    24 
    53 
    25 
    54 if sys.version_info[:2] < (2, 5):
    26 if sys.version_info[:2] < (2, 5):
    55     def make_uid(key):
    27     def make_uid(key):
    56         """forge a unique identifier
    28         """forge a unique identifier