Commit 6083a15b authored by Jérome Perrin's avatar Jérome Perrin

DateTimeKey: don't depend on DateTime internals

use calendar module and public DateTime API instead.
parent 01d10932
Pipeline #26211 failed with stage
in 0 seconds
...@@ -31,18 +31,22 @@ from __future__ import absolute_import ...@@ -31,18 +31,22 @@ from __future__ import absolute_import
import six import six
from six import string_types as basestring from six import string_types as basestring
import calendar
from .SearchKey import SearchKey from .SearchKey import SearchKey
from Products.ZSQLCatalog.Query.SimpleQuery import SimpleQuery from Products.ZSQLCatalog.Query.SimpleQuery import SimpleQuery
from Products.ZSQLCatalog.Query.ComplexQuery import ComplexQuery from Products.ZSQLCatalog.Query.ComplexQuery import ComplexQuery
from zLOG import LOG from zLOG import LOG
from DateTime.DateTime import DateTime, DateTimeError, _cache from DateTime.DateTime import DateTime, DateTimeError
from DateTime import Timezones
from Products.ZSQLCatalog.interfaces.search_key import ISearchKey from Products.ZSQLCatalog.interfaces.search_key import ISearchKey
from zope.interface.verify import verifyClass from zope.interface.verify import verifyClass
from Products.ZSQLCatalog.SearchText import parse from Products.ZSQLCatalog.SearchText import parse
MARKER = [] MARKER = []
timezone_dict = _cache._zmap # We use standard DateTime timezone, with also some timezones that were
# included before and are used (at least) in the test suite.
timezone_set = set([tz.lower() for tz in Timezones()] + ['cet', 'cest'])
date_completion_format_dict = { date_completion_format_dict = {
None: ['01/01/%s', '01/%s'], None: ['01/01/%s', '01/%s'],
...@@ -84,7 +88,7 @@ def castDate(value, change_timezone=True): ...@@ -84,7 +88,7 @@ def castDate(value, change_timezone=True):
delimiter_count = countDelimiters(value) delimiter_count = countDelimiters(value)
if delimiter_count is not None and delimiter_count < 2: if delimiter_count is not None and delimiter_count < 2:
split_value = value.split() split_value = value.split()
if split_value[-1].lower() in timezone_dict: if split_value[-1].lower() in timezone_set:
value = '%s %s' % (date_completion_format_dict[date_kw.get('datefmt')][delimiter_count] % (' '.join(split_value[:-1]), ), split_value[-1]) value = '%s %s' % (date_completion_format_dict[date_kw.get('datefmt')][delimiter_count] % (' '.join(split_value[:-1]), ), split_value[-1])
else: else:
value = date_completion_format_dict[date_kw.get('datefmt')][delimiter_count] % (value, ) value = date_completion_format_dict[date_kw.get('datefmt')][delimiter_count] % (value, )
...@@ -106,7 +110,7 @@ def castDate(value, change_timezone=True): ...@@ -106,7 +110,7 @@ def castDate(value, change_timezone=True):
delimiter_list = ' -/.:,+' delimiter_list = ' -/.:,+'
def getMonthLen(datetime): def getMonthLen(datetime):
return datetime._month_len[datetime.isLeapYear()][datetime.month()] return calendar.monthrange(datetime.year(), datetime.month())[1]
def getYearLen(datetime): def getYearLen(datetime):
return 365 + datetime.isLeapYear() return 365 + datetime.isLeapYear()
...@@ -119,7 +123,7 @@ def countDelimiters(value): ...@@ -119,7 +123,7 @@ def countDelimiters(value):
split_value = value.split() split_value = value.split()
if not split_value: if not split_value:
return None return None
if split_value[-1].lower() in timezone_dict: if split_value[-1].lower() in timezone_set:
value = ' '.join(split_value[:-1]) value = ' '.join(split_value[:-1])
# Count delimiters # Count delimiters
delimiter_count = 0 delimiter_count = 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment