Browse Source

fix: import statement corrections

pull/7268/head
Pranav C 12 months ago
parent
commit
f7b53e0d45
  1. 40
      packages/nocodb-sdk/src/lib/formulaHelpers.ts

40
packages/nocodb-sdk/src/lib/formulaHelpers.ts

@ -2,7 +2,34 @@ import jsep from 'jsep';
import { ColumnType } from './Api'; import { ColumnType } from './Api';
import UITypes from './UITypes'; import UITypes from './UITypes';
import {validateDateWithUnknownFormat} from '../../../nc-gui/utils'; import dayjs from 'dayjs';
// todo: move to date utils and export, remove duplicate from gui
export const dateFormats = [
'YYYY-MM-DD',
'YYYY/MM/DD',
'DD-MM-YYYY',
'MM-DD-YYYY',
'DD/MM/YYYY',
'MM/DD/YYYY',
'DD MM YYYY',
'MM DD YYYY',
'YYYY MM DD',
];
function validateDateWithUnknownFormat(v: string) {
for (const format of dateFormats) {
if (dayjs(v, format, true).isValid() as any) {
return true;
}
for (const timeFormat of ['HH:mm', 'HH:mm:ss', 'HH:mm:ss.SSS']) {
if (dayjs(v, `${format} ${timeFormat}`, true).isValid() as any) {
return true;
}
}
}
return false;
}
export const jsepCurlyHook = { export const jsepCurlyHook = {
name: 'curly', name: 'curly',
@ -340,7 +367,6 @@ const formulas: Record<string, FormulaMeta> = {
max: 3, max: 3,
}, },
custom: (args: FormulaDataTypes[], parsedTree: any) => { custom: (args: FormulaDataTypes[], parsedTree: any) => {
if (parsedTree.arguments[0].type === JSEPNode.LITERAL) { if (parsedTree.arguments[0].type === JSEPNode.LITERAL) {
if (!validateDateWithUnknownFormat(parsedTree.arguments[0].value)) { if (!validateDateWithUnknownFormat(parsedTree.arguments[0].value)) {
throw new FormulaError( throw new FormulaError(
@ -361,7 +387,8 @@ const formulas: Record<string, FormulaMeta> = {
} }
} }
if (parsedTree.arguments[2].type === JSEPNode.LITERAL) { if (parsedTree.arguments[2].type === JSEPNode.LITERAL) {
if (![ if (
![
'milliseconds', 'milliseconds',
'ms', 'ms',
'seconds', 'seconds',
@ -380,15 +407,16 @@ const formulas: Record<string, FormulaMeta> = {
'Q', 'Q',
'years', 'years',
'y', 'y',
].includes(parsedTree.arguments[0].value)) { ].includes(parsedTree.arguments[0].value)
) {
throw new FormulaError( throw new FormulaError(
FormulaErrorType.TYPE_MISMATCH, FormulaErrorType.TYPE_MISMATCH,
{ key: 'msg.formula.thirdParamDateDiffHaveDate' }, { key: 'msg.formula.thirdParamDateDiffHaveDate' },
'Third parameter of DATETIME_DIFF should be one of \'milliseconds\', \'ms\', \'seconds\', \'s\', \'minutes\', \'m\', \'hours\', \'h\', \'days\', \'d\', \'weeks\', \'w\', \'months\', \'M\', \'quarters\', \'Q\', \'years\', \'y\'' "Third parameter of DATETIME_DIFF should be one of 'milliseconds', 'ms', 'seconds', 's', 'minutes', 'm', 'hours', 'h', 'days', 'd', 'weeks', 'w', 'months', 'M', 'quarters', 'Q', 'years', 'y'"
); );
} }
} }
} },
}, },
description: description:
'Calculate the difference of two given date / datetime in specified units.', 'Calculate the difference of two given date / datetime in specified units.',

Loading…
Cancel
Save