def _datetime_checker(self, from_date, to_date): # get portal language for datetime locale formating # used for quering portal = plone.api.portal.get() locale = portal.language if len(from_date) > 0: try: from_date = convert(from_date, locale=locale) except DateTimeConversionError: return None if len(to_date) > 0: try: to_date = convert(to_date, locale=locale) except DateTimeConversionError: return None if isinstance(to_date, datetime.datetime) \ and to_date.hour == 0 and to_date.minute == 0: to_date = to_date.replace(hour=23, minute=59, second=59) if isinstance(from_date, str) and isinstance(to_date, str): return None if isinstance(from_date, datetime.datetime) \ and isinstance(to_date, str): return Ge('created', from_date) if isinstance(from_date, str) \ and isinstance(to_date, datetime.datetime): return Le('created', to_date) if isinstance(from_date, datetime.datetime) \ and isinstance(to_date, datetime.datetime): return InRange('created', from_date, to_date)
def datetime_extractor(widget, data): time = None if attr_value('time', widget, data): time = data.request.get('{}.time'.format(widget.dottedpath)) required = attr_value('required', widget, data) if not required and not data.extracted and not time: return '' locale = attr_value('locale', widget, data) tzinfo = attr_value('tzinfo', widget, data) try: return convert(data.extracted, time=time, tzinfo=tzinfo, locale=locale) except DateTimeConversionError: message = _('input_not_valid_date', default=u'Not a valid date input.') raise ExtractionError(message)
def datetime_extractor(widget, data): time = None if attr_value('time', widget, data): time = data.request.get('%s.time' % widget.dottedpath) required = attr_value('required', widget, data) if not required and not data.extracted and not time: return '' locale = attr_value('locale', widget, data) tzinfo = attr_value('tzinfo', widget, data) try: return convert(data.extracted, time=time, tzinfo=tzinfo, locale=locale) except DateTimeConversionError: message = _('input_not_valid_date', default=u'Not a valid date input.') raise ExtractionError(message)
def test_convert(self): self.assertEqual( convert('1.1.08', locale='de'), datetime(2008, 1, 1, 0, 0) )