'Tests for regular datetime fields'

def test_datetime_usage(self):

    class LogEntry(Document, ):
        date = DateTimeField()
    LogEntry.drop_collection()
    d1 = datetime.datetime(1970, 1, 1, 0, 0, 1)
    log = LogEntry()
    log.date = d1
    log.validate()
    log.save()
    for query in (d1, d1.isoformat('    ')):
        log1 = LogEntry.objects.get(date=query)
        self.assertEqual(log, log1)
    if dateutil:
        log1 = LogEntry.objects.get(date=d1.isoformat('T'))
        self.assertEqual(log, log1)
    for i in range(1971, 1990):
        d = datetime.datetime(i, 1, 1, 0, 0, 1)
        LogEntry(date=d).save()
    self.assertEqual(LogEntry.objects.count(), 20)
    logs = LogEntry.objects.order_by('date')
    i = 0
    while (i < 19):
        self.assertTrue((logs[i].date <= logs[(i + 1)].date))
        i += 1
    logs = LogEntry.objects.order_by('-date')
    i = 0
    while (i < 19):
        self.assertTrue((logs[i].date >= logs[(i + 1)].date))
        i += 1
    logs = LogEntry.objects.filter(date__gte=datetime.datetime(1980, 1, 1))
    self.assertEqual(logs.count(), 10)
    logs = LogEntry.objects.filter(date__lte=datetime.datetime(1980, 1, 1))
    self.assertEqual(logs.count(), 10)
    logs = LogEntry.objects.filter(date__lte=datetime.datetime(1980, 1, 1), date__gte=datetime.datetime(1975, 1, 1))
    self.assertEqual(logs.count(), 5)
