Esempio n. 1
0
 def clean(self, value):
     """
     Validates max_value and min_value.
     Returns a datetime.timedelta object.
     """
     try:
         return to_timedelta(value)
     except ValueError, e:
         raise ValidationError(e)
Esempio n. 2
0
 def clean(self, value):
     """
     Validates max_value and min_value.
     Returns a datetime.timedelta object.
     """
     try:
         return to_timedelta(value)
     except ValueError, e:
         raise ValidationError(e)
Esempio n. 3
0
 def testDataStability(self):
     """
     Data should remain the same when taking a round trip to and from the db
     """
     for value in self.test_data:
         model_test = TestModel()
         model_test.duration_field = timestring.to_timedelta(value[0])
         model_test.save()
         model_test = TestModel.objects.get(id__exact=model_test.id)
         self.assertEquals(value[1], model_test.duration_field)
         model_test.delete()
Esempio n. 4
0
 def testDataStability(self):
     """
     Data should remain the same when taking a round trip to and from the db
     """
     for value in self.test_data:
         model_test = TestModel()
         model_test.duration_field = timestring.to_timedelta(value[0])
         model_test.save()
         model_test = TestModel.objects.get(id__exact=model_test.id)
         self.assertEquals(value[1], model_test.duration_field)
         model_test.delete()
Esempio n. 5
0
 def testUnitNormalization(self):
     self.assertEquals(timestring.from_timedelta(timestring.to_timedelta("1000us")), "1ms")
     self.assertEquals(timestring.from_timedelta(timestring.to_timedelta("1000ms")), "1s")
     self.assertEquals(timestring.from_timedelta(timestring.to_timedelta("60s")), "1min")
     self.assertEquals(timestring.from_timedelta(timestring.to_timedelta("60min")), "1h")
     self.assertEquals(timestring.from_timedelta(timestring.to_timedelta("24h")), "1d")
     self.assertEquals(timestring.from_timedelta(timestring.to_timedelta("7d")), "1w")
Esempio n. 6
0
 def testUnitNormalization(self):
     self.assertEquals(
         timestring.from_timedelta(timestring.to_timedelta("1000us")),
         "1ms")
     self.assertEquals(
         timestring.from_timedelta(timestring.to_timedelta("1000ms")), "1s")
     self.assertEquals(
         timestring.from_timedelta(timestring.to_timedelta("60s")), "1min")
     self.assertEquals(
         timestring.from_timedelta(timestring.to_timedelta("60min")), "1h")
     self.assertEquals(
         timestring.from_timedelta(timestring.to_timedelta("24h")), "1d")
     self.assertEquals(
         timestring.from_timedelta(timestring.to_timedelta("7d")), "1w")
Esempio n. 7
0
 def to_python(self, value):
     try:
         return to_timedelta(value)
     except ValueError, e:
         raise ValidationError(e)
Esempio n. 8
0
 def to_python(self, value):
     try:
         return to_timedelta(value)
     except ValueError, e:
         raise ValidationError(e)
Esempio n. 9
0
 def testTimedeltaRoundtrip(self):
     for value in self.test_data:
         time = timestring.to_timedelta(value[0])
         new_value = timestring.from_timedelta(time)
         self.assertEquals(value[0], new_value)
Esempio n. 10
0
 def testTimedeltaRoundtrip(self):
     for value in self.test_data:
         time = timestring.to_timedelta(value[0])
         new_value = timestring.from_timedelta(time)
         self.assertEquals(value[0], new_value)