Exemplo n.º 1
0
 def do_draw(self, data):
     result = dict()
     low_bound = True
     high_bound = True
     for name in ('days', 'seconds', 'microseconds'):
         low = getattr(
             self.min_delta if low_bound else dt.timedelta.min, name)
         high = getattr(
             self.max_delta if high_bound else dt.timedelta.max, name)
         val = utils.centered_integer_range(data, low, high, 0)
         result[name] = val
         low_bound = low_bound and val == low
         high_bound = high_bound and val == high
     return dt.timedelta(**result)
Exemplo n.º 2
0
 def do_draw(self, data):
     result = dict()
     low_bound = True
     high_bound = True
     for name in ('days', 'seconds', 'microseconds'):
         low = getattr(
             self.min_value if low_bound else dt.timedelta.min, name)
         high = getattr(
             self.max_value if high_bound else dt.timedelta.max, name)
         val = utils.centered_integer_range(data, low, high, 0)
         result[name] = val
         low_bound = low_bound and val == low
         high_bound = high_bound and val == high
     return dt.timedelta(**result)
Exemplo n.º 3
0
    def do_draw(self, data):
        while True:
            try:
                result = dt.datetime(
                    year=cu.centered_integer_range(data, self.min_year, self.max_year, 2000),
                    month=cu.integer_range(data, 1, 12),
                    day=cu.integer_range(data, 1, 31),
                    hour=cu.integer_range(data, 0, 24),
                    minute=cu.integer_range(data, 0, 59),
                    second=cu.integer_range(data, 0, 59),
                    microsecond=cu.integer_range(data, 0, 999999),
                )
                if not self.allow_naive or (self.timezones and cu.boolean(data)):
                    result = cu.choice(data, self.timezones).localize(result)
                return result

            except (OverflowError, ValueError):
                pass
Exemplo n.º 4
0
    def do_draw(self, data):
        while True:
            try:
                result = dt.datetime(
                    year=cu.centered_integer_range(data, self.min_year,
                                                   self.max_year, 2000),
                    month=cu.integer_range(data, 1, 12),
                    day=cu.integer_range(data, 1, 31),
                    hour=cu.integer_range(data, 0, 24),
                    minute=cu.integer_range(data, 0, 59),
                    second=cu.integer_range(data, 0, 59),
                    microsecond=cu.integer_range(data, 0, 999999))
                if (not self.allow_naive
                        or (self.timezones and cu.boolean(data))):
                    result = cu.choice(data, self.timezones).localize(result)
                return result

            except (OverflowError, ValueError):
                pass
Exemplo n.º 5
0
 def _attempt_one_draw(self, data):
     result = dict()
     cap_low, cap_high = True, True
     for name in ('year', 'month', 'day',
                  'hour', 'minute', 'second', 'microsecond'):
         low = getattr(self.min_dt if cap_low else dt.datetime.min, name)
         high = getattr(self.max_dt if cap_high else dt.datetime.max, name)
         if name == 'year':
             val = utils.centered_integer_range(data, low, high, 2000)
         else:
             val = utils.integer_range(data, low, high)
         result[name] = val
         cap_low = cap_low and val == low
         cap_high = cap_high and val == high
     tz = data.draw(self.tz_strat)
     try:
         result = dt.datetime(**result)
         if is_pytz_timezone(tz):
             # Can't just construct; see http://pytz.sourceforge.net
             return tz.normalize(tz.localize(result))
         return result.replace(tzinfo=tz)
     except (ValueError, OverflowError):
         return None
Exemplo n.º 6
0
 def _attempt_one_draw(self, data):
     result = dict()
     cap_low, cap_high = True, True
     for name in ('year', 'month', 'day',
                  'hour', 'minute', 'second', 'microsecond'):
         low = getattr(self.min_dt if cap_low else dt.datetime.min, name)
         high = getattr(self.max_dt if cap_high else dt.datetime.max, name)
         if name == 'year':
             val = utils.centered_integer_range(data, low, high, 2000)
         else:
             val = utils.integer_range(data, low, high)
         result[name] = val
         cap_low = cap_low and val == low
         cap_high = cap_high and val == high
     tz = data.draw(self.tz_strat)
     try:
         result = dt.datetime(**result)
         if is_pytz_timezone(tz):
             # Can't just construct; see http://pytz.sourceforge.net
             return tz.normalize(tz.localize(result))
         return result.replace(tzinfo=tz)
     except (ValueError, OverflowError):
         return None
Exemplo n.º 7
0
 def do_draw(self, data):
     return self.min_date + dt.timedelta(days=utils.centered_integer_range(
         data, 0, self.days_apart, center=self.center))
Exemplo n.º 8
0
 def do_draw(self, data):
     return self.min_value + dt.timedelta(days=utils.centered_integer_range(
         data, 0, self.days_apart, center=self.center))