UNPKG

@qrvey/formula-lang

Version:

QFormula support for qrvey projects

66 lines 2.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HOUR = void 0; const scripts_1 = require("../utils/elasticsearch/scripts"); const utils_1 = require("../utils"); const constants_1 = require("../constants"); const isAnAllowedValue_1 = require("../utils/isAnAllowedValue"); /** * Returns the number of the HOUR in a Date. */ exports.HOUR = { identifier: 'HOUR', operationScope: constants_1.OPERATION_SCOPE.RAW, functionScope: [constants_1.OPERATION_SCOPE.RAW], parameters: [ { identifier: 'DATE', optional: false, expectedPrimitive: constants_1.AST_PRIMITIVES.DATE, validator: [utils_1.isDateParam], }, { identifier: 'TIME_FORMAT', optional: true, expectedPrimitive: constants_1.AST_PRIMITIVES.STRING, validator: [utils_1.isStringParam, (0, isAnAllowedValue_1.isAnAllowedValue)(['24h', '12h'])], }, ], transpiler: { elasticsearch, snowflake, redshift, postgresql, databricks, }, primitiveResult: constants_1.AST_PRIMITIVES.NUMBER, }; function elasticsearch(value, timeFormat) { return (0, scripts_1.hourScript)(value, (0, utils_1.removeQuotes)(timeFormat !== null && timeFormat !== void 0 ? timeFormat : '')); } function SQL(value, timeFormat) { if ((0, utils_1.removeQuotes)(timeFormat !== null && timeFormat !== void 0 ? timeFormat : '') === '12h') { return `(CASE WHEN DATE_PART('HOUR', ${value})::INTEGER % 12 = 0 THEN 12 ELSE DATE_PART('HOUR', ${value})::INTEGER % 12 END)`; } else { return `DATE_PART('HOUR', ${value})`; } } function snowflake(value, timeFormat) { return SQL(value, timeFormat); } function redshift(value, timeFormat) { return SQL(value, timeFormat); } function postgresql(value, timeFormat) { return SQL(value, timeFormat); } function databricks(value, timeFormat) { return SQL(value, timeFormat); } //# sourceMappingURL=hour.js.map