當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。