Remove custom strftime for year before 1900
The bug has been fixed in Python 3.3 issue7814 review48671002
This commit is contained in:
+2
-3
@@ -12,7 +12,6 @@ from sql import Table
|
||||
|
||||
from ..model import ModelView, ModelSQL, DeactivableMixin, fields, Check
|
||||
from ..cache import Cache
|
||||
from ..tools import datetime_strftime
|
||||
from ..transaction import Transaction
|
||||
from ..pool import Pool
|
||||
from .time_locale import TIME_LOCALE
|
||||
@@ -212,7 +211,7 @@ class Lang(DeactivableMixin, ModelSQL, ModelView):
|
||||
for lang in langs:
|
||||
date = lang.date
|
||||
try:
|
||||
datetime_strftime(datetime.datetime.now(), date)
|
||||
datetime.datetime.now().strftime(date)
|
||||
except Exception:
|
||||
cls.raise_user_error('invalid_date', {
|
||||
'format': lang.date,
|
||||
@@ -478,7 +477,7 @@ class Lang(DeactivableMixin, ModelSQL, ModelView):
|
||||
format = format.replace('%p',
|
||||
TIME_LOCALE[code]['%p'][datetime.timetuple()[3] < 12 and 0
|
||||
or 1])
|
||||
return datetime_strftime(datetime, format)
|
||||
return datetime.strftime(format)
|
||||
|
||||
|
||||
def get_parent_language(code):
|
||||
|
||||
@@ -6,7 +6,6 @@ import time
|
||||
from sql import Literal, For
|
||||
|
||||
from ..model import ModelView, ModelSQL, DeactivableMixin, fields, Check
|
||||
from ..tools import datetime_strftime
|
||||
from ..pyson import Eval, And
|
||||
from ..transaction import Transaction
|
||||
from ..pool import Pool
|
||||
@@ -283,9 +282,9 @@ class Sequence(DeactivableMixin, ModelSQL, ModelView):
|
||||
if not date:
|
||||
date = Date.today()
|
||||
return {
|
||||
'year': datetime_strftime(date, '%Y'),
|
||||
'month': datetime_strftime(date, '%m'),
|
||||
'day': datetime_strftime(date, '%d'),
|
||||
'year': date.strftime('%Y'),
|
||||
'month': date.strftime('%m'),
|
||||
'day': date.strftime('%d'),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
|
||||
import unittest
|
||||
import doctest
|
||||
import datetime
|
||||
import sql
|
||||
import sql.operators
|
||||
|
||||
from trytond.tools import reduce_ids, datetime_strftime, \
|
||||
reduce_domain, decimal_, is_instance_method, file_open
|
||||
from trytond.tools import (
|
||||
reduce_ids, reduce_domain, decimal_, is_instance_method, file_open)
|
||||
|
||||
|
||||
class ToolsTestCase(unittest.TestCase):
|
||||
@@ -59,19 +58,6 @@ class ToolsTestCase(unittest.TestCase):
|
||||
| (self.table.id.in_([15.0, 18.0, 19.0, 21.0]))))
|
||||
self.assertRaises(AssertionError, reduce_ids, self.table.id, [1.1])
|
||||
|
||||
def test_datetime_strftime(self):
|
||||
'Test datetime_strftime'
|
||||
self.assertTrue(datetime_strftime(datetime.date(2005, 3, 2),
|
||||
'%Y-%m-%d'), '2005-03-02')
|
||||
self.assertTrue(datetime_strftime(datetime.date(1805, 3, 2),
|
||||
'%Y-%m-%d'), '1805-03-02')
|
||||
self.assertTrue(datetime_strftime(datetime.datetime(2005, 3, 2, 0, 0, 0),
|
||||
'%Y-%m-%d'), '2005-03-02')
|
||||
with self.assertRaises(TypeError):
|
||||
datetime_strftime(None, '%Y-%m-%d')
|
||||
with self.assertRaises(TypeError):
|
||||
datetime_strftime(2, '%Y-%m-%d')
|
||||
|
||||
def test_reduce_domain(self):
|
||||
'Test reduce_domain'
|
||||
clause = ('x', '=', 'x')
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
|
||||
from .misc import *
|
||||
from .datetime_strftime import *
|
||||
from .decimal_ import *
|
||||
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
# Copyright (c) 2002-2007 John D. Hunter; All Rights Reserved
|
||||
import datetime
|
||||
import time
|
||||
|
||||
|
||||
def datetime_strftime(date, fmt):
|
||||
'''
|
||||
Allow datetime strftime formatting for years before 1900.
|
||||
See http://bugs.python.org/issue1777412
|
||||
'''
|
||||
if not isinstance(date, datetime.date):
|
||||
raise TypeError('datetime_strftime requires a ''datetime.date'' object'
|
||||
'but received a ''%s''' % type(date))
|
||||
if date.year > 1900:
|
||||
return date.strftime(fmt)
|
||||
|
||||
def _findall(text, substr):
|
||||
# Also finds overlaps
|
||||
sites = []
|
||||
i = 0
|
||||
while True:
|
||||
j = text.find(substr, i)
|
||||
if j == -1:
|
||||
break
|
||||
sites.append(j)
|
||||
i = j + 1
|
||||
return sites
|
||||
|
||||
year = date.year
|
||||
# For every non-leap year century, advance by
|
||||
# 6 years to get into the 28-year repeat cycle
|
||||
delta = 2000 - year
|
||||
off = 6 * (delta // 100 + delta // 400)
|
||||
year = year + off
|
||||
# Move to around the year 2000
|
||||
year = year + ((2000 - year) // 28) * 28
|
||||
timetuple = date.timetuple()
|
||||
string1 = time.strftime(fmt, (year,) + timetuple[1:])
|
||||
sites1 = _findall(string1, str(year))
|
||||
|
||||
string2 = time.strftime(fmt, (year + 28,) + timetuple[1:])
|
||||
sites2 = _findall(string2, str(year + 28))
|
||||
|
||||
sites = []
|
||||
for site in sites1:
|
||||
if site in sites2:
|
||||
sites.append(site)
|
||||
|
||||
syear = "%4d" % (date.year,)
|
||||
for site in sites:
|
||||
string1 = string1[:site] + syear + string1[site + 4:]
|
||||
return string1
|
||||
Reference in New Issue
Block a user