Example #1
0
def adapt_datetime_with_timezone_support(value,  charset=None, field=None, use_unicode=None):
    # 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 escape_string(value.strftime("%Y-%m-%d %H:%M:%S"))
Example #2
0
def adapt_datetime_warn_on_aware_datetime(value,  charset=None, field=None, use_unicode=None):
    # Equivalent to DateTimeField.get_db_prep_value. Used only by raw SQL.
    if settings.USE_TZ and timezone.is_aware(value):
        warnings.warn(
            "The MySQL database adapter received an aware datetime (%s), "
            "probably from cursor.execute(). Update your code to pass a "
            "naive datetime in the database connection's time zone (UTC by "
            "default).", RuntimeWarning)
        # This doesn't account for the database connection's timezone,
        # which isn't known. (That's why this adapter is deprecated.)
        value = value.astimezone(timezone.utc).replace(tzinfo=None)
    return escape_string(value.strftime("%Y-%m-%d %H:%M:%S.%f"))
Example #3
0
def adapt_datetime_with_timezone_support(value,
                                         charset=None,
                                         field=None,
                                         use_unicode=None):
    # 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 escape_string(value.strftime("%Y-%m-%d %H:%M:%S"))