def truncate_date(engine, interval, field):
    FUNCTIONS_FOR_ENGINES = {
        "mysql": {
            "minute": "FROM_UNIXTIME(`{}`, '%%Y-%%m-%%d %%H:%%i')",
            "hour": "FROM_UNIXTIME(`{}`, '%%Y-%%m-%%d %%H:00')",
            "day": "FROM_UNIXTIME(`{}`, '%%Y-%%m-%%d')",
            "week": "DATE_FORMAT(DATE_SUB(FROM_UNIXTIME(`{}`), INTERVAL(WEEKDAY(FROM_UNIXTIME(`{}`))) DAY), '%%Y-%%m-%%d')",
            "month": "FROM_UNIXTIME(`{}`, '%%Y-%%m-01')",
            "year": "FROM_UNIXTIME(`{}`, '%%Y-01-01')",
        },
        "postgresql": {
            "minute": "DATE_TRUNC('minute', TO_TIMESTAMP({}))",
            "hour": "DATE_TRUNC('hour', TO_TIMESTAMP({}))",
            "day": "DATE_TRUNC('day', TO_TIMESTAMP({}))",
            "week": "DATE_TRUNC('week', TO_TIMESTAMP({}))",
            "month": "DATE_TRUNC('month', TO_TIMESTAMP({}))",
            "year": "DATE_TRUNC('year', TO_TIMESTAMP({}))",
        }
    }

    if engine not in FUNCTIONS_FOR_ENGINES:
        raise NotSupportedError('Database engine %s is not supported' % engine)

    if interval not in FUNCTIONS_FOR_ENGINES[engine]:
        raise NotSupportedError('Interval %s is not supported by database' % interval)

    template = FUNCTIONS_FOR_ENGINES[engine][interval]
    return template.replace('{}', field)
Return a version of this context with admin flag set.
dataset/ETHPy150Open opennode/nodeconductor/nodeconductor/monitoring/zabbix/sql_utils.py/truncate_date--crossover with--dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/nova/context.py/RequestContext.elevated