当前位置: 首页>>代码示例>>Python>>正文


Python dateparse.parse_time方法代码示例

本文整理汇总了Python中django.utils.dateparse.parse_time方法的典型用法代码示例。如果您正苦于以下问题:Python dateparse.parse_time方法的具体用法?Python dateparse.parse_time怎么用?Python dateparse.parse_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.dateparse的用法示例。


在下文中一共展示了dateparse.parse_time方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convert_values

# 需要导入模块: from django.utils import dateparse [as 别名]
# 或者: from django.utils.dateparse import parse_time [as 别名]
def convert_values(self, value, field):
        """SQLite returns floats when it should be returning decimals,
        and gets dates and datetimes wrong.
        For consistency with other backends, coerce when required.
        """
        internal_type = field.get_internal_type()
        if internal_type == 'DecimalField':
            return util.typecast_decimal(field.format_number(value))
        elif internal_type and internal_type.endswith('IntegerField') or internal_type == 'AutoField':
            return int(value)
        elif internal_type == 'DateField':
            return parse_date(value)
        elif internal_type == 'DateTimeField':
            return parse_datetime_with_timezone_support(value)
        elif internal_type == 'TimeField':
            return parse_time(value)

        # No field, or the field isn't known to be a decimal or integer
        return value 
开发者ID:blackye,项目名称:luscan-devel,代码行数:21,代码来源:base.py

示例2: to_python

# 需要导入模块: from django.utils import dateparse [as 别名]
# 或者: from django.utils.dateparse import parse_time [as 别名]
def to_python(self, value):
        if value is None:
            return None
        if isinstance(value, datetime.time):
            return value
        if isinstance(value, datetime.datetime):
            # Not usually a good idea to pass in a datetime here (it loses
            # information), but this can be a side-effect of interacting with a
            # database backend (e.g. Oracle), so we'll be accommodating.
            return value.time()

        try:
            parsed = parse_time(value)
            if parsed is not None:
                return parsed
        except ValueError:
            msg = self.error_messages['invalid_time'] % value
            raise exceptions.ValidationError(msg)

        msg = self.error_messages['invalid'] % value
        raise exceptions.ValidationError(msg) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:23,代码来源:__init__.py

示例3: convert_timefield_value

# 需要导入模块: from django.utils import dateparse [as 别名]
# 或者: from django.utils.dateparse import parse_time [as 别名]
def convert_timefield_value(self, value, expression, connection, context):
        if value is not None and not isinstance(value, datetime.time):
            value = parse_time(value)
        return value 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:operations.py

示例4: to_python

# 需要导入模块: from django.utils import dateparse [as 别名]
# 或者: from django.utils.dateparse import parse_time [as 别名]
def to_python(self, value):
        if value is None:
            return None
        if isinstance(value, datetime.time):
            return value
        if isinstance(value, datetime.datetime):
            # Not usually a good idea to pass in a datetime here (it loses
            # information), but this can be a side-effect of interacting with a
            # database backend (e.g. Oracle), so we'll be accommodating.
            return value.time()

        try:
            parsed = parse_time(value)
            if parsed is not None:
                return parsed
        except ValueError:
            raise exceptions.ValidationError(
                self.error_messages['invalid_time'],
                code='invalid_time',
                params={'value': value},
            )

        raise exceptions.ValidationError(
            self.error_messages['invalid'],
            code='invalid',
            params={'value': value},
        ) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:29,代码来源:__init__.py

示例5: build_sub_event_time_ranges

# 需要导入模块: from django.utils import dateparse [as 别名]
# 或者: from django.utils.dateparse import parse_time [as 别名]
def build_sub_event_time_ranges(self, start_date, end_date, time_tables):
        sub_event_time_ranges = []

        for time_table in time_tables:
            current_date = start_date
            weekday = int(time_table.get('weekday'))
            start_time = parse_time(time_table.get('starttime'))
            end_time = parse_time(time_table.get('endtime'))
            repetition = int(time_table.get('repetition'))
            if repetition == 0:
                repetition = 7  # assume repetition 0 and 7 mean the same thing

            if not (weekday and repetition) or start_time >= end_time:
                continue

            while current_date.isoweekday() != weekday:
                current_date += timedelta(days=1)

            while current_date <= end_date:
                sub_event_time_ranges.append(SubEventTimeRange(
                    datetime.combine(current_date, start_time).astimezone(TIMEZONE),
                    datetime.combine(current_date, end_time).astimezone(TIMEZONE),
                ))
                current_date += timedelta(days=repetition)

        return sub_event_time_ranges 
开发者ID:City-of-Helsinki,项目名称:linkedevents,代码行数:28,代码来源:harrastushaku.py

示例6: convert_timefield_value

