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


Python FIELD_TYPE.TIME属性代码示例

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


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

示例1: adapt_datetime_with_timezone_support

# 需要导入模块: from MySQLdb.constants import FIELD_TYPE [as 别名]
# 或者: from MySQLdb.constants.FIELD_TYPE import TIME [as 别名]
def adapt_datetime_with_timezone_support(value, conv):
    # Equivalent to DateTimeField.get_db_prep_value. Used only by raw SQL.
    if settings.USE_TZ:
        if timezone.is_naive(value):
            warnings.warn("MySQL received a naive datetime (%s)"
                          " while time zone support is active." % value,
                          RuntimeWarning)
            default_timezone = timezone.get_default_timezone()
            value = timezone.make_aware(value, default_timezone)
        value = value.astimezone(timezone.utc).replace(tzinfo=None)
    return Thing2Literal(value.strftime("%Y-%m-%d %H:%M:%S"), conv)

# MySQLdb-1.2.1 returns TIME columns as timedelta -- they are more like
# timedelta in terms of actual behavior as they are signed and include days --
# and Django expects time, so we still need to override that. We also need to
# add special handling for SafeText and SafeBytes as MySQLdb's type
# checking is too tight to catch those (see Django ticket #6052).
# Finally, MySQLdb always returns naive datetime objects. However, when
# timezone support is active, Django expects timezone-aware datetime objects. 
开发者ID:blackye,项目名称:luscan-devel,代码行数:21,代码来源:base.py


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