Пример #1
0
 def when_offset_popped_from_string(self):
     self.datetime_string, timezone_offset = pop_tz_offset_from_string(
         self.initial_string)
     if timezone_offset:
         self.timezone_offset = timezone_offset.utcoffset('')
     else:
         self.timezone_offset = timezone_offset
Пример #2
0
    def is_applicable(self, date_string, strip_timezone=False, settings=None):
        """
        Check if the locale is applicable to translate date string.

        :param date_string:
            A string representing date and/or time in a recognizably valid format.
        :type date_string: str

        :param strip_timezone:
            If True, timezone is stripped from date string.
        :type strip_timezone: bool

        :return: boolean value representing if the locale is applicable for the date string or not.
        """
        if strip_timezone:
            date_string, _ = pop_tz_offset_from_string(date_string,
                                                       as_offset=False)

        date_string = self._translate_numerals(date_string)
        if settings.NORMALIZE:
            date_string = normalize_unicode(date_string)
        date_string = self._simplify(date_string, settings=settings)
        dictionary = self._get_dictionary(settings)
        date_tokens = dictionary.split(date_string)
        return dictionary.are_tokens_valid(date_tokens)
Пример #3
0
    def is_applicable(self, date_string, strip_timezone=False):
        if strip_timezone:
            date_string, timezone = pop_tz_offset_from_string(date_string, as_offset=False)

        date_string = self._simplify(date_string)
        tokens = self._split(date_string, keep_formatting=False)
        if self._is_date_consists_of_digits_only(tokens):
            return True
        else:
            return self._are_all_words_in_the_dictionary(tokens)
Пример #4
0
    def count_applicability(self, text, strip_timezone=False, settings=None):
        if strip_timezone:
            text, _ = pop_tz_offset_from_string(text, as_offset=False)

        text = self._simplify(text, settings=settings)
        sentences = self._sentence_split(text, settings=settings)
        tokens = []
        for sent in sentences:
            tokens.extend(self._split(sent, keep_formatting=False, settings=settings))
        return self._count_words_present_in_the_dictionary(tokens, settings)
Пример #5
0
    def is_applicable(self, date_string, strip_timezone=False):
        if strip_timezone:
            date_string, timezone = pop_tz_offset_from_string(date_string,
                                                              as_offset=False)

        date_string = self._simplify(date_string)
        tokens = self._split(date_string, keep_formatting=False)
        if self._is_date_consists_of_digits_only(tokens):
            return True
        else:
            return self._are_all_words_in_the_dictionary(tokens)
Пример #6
0
    def is_applicable(self, date_string, strip_timezone=False, settings=None):
        if settings.NORMALIZE:
            date_string = normalize_unicode(date_string)
        if strip_timezone:
            date_string, _ = pop_tz_offset_from_string(date_string, as_offset=False)

        date_string = self._simplify(date_string, settings=settings)
        tokens = self._split(date_string, keep_formatting=False, settings=settings)
        if self._is_date_consists_of_digits_only(tokens):
            return True
        else:
            return self._are_all_words_in_the_dictionary(tokens, settings)
Пример #7
0
    def parse(self, date_string):
        date_string = unicode(date_string)

        if not date_string.strip():
            raise ValueError("Empty string")

        date_string, tz_offset = pop_tz_offset_from_string(date_string)

        date_obj = dateutil_parse(date_string)
        if tz_offset is not None:
            date_obj = convert_to_local_tz(date_obj, tz_offset)

        return date_obj
Пример #8
0
    def parse(self, date_string):
        date_string = unicode(date_string)

        if not date_string.strip():
            raise ValueError("Empty string")

        date_string, tz_offset = pop_tz_offset_from_string(date_string)

        date_obj = dateutil_parse(date_string)
        if tz_offset is not None:
            date_obj = convert_to_local_tz(date_obj, tz_offset)

        return date_obj
Пример #9
0
 def date_strings():
     """ A generator instead of a static list to avoid calling
     pop_tz_offset_from_string if the first locale matches on unmodified
     date_string.
     """
     yield date_string
     if not pop_tz_cache:
         stripped_date_string, _ = pop_tz_offset_from_string(
             date_string, as_offset=False)
         if stripped_date_string == date_string:
             stripped_date_string = None
         pop_tz_cache[:] = [stripped_date_string]
     stripped_date_string, = pop_tz_cache
     if stripped_date_string is not None:
         yield stripped_date_string
Пример #10
0
 def date_strings():
     """ A generator instead of a static list to avoid calling
     pop_tz_offset_from_string if the first locale matches on unmodified
     date_string.
     """
     yield date_string
     if not pop_tz_cache:
         stripped_date_string, _ = pop_tz_offset_from_string(
             date_string, as_offset=False)
         if stripped_date_string == date_string:
             stripped_date_string = None
         pop_tz_cache[:] = [stripped_date_string]
     stripped_date_string, = pop_tz_cache
     if stripped_date_string is not None:
         yield stripped_date_string
Пример #11
0
    def is_applicable(self, date_string, strip_timezone=False, settings=None):
        if settings.NORMALIZE:
            date_string = normalize_unicode(date_string)
        if strip_timezone:
            date_string, _ = pop_tz_offset_from_string(date_string,
                                                       as_offset=False)

        date_string = self._simplify(date_string, settings=settings)
        tokens = self._split(date_string,
                             keep_formatting=False,
                             settings=settings)
        if self._is_date_consists_of_digits_only(tokens):
            return True
        else:
            return self._are_all_words_in_the_dictionary(tokens, settings)
Пример #12
0
 def when_offset_popped_from_string(self):
     self.datetime_string, self.timezone_offset = pop_tz_offset_from_string(
         self.initial_string)
Пример #13
0
 def when_offset_popped_from_string(self):
     self.datetime_string, self.timezone_offset = pop_tz_offset_from_string(self.initial_string)
Пример #14
0
 def when_offset_popped_from_string(self):
     self.datetime_string, timezone_offset = pop_tz_offset_from_string(self.initial_string)
     if timezone_offset:
         self.timezone_offset = timezone_offset.utcoffset('')
     else:
         self.timezone_offset = timezone_offset