#3418: MSSQL and OverflowError for django/utils/tzinfo.py
------------------------------+---------------------------------------------
Reporter:  Jaroslaw Zabiello  |       Owner:  adrian                 
  Status:  new                |   Component:  Tools                  
 Version:  SVN                |    Keywords:  mssql datetime overflow
   Stage:  Unreviewed         |   Has_patch:  1                      
------------------------------+---------------------------------------------
 {{{
 Exception Type:         OverflowError
 Exception Value:        mktime argument out of range
 Exception Location:     C:\opt\Python25\lib\site-
 packages\django\utils\tzinfo.py in _isdst, line 50
 }}}
 
 This kind of errors appears when you work with SQL Server (or transfered
 data from MSSQL to MySQL). SQL Server converts NULLs in its datetime field
 into year 1900! And this raise exception OverflowError with message
 "mktime argument out of range" for pythonic function time.mktime() used in
 utils/tzinfo.py at line 50:
 
 {{{
 def _isdst(self, dt):
     tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
 dt.weekday(), 0, -1)
     stamp = time.mktime(tt)
     tt = time.localtime(stamp)
     return tt.tm_isdst > 0
 }}}
 
 This is monkey patched code which solves this problem:
 
 {{{
 def _isdst(self, dt):
     year = dt.year
     if year == 1900: # or < 1970
         year = 1970
     tt = (year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
 dt.weekday(), 0, -1)
     stamp = time.mktime(tt)
     tt = time.localtime(stamp)
     return tt.tm_isdst > 0
 }}}
 
 Used Django SVN rev.4455, WinXP Pro.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3418>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to