Exemplo n.º 1
0
 def __str__(self):
     return '%s%s,%s%s' % (
         '[' if self.lower_inc else '(',
         str(self.lower) if not is_infinite(self.lower) else '',
         ' ' + str(self.upper) if not is_infinite(self.upper) else '',
         ']' if self.upper_inc else ')'
     )
Exemplo n.º 2
0
 def __str__(self):
     return '%s%s,%s%s' % (
         '[' if self.lower_inc else '(',
         str(self.lower) if not is_infinite(self.lower) else '',
         ' ' + str(self.upper) if not is_infinite(self.upper) else '',
         ']' if self.upper_inc else ')'
     )
Exemplo n.º 3
0
    def hyphenized(self):
        if not self.discrete:
            raise TypeError('Only discrete intervals have hyphenized format.')
        c = canonicalize(self, True, True)

        if c.lower != c.upper:
            return '%s -%s' % (
                str(c.lower) if not is_infinite(c.lower) else '',
                ' ' + str(c.upper) if not is_infinite(c.upper) else '')
        return str(c.lower)
Exemplo n.º 4
0
    def hyphenized(self):
        if not self.discrete:
            raise TypeError('Only discrete intervals have hyphenized format.')
        c = canonicalize(self, True, True)

        if c.lower != c.upper:
            return '%s -%s' % (
                str(c.lower) if not is_infinite(c.lower) else '',
                ' ' + str(c.upper) if not is_infinite(c.upper) else ''
            )
        return str(c.lower)
Exemplo n.º 5
0
def parse_duration(duration, format=None):
    start_date = duration.lower
    end_date = duration.upper
    if is_infinite(start_date):
        start_date = None
    elif format is not None:
        start_date = start_date.strftime(format)
    if is_infinite(end_date):
        end_date = None
    elif format is not None:
        end_date = end_date.strftime(format)
    return start_date, end_date
Exemplo n.º 6
0
 def round_value_by_step(self, value):
     if self.step and not is_infinite(value):
         return self.type(str(
             float(self.step) *
             round(1.0 / float(self.step) * float(value))
         ))
     return value
Exemplo n.º 7
0
 def round_value_by_step(self, value):
     if self.step and not is_infinite(value):
         return self.type(
             self.step *
             round((self.type(Decimal('1.0')) / self.step) * value)
         )
     return value
Exemplo n.º 8
0
 def round_value_by_step(self, value):
     if self.step and not is_infinite(value):
         return self.type(
             str(
                 float(self.step) *
                 round(1.0 / float(self.step) * float(value))))
     return value
Exemplo n.º 9
0
 def round_value_by_step(self, value):
     if self.step and not is_infinite(value):
         return self.type(
             self.step *
             round((self.type(Decimal('1.0')) / self.step) * value)
         )
     return value
Exemplo n.º 10
0
 def round_value_by_step(self, value):
     if self.step and not is_infinite(value):
         return self.type(
             self.rounding_type(self.step) * self.rounding_type(
                 py2round(
                     self.rounding_type('1.0') / self.rounding_type(
                         self.step) * self.rounding_type(value))))
     return value
Exemplo n.º 11
0
 def coerce_value(self, value):
     if value is None or value == '':
         return None
     elif is_infinite(value):
         return value
     elif isinstance(value, six.string_types):
         return self.coerce_string(value)
     else:
         return self.coerce_obj(value)
Exemplo n.º 12
0
 def coerce_value(self, value):
     if value is None or value == '':
         return None
     elif is_infinite(value):
         return value
     elif isinstance(value, six.string_types):
         return self.coerce_string(value)
     else:
         return self.coerce_obj(value)
Exemplo n.º 13
0
 def round_value_by_step(self, value):
     if self.step and not is_infinite(value):
         return self.type(
             self.rounding_type(self.step) *
             self.rounding_type(
                 round(
                     self.rounding_type('1.0') /
                     self.rounding_type(self.step) *
                     self.rounding_type(value)
                 )
             )
         )
     return value