summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2008-07-18 03:47:27 +0000
committerAdrian Holovaty <adrian@holovaty.com>2008-07-18 03:47:27 +0000
commitdf2b19cc17666fe36a8153c3de45b20ffe3334ab (patch)
treed491426d07dba69bfddbfb4aaa2f632331b30ef9 /django/core
parentf6fafc02c8ba60b950bbe6be3b3ba729038dbb0a (diff)
Fixed #1443 -- Django's various bits now support dates before 1900. Thanks to SmileyChris, Chris Green, Fredrik Lundh and others for patches and design help
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7946 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
-rw-r--r--django/core/serializers/base.py4
-rw-r--r--django/core/serializers/json.py9
-rw-r--r--django/core/validators.py10
3 files changed, 12 insertions, 11 deletions
diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py
index e22a35815b..f6943e543e 100644
--- a/django/core/serializers/base.py
+++ b/django/core/serializers/base.py
@@ -8,6 +8,7 @@ except ImportError:
from StringIO import StringIO
from django.db import models
from django.utils.encoding import smart_str, smart_unicode
+from django.utils import datetime_safe
class SerializationError(Exception):
"""Something bad happened during serialization."""
@@ -59,7 +60,8 @@ class Serializer(object):
Convert a field's value to a string.
"""
if isinstance(field, models.DateTimeField):
- value = getattr(obj, field.name).strftime("%Y-%m-%d %H:%M:%S")
+ d = datetime_safe.new_datetime(getattr(obj, field.name))
+ value = d.strftime("%Y-%m-%d %H:%M:%S")
else:
value = field.flatten_data(follow=None, obj=obj).get(field.name, "")
return smart_unicode(value)
diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
index 20797c02f6..a84206a0fe 100644
--- a/django/core/serializers/json.py
+++ b/django/core/serializers/json.py
@@ -6,6 +6,7 @@ import datetime
from django.utils import simplejson
from django.core.serializers.python import Serializer as PythonSerializer
from django.core.serializers.python import Deserializer as PythonDeserializer
+from django.utils import datetime_safe
try:
from cStringIO import StringIO
except ImportError:
@@ -20,7 +21,7 @@ class Serializer(PythonSerializer):
Convert a queryset to JSON.
"""
internal_use_only = False
-
+
def end_serialization(self):
self.options.pop('stream', None)
self.options.pop('fields', None)
@@ -51,9 +52,11 @@ class DjangoJSONEncoder(simplejson.JSONEncoder):
def default(self, o):
if isinstance(o, datetime.datetime):
- return o.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT))
+ d = datetime_safe.new_datetime(o)
+ return d.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT))
elif isinstance(o, datetime.date):
- return o.strftime(self.DATE_FORMAT)
+ d = datetime_safe.new_date(o)
+ return d.strftime(self.DATE_FORMAT)
elif isinstance(o, datetime.time):
return o.strftime(self.TIME_FORMAT)
elif isinstance(o, decimal.Decimal):
diff --git a/django/core/validators.py b/django/core/validators.py
index 3ef0adeda6..f94db40c1b 100644
--- a/django/core/validators.py
+++ b/django/core/validators.py
@@ -141,10 +141,6 @@ def _isValidDate(date_string):
# Could use time.strptime here and catch errors, but datetime.date below
# produces much friendlier error messages.
year, month, day = map(int, date_string.split('-'))
- # This check is needed because strftime is used when saving the date
- # value to the database, and strftime requires that the year be >=1900.
- if year < 1900:
- raise ValidationError, _('Year must be 1900 or later.')
try:
date(year, month, day)
except ValueError, e:
@@ -407,12 +403,12 @@ class IsAPowerOf(object):
"""
Usage: If you create an instance of the IsPowerOf validator:
v = IsAPowerOf(2)
-
+
The following calls will succeed:
- v(4, None)
+ v(4, None)
v(8, None)
v(16, None)
-
+
But this call:
v(17, None)
will raise "django.core.validators.ValidationError: ['This value must be a power of 2.']"