mirror of
https://fast.feibisi.com/https://github.com/parcelvoy/platform.git
synced 2025-09-01 12:26:08 +08:00
chore: better processing of dates
This commit is contained in:
parent
188edf4f81
commit
76f717bf66
3 changed files with 10 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
import { isAfter, isBefore, isEqual } from 'date-fns'
|
||||
import { format, isAfter, isBefore, isEqual } from 'date-fns'
|
||||
import { RuleCheck, RuleEvalException } from './RuleEngine'
|
||||
import { compile, queryPath, queryValue, whereQuery, whereQueryNullable } from './RuleHelpers'
|
||||
import { Rule, RuleTree } from './Rule'
|
||||
|
@ -44,7 +44,9 @@ export default {
|
|||
})
|
||||
},
|
||||
query({ rule }) {
|
||||
const path = queryPath(rule)
|
||||
|
||||
// Make sure we can handle numbers, strings and dates
|
||||
const path = `parseDateTimeBestEffortOrNull(NULLIF(toString(${queryPath(rule)}), ''))`
|
||||
|
||||
if (rule.operator === 'is set') {
|
||||
return whereQueryNullable(path, false)
|
||||
|
@ -60,6 +62,10 @@ export default {
|
|||
return whereQuery(path, rule.operator, ruleValue.getTime())
|
||||
}
|
||||
|
||||
if (rule.operator === 'is same day') {
|
||||
return `toDate(${path}) = toDate('${format(ruleValue, 'yyyy-MM-dd')}')`
|
||||
}
|
||||
|
||||
throw new RuleEvalException(rule, 'unknown operator: ' + rule.operator)
|
||||
},
|
||||
} satisfies RuleCheck
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export type Operator = '=' | '!=' | '<' |'<=' | '>' | '>=' | '=' | 'is set' | 'is not set' | 'or' | 'and' | 'empty' | 'contains' | 'not contain' | 'starts with' | 'not start with' | 'ends with' | 'any' | 'none'
|
||||
export type Operator = '=' | '!=' | '<' |'<=' | '>' | '>=' | '=' | 'is set' | 'is not set' | 'or' | 'and' | 'empty' | 'contains' | 'not contain' | 'starts with' | 'not start with' | 'ends with' | 'any' | 'none' | 'is same day'
|
||||
export type RuleType = 'wrapper' | 'string' | 'number' | 'boolean' | 'date' | 'array'
|
||||
export type RuleGroup = 'user' | 'event' | 'parent'
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ export interface OAuthResponse {
|
|||
refresh_expires_at: Date
|
||||
}
|
||||
|
||||
export type Operator = '=' | '!=' | '<' | '<=' | '>' | '>=' | '=' | 'is set' | 'is not set' | 'or' | 'and' | 'xor' | 'empty' | 'contains' | 'not contain' | 'starts with' | 'not start with' | 'any' | 'none'
|
||||
export type Operator = '=' | '!=' | '<' | '<=' | '>' | '>=' | '=' | 'is set' | 'is not set' | 'or' | 'and' | 'xor' | 'empty' | 'contains' | 'not contain' | 'starts with' | 'not start with' | 'any' | 'none' | 'is same day'
|
||||
export type RuleType = 'wrapper' | 'string' | 'number' | 'boolean' | 'date' | 'array'
|
||||
export type RuleGroup = 'user' | 'event' | 'parent'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue