﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
18766	Models with datetime fields fail to save when date is below 1900 and USE_TZ is True	Alexey Boriskin	Aymeric Augustin	"I have model with datetime field in it. When I save this model in admin site and the filled date is below 1900, I am getting the following traceback:
{{{ 
  File ""/Users/voidus/Documents/workspace/django-trunk/django/contrib/admin/options.py"", line 709, in save_model
    obj.save()
  File ""/Users/voidus/Documents/workspace/django-trunk/django/db/models/base.py"", line 524, in save
    force_update=force_update, update_fields=update_fields)
  File ""/Users/voidus/Documents/workspace/django-trunk/django/db/models/base.py"", line 595, in save_base
    rows = manager.using(using).filter(pk=pk_val)._update(values)
  File ""/Users/voidus/Documents/workspace/django-trunk/django/db/models/query.py"", line 573, in _update
    return query.get_compiler(self.db).execute_sql(None)
  File ""/Users/voidus/Documents/workspace/django-trunk/django/db/models/sql/compiler.py"", line 991, in execute_sql
    cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
  File ""/Users/voidus/Documents/workspace/django-trunk/django/db/models/sql/compiler.py"", line 813, in execute_sql
    sql, params = self.as_sql()
  File ""/Users/voidus/Documents/workspace/django-trunk/django/db/models/sql/compiler.py"", line 956, in as_sql
    val = field.get_db_prep_save(val, connection=self.connection)
  File ""/Users/voidus/Documents/workspace/django-trunk/django/db/models/fields/__init__.py"", line 303, in get_db_prep_save
    prepared=False)
  File ""/Users/voidus/Documents/workspace/django-trunk/django/db/models/fields/__init__.py"", line 834, in get_db_prep_value
    value = self.get_prep_value(value)
  File ""/Users/voidus/Documents/workspace/django-trunk/django/db/models/fields/__init__.py"", line 820, in get_prep_value
    if value is not None and settings.USE_TZ and timezone.is_naive(value):
  File ""/Users/voidus/Documents/workspace/django-trunk/django/utils/timezone.py"", line 271, in is_naive
    return value.tzinfo is None or value.tzinfo.utcoffset(value) is None
  File ""/Users/voidus/Documents/workspace/django-trunk/django/utils/timezone.py"", line 71, in utcoffset
    if self._isdst(dt):
  File ""/Users/voidus/Documents/workspace/django-trunk/django/utils/timezone.py"", line 89, in _isdst
    stamp = _time.mktime(tt)
ValueError: year out of range
}}}

I think that is because `utcoffset` and some other functions use `_isdst` function, which calls `time.mktime` and it have some limitation on the date range it can handle.

`time` module can handle dates in the more narrow range (1969-2038) then `datetime` module (1-9999). "	Cleanup/optimization	closed	Documentation	dev	Normal	fixed	timezone, tz		Accepted	0	0	0	0	0	0
