def test_date2timestamp(self): t1 = datetime.now() ts1 = date2timestamp(t1) self.assertEqual(timestamp2date(ts1),t1) t1 = date.today() ts1 = date2timestamp(t1) t = timestamp2date(ts1) self.assertEqual(t.date(),t1) self.assertEqual(t.hour,0) self.assertEqual(t.minute,0) self.assertEqual(t.second,0) self.assertEqual(t.microsecond,0)
def test_date2timestamp(self): t1 = datetime.now() ts1 = date2timestamp(t1) self.assertAlmostEqual(ts1, date2timestamp(t1)) t1 = date.today() ts1 = date2timestamp(t1) t = timestamp2date(ts1) self.assertEqual(t.date(), t1) self.assertEqual(t.hour, 0) self.assertEqual(t.minute, 0) self.assertEqual(t.second, 0) self.assertEqual(t.microsecond, 0)
def testCreate(self): mean = Decimal('56.4') started = date(2010,1,1) timestamp = datetime.now() a = self.model(dt=date.today(), data={'mean': mean, 'std': 5.78, 'started': started, 'timestamp':timestamp}).save() self.assertEqual(a.data['mean'],mean) a = self.model.objects.get(id=a.id) self.assertEqual(len(a.data),4) self.assertEqual(a.data['mean'],mean) self.assertEqual(a.data['started'],started) self.assertAlmostEqual(date2timestamp(a.data['timestamp']), date2timestamp(timestamp), 5)
def serialize(self, value): if value not in NONE_EMPTY: if isinstance(value, date): value = date2timestamp(value) else: raise FieldValueError('Field %s is not a valid date' % self) return value
def serialise(self, value, lookup=None): if value not in NONE_EMPTY: if isinstance(value, date): value = date2timestamp(value) else: raise FieldValueError('Field %s is not a valid date' % self) return value
def serialize(self, value): if value is not None: if isinstance(value,date): value = date2timestamp(value) else: raise FieldValueError('Field %s is not a valid date' % self) return value
def scorefun(self, value): if value is not None: if isinstance(value,date): value = date2timestamp(value) else: raise FieldValueError('Field %s is not a valid date' % self) return value
def testCreate(self): models = self.mapper mean = Decimal('56.4') started = date(2010,1,1) timestamp = datetime.now() a = yield models.statistics.new(dt=date.today(), data={'mean': mean, 'std': 5.78, 'started': started, 'timestamp':timestamp}) self.assertEqual(a.data['mean'], mean) a = yield models.statistics.get(id=a.id) self.assertEqual(len(a.data), 4) self.assertEqual(a.data['mean'], mean) self.assertEqual(a.data['started'], started) self.assertAlmostEqual(date2timestamp(a.data['timestamp']), date2timestamp(timestamp), 5)
def testCreate(self): models = self.mapper mean = Decimal('56.4') started = date(2010, 1, 1) timestamp = datetime.now() a = yield models.statistics.new(dt=date.today(), data={ 'mean': mean, 'std': 5.78, 'started': started, 'timestamp': timestamp }) self.assertEqual(a.data['mean'], mean) a = yield models.statistics.get(id=a.id) self.assertEqual(len(a.data), 4) self.assertEqual(a.data['mean'], mean) self.assertEqual(a.data['started'], started) self.assertAlmostEqual(date2timestamp(a.data['timestamp']), date2timestamp(timestamp), 5)
def dumps(self, value, logger = None): return date2timestamp(value)
def tokey(cls, value): return date2timestamp(value)
def dumps(self, value): return date2timestamp(value)