# 需要导入模块: from django.utils import dateparse [as 别名]
# 或者: from django.utils.dateparse import parse_time [as 别名]
def convert_timefield_value(self, value, expression, connection):
        if value is not None:
            if not isinstance(value, datetime.time):
                value = parse_time(value)
        return value 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:7,代码来源:operations.py

示例7: to_python

# 需要导入模块: from django.utils import dateparse [as 别名]
# 或者: from django.utils.dateparse import parse_time [as 别名]
def to_python(self, value):
        if value is None or isinstance(value, datetime.time):
            return value
        else:
            return parse_time(value) 
开发者ID:wagtail,项目名称:wagtail,代码行数:7,代码来源:field_block.py

示例8: convert_timefield_value

# 需要导入模块: from django.utils import dateparse [as 别名]
# 或者: from django.utils.dateparse import parse_time [as 别名]
def convert_timefield_value(self, value, expression, connection, context):
        if value is not None:
            if not isinstance(value, datetime.time):
                value = parse_time(value)
        return value 
开发者ID:Yeah-Kun,项目名称:python,代码行数:7,代码来源:operations.py

示例9: from_native

# 需要导入模块: from django.utils import dateparse [as 别名]
# 或者: from django.utils.dateparse import parse_time [as 别名]
def from_native(self, value):
        if value in validators.EMPTY_VALUES:
            return None

        if isinstance(value, datetime.time):
            return value

        for fmt in self.input_formats:
            if fmt.lower() == ISO_8601:
                try:
                    parsed = parse_time(value)
                except (ValueError, TypeError):
                    pass
                else:
                    if parsed is not None:
                        return parsed
            else:
                try:
                    parsed = datetime.datetime.strptime(value, fmt)
                except (ValueError, TypeError):
                    pass
                else:
                    return parsed.time()

        msg = self.error_messages['invalid'] % readable_time_formats(self.input_formats)

        raise ValidationError(msg) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:29,代码来源:fields.py

示例10: parse_simple_token

# 需要导入模块: from django.utils import dateparse [as 别名]
# 或者: from django.utils.dateparse import parse_time [as 别名]
def parse_simple_token(token, manager, related_models, left=False, sibling_token=None):
    """
        Parse the simple token dict.
        :param token: a dict with 'tokenType'=='PROPERTY'|'NUMBER'|'STRING'
            and 'tokenValue'==a value of the corresponding type.
        :param manager: The django model manager
        :param related_models: Related models joined to the manager model
        :param left: Default False. If set then the token is an assignee and shouldn't be wrapped in
        an F() expression if it's a property
        :param sibling_token: the left side token if we are evaluating a right side token (left=False)
    """
    if token['tokenType'] == 'PROPERTY':
        # Resolve the field path in case it's relative to a joined related_model
        field_path = resolve_field_path_via_geographies('__'.join(token['tokenValue'].split('.')), manager, related_models)
        # Wrap in an F() expression if field is a right-side argument (the thing being assigned)
        return field_path if left else F(field_path)
    elif token['tokenType'] == 'NUMBER':
        return float(token['tokenValue'])
    elif token['tokenType'] in ['STRING', 'null', 'undefined']:
        if token['tokenType'] in ['null', 'undefined']:
            # Accept the 'null' or 'undefined' tokenType to mean None
            value = None
        else:
            value = token['tokenValue']

        if sibling_token and sibling_token.get('tokenType', None) == 'PROPERTY':
            # If we are evaluating a right-side token, inspect the sibling_token (the left-side token)
            # to find out what type the property is. This only matters for Dates and Times
            # where we need to modify the resolved right-side value to be have a time zone
            # if one isn't specified

            # Resolve the possibly chained property
            field_path = resolve_field_path_via_geographies('__'.join(sibling_token['tokenValue'].split('.')), manager, related_models)
            field = resolve_field_of_path(manager, field_path)
            if not field:
                return

            parser_lookup = {DateTimeField: parse_datetime, DateField: parse_date, TimeField: parse_time}
            if isinstance(field, (DateTimeField, DateField, TimeField)):
                date_time = parser_lookup[field.__class__](value)
                if not date_time and isinstance(field, DateTimeField):
                    # Accept dates without times for datetimes
                    date_time = timezone.utc.localize(datetime.combine(parser_lookup[DateField](value), datetime.min.time()))
                if isinstance(field, (DateTimeField, TimeField)) and not date_time.tzinfo:
                    # Default the timezone to UTC
                    return date_time.replace(tzinfo=timezone.utc)
                return date_time
        return value

    # TODO handle booleans and other types
    return token['tokenType'] 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:53,代码来源:query_parsing.py


注:本文中的django.utils.dateparse.parse_time方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。